Fix MLB simulator: projected wins drive seeding, perf fix, + surface simulate errors #65

Merged
chrisp merged 2 commits from fix/simulate-route-error-handling into main 2026-06-01 20:50:04 +00:00
Owner

Summary

  • MLB simulator seeding now responds to projected wins: replaced hardcoded FanGraphs p_div/p_wc probability draws with Binomial regular-season simulation. Admin-entered projected wins (via Elo) now drive both playoff qualification odds and in-bracket game win probability, not just the latter.
  • Reads current standings mid-season: getRegularSeasonStandings is called so synced wins/gamesPlayed feed into each simulation iteration's projected final standings.
  • 27× seeding performance improvement: sampleBinomial now uses a Box-Muller normal approximation for n ≥ 30, dropping the seeding phase from ~243M to ~3M Math.random() calls per 50K-sim run (pre-season, 162 remaining games × 30 teams).
  • Missing-standings warning: when standings exist for some teams but not all recognized ones (partial sync), a logger.warn now surfaces which teams are falling back to 0 wins / 162 remaining instead of silently distorting seeding.
  • Cleanup: eloToRDif calls rawWinRateFromElo instead of inlining the same formula.
  • Simulate errors surface inline: moved simulation action from dedicated route to parent page intent="simulate" so errors display inline rather than crashing to an error page.

Test plan

  • npm run test:run -- mlb-simulator — 49 tests pass
  • npm run typecheck — clean
  • Trigger a simulation from the admin panel for an MLB season with projected wins entered; confirm teams with higher projected wins show meaningfully higher EVs
  • Confirm that running simulate with no projected wins entered (pre-season defaults) still produces a valid bracket
  • Check logs after simulating a season where some teams lack standings rows — confirm warning appears

🤖 Generated with Claude Code

## Summary - **MLB simulator seeding now responds to projected wins**: replaced hardcoded FanGraphs `p_div`/`p_wc` probability draws with Binomial regular-season simulation. Admin-entered projected wins (via Elo) now drive both playoff _qualification_ odds and in-bracket game win probability, not just the latter. - **Reads current standings mid-season**: `getRegularSeasonStandings` is called so synced `wins`/`gamesPlayed` feed into each simulation iteration's projected final standings. - **27× seeding performance improvement**: `sampleBinomial` now uses a Box-Muller normal approximation for `n ≥ 30`, dropping the seeding phase from ~243M to ~3M `Math.random()` calls per 50K-sim run (pre-season, 162 remaining games × 30 teams). - **Missing-standings warning**: when standings exist for some teams but not all recognized ones (partial sync), a `logger.warn` now surfaces which teams are falling back to 0 wins / 162 remaining instead of silently distorting seeding. - **Cleanup**: `eloToRDif` calls `rawWinRateFromElo` instead of inlining the same formula. - **Simulate errors surface inline**: moved simulation action from dedicated route to parent page `intent="simulate"` so errors display inline rather than crashing to an error page. ## Test plan - [ ] `npm run test:run -- mlb-simulator` — 49 tests pass - [ ] `npm run typecheck` — clean - [ ] Trigger a simulation from the admin panel for an MLB season with projected wins entered; confirm teams with higher projected wins show meaningfully higher EVs - [ ] Confirm that running simulate with no projected wins entered (pre-season defaults) still produces a valid bracket - [ ] Check logs after simulating a season where some teams lack standings rows — confirm warning appears 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chrisp added 2 commits 2026-06-01 18:55:45 +00:00
Fix simulate route crash and surface actual error messages
All checks were successful
🚀 Deploy / 🧪 Test (pull_request) Successful in 2m24s
🚀 Deploy / ʦ🔍 Typecheck & Lint (pull_request) Successful in 1m19s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
ba970cd571
When a simulation action threw (e.g. readiness check failure), React Router
tried to render the simulate route via GET to display the error — but the
route had no loader, so the real error was completely swallowed by React
Router's own 400 "no loader" message.

Four issues fixed:
- Move simulate into the intent-dispatch pattern on the season page (matching
  delete/rescore/sync-standings/finalize-standings), so errors surface via
  actionData instead of being lost
- Eliminate the ?simulationError= query param approach, which left stale error
  messages in browser history and reflected user-controlled text in the UI
- Match the existing bg-destructive/15 error styling used elsewhere on the page
- Strip the now-unused action from simulate.tsx; keep a loader-only redirect
  stub so any bookmarked URLs degrade gracefully to the season page

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix MLB simulator: use projected wins for playoff seeding + perf + cleanup
All checks were successful
🚀 Deploy / 🧪 Test (pull_request) Successful in 2m20s
🚀 Deploy / ʦ🔍 Typecheck & Lint (pull_request) Successful in 1m15s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
0b53570723
- Replace hardcoded FanGraphs p_div/p_wc draws with Binomial regular-season
  simulation so that admin-entered projected wins drive playoff qualification
  odds, not just in-bracket game win probability
- Add getRegularSeasonStandings call so mid-season current wins feed into
  projected final standings
- Use normal approximation (Box-Muller) in sampleBinomial for n≥30: drops
  seeding phase from ~243M to ~3M Math.random() calls per 50K-sim run
- eloToRDif now calls rawWinRateFromElo instead of inlining the same formula
- Warn when recognized teams lack a standings row during mid-season simulation
  (silent wrong seeding result with no diagnostic previously)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chrisp merged commit a528aecc86 into main 2026-06-01 20:50:04 +00:00
chrisp deleted branch fix/simulate-route-error-handling 2026-06-01 20:50:04 +00:00
Sign in to join this conversation.
No description provided.