seed data

This commit is contained in:
2025-12-30 18:33:15 +01:00
parent 83371ea839
commit 92226800df
306 changed files with 1753 additions and 501 deletions

View File

@@ -25,8 +25,51 @@ export class RacingDriverFactory {
private readonly persistence: 'postgres' | 'inmemory' = 'inmemory',
) {}
/**
* Get deterministic avatar URL for a driver based on their ID
* Uses static files from the website public directory
*/
getDriverAvatarUrl(driverId: string): string {
// Deterministic selection based on driver ID
const numericSuffixMatch = driverId.match(/(\d+)$/);
let useFemale = false;
let useNeutral = false;
if (numericSuffixMatch && numericSuffixMatch[1]) {
const numericSuffix = parseInt(numericSuffixMatch[1], 10);
// 40% female, 40% male, 20% neutral
if (numericSuffix % 5 === 0) {
useNeutral = true;
} else if (numericSuffix % 2 === 0) {
useFemale = true;
}
} else {
// Fallback hash
let hash = 0;
for (let i = 0; i < driverId.length; i++) {
hash = (hash * 31 + driverId.charCodeAt(i)) | 0;
}
const hashValue = Math.abs(hash);
if (hashValue % 5 === 0) {
useNeutral = true;
} else if (hashValue % 2 === 0) {
useFemale = true;
}
}
// Return static file paths that Next.js can serve
if (useNeutral) {
return '/images/avatars/neutral-default-avatar.jpeg';
} else if (useFemale) {
return '/images/avatars/female-default-avatar.jpeg';
} else {
return '/images/avatars/male-default-avatar.jpg';
}
}
create(): Driver[] {
const countries = ['DE', 'NL', 'FR', 'GB', 'US', 'CA', 'SE', 'NO', 'IT', 'ES', 'AU', 'BR', 'JP', 'KR', 'RU', 'PL', 'CZ', 'HU', 'AT', 'CH'] as const;
const categories = ['beginner', 'intermediate', 'advanced', 'pro', 'endurance', 'sprint'];
return Array.from({ length: this.driverCount }, (_, idx) => {
const i = idx + 1;
@@ -53,6 +96,9 @@ export class RacingDriverFactory {
joinedAt = faker.date.past({ years: 2, refDate: this.baseDate });
}
// Assign category - use all available categories
const category = faker.helpers.arrayElement(categories);
const driverData: {
id: string;
iracingId: string;
@@ -60,12 +106,14 @@ export class RacingDriverFactory {
country: string;
bio?: string;
joinedAt?: Date;
category?: string;
} = {
id: seedId(`driver-${i}`, this.persistence),
iracingId: String(100000 + i),
name: faker.person.fullName(),
country: faker.helpers.arrayElement(countries),
joinedAt,
category,
};
if (hasBio) {

View File

@@ -1,4 +1,4 @@
import { League } from '@core/racing/domain/entities/League';
import { League, LeagueSettings } from '@core/racing/domain/entities/League';
import { Driver } from '@core/racing/domain/entities/Driver';
import { faker } from '@faker-js/faker';
import { seedId } from './SeedIdHelper';
@@ -11,7 +11,7 @@ export class RacingLeagueFactory {
) {}
create(): League[] {
const leagueCount = 30;
const leagueCount = 120; // Expanded to 100+ leagues
// Create diverse league configurations covering ALL enum combinations
// Points systems: f1-2024, indycar, custom (3)
@@ -20,6 +20,8 @@ export class RacingLeagueFactory {
// Decision modes: admin_only, steward_decides, steward_vote, member_vote, steward_veto, member_veto (6)
// Total combinations: 3 * 2 * 2 * 6 = 72, but we'll sample 30 covering extremes
// Category types for leagues
const leagueConfigs = [
// 1-5: Ranked, F1-2024, various stewarding
{
@@ -277,7 +279,8 @@ export class RacingLeagueFactory {
return Array.from({ length: leagueCount }, (_, idx) => {
const i = idx + 1;
const owner = faker.helpers.arrayElement(this.drivers);
const config = leagueConfigs[idx]!;
// Cycle through the 30 configs for variety
const config = leagueConfigs[idx % 30]!;
const createdAt =
// Ensure some "New" leagues (created within 7 days) so `/leagues` featured categories are populated.
@@ -310,33 +313,29 @@ export class RacingLeagueFactory {
}
}
const leagueData: {
id: string;
name: string;
description: string;
ownerId: string;
settings: {
pointsSystem: 'f1-2024' | 'indycar' | 'custom';
maxDrivers: number;
sessionDuration: number;
qualifyingFormat: 'open' | 'single-lap';
visibility?: 'ranked' | 'unranked';
stewarding?: {
decisionMode: 'admin_only' | 'steward_decides' | 'steward_vote' | 'member_vote' | 'steward_veto' | 'member_veto';
requiredVotes?: number;
requireDefense?: boolean;
defenseTimeLimit?: number;
voteTimeLimit?: number;
protestDeadlineHours?: number;
stewardingClosesHours?: number;
notifyAccusedOnProtest?: boolean;
notifyOnVoteRequired?: boolean;
};
};
createdAt: Date;
socialLinks?: { discordUrl?: string; youtubeUrl?: string; websiteUrl?: string };
participantCount?: number;
} = {
// Determine category based on scoring configuration
let category: string | undefined;
if (config.pointsSystem === 'f1-2024') {
if (config.qualifyingFormat === 'single-lap') {
category = 'driver';
} else {
category = 'team';
}
} else if (config.pointsSystem === 'indycar') {
category = 'nations';
} else if (config.pointsSystem === 'custom') {
category = 'trophy';
}
// Override some leagues to have endurance or sprint categories
if (idx % 8 === 0) {
category = 'endurance';
} else if (idx % 7 === 0) {
category = 'sprint';
}
// Build the league data object
const leagueData = {
id: seedId(`league-${i}`, this.persistence),
name: faker.company.name() + ' Racing League',
description: faker.lorem.sentences(2),
@@ -356,6 +355,7 @@ export class RacingLeagueFactory {
notifyOnVoteRequired: true,
},
},
category,
createdAt,
participantCount,
};
@@ -374,11 +374,37 @@ export class RacingLeagueFactory {
if (type === 'website') socialLinks.websiteUrl = faker.internet.url();
});
// Create the final league data with optional fields
const finalLeagueData: {
id: string;
name: string;
description: string;
ownerId: string;
settings?: Partial<LeagueSettings>;
category?: string | undefined;
createdAt?: Date;
socialLinks?: {
discordUrl?: string;
youtubeUrl?: string;
websiteUrl?: string;
};
participantCount?: number;
} = {
id: leagueData.id,
name: leagueData.name,
description: leagueData.description,
ownerId: leagueData.ownerId,
settings: leagueData.settings,
category: leagueData.category,
createdAt: leagueData.createdAt,
participantCount: leagueData.participantCount,
};
if (Object.keys(socialLinks).length > 0) {
leagueData.socialLinks = socialLinks;
finalLeagueData.socialLinks = socialLinks;
}
return League.create(leagueData);
return League.create(finalLeagueData);
});
}
}

View File

@@ -14,6 +14,7 @@ export interface TeamStats {
totalWins: number;
totalRaces: number;
rating: number;
category?: string;
}
export class RacingTeamFactory {
@@ -33,6 +34,9 @@ export class RacingTeamFactory {
{ min: 0, max: 3 },
);
// 30-50% of teams are recruiting
const isRecruiting = faker.datatype.boolean({ probability: 0.4 });
return Team.create({
id: seedId(`team-${i}`, this.persistence),
name: faker.company.name() + ' Racing',
@@ -40,6 +44,7 @@ export class RacingTeamFactory {
description: faker.lorem.sentences(2),
ownerId: owner.id,
leagues: teamLeagues,
isRecruiting,
createdAt: faker.date.past({ years: 2, refDate: this.baseDate }),
});
});
@@ -256,6 +261,10 @@ export class RacingTeamFactory {
specialization = 'mixed';
}
// Determine category - use all available categories
const categories = ['beginner', 'intermediate', 'advanced', 'pro', 'endurance', 'sprint'];
const category = faker.helpers.arrayElement(categories);
// Generate region and languages
const region = faker.helpers.arrayElement(regions);
const languageCount = faker.number.int({ min: 1, max: 3 });
@@ -273,6 +282,7 @@ export class RacingTeamFactory {
totalWins,
totalRaces,
rating,
category,
});
});