"""Learn anchors (engine/anchors.py) for the protected templates from their source pier's drawing and write data/_템플릿//anchors.json (2026-10-19). The template's own params / expected give the values, the source pier's drawing texts give the places. usage: python tools/make_anchors.py [--force]""" import json import sys from pathlib import Path APP = Path(__file__).resolve().parents[1] sys.path.insert(0, str(APP)) from engine import anchors # noqa: E402 SOURCE = {"운곡교P1형": "운곡교P1", "산외교울산P1형": "산외교울산P1", "산외교울산P2형": "산외교울산P2", "새재1교P1형": "새재1교P1", "옥성교P1형": "옥성교P1", "Ramp-A교P1형": "Ramp-A교P1"} force = "--force" in sys.argv for t, pier in SOURCE.items(): td = APP / "data" / "_템플릿" / t out = td / "anchors.json" if out.exists() and not force: print("keep", t) continue P = json.loads((td / "params.json").read_text(encoding="utf-8")) E = json.loads((td / "expected.json").read_text(encoding="utf-8")) d = APP / "data" / pier / "drawings" texts = json.loads((d / "texts.json").read_text(encoding="utf-8")) shas = [a["source_sha256"] for a in json.loads((d / "audit.json").read_text(encoding="utf-8")) if a.get("source_sha256")] a = anchors.learn(P, E, texts, shas) out.write_text(json.dumps(a, ensure_ascii=False), encoding="utf-8") print("wrote", t, "fields", len(a["fields"]), "landmarks", len(a["landmarks"]), f"{out.stat().st_size // 1024} KB")