-- T0 — CALIBRATION OF p_win (gates T1-T4). specs/grade-diagnostic-t0.md
-- Pre-registered firing thresholds: mean |predicted-actual| > 0.05 across
-- buckets, OR a monotonic over/under-confidence slope. BOTH fired.
with r as (
  select sport, p_win::numeric as p, (outcome='hit')::int as won
  from ledger_entries
  where user_id is null and outcome in ('hit','miss') and p_win is not null
), b as (
  select sport, width_bucket(p, 0.1, 1.0, 9) as bkt, p, won from r
)
select sport, bkt, count(*) n,
       avg(p) predicted, avg(won) actual, avg(p)-avg(won) over_confidence
from b group by sport, bkt having count(*) >= 10 order by sport, bkt;
