import csv from decimal import Decimal, ROUND_HALF_UP # Run from workspace root: python output/build.py specs = {r['sku']: r for r in csv.DictReader(open('inputs/S1-manufacturer-specs.csv'))} offers = list(csv.DictReader(open('inputs/S2-store-offers.csv'))) # S3-store-correction.md supersedes the O6 delivery field only (price/shipping unchanged) corr = {'O6': ('2026-10-27', 'guaranteed')} BUDGET = Decimal('2200'); DEADLINE = '2026-10-23' rows = [] for o in offers: s = specs[o['sku']] price = Decimal(o['price_cad']); ship = Decimal(o['shipping_cad']) sub = price + ship # assumption: listed shipping is mandatory tax = (sub * Decimal('0.12')).quantize(Decimal('0.01'), ROUND_HALF_UP) total = sub + tax dl, dt = corr.get(o['offer_id'], (o['delivery'], o['delivery_type'])) src_del = ('S3-store-correction.md (# S3 — Direct Aspen correction)' if o['offer_id'] in corr else 'S2-store-offers.csv row ' + o['offer_id']) fails, unknowns = [], [] if int(s['ram_gb']) < 32: fails.append('RAM %s GB < 32' % s['ram_gb']) if int(s['ssd_gb']) < 1000: fails.append('SSD %s GB < 1 TB' % s['ssd_gb']) if int(s['vram_gb']) < 8: fails.append('VRAM %s GB < 8' % s['vram_gb']) if s['os'] != 'Windows 11': fails.append('OS not Windows 11') if total > BUDGET: fails.append('landed total over CAD 2200 by %s' % (total - BUDGET)) if dt != 'guaranteed': fails.append('no confirmed delivery: %s is an estimate only' % dl) unknowns.append('whether store will guarantee arrival by 2026-10-23') elif dl > DEADLINE: fails.append('guaranteed delivery %s is after 2026-10-23' % dl) if o['listing_note'].startswith('Title says'): fails_note = 'listing title conflicts with S1; S1 used' unknowns.append(fails_note) if o['offer_id'] in corr: unknowns.append('S2 delivery %s superseded by S3 correction (S3 08:45 vs register capture 09:00; register names S3 the later authority)' % o['delivery']) if o['sku'] == 'F16-32': s4 = 'S4: one plugged-in 12-min UHD H.264 Premiere export, no errors, 8 min 40 s, noticeable fan noise; single run, not a ranking' else: s4 = 'not tested (S4 tested F16-32 only)' if not fails: status = 'QUALIFIES' elif dt != 'guaranteed' and len(fails) == 1: status = 'FAILS (delivery unconfirmed)' else: status = 'FAILS' rows.append({ 'offer_id': o['offer_id'], 'sku': o['sku'], 'model': s['model'], 'store': o['store'], 'price_cad': str(price), 'shipping_cad': str(ship), 'taxable_subtotal_cad': str(sub), 'tax_12pct_cad': str(tax), 'landed_total_cad': str(total), 'within_budget': 'yes' if total <= BUDGET else 'no', 'ram_gb_S1': s['ram_gb'], 'ssd_gb_S1': s['ssd_gb'], 'gpu_S1': s['gpu'], 'vram_gb_S1': s['vram_gb'], 'weight_kg_S1': s['weight_kg'], 'os_S1': s['os'], 'condition': 'new (00-source-register.md default)', 'delivery_date_used': dl, 'delivery_type_used': dt, 'delivery_source': src_del, 'spec_source': 'S1-manufacturer-specs.csv row ' + o['sku'], 'price_source': 'S2-store-offers.csv row ' + o['offer_id'], 'listing_note_S2': o['listing_note'], 'test_evidence_S4': s4, 'hard_failures': '; '.join(fails) if fails else 'none', 'unknowns_or_conflicts': '; '.join(unknowns) if unknowns else 'none', 'status': status, }) with open('output/comparison.csv', 'w', newline='', encoding='utf-8') as f: w = csv.DictWriter(f, fieldnames=list(rows[0])) w.writeheader(); w.writerows(rows) for r in rows: print(r['offer_id'], r['landed_total_cad'], r['status'], '|', r['hard_failures'], '|', r['unknowns_or_conflicts']) print('O1 max price (free shipping): 2200/1.12 =', (BUDGET / Decimal('1.12')).quantize(Decimal('0.0001')), '-> 1964.28')