File size: 1,712 Bytes
e00f999 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #!/usr/bin/env python3
"""Next-change visibility: of the classes each commit modifies, the share a context
generator showed *before* the commit. Reports the published baselines, or your own.
python3 scripts/evaluate_history.py # agentkit and alphabetical
python3 scripts/evaluate_history.py mine.jsonl # yours
mine.jsonl holds one {"project": ..., "commit": "<sha>", "shown": [<qualified names>]}
per commit of data/history/commits.jsonl, computed from the parent commit only.
"""
import sys
from collections import defaultdict
from common import data, read_jsonl
commits = read_jsonl(data("history", "commits.jsonl"))
systems = {k: {(c["project"], c["commit"]): set(v) for c in commits for k2, v in c["shown_before"].items() if k2 == k} for k in ("agentkit", "alphabetical")}
if len(sys.argv) > 1:
systems = {"yours": {(r["project"], r["commit"]): set(r["shown"]) for r in read_jsonl(sys.argv[1])}}
for name, shown in systems.items():
per = defaultdict(lambda: [0, 0])
for c in commits:
modified = {m["qualified_name"] for m in c["modified"]}
hit = len(modified & shown.get((c["project"], c["commit"]), set()))
per[c["project"]][0] += hit
per[c["project"]][1] += len(modified)
hits = sum(v[0] for v in per.values())
total = sum(v[1] for v in per.values())
macro = sum(v[0] / v[1] for v in per.values() if v[1]) / len([v for v in per.values() if v[1]])
print(f"{name}: micro {100 * hits / total:.1f} % ({hits}/{total}) · macro {100 * macro:.1f} % over {len(per)} projects")
for p in sorted(per):
h, t = per[p]
print(f" {p:<18} {100 * h / t:5.1f} % ({h}/{t})" if t else f" {p:<18} —")
|