Study files

study/finalize_grades.py

3.3 KB · View on GitHub →

"""Merge two graders' tables with adjudicated overrides into final grades.
Usage: python3 -I finalize_grades.py <grades_dir> <overrides.tsv> <out.md>
Agreed cells take grader A's row; overrides.tsv (runtime\tcolumn\tD\tB\tc\tBcfg\trefs\treason\tsource)
replaces any cell. Writes the matrix, the adjudication log and agreement stats."""
import sys, pathlib, csv, collections
sys.path.insert(0, str(pathlib.Path(__file__).parent))
g, ov_path, out = pathlib.Path(sys.argv[1]), sys.argv[2], pathlib.Path(sys.argv[3])
ORDER = ["codex","goose","hermes-agent","letta-code","nullclaw","openclaw","opencode","pi","software-agent-sdk","spore"]
COLS = [("Programmable capabilities",["Capability interface","Reusable computation","Capability transfer"]),
        ("Evidence and memory",["Durable evidence","Context recovery","Memory maintenance"]),
        ("Specialist collaboration",["Specialist definition","Continuation","Coordination"]),
        ("Execution controls",["Confinement","Credential handling","Budget enforcement"]),
        ("Product integration",["Embedding interfaces","Declarative configuration","Durable execution"]),
        ("Operations and verification",["Service dependencies","Execution records","Result checks"])]
def load(p):
    rows = {}
    for l in p.read_text().splitlines():
        c = [x.strip() for x in l.strip().strip('|').split('|')]
        if len(c) >= 8 and c[0] in ORDER: rows[(c[0], c[1])] = dict(D=c[2], B=c[3], c=c[4], cfg=c[5], refs=c[6], why=c[7])
    return rows
A, B = {}, {}
for f in g.glob('*-A.md'): A.update(load(f))
for f in g.glob('*-B.md'): B.update(load(f))
ov = {}
for r in csv.reader(open(ov_path), delimiter='\t'):
    if r and not r[0].startswith('#'): ov[(r[0], r[1])] = dict(D=r[2], B=r[3], c=r[4], cfg=r[5], refs=r[6], why=r[7], src=r[8])
final, log = {}, []
for k in A:
    a, b = A[k], B.get(k)
    if k in ov:
        o = ov[k]; final[k] = o
        log.append((k, f"{a['D']}/{a['B']}", f"{b['D']}/{b['B']}" if b else '—', f"{o['D']}/{o['B']}", o['src'], o['why']))
    else:
        final[k] = a
def mark(x, col):
    if col == "Service dependencies": return f"{x['D']}"
    s = x['D'] if x['D'] == x['B'] else f"{x['D']}→{x['B']}"
    return f"{s} {x['c']}"
o = []
for grp, cols in COLS:
    o.append(f"\n### {grp}\n\n| Runtime | " + " | ".join(cols) + " |\n|---|" + "---|"*len(cols) + "\n")
    for rt in ORDER:
        cells = []
        for col in cols:
            x = final[(rt, col)]
            cfg = f" [{x['cfg']}]" if x['cfg'] not in ('-', '') and col != "Service dependencies" else ""
            cells.append(f"{mark(x, col)}{cfg} {x['refs']}")
        o.append(f"| {rt} | " + " | ".join(cells) + " |\n")
o.append("\n### Rationale per cell\n\n| Runtime | Column | Final | Rationale |\n|---|---|---|---|\n")
for rt in ORDER:
    for _, cols in COLS:
        for col in cols:
            x = final[(rt, col)]; o.append(f"| {rt} | {col} | {mark(x, col)} | {x['why']} |\n")
o.append("\n### Adjudication log\n\nCells where the graders disagreed, or where an erratum changed an agreed cell. A and B are the two independent graders' Default/Best marks.\n\n| Runtime | Column | Grader A | Grader B | Final | Basis | Reason |\n|---|---|---|---|---|---|---|\n")
for k, a, b, f, src, why in log: o.append(f"| {k[0]} | {k[1]} | {a} | {b} | {f} | {src} | {why} |\n")
out.write_text("".join(o)); print("cells", len(final), "overrides", len(log))