website refactor

This commit is contained in:
2026-01-20 18:48:14 +01:00
parent 444afda435
commit 06207bf835
4 changed files with 65 additions and 3 deletions

View File

@@ -87,6 +87,7 @@ export class SeedRacingData {
async execute(): Promise<void> { async execute(): Promise<void> {
const existingDrivers = await this.seedDeps.driverRepository.findAll(); const existingDrivers = await this.seedDeps.driverRepository.findAll();
const existingTeams = await this.seedDeps.teamRepository.findAll().catch(() => []); const existingTeams = await this.seedDeps.teamRepository.findAll().catch(() => []);
const existingRaces = await this.seedDeps.raceRepository.findAll().catch(() => []);
const persistence = this.getApiPersistence(); const persistence = this.getApiPersistence();
// Check for force reseed via environment variable // Check for force reseed via environment variable
@@ -94,7 +95,7 @@ export class SeedRacingData {
const forceReseed = forceReseedRaw !== undefined && forceReseedRaw !== '0' && forceReseedRaw.toLowerCase() !== 'false'; const forceReseed = forceReseedRaw !== undefined && forceReseedRaw !== '0' && forceReseedRaw.toLowerCase() !== 'false';
this.logger.info( this.logger.info(
`[Bootstrap] Racing seed precheck: forceReseed=${forceReseed}, drivers=${existingDrivers.length}, teams=${existingTeams.length}, persistence=${persistence}`, `[Bootstrap] Racing seed precheck: forceReseed=${forceReseed}, drivers=${existingDrivers.length}, teams=${existingTeams.length}, races=${existingRaces.length}, persistence=${persistence}`,
); );
if (existingDrivers.length > 0 && !forceReseed) { if (existingDrivers.length > 0 && !forceReseed) {
@@ -329,8 +330,20 @@ export class SeedRacingData {
// Compute and store team stats from real data // Compute and store team stats from real data
await this.computeAndStoreTeamStats(); await this.computeAndStoreTeamStats();
// Log race distribution for transparency
const raceStatusCounts = seed.races.reduce((acc, race) => {
const status = race.status.toString();
acc[status] = (acc[status] || 0) + 1;
return acc;
}, {} as Record<string, number>);
const upcomingRaces = seed.races.filter((r) => r.status.toString() === 'scheduled' && r.scheduledAt > new Date());
this.logger.info( this.logger.info(
`[Bootstrap] Seeded racing data: drivers=${seed.drivers.length}, leagues=${seed.leagues.length}, races=${seed.races.length}`, `[Bootstrap] Seeded racing data: drivers=${seed.drivers.length}, leagues=${seed.leagues.length}, races=${seed.races.length} (scheduled=${raceStatusCounts.scheduled || 0}, running=${raceStatusCounts.running || 0}, completed=${raceStatusCounts.completed || 0}, cancelled=${raceStatusCounts.cancelled || 0})`,
);
this.logger.info(
`[Bootstrap] Upcoming races: ${upcomingRaces.length} scheduled in the future`,
); );
} }

View File

@@ -0,0 +1,46 @@
import { RacingRaceFactory } from './RacingRaceFactory';
import { RacingLeagueFactory } from './RacingLeagueFactory';
import { RacingTrackFactory } from './RacingTrackFactory';
import { RacingDriverFactory } from './RacingDriverFactory';
import { describe, expect, it } from 'vitest';
describe('RacingRaceFactory', () => {
it('creates upcoming races in the future', () => {
const baseDate = new Date('2024-01-01');
const driverFactory = new RacingDriverFactory(10, baseDate, 'inmemory');
const drivers = driverFactory.create();
const leagueFactory = new RacingLeagueFactory(baseDate, drivers, 'inmemory');
const leagues = leagueFactory.create();
const trackFactory = new RacingTrackFactory();
const tracks = trackFactory.create();
const raceFactory = new RacingRaceFactory(baseDate, 'inmemory');
const races = raceFactory.create(leagues, tracks);
const scheduledRaces = races.filter((r) => r.status.toString() === 'scheduled');
expect(scheduledRaces.length).toBeGreaterThan(0);
const now = new Date();
const upcomingRaces = scheduledRaces.filter((r) => r.scheduledAt > now);
expect(upcomingRaces.length).toBeGreaterThan(0);
});
it('creates races with various statuses', () => {
const baseDate = new Date('2024-01-01');
const driverFactory = new RacingDriverFactory(10, baseDate, 'inmemory');
const drivers = driverFactory.create();
const leagueFactory = new RacingLeagueFactory(baseDate, drivers, 'inmemory');
const leagues = leagueFactory.create();
const trackFactory = new RacingTrackFactory();
const tracks = trackFactory.create();
const raceFactory = new RacingRaceFactory(baseDate, 'inmemory');
const races = raceFactory.create(leagues, tracks);
const statuses = new Set(races.map((r) => r.status.toString()));
expect(statuses.has('scheduled')).toBe(true);
expect(statuses.has('running')).toBe(true);
expect(statuses.has('completed')).toBe(true);
expect(statuses.has('cancelled')).toBe(true);
});
});

View File

@@ -47,7 +47,9 @@ export class RacingRaceFactory {
} else { } else {
// 40% scheduled (8 out of 20) // 40% scheduled (8 out of 20)
status = 'scheduled'; status = 'scheduled';
scheduledAt = this.addDays(this.baseDate, 1 + ((statusMod - 13) * 2)); // Ensure scheduled races are always in the future by using current date as reference
const now = new Date();
scheduledAt = this.addDays(now, 1 + ((statusMod - 13) * 2));
} }
const base = { const base = {

View File

@@ -39,6 +39,7 @@ services:
# Using ${VAR:-} here expands to an empty string when VAR is not set in the # Using ${VAR:-} here expands to an empty string when VAR is not set in the
# host shell, which *overrides* env_file and disables force reseed. # host shell, which *overrides* env_file and disables force reseed.
- MEDIA_STORAGE_DIR=/data/media - MEDIA_STORAGE_DIR=/data/media
- GRIDPILOT_API_FORCE_RESEED=${GRIDPILOT_API_FORCE_RESEED:-}
ports: ports:
- "3001:3000" - "3001:3000"
- "9229:9229" - "9229:9229"