feat: add track seeding migrations, catalog definitions, and test infrastructure for race leaderboards

This commit is contained in:
2026-07-15 18:59:58 +04:00
parent a56841237d
commit 53288ea670
7 changed files with 1668 additions and 1243 deletions
+6 -6
View File
@@ -294,17 +294,17 @@ func TestLeaderboard(t *testing.T) {
t.Fatalf("expected 3 calendar entries, got %d", len(res))
}
// 1. Monaco (finished)
if res[0].TrackID != "monaco" || res[0].Status != "finished" {
t.Errorf("expected monaco (finished), got %s (%s)", res[0].TrackID, res[0].Status)
// 1. Austria (planned)
if res[0].TrackID != "austria-redbull-ring" || res[0].Status != "planned" {
t.Errorf("expected austria-redbull-ring (planned), got %s (%s)", res[0].TrackID, res[0].Status)
}
// 2. Barcelona (active)
if res[1].TrackID != "barcelona-catalunya" || res[1].Status != "active" {
t.Errorf("expected barcelona-catalunya (active), got %s (%s)", res[1].TrackID, res[1].Status)
}
// 3. Austria (planned)
if res[2].TrackID != "austria-redbull-ring" || res[2].Status != "planned" {
t.Errorf("expected austria-redbull-ring (planned), got %s (%s)", res[2].TrackID, res[2].Status)
// 3. Monaco (finished)
if res[2].TrackID != "monaco" || res[2].Status != "finished" {
t.Errorf("expected monaco (finished), got %s (%s)", res[2].TrackID, res[2].Status)
}
})
}
+41 -42
View File
@@ -30,29 +30,34 @@ var DefaultNow = time.Now
var fallbackTracks = []string{"default"}
var defaultDriverSeeds = []struct {
nick string
name string
id string
nick string
name string
avatarURL string
clanID string
createdMs int64
updatedMs int64
}{
{"ACE", "Alice"},
{"BOB", "Bob"},
{"CAR", "Carol"},
{"DAV", "Dave"},
{"EVE", "Eve"},
{"FRA", "Frank"},
{"GRA", "Grace"},
{"HEI", "Heidi"},
{"IVY", "Ivy"},
{"JAC", "Jack"},
{"KEN", "Ken"},
{"LEO", "Leo"},
{"MAX", "Max"},
{"NED", "Ned"},
{"OLI", "Oliver"},
{"PEP", "Peggy"},
{"QIN", "Quincy"},
{"ROY", "Roy"},
{"SAM", "Sam"},
{"TED", "Ted"},
{"driver-seed-001", "BOR", "Gabriel Bortoleto", "https://minio.is1di.ru/x0gp/avatar/gabriel-bortoleto-f1-driver-profile-picture.webp", "clan-seed-001", 1784120584003, 1784120584003},
{"driver-seed-002", "HUL", "Nico Hulkenberg", "https://minio.is1di.ru/x0gp/avatar/nico-hulkenberg-f1-driver-profile-picture.webp", "clan-seed-002", 1784120584003, 1784120584007},
{"driver-seed-003", "ALB", "Alex Albon", "https://minio.is1di.ru/x0gp/avatar/alex-albon-f1-driver-profile-picture.webp", "clan-seed-003", 1784120584003, 1784120584008},
{"driver-seed-004", "SAI", "Carlos Sainz", "https://minio.is1di.ru/x0gp/avatar/carlos-sainz-f1-driver-profile-picture.webp", "clan-seed-001", 1784120584003, 1784120584011},
{"driver-seed-005", "BEA", "Oliver Bearman", "https://minio.is1di.ru/x0gp/avatar/oliver-bearman-f1-driver-profile-picture.webp", "clan-seed-002", 1784120584003, 1784120584012},
{"driver-seed-006", "OCO", "Esteban Ocon", "https://minio.is1di.ru/x0gp/avatar/esteban-ocon-f1-driver-profile-picture.webp", "clan-seed-003", 1784120584003, 1784120584014},
{"driver-seed-007", "LIN", "Arvid Lindblad", "https://minio.is1di.ru/x0gp/avatar/arvid-lindblad-f1-driver-profile-picture.webp", "clan-seed-001", 1784120584003, 1784120584018},
{"driver-seed-008", "LAW", "Liam Lawson", "https://minio.is1di.ru/x0gp/avatar/liam-lawson-f1-driver-profile-picture.webp", "clan-seed-002", 1784120584003, 1784120584018},
{"driver-seed-009", "COL", "Franco Colapinto", "https://minio.is1di.ru/x0gp/avatar/franco-colapinto-f1-driver-profile-picture.webp", "clan-seed-003", 1784120584003, 1784120584020},
{"driver-seed-010", "GAS", "Pierre Gasly", "https://minio.is1di.ru/x0gp/avatar/pierre-gasly-f1-driver-profile-picture.webp", "clan-seed-001", 1784120584003, 1784120584023},
{"driver-seed-011", "STR", "Lance Stroll", "https://minio.is1di.ru/x0gp/avatar/lance-stroll-f1-driver-profile-picture.webp", "clan-seed-002", 1784120584003, 1784120584023},
{"driver-seed-012", "ALO", "Fernando Alonso", "https://minio.is1di.ru/x0gp/avatar/fernando-alonso-f1-driver-profile-picture.webp", "clan-seed-003", 1784120584003, 1784120584026},
{"driver-seed-013", "ANT", "Kimi Antonelli", "https://minio.is1di.ru/x0gp/avatar/kimi-antonelli-f1-driver-profile-picture.webp", "clan-seed-001", 1784120584003, 1784120584028},
{"driver-seed-014", "RUS", "George Russel", "https://minio.is1di.ru/x0gp/avatar/george-russell-f1-driver-profile-picture.webp", "clan-seed-002", 1784120584003, 1784120584028},
{"driver-seed-015", "HAD", "Isack Hadjar", "https://minio.is1di.ru/x0gp/avatar/isack-hadjar-f1-driver-profile-picture.webp", "clan-seed-003", 1784120584003, 1784120584031},
{"driver-seed-016", "VER", "Max Verstappen", "https://minio.is1di.ru/x0gp/avatar/max-verstappen-f1-driver-profile-picture.webp", "clan-seed-001", 1784120584003, 1784120584033},
{"driver-seed-017", "HAM", "Lewis Hamilton", "https://minio.is1di.ru/x0gp/avatar/lewis-hamilton-f1-driver-profile-picture.webp", "clan-seed-002", 1784120584003, 1784120584034},
{"driver-seed-018", "NOR", "Lando Norris", "https://minio.is1di.ru/x0gp/avatar/lando-norris-f1-driver-profile-picture.webp", "clan-seed-003", 1784120584003, 1784120584036},
{"driver-seed-019", "LEC", "Charles Leclerc", "https://minio.is1di.ru/x0gp/avatar/charles-leclerc-f1-driver-profile-picture.webp", "clan-seed-001", 1784120584003, 1784120584038},
{"driver-seed-020", "PIA", "Oscar Piastri", "https://minio.is1di.ru/x0gp/avatar/oscar-piastri-f1-driver-profile-picture.webp", "clan-seed-002", 1784120584003, 1784120584039},
}
// Default clans.
@@ -96,8 +101,8 @@ type Runner struct {
// Filled by loadInputs.
trackIDs []string
driverIDs []string // driver ids in the order they exist after seed
driverInfo []seedDriver // id, nick, name, clanID, clanTag
driverIDs []string // driver ids in the order they exist after seed
driverInfo []seedDriver // id, nick, name, clanID, clanTag
clanByID map[string]string // clan id -> tag (for fast profile updates)
}
@@ -221,11 +226,11 @@ func (r *Runner) Run(ctx context.Context, opt Options) (Summary, error) {
// 3. Race plans. Mix of one-shot and recurring.
planShapes := []planShape{
{intervalS: 0, offsetS: 5 * 60}, // one-shot in 5 min
{intervalS: 60, offsetS: 30 * 60}, // every minute, start in 30 min
{intervalS: 3600, count: 24, offsetS: 60 * 60}, // hourly x24, start in 1h
{intervalS: 0, offsetS: 6 * 3600}, // one-shot in 6h
{intervalS: 86400, offsetS: 24 * 3600}, // daily, start tomorrow
{intervalS: 0, offsetS: 5 * 60}, // one-shot in 5 min
{intervalS: 60, offsetS: 30 * 60}, // every minute, start in 30 min
{intervalS: 3600, count: 24, offsetS: 60 * 60}, // hourly x24, start in 1h
{intervalS: 0, offsetS: 6 * 3600}, // one-shot in 6h
{intervalS: 86400, offsetS: 24 * 3600}, // daily, start tomorrow
}
for i := 0; i < opt.Counts.Plans && i < len(planShapes); i++ {
ps := planShapes[i]
@@ -246,7 +251,7 @@ func (r *Runner) Run(ctx context.Context, opt Options) (Summary, error) {
func (r *Runner) seedTrackCalendar(ctx context.Context) error {
now := r.now
if len(r.trackIDs) == 0 {
return nil
}
@@ -353,21 +358,15 @@ func (r *Runner) seedDriversAndClans(ctx context.Context) error {
return fmt.Errorf("count drivers: %w", err)
}
if drvCount == 0 {
now := time.Now().UnixMilli()
// Round-robin: each driver assigned to one of the seeded clans.
clanIDs := make([]string, 0, len(defaultClanSeeds))
for i := range defaultClanSeeds {
clanIDs = append(clanIDs, fmt.Sprintf("clan-seed-%03d", i+1))
}
for i, ds := range defaultDriverSeeds {
for _, ds := range defaultDriverSeeds {
d := drivers.Driver{
ID: fmt.Sprintf("driver-seed-%03d", i+1),
ID: ds.id,
Nickname: ds.nick,
Name: ds.name,
AvatarURL: fmt.Sprintf("https://cdn.example.com/drivers/%s.png", ds.nick),
ClanID: clanIDs[i%len(clanIDs)],
CreatedMs: now,
UpdatedMs: now,
AvatarURL: ds.avatarURL,
ClanID: ds.clanID,
CreatedMs: ds.createdMs,
UpdatedMs: ds.updatedMs,
}
if err := r.driversPg.Create(ctx, d); err != nil {
return fmt.Errorf("insert driver %s: %w", ds.nick, err)