Fix Sleeper scoring: TDs should not count as first downs for fantasy points
Problem
The current fantasy points calculation pipeline incorrectly counts touchdowns as first downs when using Sleeper scoring format. While the NFL play-by-play data correctly shows TDs as first downs (per official NFL rules), Sleeper's fantasy scoring system should NOT award first down points for touchdown plays.
Current Behavior
- NFL play-by-play data sets
first_down = truefor touchdown plays (correct for NFL stats) - Fantasy points pipeline awards both touchdown points AND first down points for the same play
- This affects both rushing and receiving first down bonuses in Sleeper scoring
Expected Behavior
For Sleeper scoring format specifically:
- Touchdown plays should NOT count as first downs for fantasy scoring purposes
- First down bonuses should only apply to non-touchdown plays that result in first downs
- Other scoring formats may continue to use current logic if desired
Technical Context
Files to update:
-
libs-server/data-views-column-definitions/player-fantasy-points-from-plays-column-definitions.mjs- Lines 409, 455: First down logic for rushing and receiving
-
libs-shared/calculate-points.mjs- May need updates for consistency in first down handling
Current Logic:
// Rushing first downs (line 409)
sql += ` + (CASE WHEN first_down = true AND play_type = 'RUSH' THEN ${rufd} ELSE 0 END)`
// Receiving first downs (line 455)
sql += ` + (CASE WHEN first_down = true AND play_type = 'PASS' THEN ${recfd} ELSE 0 END)`
Proposed Fix:
// Exclude TDs from first down bonuses for Sleeper scoring
sql += ` + (CASE WHEN first_down = true AND play_type = 'RUSH' AND rush_td \!= true THEN ${rufd} ELSE 0 END)`
sql += ` + (CASE WHEN first_down = true AND play_type = 'PASS' AND pass_td \!= true THEN ${recfd} ELSE 0 END)`
Acceptance Criteria
- [ ] Identify Sleeper scoring format in the scoring pipeline
- [ ] Modify first down logic to exclude touchdown plays for Sleeper scoring
- [ ] Ensure other scoring formats remain unaffected
- [ ] Add tests to verify TD vs first down points are calculated correctly
- [ ] Update both server-side column definitions and shared calculation logic
✅ Partial Fix Implemented
Fixed for Fantasy Points by Plays Data View Column
I've successfully implemented the fix for the fantasy points from plays calculation in libs-server/data-views-column-definitions/player-fantasy-points-from-plays-column-definitions.mjs.
Changes Made:
- Added logic to detect Sleeper Scott Fish Bowl scoring format (
ed9c2daa0f00d9389f450b577c16fb0864fa22c6e261c0161db5f2da54457286) - Modified rushing scoring SQL to exclude touchdown plays from first down calculations:
CASE WHEN first_down = true AND play_type = 'RUSH' AND COALESCE(rush_td::int, 0) = 0 THEN ${rufd} ELSE 0 END - Modified receiving scoring SQL to exclude touchdown plays from first down calculations:
CASE WHEN first_down = true AND play_type = 'PASS' AND COALESCE(pass_td::int, 0) = 0 THEN ${recfd} ELSE 0 END
What's Working Now:
- Fantasy points calculations in data views for Sleeper Scott Fish Bowl format no longer double-count TD plays as first downs
- All other scoring formats remain unaffected
- Fantasy points from plays table field correctly handles the Sleeper format
🔄 Still Needs to be Addressed
- Saved gamelogs - Historical data stored with the Sleeper scoring format will still have the incorrect calculations
-
Client-side calculate points - The
calculate-points.mjsfile likely needs similar updates for frontend calculations
Next Steps:
- [ ] Update
libs-shared/calculate-points.mjsfor client-side calculations - [ ] Consider whether to regenerate/fix historical gamelog data with Sleeper scoring
- [ ] Test the fix with actual Sleeper Scott Fish Bowl data
The fantasy points by plays data view column now correctly handles this scoring scenario.