Files
Aislo/resources/tester/scratch/audit_missing.py
T

70 lines
2.3 KiB
Python

import json
import sys
import re
from pathlib import Path
from collections import defaultdict
sys.stdout.reconfigure(encoding='utf-8')
# Load master
with open('resources/data_work_item_master/work_item_master_2026-01-01.json', 'r', encoding='utf-8') as f:
master = json.load(f)
# Load pum_forest
with open('resources/data_cost_input_value/pum_forest_2026.json', 'r', encoding='utf-8') as f:
pum_data = json.load(f)
pum_tables = pum_data.get('variables', {}).get('pum', {}).get('tables', [])
pum_map = {t['table_id']: t for t in pum_tables}
# Map master tables
master_wi_tables = {}
for wi in master['work_items']:
for t in wi.get('tables', []):
tid = t.get('pum_table_id')
if tid:
master_wi_tables[tid] = (wi, t)
orphan_map = {t.get('pum_table_id'): t for t in master.get('orphan_tables', []) if t.get('pum_table_id')}
print("=== 1. 표(Table) 누락 및 매핑 현황 ===")
all_f_ids = [f"F{i+1:04d}" for i in range(476)]
in_wi = []
in_orphan = []
missing = []
for tid in all_f_ids:
if tid in master_wi_tables:
in_wi.append(tid)
elif tid in orphan_map:
in_orphan.append(tid)
else:
missing.append(tid)
print(f"Total Tables in MD/pum_forest: {len(all_f_ids)}")
print(f"Tables mapped to Work Items: {len(in_wi)}")
print(f"Tables in orphan_tables: {len(in_orphan)}")
print(f"Tables missing from master completely: {len(missing)}")
for tid in missing:
pt = pum_map.get(tid, {})
print(f" Missing: {tid} | line {pt.get('line')} | section: {pt.get('section')}")
print("\n--- Orphan Tables Analysis (22 tables) ---")
orphan_by_section = defaultdict(list)
for tid in in_orphan:
ot = orphan_map[tid]
pt = pum_map.get(tid, {})
orphan_by_section[pt.get('section', ot.get('section'))].append((tid, pt.get('line'), ot.get('pum_form')))
for sec, tbls in orphan_by_section.items():
print(f"Section: {sec}")
for tid, line, pform in tbls:
print(f" - {tid} (line {line}): form={pform}")
print("\n--- Sections in MD vs Work Items ---")
# Check which chapters/sections exist in MD but have 0 work items or orphan only
wi_sections = {wi.get('toc_number'): wi for wi in master['work_items']}
wi_codes = {wi.get('work_item_code'): wi for wi in master['work_items']}
print(f"Work items count: {len(master['work_items'])}")