seed data
This commit is contained in:
34
adapters/bootstrap/racing/RacingResultFactory.ts
Normal file
34
adapters/bootstrap/racing/RacingResultFactory.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Driver } from '@core/racing/domain/entities/Driver';
|
||||
import { Race } from '@core/racing/domain/entities/Race';
|
||||
import { Result as RaceResult } from '@core/racing/domain/entities/result/Result';
|
||||
|
||||
export class RacingResultFactory {
|
||||
create(drivers: Driver[], races: Race[]): RaceResult[] {
|
||||
const results: RaceResult[] = [];
|
||||
const completed = races.filter((r) => r.status === 'completed');
|
||||
|
||||
for (const race of completed) {
|
||||
const participants = drivers.slice(0, Math.min(16, drivers.length));
|
||||
|
||||
for (let idx = 0; idx < participants.length; idx++) {
|
||||
const driver = participants[idx]!;
|
||||
const position = idx + 1;
|
||||
const startPosition = ((idx + 3) % participants.length) + 1;
|
||||
|
||||
results.push(
|
||||
RaceResult.create({
|
||||
id: `${race.id}:${driver.id}`,
|
||||
raceId: race.id,
|
||||
driverId: driver.id,
|
||||
position,
|
||||
startPosition,
|
||||
fastestLap: 88_000 + idx * 120,
|
||||
incidents: idx % 4 === 0 ? 2 : 0,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user