"""Bearing seat check: EL.'X' - (h1 + h2) per bearing vs coping top step elevation. Inputs (read only): 판독/2_survey.json D2 '교량받침 ELEVATION TABLE' texts (rows NO.1..10) params.json coping top steps (from D1, independent of D2 table) Bearing NO.1..5 (3500 kN) and NO.6..10 (2800 kN) are mapped to girder lines 1..5 left->right (front view), i.e. coping top steps 1..5. Writes 검증/bearing_seat_check.json. """ import json from collections import defaultdict from pathlib import Path HERE = Path(__file__).resolve().parent COLS = {"NO": 21594, "type": 22729, "EL_X": 24938, "h1": 26142, "h2": 27093, "h3": 27942, "h4": 28893, "E": 36942} def table_rows(): texts = json.loads((HERE / "판독" / "2_survey.json").read_text(encoding="utf-8"))["texts"] rows = defaultdict(dict) for t in texts: if not (21000 < t["x"] < 37500 and 3500 < t["y"] < 8500): continue col = min(COLS, key=lambda c: abs(COLS[c] - t["x"])) if abs(COLS[col] - t["x"]) < 300: rows[round(t["y"])][col] = t["text"] out = [] for y in sorted(rows, reverse=True): r = rows[y] if r.get("NO", "").isdigit(): out.append(dict(no=int(r["NO"]), type=r["type"], el_x=float(r["EL_X"]), h1=int(r["h1"]), h2=int(r["h2"]), h3=int(r["h3"]), h4=int(r["h4"]), E=int(r["E"]), src_y=y)) return out def main(): steps = json.loads((HERE / "params.json").read_text(encoding="utf-8"))["coping"]["top_steps"] rows = table_rows() assert [r["no"] for r in rows] == list(range(1, 11)), "table rows incomplete" result = [] for r in rows: step = steps[(r["no"] - 1) % 5]["z"] seat_old = round(r["el_x"] * 1000 - r["E"]) # previous basis: E = h1+h2+h3+h4 seat_new = round(r["el_x"] * 1000 - (r["h1"] + r["h2"])) # user basis: h1+h2 result.append(dict(r, girder_line=(r["no"] - 1) % 5 + 1, coping_top=step, E_check=r["h1"] + r["h2"] + r["h3"] + r["h4"] == r["E"], seat_by_E=seat_old, diff_by_E=seat_old - step, seat_by_h1h2=seat_new, diff_by_h1h2=seat_new - step, pedestal_top=step + r["h1"])) out = HERE / "검증" / "bearing_seat_check.json" out.write_text(json.dumps(result, ensure_ascii=False, indent=1), encoding="utf-8") print("NO | type | EL.X | h1+h2 | EL.X-(h1+h2) | coping top | diff | (old EL.X-E diff)") for r in result: print(r["no"], r["type"], r["el_x"], r["h1"] + r["h2"], r["seat_by_h1h2"] / 1000, r["coping_top"] / 1000, r["diff_by_h1h2"], r["diff_by_E"], "E=h1..h4" if r["E_check"] else "E!=sum") if __name__ == "__main__": main()