from pathlib import Path import csv,json,datetime,sys ROOT=Path(__file__).resolve().parent def clean(value):return str(value or '').strip() def known(value):return clean(value).lower() not in {'','미확인','미상','unknown'} def j(row,key):return clean(row.get(key)) def read(root,name): with (root/name).open(encoding='utf-8-sig',newline='') as f:return list(csv.DictReader(f)) LIMITS='가상 관찰문에 맥락이 기록됐는지 확인합니다. 열림각도·닫힘시간을 측정한 것이 아니며 문 안전성·고장원인·닫힘 성능을 판정하지 않습니다.' REPORT_HEADERS=['관찰번호', '문번호', '맥락 대조'] def compute(root=ROOT): data=read(root,'example.csv');complete=[];missing=[];report=[] for r in data: gaps=[k for k in ['문번호','시각','열림범위표현','사용맥락'] if not known(j(r,k))] rid=j(r,'관찰번호');(missing if gaps else complete).append(rid);report.append([rid,j(r,'문번호'),' / '.join(gaps) if gaps else '맥락 항목 기록됨']) claims=read(root,'input_bad_report.csv');actual={'observations':len(data),'context_recorded':complete,'context_missing':missing,'same_door_contexts':len([r for r in data if j(r,'문번호')=='DR01']),'unsupported_cause_claims':[j(r,'문번호') for r in claims if j(r,'주장유형')=='원인확정']} return actual,report,{'policy':'Presence is checked after judgment-only trimming;observed phrases are not rewritten and no angle/safety diagnosis is made.'} def run(root=ROOT): actual,rows,details=compute(root);expected=json.loads((root/'expected.json').read_text(encoding='utf-8')) checks=[{'field':k,'expected':v,'actual':actual.get(k),'passed':actual.get(k)==v} for k,v in expected.items()] result={'synthetic_fixture':True,'executed_at_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'runtime':sys.version.split()[0],'status':'PASS' if all(c['passed'] for c in checks) else 'FAIL','assertion_count':len(checks),'actual':actual,'assertions':checks,'details':details,'limits':LIMITS} (root/'results.json').write_text(json.dumps(result,ensure_ascii=False,indent=2),encoding='utf-8') with (root/'results.csv').open('w',encoding='utf-8-sig',newline='') as f:w=csv.writer(f);w.writerow(REPORT_HEADERS);w.writerows(rows) print(json.dumps(result,ensure_ascii=False,indent=2));return result if __name__=='__main__': r=run() if r['status']!='PASS':raise SystemExit(1)