from pathlib import Path import json,openpyxl from collections import Counter P=Path(__file__).resolve().parent d=json.loads((P/'august_calculation.json').read_text());s=json.loads((P/'recalculation_summary.json').read_text()) comp=json.loads((P/'comparison.json').read_text());paid=json.loads((P/'historical_paid.json').read_text()) w=openpyxl.load_workbook(P/'里程任务考核_8月核算_纯氢修正版.xlsx',data_only=True) orig=openpyxl.load_workbook('/Users/shishengliang/Documents/羚牛/里程考核核算/8月/8月核算结果/里程任务考核_8月核算.xlsx',data_only=True) assert w.sheetnames[:len(orig.sheetnames)]==orig.sheetnames def same(a,b): if a in (None,'') and b in (None,''):return True if isinstance(a,(int,float)) and isinstance(b,(int,float)):return abs(a-b)<1e-8 return a==b for row in w['里程明细8月']: for c in row:assert same(c.value,orig['里程明细8月'][c.coordinate].value),('August assessment records changed',c.coordinate,c.value,orig['里程明细8月'][c.coordinate].value) assert abs(w['8月汇总(新版界面)']['M22'].value-s['new_amount'])<1e-7 rr=list(w['8月奖金发放记录'].values) for row,l in zip(rr[1:],d['ledger']): assert (row[0],row[1],row[4])==(l['plate'],l['sales'],l['category']) assert row[6]==l['gross_amount'] and row[8]==l['withheld'] and row[9]==l['amount'] assert abs(w['8月调整对照']['D14'].value-s['difference'])<1e-7 for row,x in zip(list(w['历史里程修正'].values)[1:],comp): assert row[5]==x['corrected'] assert x['corrected']<=x['original'] if x['hydrogen'] is None:assert row[4] is None and row[5]==x['original'] if x['hydrogen']==0:assert row[5]==min(0,x['original']) for l in d['ledger']: if l['assessment_month']<8: assert not any(r['plate']==l['plate'] and r['owner']==l['sales'] and r['assessment_month']==l['assessment_month'] for r in paid) errors=[] for sh in w: for row in sh: for c in row: if c.data_type=='e':errors.append((sh.title,c.coordinate,c.value)) assert not errors,errors[:10] # Independent cumulative check: same contiguous monthly chain as the established engine; # every historical correction reduces only the matching owner and interval. for g in d['groups']: target=actual=0 for t,a in g['history']: if t is None:target=actual=0 else:target+=t;actual+=a assert abs(g['cum_target']-target)<.03 and abs(g['cum_actual']-actual)<.03,(g['plate'],g['sales']) result=dict(total=s['new_amount'],difference=s['difference'],sheets=len(w.sheetnames),ledger_items=len(d['ledger']),missing_hydrogen_groups=s['missing_groups'],overlap_days_deduplicated=sum(x['overlap_days'] for x in comp),formula_errors=errors,august_detail_unchanged=True,historical_paid_no_duplicate=True,monthly_baseline_reproduced=True) (P/'verification.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)) print(json.dumps(result,ensure_ascii=False,indent=2))