Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func newUpstreamMock(t *testing.T) *upstreamMock {
}
switch r.URL.Path {
case "/ergast/2026/driverStandings.json":
io.WriteString(w, `{"MRData":{"StandingsTable":{"StandingsLists":[{"DriverStandings":[{"position":"1","points":"100.5","Driver":{"familyName":"Verstappen","nationality":"Dutch"},"Constructors":[{"constructorId":"red_bull"}]}]}]}}}`)
io.WriteString(w, `{"MRData":{"StandingsTable":{"StandingsLists":[{"DriverStandings":[{"position":"1","points":"100.5","wins":"4","Driver":{"familyName":"Verstappen","nationality":"Dutch"},"Constructors":[{"constructorId":"red_bull"}]}]}]}}}`)
case "/ergast/2026/constructorStandings.json":
io.WriteString(w, `{"MRData":{"StandingsTable":{"StandingsLists":[{"ConstructorStandings":[{"position":1,"points":150,"wins":3,"country":"Great Britain","flag":"gb","Constructor":{"name":"McLaren","nationality":"British","url":"https://example.test/mclaren"}}]}]}}}`)
io.WriteString(w, `{"MRData":{"StandingsTable":{"StandingsLists":[{"ConstructorStandings":[{"position":1,"points":150,"wins":3,"country":"Great Britain","flag":"gb","Constructor":{"name":"McLaren","nationality":"British","url":"https://example.test/mclaren"}},{"position":2,"points":100,"wins":0,"Constructor":{"name":"Haas F1 Team","nationality":"American","url":"https://example.test/haas"}}]}]}}}`)
case "/ergast/current/last/results.json":
io.WriteString(w, `{"MRData":{"RaceTable":{"Races":[{"season":"2026","round":"2","raceName":"Previous Grand Prix","url":"https://example.test/previous-race","date":"2026-02-22","Results":[{"position":"1","positionText":"1","laps":"57","Time":{"time":"1:30:00.000"},"Driver":{"familyName":"Verstappen","nationality":"Dutch"},"Constructor":{"constructorId":"red_bull"}},{"position":"20","positionText":"R","laps":"12","Driver":{"familyName":"Kimi Antonelli","nationality":"Italian"},"Constructor":{"constructorId":"mercedes"}}]}]}}}`)
case "/ergast/2026.json":
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestDriversContractAndCache(t *testing.T) {
server := newServer(testApp(t, mock))
result := decode(t, request(t, server, "/f1/drivers_standings/"))
driver := result["drivers"].([]any)[0].(map[string]any)
if result["season"] != float64(2026) || driver["position"] != float64(1) || driver["points"] != 100.5 || driver["teamId"] != "Red Bull" || driver["country"] != "Netherlands" || driver["flag"] != "nl" {
if result["season"] != float64(2026) || driver["position"] != float64(1) || driver["points"] != 100.5 || driver["wins"] != float64(4) || driver["teamId"] != "Red Bull" || driver["country"] != "Netherlands" || driver["flag"] != "nl" {
t.Fatalf("unexpected response: %#v", result)
}
request(t, server, "/f1/drivers_standings")
Expand All @@ -110,7 +110,7 @@ func TestConstructorsContract(t *testing.T) {
mock := newUpstreamMock(t)
result := decode(t, request(t, newServer(testApp(t, mock)), "/f1/constructors_standings/"))
item := result["constructors"].([]any)[0].(map[string]any)
if item["position"] != float64(1) || item["points"] != float64(150) || item["wins"] != float64(3) || item["country"] != "Great Britain" || item["flag"] != "gb" {
if item["position"] != float64(1) || item["points"] != float64(150) || item["wins"] != float64(3) || item["country"] != "Great Britain" || item["flag"] != "gb" || result["constructors"].([]any)[1].(map[string]any)["team"] != "Haas" {
t.Fatalf("unexpected response: %#v", result)
}
}
Expand Down
5 changes: 3 additions & 2 deletions standings.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (a *app) drivers(c echo.Context) error {
Standings []struct {
Position json.Number `json:"position"`
Points json.Number `json:"points"`
Wins json.Number `json:"wins"`
Driver struct{ FamilyName, Nationality string } `json:"Driver"`
Constructors []struct {
ID string `json:"constructorId"`
Expand All @@ -57,7 +58,7 @@ func (a *app) drivers(c echo.Context) error {
team = formatTeamName(standing.Constructors[0].ID)
}
country := normalizeNationality(standing.Driver.Nationality)
results = append(results, map[string]any{"surname": standing.Driver.FamilyName, "position": numberInt(standing.Position), "points": numberFloat(standing.Points), "teamId": team, "country": country, "flag": countryCodes[country]})
results = append(results, map[string]any{"surname": standing.Driver.FamilyName, "position": numberInt(standing.Position), "points": numberFloat(standing.Points), "wins": numberInt(standing.Wins), "teamId": team, "country": country, "flag": countryCodes[country]})
}
}
result := map[string]any{"season": year, "drivers": results}
Expand Down Expand Up @@ -94,7 +95,7 @@ func (a *app) constructors(c echo.Context) error {
if len(upstream.MRData.StandingsTable.Lists) > 0 {
for _, standing := range upstream.MRData.StandingsTable.Lists[0].Standings {
country := normalizeNationality(standing.Constructor.Nationality)
results = append(results, map[string]any{"team": standing.Constructor.Name, "position": numberInt(standing.Position), "points": numberFloat(standing.Points), "wins": numberInt(standing.Wins), "country": country, "flag": countryCodes[country], "wiki": standing.Constructor.URL})
results = append(results, map[string]any{"team": strings.TrimSuffix(standing.Constructor.Name, " F1 Team"), "position": numberInt(standing.Position), "points": numberFloat(standing.Points), "wins": numberInt(standing.Wins), "country": country, "flag": countryCodes[country], "wiki": standing.Constructor.URL})
}
}
result := map[string]any{"season": year, "constructors": results}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
</span>
</span>
<span class="shrink-0 text-right">
{{ .String "points" }}
<span class="size-h6">({{ .String "wins" }}W)</span>
{{ $w := .Int "wins" }}<span class="size-h6 color-subdue" style="display: inline-block; min-width: 3.4em;"{{ if gt $w 0 }} title="{{ $w }} {{ if eq $w 1 }}win{{ else }}wins{{ end }}"{{ end }}>{{ if gt $w 0 }}🏆 {{ $w }}{{ end }}</span> <span title="Points">{{ .String "points" }}</span>
</span>
</li>
{{ end }}
Expand Down
4 changes: 3 additions & 1 deletion widgets/drivers-championship/f1_drivers_championship.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<span class="size-h6">({{ .String "teamId" }})</span>
{{ end }}
</div>
<span class="shrink-0 text-right">{{ .String "points" }}</span>
<span class="shrink-0 text-right">
{{ $w := .Int "wins" }}<span class="size-h6 color-subdue" style="display: inline-block; min-width: 3.4em;"{{ if gt $w 0 }} title="{{ $w }} {{ if eq $w 1 }}win{{ else }}wins{{ end }}"{{ end }}>{{ if gt $w 0 }}🏆 {{ $w }}{{ end }}</span> <span title="Points">{{ .String "points" }}</span>
</span>
</li>
{{ end }}
</ul>
Loading