import json import sys from pathlib import Path sys.stdout.reconfigure(encoding='utf-8') # Load 1st audit results with open('resources/knowledge/technical_info/01_임도/05_원가정보/품셈_원문md_마스터데이터_대조_검증보고서.json', 'r', encoding='utf-8') as f: audit_v1 = json.load(f) # Load updated master with open('resources/data_work_item_master/work_item_master_2026-01-01.json', 'r', encoding='utf-8') as f: master_v3 = json.load(f) tables_v3 = {} for wi in master_v3['work_items']: for t in wi.get('tables', []): tid = t.get('pum_table_id') if tid: tables_v3[tid] = (wi, t) for t in master_v3.get('orphan_tables', []): tid = t.get('pum_table_id') if tid: tables_v3[tid] = (None, t) print("=== 1. 밑수 60건 추적 (3바퀴 최신) ===") basis_v1 = audit_v1['item3_basis'] resolved_basis = [] remaining_basis = [] changed_basis = [] for item in basis_v1: tid = item['table_id'] pair = tables_v3.get(tid) if not pair: continue wi, t_v3 = pair q3 = t_v3.get('basis_quantity') u3 = t_v3.get('basis_unit') old_q = item['master_qty'] old_u = item['master_unit'] md_q = item['md_qty'] md_u = item['md_unit'] u3_norm = str(u3).replace('㎡','m2').replace('㎥','m3').replace('인/','').replace('당','') md_u_norm = str(md_u).replace('㎡','m2').replace('㎥','m3').replace('인/','').replace('당','') is_resolved = False if q3 is not None and u3 is not None: if abs(float(q3) - float(md_q)) < 1e-4 and u3_norm == md_u_norm: is_resolved = True # also handle special known corrections: e.g. F0294 제근 if tid == 'F0294' and float(q3) == 100.0: is_resolved = True if is_resolved: resolved_basis.append({ 'table_id': tid, 'section': item['section'], 'v1': f"{old_q} {old_u}", 'v3': f"{q3} {u3}", 'md': f"{md_q} {md_u}" }) else: if q3 != old_q or u3 != old_u: changed_basis.append({ 'table_id': tid, 'section': item['section'], 'v1': f"{old_q} {old_u}", 'v3': f"{q3} {u3}", 'md': f"{md_q} {md_u}" }) else: remaining_basis.append({ 'table_id': tid, 'section': item['section'], 'v1': f"{old_q} {old_u}", 'v3': f"{q3} {u3}", 'md': f"{md_q} {md_u}" }) print(f"Total Basis v1 issues: {len(basis_v1)}") print(f" - Resolved: {len(resolved_basis)}") print(f" - Changed: {len(changed_basis)}") print(f" - Remaining unchanged: {len(remaining_basis)}") print("\n--- Resolved Sample ---") for r in resolved_basis[:10]: print(f" [{r['table_id']}] {r['section']}: {r['v1']} -> {r['v3']} (MD: {r['md']})") if changed_basis: print("\n--- Changed Sample ---") for c in changed_basis[:10]: print(f" [{c['table_id']}] {c['section']}: {c['v1']} -> {c['v3']} (MD: {c['md']})") print("\n=== 2. [주] 계수 누락 9건 추적 (3바퀴 최신) ===") notes_v1 = audit_v1['item4_notes'] resolved_notes = [] remaining_notes = [] for item in notes_v1: tid = item['table_id'] pair = tables_v3.get(tid) if not pair: continue wi, t_v3 = pair notes_v3 = t_v3.get('notes', []) if notes_v3: resolved_notes.append((tid, len(notes_v3), notes_v3[0])) else: remaining_notes.append(tid) print(f"Total [주] v1 missing: {len(notes_v1)}") print(f" - Resolved (notes 채워짐): {len(resolved_notes)}") for r in resolved_notes: print(f" [{r[0]}] {r[1]} notes: {r[2][:60]}") print(f" - Remaining empty: {len(remaining_notes)}") for rm in remaining_notes: print(f" [{rm}] STILL EMPTY") print("\n=== 3. reference 27건 추적 (3바퀴 최신) ===") refs_v1 = audit_v1['item5_references'] changed_refs = [] rem_refs = [] for item in refs_v1: tid = item['table_id'] pair = tables_v3.get(tid) if not pair: continue wi, t_v3 = pair pform_v3 = t_v3.get('pum_form') if pform_v3 != 'reference': changed_refs.append((tid, item['section'], pform_v3)) else: rem_refs.append((tid, item['section'], pform_v3)) print(f"Total reference v1 suspects: {len(refs_v1)}") print(f" - Changed form: {len(changed_refs)}") for cr in changed_refs: print(f" [{cr[0]}] {cr[1]} -> form: {cr[2]}") print(f" - Kept reference: {len(rem_refs)}") for rr in rem_refs: print(f" [{rr[0]}] {rr[1]} -> form: {rr[2]}")