"""Stage B fixes after the first run on the real piers (2026-10-16): C6 false positives on directional values (pitch < 0, translation checks), C7 for fixed bundles of piers without an origin record (compare with the protected templates), status summaries.""" from pathlib import Path APP = Path(__file__).resolve().parents[2] V, S = APP / "engine" / "verify.py", APP / "web" / "store.py" def patch(path, pairs): s = path.read_text(encoding="utf-8") for a, b in pairs: assert s.count(a) == 1, (path.name, a[:70]) s = s.replace(a, b) path.write_text(s, encoding="utf-8") patch(V, [ ('''SIZE_KEYS = re.compile(r"^(size_[xy]|thickness|diameter|d|height|length|width_y|plan_length|top_length|dx|dy|half|count_[xy]|nx|ny|pitch.*|dia|" r"half_.*|bottom_flat_half|tip_half|top_half|soffit_rise|margin)$")''', '''SIZE_KEYS = re.compile(r"^(size_[xy]|thickness|diameter|height|length|width_y|plan_length|top_length|half|count_[xy]|nx|ny|dia|" r"half_.*|bottom_flat_half|tip_half|top_half|soffit_rise)$") SIZE_IN = {"d": ("column", "piles"), "dx": ("footing", "lean"), "dy": ("footing", "lean")} # short names only where they are sizes NOT_SIZE = ("translation_checks", "pitch", "negative", "chain") # directional / check values may be negative or 0'''), (''' elif isinstance(v, (int, float)) and not isinstance(v, bool): if SIZE_KEYS.match(name) and v <= 0:''', ''' elif isinstance(v, (int, float)) and not isinstance(v, bool): is_size = (SIZE_KEYS.match(name) or (name in SIZE_IN and len(path) > 1 and path[-2] in SIZE_IN[name])) \ and not any(p.startswith(NOT_SIZE) for p in path) if is_size and v <= 0:'''), ('''def verify(params, expected, texts, meta, origin_fixed=None, edit_log=None, current_fixed=None):''', '''def verify(params, expected, texts, meta, origin_fixed=None, edit_log=None, current_fixed=None, template_values=None):'''), (''' origin_fixed = origin_fixed or {} edit_log = edit_log or []''', ''' origin_fixed = origin_fixed or {} edit_log = edit_log or [] template_values = template_values or {}'''), (''' if m["grade"] == "F": if m.get("origin") is None: checks.append(chk("C7", "변수 등급 위반", "n", "템플릿 원본 기록이 없어 고정 항목을 비교하지 못했다"))''', ''' if m["grade"] == "F": if m.get("origin") is None: tv = template_values.get(b) or {} now = json.dumps(value, sort_keys=True, ensure_ascii=False) same = sorted(t for t, v in tv.items() if v == now) if key == "pier_id": checks.append(chk("C7", "변수 등급 위반", "x", "교각 식별자라 비교하지 않는다")) elif same: checks.append(chk("C7", "변수 등급 위반", "g", f"템플릿 복사 기록은 없지만 보호 템플릿 {len(same)}종({', '.join(same[:3])})과 같은 값이다", strength="F")) elif tv: checks.append(chk("C7", "변수 등급 위반", "w", "템플릿 복사 기록이 없고 어느 보호 템플릿과도 같지 않다 — 새 형식인지 확인")) else: checks.append(chk("C7", "변수 등급 위반", "n", "템플릿 원본 기록이 없어 고정 항목을 비교하지 못했다"))'''), ('''def summarize(st, checks): if st == "x": return "사람 결정 기록 또는 참고 정보 — 앱이 도면과 대조하지 않는다" key = [c for c in checks if c["st"] in ("b", "w", "n") and c["id"] != "C1"] or [c for c in checks if c["st"] == "g"] return (key[0]["id"] + " " + key[0]["text"]) if key else ""''', '''def summarize(st, checks): """One sentence for the table: the check that decides the status.""" if st == "x": return "사람 결정 기록 또는 참고 정보 — 앱이 도면과 대조하지 않는다" pick = {"b": [c for c in checks if c["st"] == "b"], "w": [c for c in checks if c["st"] == "w"] or [c for c in checks if c["strength"] == "C" and c["st"] == "g"], "g": [c for c in checks if c["strength"] in ("S", "F") and c["st"] == "g"], "n": [c for c in checks if c["id"] in ("C3", "C7", "C2") and c["st"] == "n"]}[st] if pick: c = pick[0] return f"{c['id']} {c['text']}" + (" — 수량만 확인, 위치·좌표는 도면과 직접 대조" if st == "w" and c["strength"] == "C" and c["st"] == "g" else "") return "앱이 독립적으로 대조할 근거가 없다 — 도면과 직접 대조한 뒤 사유와 함께 확정"'''), ]) patch(S, [ (''' res = verify.verify(P0, E0, self.texts(), meta, (self.info.get("origin") or {}).get("fixed"), rjson(self.dir / "edit_log.json", []), cur_fixed)''', ''' tvals = {} # fixed bundles: value in every protected template (for piers without origin record) for t in templates(): td = template_dir(t["name"]) for w in ("params", "expected"): tdoc = rjson(td / f"{w}.json", {}) for k, v in tdoc.items(): if meta.get(f"{w}:{k}", {}).get("grade") == "F": tvals.setdefault(f"{w}:{k}", {})[t["name"]] = json.dumps(v, sort_keys=True, ensure_ascii=False) res = verify.verify(P0, E0, self.texts(), meta, (self.info.get("origin") or {}).get("fixed"), rjson(self.dir / "edit_log.json", []), cur_fixed, tvals)'''), ]) print("patched")