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_v2 = json.load(f) tables_v2 = {} for wi in master_v2['work_items']: for t in wi.get('tables', []): tid = t.get('pum_table_id') if tid: tables_v2[tid] = t for t in master_v2.get('orphan_tables', []): tid = t.get('pum_table_id') if tid: tables_v2[tid] = t print("=== 1. 밑수 60건 추적 ===") basis_v1 = audit_v1['item3_basis'] resolved_basis = [] remaining_basis = [] changed_basis = [] for item in basis_v1: tid = item['table_id'] t_v2 = tables_v2.get(tid) if not t_v2: continue q2 = t_v2.get('basis_quantity') u2 = t_v2.get('basis_unit') # compare with v1 master state old_q = item['master_qty'] old_u = item['master_unit'] md_q = item['md_qty'] md_u = item['md_unit'] # Check if resolved # resolved means q2 == md_q and u2 == md_u (or unit alias matched) u2_norm = str(u2).replace('㎡','m2').replace('㎥','m3').replace('인/','').replace('당','') md_u_norm = str(md_u).replace('㎡','m2').replace('㎥','m3').replace('인/','').replace('당','') is_resolved = False if q2 is not None and u2 is not None: if abs(float(q2) - float(md_q)) < 1e-4 and u2_norm == md_u_norm: is_resolved = True if is_resolved: resolved_basis.append({ 'table_id': tid, 'section': item['section'], 'v1_master': f"{old_q} {old_u}", 'v2_master': f"{q2} {u2}", 'md': f"{md_q} {md_u}" }) else: if q2 != old_q or u2 != old_u: changed_basis.append({ 'table_id': tid, 'section': item['section'], 'v1_master': f"{old_q} {old_u}", 'v2_master': f"{q2} {u2}", 'md': f"{md_q} {md_u}" }) else: remaining_basis.append({ 'table_id': tid, 'section': item['section'], 'v1_master': f"{old_q} {old_u}", 'v2_master': f"{q2} {u2}", 'md': f"{md_q} {md_u}" }) print(f"Total Basis v1 issues: {len(basis_v1)}") print(f" - Resolved (일치 해결됨): {len(resolved_basis)}") print(f" - Changed but still mismatch (변경되었으나 여전히 불일치): {len(changed_basis)}") print(f" - Unchanged (미해결/그대로): {len(remaining_basis)}") print("\n--- Resolved Basis Sample (해결된 16건) ---") for r in resolved_basis: print(f" [{r['table_id']}] {r['section']}: {r['v1_master']} -> {r['v2_master']} (MD: {r['md']})") if changed_basis: print("\n--- Changed Basis ---") for c in changed_basis: print(f" [{c['table_id']}] {c['section']}: {c['v1_master']} -> {c['v2_master']} (MD: {c['md']})") print("\n=== 2. [주] 계수 누락 9건 추적 ===") notes_v1 = audit_v1['item4_notes'] resolved_notes = [] remaining_notes = [] for item in notes_v1: tid = item['table_id'] t_v2 = tables_v2.get(tid) if not t_v2: continue notes_v2 = t_v2.get('notes', []) # Check if notes_v2 has content now if notes_v2: resolved_notes.append({ 'table_id': tid, 'section': item['section'], 'notes_count_v2': len(notes_v2), 'notes_preview': notes_v2[:2] }) else: remaining_notes.append({ 'table_id': tid, 'section': item['section'] }) print(f"Total [주] v1 missing: {len(notes_v1)}") print(f" - Resolved (notes 채워짐): {len(resolved_notes)}") print(f" - Remaining (여전히 notes 빈칸): {len(remaining_notes)}") for r in resolved_notes: print(f" [{r['table_id']}] {r['section']}: {r['notes_count_v2']} notes added -> sample: {r['notes_preview'][0][:60]}") for rm in remaining_notes: print(f" [{rm['table_id']}] {rm['section']}: STILL EMPTY") print("\n=== 3. reference 27건 추적 ===") refs_v1 = audit_v1['item5_references'] changed_refs = [] rem_refs = [] for item in refs_v1: tid = item['table_id'] t_v2 = tables_v2.get(tid) if not t_v2: continue pform_v2 = t_v2.get('pum_form') if pform_v2 != 'reference': changed_refs.append({'table_id': tid, 'section': item['section'], 'form_v2': pform_v2}) else: rem_refs.append({'table_id': tid, 'section': item['section']}) print(f"Total reference v1 suspects: {len(refs_v1)}") print(f" - Changed form: {len(changed_refs)}") print(f" - Kept reference: {len(rem_refs)}")