| |
| """Resolve the locked CycleGate result table to Soft RadGraph pair inputs.""" |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import csv |
| import json |
| import re |
| from pathlib import Path |
|
|
|
|
| def existing_path(raw: str) -> Path: |
| path = Path(raw) |
| if path.exists(): |
| return path |
| alias = Path(str(path).replace("/opt/dlami/nvme/report", "/data1/report")) |
| if alias.exists(): |
| return alias |
| raise FileNotFoundError(path) |
|
|
|
|
| def slug(value: str) -> str: |
| return re.sub(r"[^a-z0-9]+", "_", value.lower()).strip("_") |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser() |
| parser.add_argument("--full-results", required=True, type=Path) |
| parser.add_argument("--output-csv", required=True, type=Path) |
| args = parser.parse_args() |
|
|
| payload = json.loads(args.full_results.read_text(encoding="utf-8")) |
| rows = [] |
| for result in payload["report_rows"]: |
| aggregate_path = existing_path(result["source"]) |
| aggregate = json.loads(aggregate_path.read_text(encoding="utf-8")) |
| pairs_path = existing_path(aggregate["pairs_csv"]) |
| if int(aggregate["rows"]) != 4394: |
| raise ValueError(f"unexpected CycleGate row count in {aggregate_path}") |
| aligned = aggregate["aligned_overall"] |
| rows.append({ |
| "model_id": slug(result["model"]), |
| "model": result["model"], |
| "pairs_csv": str(pairs_path.resolve()), |
| "radgraph_simple_f1": aligned["radgraph_simple_f1"], |
| "radgraph_partial_f1": aligned["radgraph_partial_f1"], |
| "radgraph_complete_f1": aligned["radgraph_complete_f1"], |
| "aggregate_json": str(aggregate_path.resolve()), |
| }) |
|
|
| if len(rows) != 12: |
| raise ValueError(f"expected 12 locked report rows, found {len(rows)}") |
| args.output_csv.parent.mkdir(parents=True, exist_ok=True) |
| with args.output_csv.open("w", newline="", encoding="utf-8") as handle: |
| writer = csv.DictWriter(handle, fieldnames=list(rows[0])) |
| writer.writeheader() |
| writer.writerows(rows) |
| print(json.dumps({"models": len(rows), "output_csv": str(args.output_csv)}, indent=2)) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|