File size: 1,781 Bytes
eafbe80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""Aggregate geometry diagnostics from geometry_diagnostics.json files."""
from __future__ import annotations

import argparse
import json
import os
from typing import Any, Dict, List, Optional


def _mean(xs: List[float]) -> Optional[float]:
    if not xs:
        return None
    return float(sum(xs) / len(xs))


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--root", required=True, help="root directory containing geometry_diagnostics.json")
    ap.add_argument("--output_json", required=True)
    args = ap.parse_args()

    root = os.path.abspath(args.root)
    rows: List[Dict[str, Any]] = []
    vals: List[float] = []
    for dirpath, _dirnames, filenames in os.walk(root):
        if "geometry_diagnostics.json" not in filenames:
            continue
        p = os.path.join(dirpath, "geometry_diagnostics.json")
        try:
            with open(p, "r", encoding="utf-8") as f:
                d = json.load(f)
            d["rel_dir"] = os.path.relpath(dirpath, root)
            rows.append(d)
            v = d.get("ghosting_proxy_color_var")
            if v is not None:
                vals.append(float(v))
        except Exception as e:
            rows.append({"rel_dir": os.path.relpath(dirpath, root), "error": str(e)})

    out = {"root": root, "num_runs": len(rows), "mean_ghosting_proxy_color_var": _mean(vals), "per_run": rows}
    outp = os.path.abspath(args.output_json)
    os.makedirs(os.path.dirname(outp), exist_ok=True)
    with open(outp, "w", encoding="utf-8") as f:
        json.dump(out, f, indent=2)
    print(f"[aggregate_geometry_consistency] runs={len(rows)} mean={out['mean_ghosting_proxy_color_var']} -> {outp}")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())