Commit graph

536 commits

Author SHA1 Message Date
Chris Parsons
83994b7a74
Fix draft round showing Infinity before draft starts (#9)
When draftSlots is empty (pre-draft state), dividing by zero caused
Math.ceil to return Infinity. Guard the division to fall back to round 1.

https://claude.ai/code/session_017mLmGc5wTrESaDeRQHkSPy

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 11:16:34 -08:00
Chris Parsons
47b69ce9cf
Include commissioner leagues in user's active leagues (#8)
* Show leagues where user is a member regardless of team assignment

The homepage now uses a union query to show leagues where the user
either has a team in the current season OR is a commissioner. Previously,
commissioners without a team could not see their leagues on the homepage.

https://claude.ai/code/session_01E3ugKTfatkEc5TcDGXvHiW

* Fix stale empty state card title in home route

Update 'No Active Leagues' to 'No Leagues' to match the updated
description which is now about membership rather than active seasons.

https://claude.ai/code/session_01E3ugKTfatkEc5TcDGXvHiW

* Fix union import: use two queries with JS deduplication

drizzle-orm 0.36.x does not export a standalone union() function.
Replace with two awaited queries merged via a Map (dedup by id),
then sorted by createdAt descending in JS.

https://claude.ai/code/session_01E3ugKTfatkEc5TcDGXvHiW

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 10:28:37 -08:00
Chris Parsons
8c9b131c00
Update scoring system and add Counter-Strike to special scoring (#7)
* Update how-to-play scoring rules to match standard scoring

- Update placement points: 1st 100, 2nd 70, 3rd-4th 45, 5th-8th 20
- Add Counter-Strike to the special majors scoring section alongside Golf & Tennis
- Add qualifying points breakdown (8/5/3/2/1) per major tournament

https://claude.ai/code/session_01JUAqVZgo7M7XRBLzpeaWpH

* Fix scoring to show all 8 individual placements correctly

Display each placement (1st-8th) with its own point value rather than
grouping/averaging: 100, 70, 50, 40, 25, 25, 15, 15

https://claude.ai/code/session_01JUAqVZgo7M7XRBLzpeaWpH

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 10:00:35 -08:00
Chris Parsons
eb7aa42cef
Add implementation plan for commissioner-without-team feature (#6)
* Add implementation plan for commissioner-without-team feature

https://claude.ai/code/session_01NSRMSYtb7jSFbngDS8okn3

* Allow commissioners to exist without owning a team

- Add opt-out checkbox on league creation ("I want to play in this league")
  so the creator can be commissioner-only without claiming a team
- Add Commissioner Management card to league settings with add/remove
  commissioner UI; guards against removing the last commissioner
- Add countCommissionersByLeagueId model helper for the last-commissioner guard
- Show "No team" indicator on the league homepage next to commissioners
  who don't own a team in the current season

https://claude.ai/code/session_01NSRMSYtb7jSFbngDS8okn3

* Fix code review issues in commissioner management

- Add success/error feedback banners to commissioner add/remove actions
- Gate allUsers query to admin-only (prevents exposing all users to non-admin commissioners)
- Prevent commissioner self-removal in both action (server) and UI (client)
- Add "(you)" label next to current user in commissioner list
- Remove all unnecessary `any` type casts in favor of inferred types

https://claude.ai/code/session_01NSRMSYtb7jSFbngDS8okn3

* Allow commissioners to add league members as co-commissioners

Non-admin commissioners can now add users who already own a team in
the league as co-commissioners. Admins still see the full user list.
Previously the add-commissioner form was admin-only.

https://claude.ai/code/session_01NSRMSYtb7jSFbngDS8okn3

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 08:45:09 -08:00
Chris Parsons
03fdba3022
Remove EV column from available participants table (#5)
* Hide EV column from draft board available participants table

https://claude.ai/code/session_016oJK1gmWZ48YWEZmVqm6f9

* Clean up dead expectedValue references after hiding EV column

- Remove expectedValue from AvailableParticipantsSection interface
- Remove EV column from Force Manual Pick commissioner dialog
- Remove expectedValue from participants loader SELECT and parsing step
- Retain ORDER BY expectedValue for default sort order

https://claude.ai/code/session_016oJK1gmWZ48YWEZmVqm6f9

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 17:02:55 -08:00
Chris Parsons
2d6dd6ec9f
Refactor expected values form to batch save all participants (#4)
* fix: remove probability sum validation and add batch save with total EV

- Remove the requirement that manual probabilities sum to 1.0, allowing
  partial distributions (e.g. when a participant has <100% chance of top 8)
- Replace per-row save buttons with a single "Save All" button that submits
  all participants at once
- Add a Total EV row at the bottom of the table summing all participant EVs
- Update action to batch process all participants from a single form submission

https://claude.ai/code/session_01WHRynBCcugSK7HHEmN6Yuy

* fix: validate participantIds server-side instead of trusting form input

Fetch participants from the DB in the action using the season ID from
the URL params, eliminating the untrusted participantIds hidden field.
Remove the now-unused hidden input from the frontend form.

https://claude.ai/code/session_01WHRynBCcugSK7HHEmN6Yuy

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 15:57:05 -08:00
Chris Parsons
eb260649b1
Add bulk import feature for futures odds with fuzzy matching (#3)
* Add bulk import to futures odds page

Adds a textarea where admins can paste odds from FanDuel, DraftKings,
OddsChecker, or any site. A client-side parser extracts American odds
from each line and fuzzy-matches team names to participants (exact,
substring, and word-overlap matching). Shows matched/unmatched results
before applying to the individual input fields.

https://claude.ai/code/session_01JvgcqKSJZ36bEztfg6CkWP

* Code review fixes for futures-odds page

- Remove unused upsertParticipantEVWithNormalization import
- Remove debug console.log statements left in save action
- Move normalizeName to module level (pure function, no component deps)
- Pre-compute normalized participant names once in findParticipantMatch
  instead of re-normalizing across three separate passes
- Fix array index key on unmatched list to use composite string key
- Drop unused result variable from upsertParticipantEV call

https://claude.ai/code/session_01JvgcqKSJZ36bEztfg6CkWP

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 14:34:45 -08:00
Chris Parsons
740ffbb411
fix: exclude database/context from browser bundle to fix Docker build (#2)
database/context.ts uses AsyncLocalStorage from node:async_hooks which
is a Node.js-only API. Vite externalizes it for browser builds but the
resulting error "AsyncLocalStorage is not exported by __vite-browser-external"
caused npm run build to fail.

Fix: add a Vite resolve.alias for the browser (non-SSR) build that maps
~/database/context to a browser-safe stub. The stub is never called at
runtime since database() is only invoked in server-side loaders, but it
allows the client bundle to build without errors.

https://claude.ai/code/session_01Fjf9WFqNnuHmmC5yTedL7G

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 11:54:32 -08:00
Chris Parsons
3210ab265f
Change participant expectedValue from integer to decimal (#1)
* feat: sync odds-based EV to participants table for draft room ranking

When admin enters futures odds or manual probabilities, the calculated EV
is now synced from participantExpectedValues to participants.expectedValue.
This closes the gap where EVs were calculated but never reflected in the
draft room ranking. Also changes expectedValue from integer to decimal(10,2)
for better precision, and displays "—" for participants with no odds data.

https://claude.ai/code/session_01JWG2zg2EMzCn6RgEufPC1T

* fix: correct expectedValue type to string in participants route

Missed instance of `expectedValue: 0` (number) that failed typecheck
after schema change from integer to decimal.

https://claude.ai/code/session_01JWG2zg2EMzCn6RgEufPC1T

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-19 11:26:40 -08:00
Chris Parsons
9211cad7d1 fix: correct test expectations for ICM edge cases and duplicate text queries
- ICM tests: fix single participant, zero probabilities, and 2-participant
  tests to account for simulation only filling min(participants, 8) positions
- TeamScoreBreakdown tests: use getAllByText for "150.0" which now appears
  in both the header and the Actual Points summary card

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 14:24:07 -08:00
Chris Parsons
96b4c5a350 fix: align ev-calculator tests with decimal (0-1) probability format
The implementation and rest of the system (ICM calculator, probability
updater) use decimals (0-1) for probabilities, but the tests were using
percentages (0-100). Updated tests and docs to match.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 23:26:32 -08:00
Chris Parsons
24126fe389 fix: add missing projectedPoints and actualPoints to TeamScoreBreakdown test fixtures
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 23:08:06 -08:00
Chris Parsons
7970cb6a9c feat: add FIFA World Cup 48-team bracket template with group stage and projected scoring
- Add FIFA_48 bracket template with 12 groups of 4, knockout stage of 32
- Add tournament groups schema, model, and GroupStageDisplay component
- Add projected/expected value scoring to standings and team breakdowns
- Add docker-compose for local PostgreSQL development
- Move DRAFT_ORDER_IMPLEMENTATION.md to plans directory

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 22:30:12 -08:00
Chris Parsons
840212c4f8 feat: implement sports season expected value calculations and probability updates
- Added loader and action functions for managing expected values in sports seasons.
- Implemented UI for recalculating probabilities based on participant results.
- Created a service to update probabilities after results are finalized, including handling finished and unfinished participants.
- Developed tests for the probability updater service to ensure correct functionality.
- Introduced a preview feature to show potential changes before applying updates.
2025-11-21 22:05:50 -08:00
Chris Parsons
79ec477a98 feat: implement Expected Value System with ICM probability calculator
Implements Phase 5.2 of the EV system with Harville-Malmuth Independent Chip Model
for calculating participant placement probabilities from futures odds.

## Key Features

### ICM Probability Calculator
- Implements Harville-Malmuth method for distributing probabilities
- Converts American odds to championship probabilities
- Generates P(1st) through P(8th) for all participants
- Column-normalized: each placement sums to 100% across all teams
- Works with any number of participants (not limited to 8)

### Admin UI - Futures Odds Entry
- Enter American odds (e.g., +550, -200) for championship futures
- Live preview of ICM-calculated probability distributions
- Displays all 8 placement probabilities
- Persists odds for editing on subsequent visits
- Automatic probability normalization (removes bookmaker vig)

### Database Schema Updates
- Renamed participant_expected_values.season_id → sports_season_id
- Updated foreign key to reference sports_seasons instead of seasons
- Added source_odds field to store original futures odds
- Migration 0025: Column rename and FK update
- Migration 0026: Add source_odds field

### Model Layer
- participant-expected-value: CRUD operations for probability distributions
- Supports multiple probability sources (manual, futures_odds, elo_simulation)
- Automatic EV calculation based on league scoring rules
- Probability validation and normalization

### Service Layer
- icm-calculator: Harville-Malmuth probability distribution
- probability-engine: Odds conversion and Elo utilities (for future use)
- bracket-simulator: Monte Carlo simulation (for future hybrid approach)
- ev-calculator: Expected value computation from probabilities

## Technical Details

- Uses exponential decay favoring top positions for strong teams
- Preserves championship probability ordering in final distributions
- Row sums vary (strong teams ~100%, weak teams lower)
- All probabilities between 0-1, mathematically valid
- Comprehensive test suite: 97 tests passing

## Future Enhancements

- Hybrid approach: ICM pre-playoffs, bracket simulation during playoffs
- Integration with league-specific scoring rules
- Historical probability tracking for accuracy analysis

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 22:19:46 -08:00
Chris Parsons
41b81771d4 Implement detailed Phase 5 implementation plan for Expected Value System
- Added comprehensive implementation plan for Phase 5, including executive summary, clarifications, recommended architecture, task breakdown, and performance considerations.
- Defined database schema changes for participant probabilities and expected values.
- Outlined service layer architecture for probability generation, EV calculation, and probability updates.
- Included detailed task breakdown for each sub-phase, focusing on manual entry, futures odds integration, real results integration, projected totals display, draft integration, and daily update job.
- Incorporated validation data and calibration goals for NHL futures odds.
- Updated planning questions and answers based on previous discussions to refine the approach for EV calculations and autodraft integration.
2025-11-15 22:54:59 -08:00
Chris Parsons
6ef829f667 feat: add recharts library and implement PointProgressionChart component for historical views
- Added recharts dependency to package.json for data visualization.
- Implemented PointProgressionChart component to display team point progression over time.
- Updated scoring-system.md to reflect completion of historical views and added implementation notes.
- Created unit tests for PointProgressionChart to ensure correct rendering and data handling.
- Developed season completion detection and percentage calculation functions in season-helpers.server.ts.
- Added tests for season completion logic and point progression data formatting.
- Enhanced league loader to fetch necessary data for current season and teams.
2025-11-14 21:18:34 -08:00
Chris Parsons
0eeb1b6245 feat: Enhance league home page with sports seasons section and scoring pattern display 2025-11-14 20:39:51 -08:00
Chris Parsons
f17699e4c5 feat: Implement team breakdown pages with detailed score breakdown
- Created `TeamScoreBreakdown` component to display all drafted participants, their placements, and points.
- Added new route for team breakdown at `/leagues/:leagueId/standings/:seasonId/teams/:teamId`.
- Enhanced `getTeamScoreBreakdown` model to include `sportsSeasonId` for grouping.
- Updated `StandingsTable` to include clickable team name links.
- Added functionality to finalize brackets in playoff events, including error handling and recalculating standings.
- Implemented tests for `TeamScoreBreakdown` component to ensure proper rendering and functionality.
- Updated routing to support new team breakdown feature and ensure seamless navigation.
2025-11-14 20:01:21 -08:00
Chris Parsons
9d38bdf1ca feat: implement daily standings snapshot system with admin management interface 2025-11-14 09:15:58 -08:00
Chris Parsons
0385ca220c feat: add standings page and enhance standings functionality
- Added a new route for league standings: `/leagues/:leagueId/standings/:seasonId`
- Implemented the `StandingsTable` component to display team standings with ranking, points, and placement breakdown.
- Integrated tiebreaker logic for ranking teams based on total points and placements.
- Enhanced the league home page with a link to view standings.
- Updated scoring system documentation to reflect the new standings features.
- Added comprehensive tests for tiebreaker logic and `StandingsTable` component.
- Created shared types for standings to be used in both server and client code.
2025-11-13 13:24:03 -08:00
Chris Parsons
604eb6980c feat: Add routes and components for sports season display, including playoff brackets and standings 2025-11-12 23:44:33 -08:00
Chris Parsons
4d5b4efc23 feat: Implement AFL Finals bracket template and scoring logic with double-chance system 2025-11-12 23:21:22 -08:00
Chris Parsons
1089022c09 feat: Implement Qualifying Points Standings component and related logic
- Added `QualifyingPointsStandings` component to display standings based on qualifying points.
- Introduced scoring rules and projected points calculation for participants.
- Implemented tie handling for rankings and displayed appropriate UI elements based on finalization status.
- Created tests for qualifying points configuration, accumulation logic, ranking logic, and scoring workflow.
- Developed scoring calculator tests to validate fantasy points conversion from qualifying points.
- Established qualifying points management functions including initialization, retrieval, updating, and resetting of points.
2025-11-11 10:08:25 -08:00
Chris Parsons
d926486934 feat: Implement season standings processing and participant result management for final standings events 2025-11-08 22:35:07 -08:00
Chris Parsons
5d0e6b999c feat: Implement NFL 14 bracket template with bye week handling and comprehensive unit tests 2025-11-08 21:56:57 -08:00
Chris Parsons
4d305c4117 feat: Add ParticipantSelector component for improved participant selection in brackets 2025-11-08 21:36:29 -08:00
Chris Parsons
bbacb00d6c feat: Implement NCAA 68 tournament structure with First Four play-in games and Round of 64 seeding logic 2025-11-08 21:18:09 -08:00
Chris Parsons
dfe4b7b643 Add bracket seeding tests and implement tournament-style seeding for 16 and 32-team brackets
- Introduced `generateStandardSeeding()` function to create proper tournament matchups (e.g., 1v16, 8v9).
- Added comprehensive tests for 4, 8, 16, and 32-team brackets to ensure correct seeding and balance.
- Updated testing instructions to reflect new features and improvements in bracket generation.
- Fixed issues with sequential seeding and ensured all matchups sum to n+1 for balance.
- Implemented batch winner selection and duplicate participant prevention for improved user experience.
- Enhanced fantasy points display on event pages for better visibility of participant results.
2025-11-04 22:09:44 -08:00
Chris Parsons
da1a17f2d3 Refactor code structure for improved readability and maintainability 2025-11-03 13:16:37 -08:00
Chris Parsons
a3b8fa6309 feat: Implement bracket expansion plan to support various tournament structures
- Added a comprehensive plan for bracket expansion, including support for 4, 8, 16, 32, and 68 team formats.
- Introduced a template-based bracket system with predefined templates for NCAA March Madness, NFL Playoffs, NBA Playoffs, and simple brackets.
- Updated UI flow for bracket creation, allowing admins to select templates and assign participants flexibly.
- Enhanced database schema to accommodate new scoring rules and bracket templates.
- Proposed updates to scoring logic to handle non-scoring rounds and participant placements correctly.
- Documented implementation phases for gradual rollout of new features.
- Addressed critical bugs in the playoff event processing and scoring logic, ensuring proper advancement and scoring rules across multiple leagues.
2025-11-03 09:36:16 -08:00
Chris Parsons
60ba3d4a6e feat: Implement event management for sports seasons with CRUD operations and UI 2025-10-31 22:13:12 -07:00
Chris Parsons
7dddf2c9a7 feat: Add scoring rules editor to league settings and creation pages
- Created ScoringRulesEditor component with 8 placement point inputs
- Added scoring-types.ts for shared client/server types
- Integrated scoring rules into league settings page
- Integrated scoring rules into league creation form
- Added validation for point values (0-1000 range)
- Disabled editing in settings after draft starts
- Included helpful tips and preview display

Phase 1.3 complete

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 00:04:27 -07:00
Chris Parsons
e49bb3df8b feat: Add scoring event and results management with comprehensive scoring rules and standings tracking 2025-10-28 23:50:50 -07:00
Chris Parsons
8e422c6503 fix: Pass database instance to isParticipantDrafted in timer context
The timer system runs outside the request context and uses its own database
  connection. This fix allows isParticipantDrafted to accept an optional db
  parameter so it works in both request handlers and timer contexts.

  Fixes: DatabaseContext not set error during autopick
2025-10-28 23:40:29 -07:00
Chris Parsons
ad16f9d046 feat: Add comprehensive scoring system database schema
- Add scoringPattern and eventType enums for 4 scoring patterns
    (single_elimination_playoff, page_playoff, season_standings, qualifying_points)
  - Add 8 placement point fields to seasons table (1st-8th) with defaults
  - Add scoring pattern fields to sportsSeasons table (scoringPattern, totalMajors, etc.)
  - Create 10 new tables:
    - scoring_events: Individual games, tournaments, races
    - event_results: Participant results per event
    - playoff_matches: Bracket tracking for playoffs
    - participant_qualifying_totals: QP aggregation for golf/tennis
    - qualifying_point_config: Configurable QP values per sport
    - team_sport_scores: Aggregated scores per sport
    - team_standings: Current standings with tiebreakers
    - team_standings_snapshots: Daily snapshots for 7-day tracking
    - participant_expected_values: EV calculations per league
    - participant_season_results: F1 current points tracking
  - Add all necessary relations for new tables
  - Update test fixtures with new required scoring fields
2025-10-28 23:40:11 -07:00
Chris Parsons
1a1af87d3c feat: Implement comprehensive scoring system with multiple patterns and configurations 2025-10-28 23:18:17 -07:00
Chris Parsons
be8cabeac7 feat: Prevent simultaneous updates in AutodraftSettings and disable controls during updates 2025-10-26 22:09:22 -07:00
Chris Parsons
609c4e7b2c feat: Add hide ineligible participants functionality in AvailableParticipantsSection 2025-10-26 21:09:30 -07:00
Chris Parsons
5b10548f13 feat: Add ConnectionOverlay component for improved socket connection handling and user feedback 2025-10-26 21:01:12 -07:00
Chris Parsons
88b44b4616 feat: Simplify disabled state logic for autodraft settings controls 2025-10-26 20:52:11 -07:00
Chris Parsons
f0c289353e feat: Refactor database connection handling in draft-related functions for improved flexibility 2025-10-26 20:35:55 -07:00
Chris Parsons
918e9ff04a feat: Implement autodraft chain logic and timer initialization for next team picks 2025-10-25 22:11:10 -07:00
Chris Parsons
1825c0e271 feat: Enhance AvailableParticipantsSection with icon buttons for queue actions and simplify draft button visibility logic 2025-10-25 21:35:44 -07:00
Chris Parsons
98b84095fd feat: Implement drag-and-drop functionality for queue items; add duplicate prevention for participants in queue 2025-10-25 21:02:16 -07:00
Chris Parsons
c9d3ee73cd feat: Update DraftSidebar to include recent picks section and refactor layout; enhance AvailableParticipantsSection and QueueSection styling 2025-10-25 18:25:26 -07:00
Chris Parsons
714ab0f484 feat: Refactor autopick logic to use unified executeAutoPick function and enhance eligibility checks 2025-10-25 10:14:36 -07:00
Chris Parsons
32980428f2 feat: Integrate accordion component for sidebar and update autodraft settings to sync with props 2025-10-25 10:04:21 -07:00
Chris Parsons
2cd4096e70 feat: Implement draft room redesign with collapsible sidebar and tabbed content
- Added AvailableParticipantsSection for participant search and filtering.
- Created DraftGridSection for displaying the draft grid with team timers and context menu.
- Developed QueueSection for managing participant queue and autodraft settings.
- Introduced RecentPicksSection to show recent draft picks.
- Implemented TeamsDraftedGrid to visualize drafted participants by team and sport.
- Added collapsible UI components for better layout management.
- Established tabbed navigation for draft board, recent picks, and teams drafted.
- Enhanced responsiveness for mobile and desktop views.
- Updated styles for a cohesive design across components.
2025-10-25 03:23:41 -07:00
Chris Parsons
190dfb92ca feat: add socket event for participant removal from queues 2025-10-24 21:46:55 -07:00