brackt/drizzle/0035_increase_prob_precision.sql
Chris Parsons c6ba59b0e6
User/chris/ev f1 framework (#93)
* feat: EV simulation framework with F1 Monte Carlo simulator

- Add EV snapshot tables (participant_ev_snapshots, team_ev_snapshots) and simulation_status column on sports seasons
- Add ev-snapshot model with upsert and history query functions
- Add simulator framework: types, bracket/F1/golf simulators, registry
- F1 simulator: vig-removed ICM weighted draw (pre-season) + race-by-race Monte Carlo from current standings (in-season); per-position column normalization to prevent floating-point EV drift
- Add admin simulate route and Run Simulation button on sports season page
- Rework futures-odds admin page to save odds then run simulation in one action
- Remove recalculate-probabilities route (superseded by simulate route)
- Remove EV trend chart panel and associated DB queries

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: map simulators to sports via simulatorType field

Adds a `simulator_type` enum column to the `sports` table so each sport
can be assigned a specific simulation algorithm rather than deriving it
from the sports season's scoring pattern.

- Add `simulatorTypeEnum` (f1_standings, indycar_standings,
  golf_qualifying_points, playoff_bracket) + `simulatorType` nullable
  column on `sports` table; migration 0037
- Rewrite simulator registry to key off `SimulatorType` instead of
  `ScoringPattern`; indycar_standings shares F1Simulator for now
- `findSportsSeasonById` now returns `SportsSeasonWithSport` so callers
  have typed access to `sport.simulatorType`
- Simulate and futures-odds actions read `sport.simulatorType`; guard
  fires before setting `simulationStatus: running`
- Admin sport edit page gains a Simulator Type dropdown

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 15:34:31 -07:00

24 lines
1.6 KiB
SQL

-- Increase probability column precision from numeric(5,2) to numeric(6,4)
-- numeric(5,2) only stores 2 decimal places (e.g. 0.05), causing EV sums to drift
-- from the expected 340 due to rounding. numeric(6,4) stores 4 decimal places
-- (e.g. 0.0457), sufficient for 10,000-simulation output (min step = 0.0001).
ALTER TABLE "participant_expected_values"
ALTER COLUMN "prob_first" TYPE numeric(6,4) USING prob_first::numeric(6,4),
ALTER COLUMN "prob_second" TYPE numeric(6,4) USING prob_second::numeric(6,4),
ALTER COLUMN "prob_third" TYPE numeric(6,4) USING prob_third::numeric(6,4),
ALTER COLUMN "prob_fourth" TYPE numeric(6,4) USING prob_fourth::numeric(6,4),
ALTER COLUMN "prob_fifth" TYPE numeric(6,4) USING prob_fifth::numeric(6,4),
ALTER COLUMN "prob_sixth" TYPE numeric(6,4) USING prob_sixth::numeric(6,4),
ALTER COLUMN "prob_seventh" TYPE numeric(6,4) USING prob_seventh::numeric(6,4),
ALTER COLUMN "prob_eighth" TYPE numeric(6,4) USING prob_eighth::numeric(6,4);
ALTER TABLE "participant_ev_snapshots"
ALTER COLUMN "prob_first" TYPE numeric(6,4) USING prob_first::numeric(6,4),
ALTER COLUMN "prob_second" TYPE numeric(6,4) USING prob_second::numeric(6,4),
ALTER COLUMN "prob_third" TYPE numeric(6,4) USING prob_third::numeric(6,4),
ALTER COLUMN "prob_fourth" TYPE numeric(6,4) USING prob_fourth::numeric(6,4),
ALTER COLUMN "prob_fifth" TYPE numeric(6,4) USING prob_fifth::numeric(6,4),
ALTER COLUMN "prob_sixth" TYPE numeric(6,4) USING prob_sixth::numeric(6,4),
ALTER COLUMN "prob_seventh" TYPE numeric(6,4) USING prob_seventh::numeric(6,4),
ALTER COLUMN "prob_eighth" TYPE numeric(6,4) USING prob_eighth::numeric(6,4);