"""Recompute comparison.csv values from inputs/ and check recommendation.md. Revision 2.""" import csv, os, re from decimal import Decimal, ROUND_HALF_UP def find(p): for base in ('.', '..'): q = os.path.join(base, p) if os.path.exists(q): return q raise SystemExit('missing ' + p) offers = list(csv.DictReader(open(find('inputs/S2-store-offers.csv')))) specs = {r['sku']: r for r in csv.DictReader(open(find('inputs/S1-manufacturer-specs.csv')))} comp = {r['offer_id']: r for r in csv.DictReader(open(find('output/comparison.csv')))} q = lambda d: d.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) ok = True print('column counts per row:', {len(r) for r in csv.reader(open(find('output/comparison.csv')))}) print('offers in inputs / in comparison:', len(offers), len(comp)) s3 = open(find('inputs/S3-store-correction.md')).read() print('S3 mentions O6 and October 27:', 'O6' in s3 and 'October 27' in s3) qualifying = [] for o in offers: s = specs[o['sku']] sub = Decimal(o['price_cad']) + Decimal(o['shipping_cad']) total = q(sub * Decimal('1.12')) deliv = '2026-10-27' if o['offer_id'] == 'O6' else o['delivery'] exp = { 'sku': o['sku'], 'price_cad': o['price_cad'], 'shipping_cad': o['shipping_cad'], 'pre_tax_subtotal_cad': str(q(sub)), 'tax_12pct_cad': str(q(sub * Decimal('0.12'))), 'landed_total_cad': str(total), 'budget_margin_cad': str(q(Decimal('2200') - total)), 'budget_ok': 'PASS' if total <= 2200 else 'FAIL', 'ram_gb_S1': s['ram_gb'], 'ram_ok': 'PASS' if int(s['ram_gb']) >= 32 else 'FAIL', 'ssd_gb_S1': s['ssd_gb'], 'ssd_ok': 'PASS' if int(s['ssd_gb']) >= 1024 else 'FAIL', 'vram_gb_S1': s['vram_gb'], 'vram_ok': 'PASS' if int(s['vram_gb']) >= 8 else 'FAIL', 'os_S1': s['os'], 'os_ok': 'PASS' if s['os'] == 'Windows 11' else 'FAIL', 'gpu_S1': s['gpu'], 'weight_kg_S1': s['weight_kg'], 'model': s['model'], 'store': o['store'], 'delivery_date_S2': o['delivery'], 'delivery_date_effective': deliv, 'delivery_type': o['delivery_type'], 'delivery_ok': 'PASS' if (o['delivery_type'] == 'guaranteed' and deliv <= '2026-10-23') else 'FAIL', } c = comp[o['offer_id']] for k, v in exp.items(): if c[k] != v: ok = False print('MISMATCH', o['offer_id'], k, repr(c[k]), repr(v)) allpass = all(exp[k] == 'PASS' for k in exp if k.endswith('_ok')) if allpass: qualifying.append(o['offer_id']) if allpass != c['status'].startswith('QUALIFIES'): ok = False print('STATUS MISMATCH', o['offer_id']) print(o['offer_id'], total, 'ALL PASS' if allpass else 'fails', '|', c['status']) print('comparison.csv matches recomputation:', ok) print('qualifying offers:', qualifying) txt = open(find('output/recommendation.md')).read() print('words (whitespace split, counts table pipes):', len(txt.split())) print('words (tokens containing a letter or digit):', len([t for t in txt.split() if re.search(r'[A-Za-z0-9]', t)])) for o in offers: t = q((Decimal(o['price_cad']) + Decimal(o['shipping_cad'])) * Decimal('1.12')) print(o['offer_id'], 'landed total present in md:', f'{t:,}' in txt) for f in ('00-source-register.md', 'S1-manufacturer-specs.csv', 'S2-store-offers.csv', 'S3-store-correction.md', 'S4-independent-test.md'): print('md cites', f, f in txt, '| file exists:', os.path.exists(find('inputs/' + f))) for f in ('00-source-register.md', 'S3-store-correction.md', 'S4-independent-test.md'): h = open(find('inputs/' + f)).readline().lstrip('# ').strip() print('heading quoted exactly:', f, h in txt) for quote in ('Title says 32 GB / 1 TB', 'Title says 8 GB graphics', 'Delivery estimates are not commitments'): src = open(find('inputs/S2-store-offers.csv')).read() + open(find('inputs/00-source-register.md')).read() print('quote found in inputs and md:', quote, quote in src and quote in txt) d = find('output/original_submission') print('original_submission files:', sorted(os.listdir(d)))