"""OPEN #19 regression snapshot: table records and expected-side proposals of the reference piers. usage: python tools/open19_snapshot.py -> 검증/open19_snapshot_.json Run before and after the OPEN #19 changes and compare (tools/test_open19.py reads both). Sources are read only: Ungok P1 / P2 data folders, Ulsan texts from the recycle-bin copy + protected template. """ import json import re import sys from pathlib import Path APP = Path(__file__).resolve().parents[1] sys.path.insert(0, str(APP)) sys.path.insert(0, str(APP / "tools")) from engine import reader # noqa: E402 from testlib import pier_dir # noqa: E402 PIERS = { "운곡교P1": (APP / "data/운곡교P1/drawings/texts.json", APP / "data/운곡교P1"), "운곡교p2": (pier_dir("운곡교p2") / "drawings/texts.json", pier_dir("운곡교p2")), "산외교울산P1": (APP / "data/_휴지통/산외교울산P1_20261013_131140/drawings/texts.json", APP / "data/_템플릿/산외교울산P1형"), } def snapshot(): out = {} for name, (tx, d) in PIERS.items(): texts = json.loads(tx.read_text(encoding="utf-8")) P = json.loads((d / "params.json").read_text(encoding="utf-8")) X = json.loads((d / "expected.json").read_text(encoding="utf-8")) tables = reader.table_candidates(texts) recs = {} for t in tables: if not t["rows"]: continue pred = (lambda s: s.isdigit()) if not t["key"].startswith("schedule") else (lambda s: bool(reader.MARK_RE.match(s))) recs[f"{t['anchor']['dwg']}|{t['key']}|{t['anchor']['y']}"] = [r for _, r in reader.table_records(t["rows"], pred)] rows = reader.proposals(reader.field_candidates(tables), P, X) out[name] = {"records": recs, "proposals": [{k: r[k] for k in ("file", "path", "current", "candidate", "same")} for r in rows]} return out if __name__ == "__main__": tag = sys.argv[1] p = APP / "검증" / f"open19_snapshot_{tag}.json" p.write_text(json.dumps(snapshot(), ensure_ascii=False, indent=1), encoding="utf-8") s = json.loads(p.read_text(encoding="utf-8")) for k, v in s.items(): props = v["proposals"] print(k, "tables", len(v["records"]), "records", sum(len(x) for x in v["records"].values()), "proposals", len(props), "differ", sum(not r["same"] for r in props), "params rows", sum(r["file"] == "params" for r in props))