Mercurial > hg > cc > cirrus_work
changeset 382:ec914a136771 plus
for 2026 MSc
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Thu, 11 Jun 2026 21:23:19 +0100 |
| parents | fb5e2d06a650 |
| children | def4c3375b02 |
| files | lib/python/cc/ex3.py lib/python/cc/ex4.py |
| diffstat | 2 files changed, 44 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/python/cc/ex3.py Thu Jun 11 21:23:19 2026 +0100 @@ -0,0 +1,19 @@ +'''Use this to get called by cdx2tsv.py''' + +from collections import defaultdict + +def init(): + global d + d=defaultdict(int) + +def cbf(lang): + global d + if lang=='NA' or ',' in lang: + return + d[lang] += 1 + +def finish(): + global d + for k,v in (sorted(d.items(), key = lambda i : i[1], reverse = True): + print(v, k) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/python/cc/ex4.py Thu Jun 11 21:23:19 2026 +0100 @@ -0,0 +1,25 @@ +'''Use this to get called by cdx2tsv.py''' + +from collections import defaultdict +from datetime import datetime + +def init(): + global d, N, M + d=defaultdict(lambda: defaultdict(int)) + N = M = 0 + +def cbf(lang,lastmod): + global d, N, M + N += 1 + if lastmod=='NA' or lang=='NA' or ',' in lang: + return + M += 1 + d[datetime.fromtimestamp(int(lastmod)).year][lang] += 1 + +def finish(): + global d, N, M + print("%s with lastmod out of %s in total"%(M, N)) + for k,lv in sorted(d.items(), key = lambda i : i[0]): + print(k, ["%s: %d"%(k,v) for k,v in (sorted(lv.items(), key = lambda i : i[1], + reverse = True))][:10]) +
