Skip to content

Commit 8f09b29

Browse files
committed
Add visitors ratio
1 parent f2cf055 commit 8f09b29

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

generate.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@
3333
for language, repo in repositories.get_languages_and_repos(devguide_dir):
3434
if repo:
3535
completion_number, translators_number = get_completion(clones_dir, repo)
36-
visitors_number = visitors.get_number_of_visitors(language)
36+
visitors_number, p = visitors.get_number_of_visitors(language)
3737
else:
3838
completion_number, visitors_number = 0.0, 0
39-
completion_progress.append((language, repo, completion_number, translators_number, visitors_number))
39+
completion_progress.append((language, repo, completion_number, translators_number, visitors_number, p))
4040
print(completion_progress[-1])
4141

4242
template = Template(
4343
"""
4444
<html lang="en">
4545
<head>
46+
<meta charset="utf-8">
4647
<title>Python Docs Translation Dashboard</title>
4748
<link rel="stylesheet" href="style.css">
4849
</head>
@@ -58,7 +59,7 @@
5859
</tr>
5960
</thead>
6061
<tbody>
61-
{% for language, repo, completion, translators, visitors in completion_progress | sort(attribute=2) | reverse %}
62+
{% for language, repo, completion, translators, visitors, p in completion_progress | sort(attribute=2) | reverse %}
6263
<tr>
6364
{% if repo %}
6465
<td data-label="language">
@@ -68,8 +69,8 @@
6869
</td>
6970
<td data-label="visitors">
7071
<a href="https://plausible.io/docs.python.org?filters=((contains,page,(/{{ language }}/)))" target="_blank">
71-
{{ '{:,}'.format(visitors) }}
72-
</a>
72+
{{ '{:,}'.format(visitors) }}</a>
73+
{% if p %}({{ p | round(2) }}‱){% endif %}
7374
</td>
7475
<td data-label="translators">{{ '{:,}'.format(translators) }}</td>
7576
{% else %}

visitors.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,37 @@
66
import requests
77

88

9-
def get_number_of_visitors(language: str) -> int:
9+
def get_number_of_visitors(language: str) -> tuple[int, float | None]:
1010
param = urllib.parse.urlencode({'filters': f'[["contains","event:page",["/{language}/"]]]'})
1111
r = requests.get(f'https://plausible.io/docs.python.org/export?{param}', timeout=10)
12+
d = languages_data.get(language)
13+
p = d and (d['native_speakers_millions'] * d['literacy_rate_percentage'] + d["second_language_learners_millions"] * 10e6)
1214
with zipfile.ZipFile(io.BytesIO(r.content), 'r') as z, z.open('visitors.csv') as csv_file:
1315
csv_reader = csv.DictReader(io.TextIOWrapper(csv_file))
14-
return sum(int(row["visitors"]) for row in csv_reader)
16+
sum_ = sum(int(row["visitors"]) for row in csv_reader)
17+
return sum_, p and (sum_ / p * 10000)
18+
19+
languages_data = {
20+
"ar": {"native_speakers_millions": 310, "literacy_rate_percentage": 76, "second_language_learners_millions": 24},
21+
"bn-in": {"native_speakers_millions": 230, "literacy_rate_percentage": 74, "second_language_learners_millions": 20},
22+
"es": {"native_speakers_millions": 495, "literacy_rate_percentage": 97, "second_language_learners_millions": 24},
23+
"fa": {"native_speakers_millions": 80, "literacy_rate_percentage": 85, "second_language_learners_millions": 50},
24+
"fr": {"native_speakers_millions": 80, "literacy_rate_percentage": 99, "second_language_learners_millions": 200},
25+
"gr": {"native_speakers_millions": 13, "literacy_rate_percentage": 97, "second_language_learners_millions": 0.4},
26+
"id": {"native_speakers_millions": 43, "literacy_rate_percentage": 96, "second_language_learners_millions": 12},
27+
"it": {"native_speakers_millions": 67, "literacy_rate_percentage": 99, "second_language_learners_millions": 2},
28+
"hi-in": {"native_speakers_millions": 341, "literacy_rate_percentage": 74, "second_language_learners_millions": 120},
29+
"hu": {"native_speakers_millions": 13, "literacy_rate_percentage": 99.1, "second_language_learners_millions": 2},
30+
"ja": {"native_speakers_millions": 125, "literacy_rate_percentage": 99, "second_language_learners_millions": 3},
31+
"ko": {"native_speakers_millions": 81, "literacy_rate_percentage": 98, "second_language_learners_millions": 13},
32+
"lt": {"native_speakers_millions": 3, "literacy_rate_percentage": 99.8, "second_language_learners_millions": 0.2},
33+
"mr": {"native_speakers_millions": 83, "literacy_rate_percentage": 82.9, "second_language_learners_millions": 3},
34+
"pl": {"native_speakers_millions": 38, "literacy_rate_percentage": 98, "second_language_learners_millions": 2},
35+
"pt": {"native_speakers_millions": 232, "literacy_rate_percentage": 93.5, "second_language_learners_millions": 25},
36+
"pt-br": {"native_speakers_millions": 260, "literacy_rate_percentage": 94, "second_language_learners_millions": 10},
37+
"ru": {"native_speakers_millions": 154, "literacy_rate_percentage": 99.7, "second_language_learners_millions": 61},
38+
"tr": {"native_speakers_millions": 88, "literacy_rate_percentage": 96, "second_language_learners_millions": 5},
39+
"uk": {"native_speakers_millions": 40, "literacy_rate_percentage": 99, "second_language_learners_millions": 2},
40+
"zh-cn": {"native_speakers_millions": 920, "literacy_rate_percentage": 96, "second_language_learners_millions": 300},
41+
"zh-tw": {"native_speakers_millions": 25, "literacy_rate_percentage": 98, "second_language_learners_millions": 20},
42+
}

0 commit comments

Comments
 (0)