import csv,json,sys
from decimal import Decimal
rows=list(csv.DictReader(open(sys.argv[1] if len(sys.argv)>1 else 'observations-2026-10-14.csv')))
for r in rows:
    levels=[(Decimal(p),Decimal(q)) for p,q in json.loads(r['raw_no_bid_levels']) if Decimal(q)>0]
    limit=Decimal(r['logged_alert_price_cents'])/100
    qty=sum((q for p,q in levels if 1-p<=limit),Decimal(0))
    assert abs(qty-Decimal(r['visible_contracts_at_or_below_logged_price']))<Decimal('.011')
for sport in ('mlb','nfl'):
    first=[r for r in rows if r['sport']==sport and r['scheduled_offset_s']=='0' and r['analysis_eligible']=='1']
    quoted=[r for r in first if r['observed_yes_ask_cents']]
    higher=sum(Decimal(r['observed_yes_ask_cents'])>Decimal(r['logged_alert_price_cents']) for r in quoted)
    print(sport, 'first books',len(first),'asks above logged price',higher,'of',len(quoted))
