seed data

This commit is contained in:
2025-12-30 00:15:35 +01:00
parent 7a853d4e43
commit ccaa39c39c
22 changed files with 1342 additions and 173 deletions

View File

@@ -0,0 +1,50 @@
import type { DriverStats } from '@core/racing/domain/services/IDriverStatsService';
/**
* Global store for driver stats that can be populated during seeding
* and read by the InMemoryDriverStatsService
*/
export class DriverStatsStore {
private static instance: DriverStatsStore;
private statsMap = new Map<string, DriverStats>();
private constructor() {}
static getInstance(): DriverStatsStore {
if (!DriverStatsStore.instance) {
DriverStatsStore.instance = new DriverStatsStore();
}
return DriverStatsStore.instance;
}
/**
* Populate the store with stats (called during seeding)
*/
loadStats(stats: Map<string, DriverStats>): void {
this.statsMap.clear();
stats.forEach((input, driverId) => {
this.statsMap.set(driverId, input);
});
}
/**
* Get stats for a specific driver
*/
getDriverStats(driverId: string): DriverStats | null {
return this.statsMap.get(driverId) ?? null;
}
/**
* Clear all stats (useful for reseeding)
*/
clear(): void {
this.statsMap.clear();
}
/**
* Get all stats (for debugging)
*/
getAllStats(): Map<string, DriverStats> {
return new Map(this.statsMap);
}
}

View File

@@ -1,33 +1,17 @@
import type { IDriverStatsService, DriverStats } from '@core/racing/domain/services/IDriverStatsService';
import type { Logger } from '@core/shared/application';
import { DriverStatsStore } from './DriverStatsStore';
export class InMemoryDriverStatsService implements IDriverStatsService {
private store: DriverStatsStore;
constructor(private readonly logger: Logger) {
this.logger.info('InMemoryDriverStatsService initialized.');
this.store = DriverStatsStore.getInstance();
}
getDriverStats(driverId: string): DriverStats | null {
this.logger.debug(`[InMemoryDriverStatsService] Getting stats for driver: ${driverId}`);
// Mock data for demonstration purposes
if (driverId === 'driver-1') {
return {
rating: 2500,
wins: 10,
podiums: 15,
totalRaces: 50,
overallRank: 1,
};
}
if (driverId === 'driver-2') {
return {
rating: 2400,
wins: 8,
podiums: 12,
totalRaces: 45,
overallRank: 2,
};
}
return null;
return this.store.getDriverStats(driverId);
}
}
}

View File

@@ -1,5 +1,6 @@
import type { IRankingService, DriverRanking } from '@core/racing/domain/services/IRankingService';
import type { Logger } from '@core/shared/application';
import { DriverStatsStore } from './DriverStatsStore';
export class InMemoryRankingService implements IRankingService {
constructor(private readonly logger: Logger) {
@@ -9,12 +10,29 @@ export class InMemoryRankingService implements IRankingService {
getAllDriverRankings(): DriverRanking[] {
this.logger.debug('[InMemoryRankingService] Getting all driver rankings.');
// Mock data for demonstration purposes
const mockRankings: DriverRanking[] = [
{ driverId: 'driver-1', rating: 2500, overallRank: 1 },
{ driverId: 'driver-2', rating: 2400, overallRank: 2 },
{ driverId: 'driver-3', rating: 2300, overallRank: 3 },
];
return mockRankings;
// Get stats from the DriverStatsStore
const statsStore = DriverStatsStore.getInstance();
const allStats = statsStore.getAllStats();
// Convert stats to rankings
const rankings: DriverRanking[] = [];
allStats.forEach((stats, driverId) => {
rankings.push({
driverId,
rating: stats.rating,
overallRank: stats.overallRank ?? 0,
});
});
// Sort by rating descending to get proper rankings
rankings.sort((a, b) => b.rating - a.rating);
// Assign ranks
rankings.forEach((ranking, index) => {
ranking.overallRank = index + 1;
});
return rankings;
}
}

View File

@@ -0,0 +1,50 @@
import type { TeamStats } from '@adapters/bootstrap/racing/RacingTeamFactory';
/**
* Global store for team stats that can be populated during seeding
* and read by the AllTeamsPresenter
*/
export class TeamStatsStore {
private static instance: TeamStatsStore;
private statsMap = new Map<string, TeamStats>();
private constructor() {}
static getInstance(): TeamStatsStore {
if (!TeamStatsStore.instance) {
TeamStatsStore.instance = new TeamStatsStore();
}
return TeamStatsStore.instance;
}
/**
* Populate the store with stats (called during seeding)
*/
loadStats(stats: Map<string, TeamStats>): void {
this.statsMap.clear();
stats.forEach((input, teamId) => {
this.statsMap.set(teamId, input);
});
}
/**
* Get stats for a specific team
*/
getTeamStats(teamId: string): TeamStats | null {
return this.statsMap.get(teamId) ?? null;
}
/**
* Clear all stats (useful for reseeding)
*/
clear(): void {
this.statsMap.clear();
}
/**
* Get all stats (for debugging)
*/
getAllStats(): Map<string, TeamStats> {
return new Map(this.statsMap);
}
}