from pathlib import Path import json, shutil, csv, hashlib, zipfile from decimal import Decimal B=Path(__file__).resolve().parents[1]; K=B/'kit'; C=K/'candidate'; O=K/'operator' def read(p):return list(csv.DictReader(p.open())) sales=read(C/'task-01/inputs/sales.csv') selected={} for r in sales: if r['order_id'] not in selected or r['updated_at']>selected[r['order_id']]['updated_at']:selected[r['order_id']]=r chosen=[r for r in selected.values() if r['status']=='paid' and r['row_id'] not in ['S11','S15']] totals={} for r in chosen: p=r['product'].strip().lower(); amount=Decimal(r['gross_cad'].replace('CAD','').replace('$','').strip()) totals[p]=totals.get(p,0)+amount assert totals=={'workshop':Decimal('1920'),'course':Decimal('900')} assert len(chosen)==9 offers=read(C/'task-02/inputs/S2-store-offers.csv') landed=[((Decimal(r['price_cad'])+Decimal(r['shipping_cad']))*Decimal('1.12')).quantize(Decimal('.01')) for r in offers] assert landed==list(map(Decimal,['2238.88','2098.88','1790.88','1902.88','2126.88','2037.28'])) raw=C/'task-03/site'; fixed=B/'build/reference-fixed-site';shutil.copytree(raw,fixed,dirs_exist_ok=True) p=fixed/'app.js';s=p.read_text().replace('subtotal * discount * 1.12','subtotal * (1-discount) * 1.12').replace("fetch('/api/lead'","fetch('/api/leads'") s=s.replace("function renderTotal(){document.querySelector('#total').textContent='CAD '+calculateTotal(Number(seatsInput.value)).toFixed(2)}", "function renderTotal(){const n=Number(seatsInput.value); document.querySelector('#total').textContent=seatsInput.value!==''&&Number.isInteger(n)&&n>=1&&n<=8?'CAD '+calculateTotal(n).toFixed(2):'Enter 1–8 whole seats';}") # No digits in invalid-total message, so the checker does not mistake a range for a price. s=s.replace('Enter 1–8 whole seats','Enter a valid whole seat count');p.write_text(s) with (fixed/'style.css').open('a') as f:f.write('\n.shell{width:min(1120px,calc(100% - 32px))}@media(max-width:700px){.shell{padding:20px;margin:16px auto}.layout{grid-template-columns:1fr;gap:24px}h1{font-size:32px}}\n') checker=O/'verify_site.mjs';shutil.copyfile(checker,B/'build/verify_site.mjs') print(json.dumps({'selected_order_count':len(chosen),'gross':{k:str(v) for k,v in totals.items()},'landed_costs':[str(x)for x in landed],'reference_fix':'private build only'},indent=2))