Skip to content

Commit d4303e9

Browse files
Track difference in translation progress (JSON) (#60)
Co-authored-by: Maciej Olko <[email protected]>
1 parent 5a0d06d commit d4303e9

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

completion.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]:
2020
]
2121

2222

23-
def get_completion(clones_dir: str, repo: str) -> tuple[float, 'TranslatorsData', str]:
23+
def get_completion(
24+
clones_dir: str, repo: str
25+
) -> tuple[float, 'TranslatorsData', str, float]:
2426
clone_path = Path(clones_dir, repo)
2527
for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + ['master']:
2628
try:
27-
git.Repo.clone_from(
29+
clone_repo = git.Repo.clone_from(
2830
f'https://github.com/{repo}.git', clone_path, branch=branch
2931
)
3032
except git.GitCommandError:
@@ -44,7 +46,27 @@ def get_completion(clones_dir: str, repo: str) -> tuple[float, 'TranslatorsData'
4446
hide_reserved=False,
4547
api_url='',
4648
).completion
47-
return completion, translators_data, branch
49+
50+
if completion:
51+
# Fetch commit from before 30 days ago and checkout
52+
commit = next(
53+
clone_repo.iter_commits('HEAD', max_count=1, before='30 days ago')
54+
)
55+
clone_repo.git.checkout(commit.hexsha)
56+
with TemporaryDirectory() as tmpdir:
57+
month_ago_completion = potodo.merge_and_scan_path(
58+
clone_path,
59+
pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'),
60+
merge_path=Path(tmpdir),
61+
hide_reserved=False,
62+
api_url='',
63+
).completion
64+
else:
65+
month_ago_completion = 0.0
66+
67+
change = completion - month_ago_completion
68+
69+
return completion, translators_data, branch, change
4870

4971

5072
@dataclass(frozen=True)

generate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,20 @@ def get_project_data(
6969
) -> 'LanguageProjectData':
7070
built = language.code in languages_built
7171
if repo:
72-
completion, translators_data, branch = get_completion(clones_dir, repo)
72+
completion, translators_data, branch, change = get_completion(clones_dir, repo)
7373
visitors_num = get_number_of_visitors(language.code, http) if built else 0
7474
else:
7575
completion = 0.0
7676
translators_data = TranslatorsData(0, False)
77+
change = 0.0
7778
visitors_num = 0
7879
branch = None
7980
return LanguageProjectData(
8081
language,
8182
repo,
8283
branch,
8384
completion,
85+
change,
8486
translators_data,
8587
visitors_num,
8688
built,
@@ -96,6 +98,7 @@ class LanguageProjectData:
9698
repository: str | None
9799
branch: str | None
98100
completion: float
101+
change: float
99102
translators: TranslatorsData
100103
visitors: int
101104
built: bool

0 commit comments

Comments
 (0)