"""Reproduce document-study counts and a decision matrix, without network access. This verifies the coding's internal consistency, not whether a vendor's product works. Run: python reproduce.py [directory containing observations.json] """ from pathlib import Path import csv, hashlib, json, sys root=Path(sys.argv[1]).resolve() if len(sys.argv)>1 else Path(__file__).resolve().parent facts=json.loads((root/'observations.json').read_text(encoding='utf-8')) sources={s['code']:s for s in json.loads((root/'sources.json').read_text(encoding='utf-8'))} matrix=json.loads((root/'decision-matrix.json').read_text(encoding='utf-8')) by_code={r['code']:r for r in facts} assert len(by_code)==len(facts), 'duplicate observation code' assert all(r['kind']=='documented-fact' and r['productExecutionObserved'] is False for r in facts) for r in facts: s=sources[r['sourceCode']] assert r['provider']==s['provider'] and r['sourceId']==s['id'] and r['sourceUrl']==s['url'] assert r['evidenceLocator'].strip() and r['conditions'].strip() assert r['sourceUrl'].startswith('https://') for cell in matrix: assert cell['status'] in ('documented','not-observed') assert bool(cell['factCodes'])==(cell['status']=='documented') for code in cell['factCodes']: assert code in by_code and by_code[code]['provider']==cell['provider'] if cell['status']=='not-observed': assert '불가를 뜻하지' in cell['meaning'] providers=sorted({r['provider'] for r in facts}) stats={ 'method':'coded primary-document observation; no product execution or AI experiment', 'observedAt':sorted({r['observedAt'] for r in facts}), 'sources':len(sources),'providers':len(providers),'observations':len(facts), 'providerObservationCounts':{p:sum(r['provider']==p for r in facts) for p in providers}, 'matrixCells':len(matrix), 'documentedCells':sum(c['status']=='documented' for c in matrix), 'notObservedCells':sum(c['status']=='not-observed' for c in matrix), 'providersWithDocumentedResponseTable':len({r['provider'] for r in facts if r['dimension']=='response-table'}), 'providersWithDocumentedOriginalFilePath':len({r['provider'] for r in facts if r['dimension']=='file-original'}), 'providersWithDocumentedPDFPath':len({r['provider'] for r in facts if r['dimension']=='pdf'}), 'productExecutionCount':0,'AIExperimentCount':0, 'inputSHA256':{name:hashlib.sha256((root/name).read_bytes()).hexdigest() for name in ('sources.json','observations.json','decision-matrix.json')}, } (root/'reproduced-summary.json').write_text(json.dumps(stats,ensure_ascii=False,indent=2)+'\n',encoding='utf-8') with (root/'decision-matrix.csv').open('w',encoding='utf-8-sig',newline='') as f: w=csv.DictWriter(f,fieldnames=['dimension','question','provider','value','status','factCodes','meaning']) w.writeheader();w.writerows({**c,'factCodes':','.join(c['factCodes'])} for c in matrix) print(json.dumps(stats,ensure_ascii=False,indent=2))