From 04e4dd09f9a8956fae1d4446c7df790a1fe47929 Mon Sep 17 00:00:00 2001 From: Maris Popens Date: Thu, 24 Sep 2026 13:26:22 +0300 Subject: [PATCH] fix: consistent team names - McLaren, and OpenF1's names matched to the rest formatTeamName rebuilt names from Ergast constructor ids by capitalising words, so "mclaren" came out as "Mclaren" on the drivers standings tile. And latest_session passed OpenF1's own team names through, so the same team read "Red Bull Racing" there but "Red Bull" everywhere else. --- latest.go | 17 +++++++++++++++-- main_test.go | 15 ++++++++++++++- standings.go | 7 +++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/latest.go b/latest.go index 05a651d..9625184 100644 --- a/latest.go +++ b/latest.go @@ -6,7 +6,6 @@ import ( "math" "net/http" "sort" - "strings" "time" "github.com/labstack/echo/v4" @@ -140,7 +139,7 @@ func (a *app) fetchSessionResults(key string, at, now time.Time) ([]map[string]a driver := fmt.Sprint(r.DriverNumber) row := map[string]any{"position": nil, "driver": driver, "surname": driver, "team": "", "laps": r.Laps} if i, ok := byNumber[r.DriverNumber]; ok { - row["driver"], row["surname"], row["team"] = drivers[i].Acronym, drivers[i].LastName, formatTeamName(strings.ReplaceAll(strings.ToLower(drivers[i].Team), " ", "_")) + row["driver"], row["surname"], row["team"] = drivers[i].Acronym, drivers[i].LastName, shortTeamName(drivers[i].Team) } if r.Position != nil { row["position"] = *r.Position @@ -209,3 +208,17 @@ func formatSessionDuration(seconds float64) string { } return fmt.Sprintf("%d:%02d.%03d", m, s, ms) } + +// shortTeamName maps OpenF1's team names onto the short names the rest of +// the API uses (from Ergast constructor ids), so tiles read consistently. +func shortTeamName(name string) string { + switch name { + case "Red Bull Racing": + return "Red Bull" + case "Racing Bulls": + return "RB" + case "Haas F1 Team": + return "Haas" + } + return name +} diff --git a/main_test.go b/main_test.go index 9e7e1d2..2dabf3a 100644 --- a/main_test.go +++ b/main_test.go @@ -226,7 +226,7 @@ func TestLatestSessionContract(t *testing.T) { result := decode(t, request(t, newServer(testApp(t, mock)), "/f1/latest_session/")) rows := result["results"].([]any) first, second, third := rows[0].(map[string]any), rows[1].(map[string]any), rows[2].(map[string]any) - if result["session"] != "Free Practice 1" || result["raceName"] != "Test Grand Prix" || first["surname"] != "Verstappen" || first["team"] != "Red Bull Racing" || first["time"] != "1:17.738" || second["time"] != "+0.162" || third["time"] != "DNF" { + if result["session"] != "Free Practice 1" || result["raceName"] != "Test Grand Prix" || first["surname"] != "Verstappen" || first["team"] != "Red Bull" || first["time"] != "1:17.738" || second["time"] != "+0.162" || third["time"] != "DNF" { t.Fatalf("unexpected response: %#v", result) } } @@ -263,3 +263,16 @@ func TestNextRaceHandsOverWhenRaceEnds(t *testing.T) { t.Fatalf("finished race should hand over: %#v", after) } } + +func TestTeamNames(t *testing.T) { + for id, want := range map[string]string{"mclaren": "McLaren", "rb": "RB", "red_bull": "Red Bull", "aston_martin": "Aston Martin"} { + if got := formatTeamName(id); got != want { + t.Errorf("formatTeamName(%q) = %q, want %q", id, got, want) + } + } + for name, want := range map[string]string{"Red Bull Racing": "Red Bull", "Racing Bulls": "RB", "Haas F1 Team": "Haas", "McLaren": "McLaren"} { + if got := shortTeamName(name); got != want { + t.Errorf("shortTeamName(%q) = %q, want %q", name, got, want) + } + } +} diff --git a/standings.go b/standings.go index 37ddbbe..52503b7 100644 --- a/standings.go +++ b/standings.go @@ -108,9 +108,12 @@ func normalizeNationality(value string) string { } return "" } + +var teamNameOverrides = map[string]string{"rb": "RB", "mclaren": "McLaren"} + func formatTeamName(value string) string { - if value == "rb" { - return "RB" + if name, ok := teamNameOverrides[value]; ok { + return name } words := strings.Fields(strings.ReplaceAll(value, "_", " ")) for i := range words {