website refactor
This commit is contained in:
@@ -105,16 +105,22 @@ export class RacingMembershipFactory {
|
||||
}
|
||||
|
||||
// Spread remaining drivers across remaining leagues to create realistic overlap.
|
||||
// IMPORTANT: in postgres mode league ids are UUIDs, so never parse numeric suffixes from ids.
|
||||
for (const driver of drivers) {
|
||||
const driverId = driver.id.toString();
|
||||
const driverNumber = Number(driverId.split('-')[1]);
|
||||
|
||||
for (const league of leagues) {
|
||||
const leagueId = league.id.toString();
|
||||
if (leagueId === seedId('league-5', this.persistence)) continue;
|
||||
if (emptyLeagueId && leagueId === emptyLeagueId) continue;
|
||||
|
||||
if (driverNumber % 11 === 0 && leagueId === seedId('league-3', this.persistence)) {
|
||||
// Deterministic membership distribution that works with UUID ids.
|
||||
// Use stable hash of (driverId + leagueId) rather than parsing numeric suffixes.
|
||||
const distKey = `${driverId}:${leagueId}`;
|
||||
const dist = this.stableHash(distKey);
|
||||
|
||||
// Some inactive memberships for league-3 to exercise edge cases.
|
||||
if (leagueId === seedId('league-3', this.persistence) && dist % 11 === 0) {
|
||||
add({
|
||||
leagueId,
|
||||
driverId,
|
||||
@@ -126,7 +132,7 @@ export class RacingMembershipFactory {
|
||||
}
|
||||
|
||||
// Sparse membership distribution (not every driver in every league)
|
||||
if ((driverNumber + Number(leagueId.split('-')[1] ?? 0)) % 9 === 0) {
|
||||
if (dist % 9 === 0) {
|
||||
add({
|
||||
leagueId,
|
||||
driverId,
|
||||
@@ -330,6 +336,15 @@ export class RacingMembershipFactory {
|
||||
return registrations;
|
||||
}
|
||||
|
||||
private stableHash(input: string): number {
|
||||
// Simple deterministic string hash (non-crypto), stable across runs.
|
||||
let hash = 0;
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
hash = (hash * 31 + input.charCodeAt(i)) | 0;
|
||||
}
|
||||
return Math.abs(hash);
|
||||
}
|
||||
|
||||
private addDays(date: Date, days: number): Date {
|
||||
return new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user