main
John Lauer Adopt DRC-clean v85 and passing exact-board current screen; retain open cooling validation and reviewed build clips a897f04
import csv,json
from pathlib import Path
P=Path(__file__).resolve().parents[1];net=json.loads((P/'design/netlist.json').read_text());catalog=json.loads((P/'design/basic-mpn-map.json').read_text());basic=set(catalog['resistors'].values())|set(catalog['capacitors'].values());hits={}
for p in (P/'design').glob('ps_*.json'):
 try:d=json.loads(p.read_text())
 except:continue
 for h in d.get('mouser',{}).get('hits',[]):
  if h.get('stock',0)>0:hits[h['mpn']]=h
# Later exact-part snapshot overrides only its MPN; preserve older source dates.
for h in json.loads((P/'design/parts-search-sbr10u45sp5.json').read_text()).get('mouser',{}).get('hits',[]):
 if h.get('mpn')=='SBR10U45SP5-13' and h.get('stock',0)>0:hits[h['mpn']]={**h,'checkedOn':'2026-10-10'}
rows=[]
for c in net['components']:
 mpn=c['mpn'];h=hits.get(mpn);no=mpn=='no part';adom=mpn in basic or c['block']=='molecule'
 rows.append({'ref':c['ref'],'value':c['value'],'mpn':mpn,'manufacturer':h.get('manufacturer','') if h else '', 'source':'none' if no else 'Mouser' if h else 'Adom stock catalog' if adom else 'unresolved','vendor_pn':h.get('vendor_pn','') if h else '', 'stock_snapshot':h.get('stock','') if h else '', 'stock_checked_on':h.get('checkedOn','2026-10-07') if h else '', 'unit_price_usd':h.get('unit_price','').replace('$','').replace(',','') if h else '', 'product_url':h.get('product_url','') if h else '', 'note':'bare copper; no purchased part' if no else 'live inventory unavailable; catalog only, no quantity verified' if adom and not h else 'stock/price snapshot, excludes freight/tax' if h else 'exact sourcing unresolved'})
with (P/'design/bom.csv').open('w') as f:
 w=csv.DictWriter(f,fieldnames=list(rows[0]));w.writeheader();w.writerows(rows)
known=sum(float(r['unit_price_usd'])for r in rows if r['unit_price_usd']);unknown=[r['ref']for r in rows if not r['unit_price_usd'] and r['source']!='none']
(P/'design/cost-summary.json').write_text(json.dumps({'priced_electrical_subtotal_usd':round(known,2),'unpriced_refs':unknown,'not_total_build_cost':True,'exclusions':['fan','heatsink','sensor','thermal interface and clamp','machine pins/contacts where unpriced','passives where unpriced','PCB fabrication','assembly and test','shipping and tax'],'date':'2026-10-10','source_dates':'Mixed source snapshots; see each BOM row'},indent=2));print('Priced electrical subtotal',round(known,2),'unpriced refs',len(unknown))