mirror of
https://github.com/IS1DI/x0gp.git
synced 2026-07-16 20:47:55 +00:00
feat: add track seeding migrations, catalog definitions, and test infrastructure for race leaderboards
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user