"""Where the proposed rule still loses to Chandrupatla, per family, from results already on disk (no new run). Cells: the proposed rule, + sticky/exit, and the decision-place records, if the files hold them. python -u where_we_lose.py """ from __future__ import annotations import json import os from collections import defaultdict MAXFEV = 200 def load(p): with open(p, encoding="utf8") as fh: return {r["label"]: r for r in json.load(fh)} def fam(pid): return pid.split(".")[0] if not pid.startswith("aps") else "aps" def per_family(r, s): out = defaultdict(int) for pid, (n, ok) in r[s]["per"].items(): out[fam(pid)] += n if ok else MAXFEV return out def main(): full = load("sweep_full.json") cells = {"chandrupatla": full["chandrupatla"], "proposed": full["pure.ratio.derived3.project"]} if os.path.exists("sweep_flatexit.json"): cells["+exit"] = load("sweep_flatexit.json")["flatstickexit.ratio.derived3.project"] for path in ("sweep_decision.json", "sweep_order.json", "sweep_points.json", "sweep_combo.json", "sweep_slope.json"): if not os.path.exists(path): continue for lab, r in load(path).items(): if lab.endswith("ratio.derived3.project") and lab not in cells and ( "defect" in lab or "shape" in lab or "slope" in lab): cells[lab] = r print(f"{'cell':<45} {'APS':>6} {'CHA':>6} {'both':>6}") for k, r in cells.items(): print(f"{k:<45} {r['APS']['total']:6d} {r['CHA']['total']:6d} " f"{r['APS']['total'] + r['CHA']['total']:6d}") ch = per_family(cells["chandrupatla"], "CHA") print("\nCHA per family (Chandrupatla | proposed | +exit):") pr = per_family(cells["proposed"], "CHA") ex = per_family(cells["+exit"], "CHA") if "+exit" in cells else {} for f in sorted(ch): print(f" {f:<6} {ch[f]:5d} | {pr[f]:5d} | {ex.get(f, 0):5d} " f"(+exit - Chandrupatla {ex.get(f, 0) - ch[f]:+d})") if __name__ == "__main__": main()