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) {