Add weekly lineup optimizer - #281
Conversation
Use Sleeper matchup and projection data to rank complete lineups against the weekly opponent, then explain recommended start/sit changes with AI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The current lineup optimization flow can produce and publish incomplete lineups (skipping unfillable slots) and has overly strict lineupSummary validation that can unnecessarily fail AI responses.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a weekly “lineup optimizer” feature that computes min/max projected lineup potential from Sleeper projections, compares it to the current matchup opponent, and surfaces recommended start/bench changes with an AI-generated explanation (with a fail-closed unavailable state when projections can’t be retrieved).
Changes:
- Backend: fetches Sleeper weekly projections + matchups, builds an optimized lineup recommendation, and includes a new
lineupStatus/lineupRecommendationin the fantasy overview response. - Backend: extends the AI response schema to include
lineupSummary, and uses a deterministic fallback summary when AI is unavailable. - Frontend: renders the lineup optimizer section and updates page tests/types to include the new overview fields.
File summaries
| File | Description |
|---|---|
| packages/frontend/src/pages/FantasyPage.tsx | Adds lineup optimizer UI section with status-driven empty/unavailable states and lineup details rendering. |
| packages/frontend/src/pages/FantasyPage.spec.tsx | Extends UI test fixtures/assertions to cover the new lineup optimizer section. |
| packages/frontend/src/app.model.ts | Introduces LineupRecommendation types and adds lineupStatus/lineupRecommendation to FantasyOverview. |
| packages/backend/src/fantasy/fantasy.service.ts | Implements projections fetch, lineup optimization/recommendations, and threads lineup summary through AI + overview response. |
| packages/backend/src/fantasy/fantasy.service.spec.ts | Adds coverage for lineup recommendation generation and projections-unavailable behavior. |
| packages/backend/src/fantasy/fantasy.model.ts | Adds Sleeper matchup/projection models and extends API models with lineup recommendation/status + lineupSummary. |
Review details
Suppressed comments (1)
packages/backend/src/fantasy/fantasy.service.ts:435
opponentPotentialis currently computed as long as the optimized lineups are non-empty, which can still be a partial lineup if some slots were skipped. Only publish opponent potential when both min and max lineups fill all starting slots, otherwise leave it null.
opponentPotential:
opponentMaximum.length && opponentMinimum.length
? {
min: this.lineupTotal(opponentMinimum),
max: this.lineupTotal(opponentMaximum),
}
: null,
- Files reviewed: 6/6 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const maximum = this.optimizeLineup(ownPlayers, slots, 'max'); | ||
| const minimum = this.optimizeLineup(ownPlayers, slots, 'min'); | ||
| if (!maximum.length || !minimum.length) { | ||
| return null; | ||
| } |
| !Array.isArray(waiverSuggestions) || | ||
| typeof lineupSummary !== 'string' || | ||
| !lineupSummary.trim() | ||
| ) { |
| summary: | ||
| aiStatus === 'ready' ? analysis.lineupSummary : this.buildLineupFallbackSummary(lineupRecommendation), | ||
| } |
| <h2 className="mb-3 flex items-center gap-2 text-lg font-semibold"> | ||
| <Users className="h-5 w-5 text-primary" aria-hidden="true" /> Week{' '} | ||
| {overview.lineupRecommendation?.week ?? ''} lineup optimizer | ||
| </h2> |
Run both workspace coverage gates from Husky and cover the lineup optimizer branches that brought backend coverage below the existing 80 percent threshold. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
Summary
Data source note
Weekly projections come from
api.sleeper.com/projections. This endpoint is operational but is not documented with Sleeper's public v1 league API, so the feature fails closed if projection data is missing or unusable.Testing