"""Okseong P1 column rebar reading (G2: P1~P5) -> 판독/g2_values.json. Sheet 구조도(1) front view: column CL x 573551.6, z = drawing y - 309179.8 (footing top EL 14.375 at y 323554.8). Sheet 구조도(2) sections: quarter arcs r 1,250 (column) / 1,148 (hoop), bar symbols on r 1,125 and 1,080. Chains (front, left): '띠철근외측' 150 | 1.450 | 2@300 | 16@150 | 8@300 | 2@600 | 680 | 120 (= 9.000), '크로스타이' 150 | 1.500 | 450 | 8@300 | 8@300 | 2@600 | 780 | 120 (= 9.000), from the footing bottom EL 12.175. """ import json import math from collections import Counter from pathlib import Path from dxftools import entities CX, ZO = 573551.6, -309179.8 out = {} hz = sorted({round(e.dxf.start.y + ZO, 1) for e in entities("D1", CX - 1300, 314000, CX + 1300, 334500, "CS-RBAR") if e.dxftype() == "LINE" and abs(e.dxf.start.y - e.dxf.end.y) < 0.5 and abs(abs(e.dxf.start.x - e.dxf.end.x) - 2250) < 1}) out["hoops_drawn"] = {"count": len(hz), "levels": hz} cx, cy = 624043.7, 335398.4 ins = [e for e in entities("D1", cx - 1300, cy - 1300, cx + 1300, cy + 1300, "CS-RBAR") if e.dxftype() == "INSERT"] rr = Counter(round(math.hypot(e.dxf.insert.x - cx, e.dxf.insert.y - cy), 1) for e in ins) out["section"] = {"rings": {str(r): n for r, n in rr.most_common(2)}, "first_deg": round(min(math.degrees(math.atan2(e.dxf.insert.y - cy, e.dxf.insert.x - cx)) % 360 for e in ins), 3), "pitch_deg": 6.0, "tie_lines": 2295.0} arcs = [(round(e.dxf.center.x - CX, 1), round(e.dxf.center.y + ZO, 1), e.dxf.radius) for e in entities("D1", CX - 2200, 12100 - ZO, CX + 2200, 12750 - ZO, "CS-RBAR") if e.dxftype() == "ARC"] out["main_hooks_drawn"] = {"arc_centres": sorted(set(arcs)), "leg_z": 12375.0, "outer": "outwards (centre r 1,395)", "inner": "inwards (centre r 810)", "top_z": 20907.8, "straight_from_drawn": 12645.0} B = 12175.0 hoops = [B + 150 + 1450 + 300 * k for k in range(3)] hoops += [hoops[-1] + 150 * k for k in range(1, 17)] hoops += [hoops[-1] + 300 * k for k in range(1, 9)] hoops += [hoops[-1] + 600 * k for k in range(1, 3)] ties = [B + 150 + 1500, B + 150 + 1500 + 450] ties += [ties[-1] + 300 * k for k in range(1, 17)] ties += [ties[-1] + 600 * k for k in range(1, 3)] out["hoops_chain"] = hoops out["ties_chain"] = ties out["check"] = {"hoops_chain_equals_drawn": hoops == hz, "n_hoops": len(hoops), "n_tie_levels": len(ties)} p = Path(__file__).resolve().parent / "판독" / "g2_values.json" p.write_text(json.dumps(out, ensure_ascii=False, indent=1), encoding="utf-8") print(json.dumps({k: out[k] for k in ("section", "check")}, ensure_ascii=False), out["ties_chain"][:3], out["ties_chain"][-2:])