Files
gridpilot.gg/docs/DEBUGGING_STANDINGS.md
2026-01-21 16:52:43 +01:00

102 lines
2.8 KiB
Markdown

# Debugging Standings Issues
## Issue: "No standings data available for this season"
### Root Cause
Standings are only created from **completed races** with results. If a league has:
- No completed races
- Or completed races but no results
Then no standings will be created, and the API will return an empty array.
### How Standings Are Created
1. **During seeding**: The `RacingStandingFactory.create()` method only creates standings for leagues that have completed races
2. **When races are completed**: Standings are recalculated when race results are imported
### Debugging Steps
1. **Check if the league has any races**:
```bash
curl http://localhost:3000/api/leagues/{leagueId}/races
```
2. **Check if any races are completed**:
- Look at the `status` field in the race data
- Completed races have `status: "completed"`
3. **Check if completed races have results**:
- Results are stored separately from races
- Without results, standings cannot be calculated
4. **Check if standings exist**:
```bash
curl http://localhost:3000/api/leagues/{leagueId}/standings
```
- If this returns an empty array `[]`, no standings exist
### Solutions
#### Option 1: Add Completed Races with Results
1. Create completed races for the league
2. Add race results for those races
3. Standings will be automatically calculated
#### Option 2: Use the Recalculate Endpoint (if available)
If there's a standings recalculate endpoint, call it to generate standings from existing race results.
#### Option 3: Reseed the Database
If the league was created manually and you want to start fresh:
```bash
npm run docker:dev:reseed
```
This will:
1. Stop all containers
2. Remove the database volume
3. Start fresh with seed data
4. Create standings for leagues with completed races
### Related Issues
#### Schedule Empty
If the schedule is empty but races exist, it's likely because:
1. No seasons are configured for the league
2. The season's date window doesn't include the races
**Fix**: The `GetLeagueScheduleUseCase` now handles leagues without seasons by showing all races.
#### Standings Empty
If standings are empty but races exist, it's likely because:
1. No completed races exist
2. No results exist for completed races
**Fix**: Add completed races with results, or use the recalculate endpoint.
### Example: Creating Standings Manually
If you need to create standings for testing:
1. Create completed races with results
2. Call the standings endpoint - it will automatically calculate standings from the results
Or, if you have a recalculate endpoint:
```bash
curl -X POST http://localhost:3000/api/leagues/{leagueId}/standings/recalculate
```
### Prevention
To avoid this issue in the future:
1. Always create seasons when creating leagues
2. Add completed races with results
3. Use the `docker:dev:reseed` command to ensure a clean database state