league icon indicating copy to clipboard operation
league copied to clipboard

Fix Sleeper scoring: TDs should not count as first downs for fantasy points

Open mistakia opened this issue 9 months ago • 1 comments

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 = true for 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:

  1. libs-server/data-views-column-definitions/player-fantasy-points-from-plays-column-definitions.mjs
    • Lines 409, 455: First down logic for rushing and receiving
  2. 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

mistakia avatar Jul 05 '25 22:07 mistakia

✅ 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

  1. Saved gamelogs - Historical data stored with the Sleeper scoring format will still have the incorrect calculations
  2. Client-side calculate points - The calculate-points.mjs file likely needs similar updates for frontend calculations

Next Steps:

  • [ ] Update libs-shared/calculate-points.mjs for 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.

mistakia avatar Jul 07 '25 18:07 mistakia