Skip to content

Commit

Permalink
Enhanced github action to write to a wiki page
Browse files Browse the repository at this point in the history
  • Loading branch information
nomius10 committed Jan 10, 2022
1 parent f00fac3 commit f73d30e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
31 changes: 25 additions & 6 deletions .github/workflows/translation_stats.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
name: Translation Stats

on: push
on:
push:
branches: [ master ]

jobs:
comp-stats:
name: Compute translation stats
runs-on: ubuntu-latest
timeout-minutes: 1

steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Setup python env
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: run script (t_stats.py)
- name: Checkout repo
uses: actions/checkout@v2
- name: Checkout the wiki
uses: actions/checkout@v2
with:
repository: "${{ github.repository }}.wiki"
path: .wiki
- name: Run script (t_stats.py)
run: |
python scripts/t_stats.py . -s | tee .wiki/Translation-progress.md
- name: Commit to wiki
working-directory: .wiki
run: |
python scripts/t_stats.py .
git config user.name "[bot] ${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add .
if git commit -m "auto-update wiki report (${GITHUB_WORKFLOW})"; then
git push origin master
fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ http://ludeon.com/forums/index.php?topic=2933.0

Version being translated: `1.3.3200`

For translation progress [check this wiki page](https://github.com/Ludeon/RimWorld-Romanian/wiki/Translation-progress-status)
For an up-to-date translation progress report, [check this wiki page](https://github.com/Ludeon/RimWorld-Romanian/wiki/Translation-progress)

### Current translators:
- nomius10
Expand Down
49 changes: 46 additions & 3 deletions scripts/t_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
from typing import Union
from copy import deepcopy

SUMMARY_DIRS = list(map(Path, [
"Core/Backstories",
"Core/DefInjected",
"Core/Keyed",
"Core",
"Ideology/DefInjected",
"Ideology/Keyed",
"Ideology",
"Royalty/DefInjected",
"Royalty/Keyed",
"Royalty",
".",
]))

RecDict = lambda: defaultdict(RecDict)

class TranslationStat:
Expand Down Expand Up @@ -107,10 +121,10 @@ def save_xmls(xtree, crtPath=Path(".")):
for (k, v) in xtree.items():
save_xmls(v, crtPath=crtPath/k)

def print_xtree(xtree, minWordThresh=None):
def print_xtree(xtree, minWordThresh=None, whitelist=None):
def dfs(xtree, path=Path(".")):
total_stats = TranslationStat()
for (k, v) in xtree.items():
for (k, v) in sorted(xtree.items(), key=lambda x: x[0]):
if type(v) == ET.ElementTree:
stats = v.getroot().stats
total_stats += stats
Expand All @@ -128,6 +142,8 @@ def dfs(xtree, path=Path(".")):
v = list(dfs(xtree))
t = []
for (s, path) in v:
if whitelist and path not in whitelist:
continue
t.append([
f"{s.w_pct:.2f}",
s.w_total,
Expand All @@ -147,17 +163,44 @@ def dfs(xtree, path=Path(".")):
print(fmt.format(e), end="")
print(f"|{line[-1]}|")

def print_summary(xtree):
print('''
This is an auto-generated report from the latest commit
Legend:
- EN_words - count of english words
- w_density - words/tag ratio, on average
- w_script - count of english words within 'script' tags
- Path - path towards the respective file/folder
## Overall progress
Note: The overall progress across all expansions is the last line (Path ".")
''')
print_xtree(xtree, whitelist=SUMMARY_DIRS)
print('''
## File by file progress
Note: files under 100 words are hidden, however all folders are shown
''')
print_xtree(xtree, 100)

def parse_args():
parser = argparse.ArgumentParser(description="t_stats - obtain statistics regarding translation progress")
parser.add_argument("input", type=Path,
help="XML root to process (useful for specifying only indiviual folders)")
parser.add_argument("-t", "--thresh", type=int, required=False, default=100,
help="Number of tags threshold under which to hide entries from being printed in the final stats")
parser.add_argument("-s", "--summary", action="store_true", default=False,
help="Print a summary md file for the github wiki")

return parser.parse_args()

if __name__ == "__main__":
args = parse_args()
xtree = load_xmls(args.input)
print_xtree(xtree, args.thresh)

if not args.summary:
print_xtree(xtree, args.thresh)
else:
print_summary(xtree)

0 comments on commit f73d30e

Please sign in to comment.