import csv from decimal import Decimal, ROUND_HALF_UP 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 correction supersedes O6 delivery 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 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' if o['offer_id'] in corr else 'S2-store-offers.csv' fails = [] 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') if total > BUDGET: fails.append('landed total over CAD 2200 by %s' % (total - BUDGET)) if dt != 'guaranteed': fails.append('delivery %s is estimate only (no commitment)' % dl) elif dl > DEADLINE: fails.append('guaranteed delivery %s after Oct 23' % dl) 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)', 'delivery_date_used': dl, 'delivery_type_used': dt, 'delivery_source': src_del, 'listing_note_S2': o['listing_note'], 'hard_failures': '; '.join(fails) if fails else 'none', 'status': 'QUALIFIES' if not fails else 'FAILS', }) w = csv.DictWriter(open('output/comparison.csv', 'w', newline=''), 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']) print('max pre-tax price for free-ship offer:', (BUDGET / Decimal('1.12')).quantize(Decimal('0.01')))