Match a race's circuit on Jolpica's circuitId, not its name

Jolpica renamed Losail to Lusail International Circuit, so the name match
found no circuit and every Qatar Grand Prix poster, thumb and track image
answered 404 (reported by Brad Johnston for 2025 and 2026; every season
since 2021 failed). Names drift, ids do not: each circuit in circuits.json
now carries its ergastId, the lookup keys on it, and the poster's zoom
fallback resolves our circuit slug the same way. The name match also sent
Caesars Palace (1981-82) to the Las Vegas Strip circuit; by id it resolves
to nothing, as there is no layout of it.

tests/ checks every circuit has one unique ergastId and that a race
resolves by id; the merge check runs it.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
This commit is contained in:
2026-11-27 09:40:27 +01:00
parent 60c4f20158
commit 11c17cb9ad
9 changed files with 183 additions and 23 deletions
+77
View File
@@ -5,6 +5,7 @@
"circuits": {
"autodromo-juan-y-oscar-gálvez": {
"name": "Autodromo Juan y Oscar Gálvez",
"ergastId": "galvez",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Aut%C3%B3dromo_Oscar_Alfredo_G%C3%A1lvez",
"fandom": "https://f1.fandom.com/wiki/Aut%C3%B3dromo_Juan_y_Oscar_G%C3%A1lvez"
@@ -40,6 +41,7 @@
"circuits": {
"adelaide-street-circuit": {
"name": "Adelaide Street Circuit",
"ergastId": "adelaide",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Adelaide_Street_Circuit",
"fandom": "https://f1.fandom.com/wiki/Adelaide_Street_Circuit"
@@ -58,6 +60,7 @@
"circuits": {
"albert-park-grand-prix-circuit": {
"name": "Albert Park Grand Prix Circuit",
"ergastId": "albert_park",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Melbourne_Grand_Prix_Circuit",
"fandom": "https://f1.fandom.com/wiki/Albert_Park_Circuit"
@@ -85,6 +88,7 @@
"circuits": {
"red-bull-ring": {
"name": "Red Bull Ring",
"ergastId": "red_bull_ring",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Red_Bull_Ring",
"fandom": "https://f1.fandom.com/wiki/Red_Bull_Ring"
@@ -115,6 +119,7 @@
"circuits": {
"zeltweg": {
"name": "Zeltweg",
"ergastId": "zeltweg",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Zeltweg_Airfield",
"fandom": "https://f1.fandom.com/wiki/Zeltweg_Airfield"
@@ -138,6 +143,7 @@
"circuits": {
"baku-city-circuit": {
"name": "Baku City Circuit",
"ergastId": "baku",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Baku_City_Circuit",
"fandom": "https://f1.fandom.com/wiki/Baku_City_Circuit"
@@ -161,6 +167,7 @@
"circuits": {
"bahrain-international-circuit": {
"name": "Bahrain International Circuit",
"ergastId": "bahrain",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Bahrain_International_Circuit",
"fandom": "https://f1.fandom.com/wiki/Bahrain_International_Circuit"
@@ -192,6 +199,7 @@
"circuits": {
"nivelles-baulers": {
"name": "Nivelles-Baulers",
"ergastId": "nivelles",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Nivelles-Baulers",
"fandom": "https://f1.fandom.com/wiki/Nivelles-Baulers"
@@ -210,6 +218,7 @@
"circuits": {
"zolder": {
"name": "Zolder",
"ergastId": "zolder",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Zolder",
"fandom": "https://f1.fandom.com/wiki/Circuit_Zolder"
@@ -228,6 +237,7 @@
"circuits": {
"circuit-de-spa-francorchamps": {
"name": "Circuit de Spa-Francorchamps",
"ergastId": "spa",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_de_Spa-Francorchamps",
"fandom": "https://f1.fandom.com/wiki/Circuit_de_Spa-Francorchamps"
@@ -255,6 +265,7 @@
"circuits": {
"autodromo-internacional-nelson-piquet": {
"name": "Autodromo Internacional Nelson Piquet",
"ergastId": "jacarepagua",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Aut%C3%B3dromo_Internacional_Nelson_Piquet",
"fandom": "https://f1.fandom.com/wiki/Aut%C3%B3dromo_Internacional_Nelson_Piquet"
@@ -273,6 +284,7 @@
"circuits": {
"autódromo-josé-carlos-pace": {
"name": "Autodromo Jose Carlos Pace",
"ergastId": "interlagos",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Aut%C3%B3dromo_Jos%C3%A9_Carlos_Pace",
"fandom": "https://f1.fandom.com/wiki/Aut%C3%B3dromo_Jos%C3%A9_Carlos_Pace"
@@ -300,6 +312,7 @@
"circuits": {
"circuit-gilles-villeneuve": {
"name": "Circuit Gilles Villeneuve",
"ergastId": "villeneuve",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_Gilles_Villeneuve",
"fandom": "https://f1.fandom.com/wiki/Circuit_Gilles_Villeneuve"
@@ -318,6 +331,7 @@
"circuits": {
"mosport-international-raceway": {
"name": "Mosport International Raceway",
"ergastId": "mosport",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Mosport",
"fandom": "https://f1.fandom.com/wiki/Mosport_Park"
@@ -336,6 +350,7 @@
"circuits": {
"circuit-mont-tremblant": {
"name": "Circuit Mont-Tremblant",
"ergastId": "tremblant",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_Mont-Tremblant",
"fandom": "https://f1.fandom.com/wiki/Circuit_Mont-Tremblant"
@@ -359,6 +374,7 @@
"circuits": {
"shanghai-international-circuit": {
"name": "Shanghai International Circuit",
"ergastId": "shanghai",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Shanghai_International_Circuit",
"fandom": "https://f1.fandom.com/wiki/Shanghai_International_Circuit"
@@ -382,6 +398,7 @@
"circuits": {
"charade-circuit": {
"name": "Charade Circuit",
"ergastId": "charade",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Charade_Circuit",
"fandom": "https://f1.fandom.com/wiki/Charade_Circuit"
@@ -400,6 +417,7 @@
"circuits": {
"dijon-prenois": {
"name": "Dijon-Prenois",
"ergastId": "dijon",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Dijon-Prenois",
"fandom": "https://f1.fandom.com/wiki/Dijon-Prenois"
@@ -418,6 +436,7 @@
"circuits": {
"circuit-paul-ricard": {
"name": "Circuit Paul Ricard",
"ergastId": "ricard",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Paul_Ricard_Circuit",
"fandom": "https://f1.fandom.com/wiki/Circuit_Paul_Ricard"
@@ -444,6 +463,7 @@
"circuits": {
"le-mans": {
"name": "Bugatti Circuit",
"ergastId": "lemans",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_de_la_Sarthe#Bugatti_Circuit",
"fandom": "https://f1.fandom.com/wiki/Bugatti_Circuit"
@@ -462,6 +482,7 @@
"circuits": {
"circuit-de-nevers-magny-cours": {
"name": "Circuit de Nevers Magny-Cours",
"ergastId": "magny_cours",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_de_Nevers_Magny-Cours",
"fandom": "https://f1.fandom.com/wiki/Circuit_de_Nevers_Magny-Cours"
@@ -480,6 +501,7 @@
"circuits": {
"reims-gueux": {
"name": "Reims-Gueux",
"ergastId": "reims",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Reims-Gueux",
"fandom": "https://f1.fandom.com/wiki/Reims"
@@ -502,6 +524,7 @@
"circuits": {
"rouen-les-essarts": {
"name": "Rouen-Les-Essarts",
"ergastId": "essarts",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Rouen-Les-Essarts",
"fandom": "https://f1.fandom.com/wiki/Rouen-Les-Essarts"
@@ -529,6 +552,7 @@
"circuits": {
"avus": {
"name": "AVUS",
"ergastId": "avus",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/AVUS",
"fandom": "https://f1.fandom.com/wiki/AVUS"
@@ -547,6 +571,7 @@
"circuits": {
"hockenheimring": {
"name": "Hockenheimring",
"ergastId": "hockenheimring",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Hockenheimring",
"fandom": "https://f1.fandom.com/wiki/Hockenheimring"
@@ -565,6 +590,7 @@
"circuits": {
"nürburgring": {
"name": "Nurburgring",
"ergastId": "nurburgring",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/N%C3%BCrburgring",
"fandom": "https://f1.fandom.com/wiki/N%C3%BCrburgring"
@@ -588,6 +614,7 @@
"circuits": {
"hungaroring": {
"name": "Hungaroring",
"ergastId": "hungaroring",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Hungaroring",
"fandom": "https://f1.fandom.com/wiki/Hungaroring"
@@ -619,6 +646,7 @@
"circuits": {
"buddh-international-circuit": {
"name": "Buddh International Circuit",
"ergastId": "buddh",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Buddh_International_Circuit",
"fandom": "https://f1.fandom.com/wiki/Buddh_International_Circuit"
@@ -642,6 +670,7 @@
"circuits": {
"autodromo-enzo-e-dino-ferrari": {
"name": "Autodromo Enzo e Dino Ferrari",
"ergastId": "imola",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Autodromo_Enzo_e_Dino_Ferrari",
"fandom": "https://f1.fandom.com/wiki/Autodromo_Enzo_e_Dino_Ferrari"
@@ -668,6 +697,7 @@
"circuits": {
"autodromo-nazionale-di-monza": {
"name": "Autodromo Nazionale di Monza",
"ergastId": "monza",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Autodromo_Nazionale_Monza",
"fandom": "https://f1.fandom.com/wiki/Autodromo_Nazionale_Monza"
@@ -686,6 +716,7 @@
"circuits": {
"autodromo-internazionale-del-mugello": {
"name": "Autodromo Internazionale del Mugello",
"ergastId": "mugello",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Mugello_Circuit",
"fandom": "https://f1.fandom.com/wiki/Mugello_Circuit"
@@ -704,6 +735,7 @@
"circuits": {
"pescara-circuit": {
"name": "Pescara Circuit",
"ergastId": "pescara",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Pescara_Circuit",
"fandom": "https://f1.fandom.com/wiki/Pescara_Circuit"
@@ -727,6 +759,7 @@
"circuits": {
"okayama-international-circuit": {
"name": "Okayama International Circuit",
"ergastId": "okayama",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/TI_Circuit",
"fandom": "https://f1.fandom.com/wiki/Okayama_International_Circuit"
@@ -745,6 +778,7 @@
"circuits": {
"fuji-speedway": {
"name": "Fuji Speedway",
"ergastId": "fuji",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Fuji_Speedway",
"fandom": "https://f1.fandom.com/wiki/Fuji_Speedway"
@@ -767,6 +801,7 @@
"circuits": {
"suzuka-circuit": {
"name": "Suzuka Circuit",
"ergastId": "suzuka",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Suzuka_Circuit",
"fandom": "https://f1.fandom.com/wiki/Suzuka_International_Racing_Course"
@@ -790,6 +825,7 @@
"circuits": {
"korean-international-circuit": {
"name": "Korean International Circuit",
"ergastId": "yeongam",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Korean_International_Circuit",
"fandom": "https://f1.fandom.com/wiki/Korea_International_Circuit"
@@ -813,6 +849,7 @@
"circuits": {
"sepang-international-circuit": {
"name": "Sepang International Circuit",
"ergastId": "sepang",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Sepang_International_Circuit",
"fandom": "https://f1.fandom.com/wiki/Sepang_International_Circuit"
@@ -836,6 +873,7 @@
"circuits": {
"autódromo-hermanos-rodríguez": {
"name": "Autodromo Hermanos Rodriguez",
"ergastId": "rodriguez",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Aut%C3%B3dromo_Hermanos_Rodr%C3%ADguez",
"fandom": "https://f1.fandom.com/wiki/Aut%C3%B3dromo_Hermanos_Rodr%C3%ADguez"
@@ -867,6 +905,7 @@
"circuits": {
"circuit-de-monaco": {
"name": "Circuit de Monaco",
"ergastId": "monaco",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_de_Monaco",
"fandom": "https://f1.fandom.com/wiki/Circuit_de_Monaco"
@@ -914,6 +953,7 @@
"circuits": {
"ain-diab": {
"name": "Ain Diab",
"ergastId": "ain-diab",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Ain-Diab_Circuit",
"fandom": "https://f1.fandom.com/wiki/Ain-Diab_Circuit"
@@ -937,6 +977,7 @@
"circuits": {
"circuit-park-zandvoort": {
"name": "Circuit Park Zandvoort",
"ergastId": "zandvoort",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_Zandvoort",
"fandom": "https://f1.fandom.com/wiki/Circuit_Zandvoort"
@@ -968,6 +1009,7 @@
"circuits": {
"autódromo-do-estoril": {
"name": "Autódromo do Estoril",
"ergastId": "estoril",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Aut%C3%B3dromo_do_Estoril",
"fandom": "https://f1.fandom.com/wiki/Aut%C3%B3dromo_do_Estoril"
@@ -990,6 +1032,7 @@
"circuits": {
"monsanto-park-circuit": {
"name": "Monsanto Park Circuit",
"ergastId": "monsanto",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Monsanto_Park_Circuit",
"fandom": "https://f1.fandom.com/wiki/Circuito_de_Monsanto"
@@ -1008,6 +1051,7 @@
"circuits": {
"circuito-da-boavista": {
"name": "Circuito da Boavista",
"ergastId": "boavista",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuito_da_Boavista",
"fandom": "https://f1.fandom.com/wiki/Circuito_da_Boavista"
@@ -1026,6 +1070,7 @@
"circuits": {
"autodromo-internacional-do-algarve": {
"name": "Autodromo Internacional do Algarve",
"ergastId": "portimao",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Algarve_International_Circuit",
"fandom": "https://f1.fandom.com/wiki/Algarve_International_Circuit"
@@ -1049,6 +1094,7 @@
"circuits": {
"losail-international-circuit": {
"name": "Losail International Circuit",
"ergastId": "losail",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Losail_International_Circuit",
"fandom": "https://f1.fandom.com/wiki/Lusail_International_Circuit"
@@ -1072,6 +1118,7 @@
"circuits": {
"sochi-autodrom": {
"name": "Sochi Autodrom",
"ergastId": "sochi",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Sochi_Autodrom",
"fandom": "https://f1.fandom.com/wiki/Sochi_Autodrom"
@@ -1095,6 +1142,7 @@
"circuits": {
"jeddah-corniche-circuit": {
"name": "Jeddah Corniche Circuit",
"ergastId": "jeddah",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Jeddah_Street_Circuit",
"fandom": "https://f1.fandom.com/wiki/Jeddah_Corniche_Circuit"
@@ -1118,6 +1166,7 @@
"circuits": {
"marina-bay-street-circuit": {
"name": "Marina Bay Street Circuit",
"ergastId": "marina_bay",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Marina_Bay_Street_Circuit",
"fandom": "https://f1.fandom.com/wiki/Marina_Bay_Street_Circuit"
@@ -1145,6 +1194,7 @@
"circuits": {
"prince-george-circuit": {
"name": "Prince George Circuit",
"ergastId": "george",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Prince_George_Circuit",
"fandom": "https://f1.fandom.com/wiki/Prince_George_Circuit"
@@ -1163,6 +1213,7 @@
"circuits": {
"kyalami": {
"name": "Kyalami",
"ergastId": "kyalami",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Kyalami",
"fandom": "https://f1.fandom.com/wiki/Kyalami_Circuit"
@@ -1190,6 +1241,7 @@
"circuits": {
"circuit-de-pedralbes": {
"name": "Circuit de Pedralbes",
"ergastId": "pedralbes",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Pedralbes_Circuit",
"fandom": "https://f1.fandom.com/wiki/Pedralbes_Circuit"
@@ -1203,6 +1255,7 @@
},
"montjuïc": {
"name": "Montjuïc",
"ergastId": "montjuic",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Montju%C3%AFc_circuit",
"fandom": "https://f1.fandom.com/wiki/Montju%C3%AFc_Park_Circuit"
@@ -1221,6 +1274,7 @@
"circuits": {
"circuito-de-jerez": {
"name": "Circuito de Jerez",
"ergastId": "jerez",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuito_Permanente_de_Jerez",
"fandom": "https://f1.fandom.com/wiki/Circuito_de_Jerez"
@@ -1243,6 +1297,7 @@
"circuits": {
"jarama": {
"name": "Jarama",
"ergastId": "jarama",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuito_Permanente_Del_Jarama",
"fandom": "https://f1.fandom.com/wiki/Circuito_del_Jarama"
@@ -1256,6 +1311,7 @@
},
"madring": {
"name": "Madring",
"ergastId": "madring",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Madring",
"fandom": "https://f1.fandom.com/wiki/Madring"
@@ -1274,6 +1330,7 @@
"circuits": {
"circuit-de-barcelona-catalunya": {
"name": "Circuit de Barcelona-Catalunya",
"ergastId": "catalunya",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_de_Barcelona-Catalunya",
"fandom": "https://f1.fandom.com/wiki/Circuit_de_Barcelona-Catalunya"
@@ -1312,6 +1369,7 @@
"circuits": {
"valencia-street-circuit": {
"name": "Valencia Street Circuit",
"ergastId": "valencia",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Valencia_Street_Circuit",
"fandom": "https://f1.fandom.com/wiki/Valencia_Street_Circuit"
@@ -1335,6 +1393,7 @@
"circuits": {
"scandinavian-raceway": {
"name": "Scandinavian Raceway",
"ergastId": "anderstorp",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Scandinavian_Raceway",
"fandom": "https://f1.fandom.com/wiki/Scandinavian_Raceway"
@@ -1362,6 +1421,7 @@
"circuits": {
"circuit-bremgarten": {
"name": "Circuit Bremgarten",
"ergastId": "bremgarten",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_Bremgarten",
"fandom": "https://f1.fandom.com/wiki/Circuit_Bremgarten"
@@ -1385,6 +1445,7 @@
"circuits": {
"istanbul-park": {
"name": "Istanbul Park",
"ergastId": "istanbul",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Istanbul_Park",
"fandom": "https://f1.fandom.com/wiki/Istanbul_Park"
@@ -1408,6 +1469,7 @@
"circuits": {
"yas-marina-circuit": {
"name": "Yas Marina Circuit",
"ergastId": "yas_marina",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Yas_Marina_Circuit",
"fandom": "https://f1.fandom.com/wiki/Yas_Marina_Circuit"
@@ -1431,6 +1493,7 @@
"circuits": {
"donington-park": {
"name": "Donington Park",
"ergastId": "donington",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Donington_Park",
"fandom": "https://f1.fandom.com/wiki/Donington_Park"
@@ -1449,6 +1512,7 @@
"circuits": {
"brands-hatch": {
"name": "Brands Hatch",
"ergastId": "brands_hatch",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Brands_Hatch",
"fandom": "https://f1.fandom.com/wiki/Brands_Hatch"
@@ -1471,6 +1535,7 @@
"circuits": {
"aintree": {
"name": "Aintree",
"ergastId": "aintree",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Aintree_Motor_Racing_Circuit",
"fandom": "https://f1.fandom.com/wiki/Aintree_Motor_Racing_Circuit"
@@ -1489,6 +1554,7 @@
"circuits": {
"silverstone-circuit": {
"name": "Silverstone Circuit",
"ergastId": "silverstone",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Silverstone_Circuit",
"fandom": "https://f1.fandom.com/wiki/Silverstone_Circuit"
@@ -1512,6 +1578,7 @@
"circuits": {
"circuit-of-the-americas": {
"name": "Circuit of the Americas",
"ergastId": "americas",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Circuit_of_the_Americas",
"fandom": "https://f1.fandom.com/wiki/Circuit_of_the_Americas"
@@ -1530,6 +1597,7 @@
"circuits": {
"riverside-international-raceway": {
"name": "Riverside International Raceway",
"ergastId": "riverside",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Riverside_International_Raceway",
"fandom": "https://f1.fandom.com/wiki/Riverside_International_Raceway"
@@ -1543,6 +1611,7 @@
},
"long-beach": {
"name": "Long Beach",
"ergastId": "long_beach",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Long_Beach,_California",
"fandom": "https://f1.fandom.com/wiki/Long_Beach_Street_Circuit"
@@ -1569,6 +1638,7 @@
"circuits": {
"fair-park": {
"name": "Fair Park",
"ergastId": "dallas",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Fair_Park",
"fandom": "https://f1.fandom.com/wiki/Dallas_Grand_Prix_Circuit"
@@ -1587,6 +1657,7 @@
"circuits": {
"detroit-street-circuit": {
"name": "Detroit Street Circuit",
"ergastId": "detroit",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Detroit_street_circuit",
"fandom": "https://f1.fandom.com/wiki/Detroit_Street_Circuit"
@@ -1605,6 +1676,7 @@
"circuits": {
"sebring-international-raceway": {
"name": "Sebring International Raceway",
"ergastId": "sebring",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Sebring_Raceway",
"fandom": "https://f1.fandom.com/wiki/Sebring_International_Raceway"
@@ -1623,6 +1695,7 @@
"circuits": {
"indianapolis-motor-speedway": {
"name": "Indianapolis Motor Speedway",
"ergastId": "indianapolis",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Indianapolis_Motor_Speedway",
"fandom": "https://f1.fandom.com/wiki/Indianapolis_Motor_Speedway"
@@ -1645,6 +1718,7 @@
"circuits": {
"miami-international-autodrome": {
"name": "Miami International Autodrome",
"ergastId": "miami",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Miami_International_Autodrome",
"fandom": "https://f1.fandom.com/wiki/Miami_International_Autodrome"
@@ -1663,6 +1737,7 @@
"circuits": {
"las-vegas-strip-street-circuit": {
"name": "Las Vegas Street Circuit",
"ergastId": "vegas",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Las_Vegas_Street_Circuit",
"fandom": "https://f1.fandom.com/wiki/Las_Vegas_Strip_Circuit"
@@ -1681,6 +1756,7 @@
"circuits": {
"watkins-glen": {
"name": "Watkins Glen",
"ergastId": "watkins_glen",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Watkins_Glen_International",
"fandom": "https://f1.fandom.com/wiki/Watkins_Glen_International"
@@ -1699,6 +1775,7 @@
"circuits": {
"phoenix-street-circuit": {
"name": "Phoenix street circuit",
"ergastId": "phoenix",
"urls": {
"wikipedia": "https://en.wikipedia.org/wiki/Phoenix_street_circuit",
"fandom": "https://f1.fandom.com/wiki/Phoenix_Street_Circuit"
+18 -16
View File
@@ -36,22 +36,23 @@ class ErgastService:
def __init__(self, circuits_service: 'CircuitService' = None):
self.circuits_service = circuits_service
self.logger = logging.getLogger(__name__)
self._circuit_name_index = self._build_circuit_name_index()
self._circuit_id_index = self._build_circuit_id_index()
def _build_circuit_name_index(self) -> dict[str, tuple[str, str, str]]:
"""Build a lookup from slugified circuit name → (country_slug, locality_slug, circuit_slug)."""
def _build_circuit_id_index(self) -> dict[str, tuple[str, str, str]]:
"""Build a lookup from Jolpica's circuitId → (country_slug, locality_slug, circuit_slug).
A race's circuit is matched on its circuitId, never on its name: Jolpica renames
circuits (Losail became Lusail) while the id stays the same."""
index = {}
if not self.circuits_service:
return index
for country_slug, country in self.circuits_service.circuit_data.items():
for locality_slug, locality in country.localities.items():
for circuit_slug, circuit in locality.circuits.items():
# Index by our circuit slug (which is the slugified circuit name)
index[circuit_slug] = (country_slug, locality_slug, circuit_slug)
# Also index by ASCII-slugified version for unicode mismatches
ascii_slug = slugify(circuit.name)
if ascii_slug not in index:
index[ascii_slug] = (country_slug, locality_slug, circuit_slug)
if not circuit.ergast_id:
self.logger.error(f"Circuit '{circuit_slug}' has no ergastId: no race can resolve to it")
continue
index[circuit.ergast_id] = (country_slug, locality_slug, circuit_slug)
return index
@lru_cache(maxsize=128)
@@ -76,12 +77,13 @@ class ErgastService:
self.logger.error(f"Race '{grand_prix_name}' not found in {season} schedule")
return None, None, None
circuit = race['Circuit']
circuit_name_slug = slugify(circuit['circuitName'])
return self.find_slugs_for_circuit(race["Circuit"])
# Try matching by slugified circuit name
if circuit_name_slug in self._circuit_name_index:
return self._circuit_name_index[circuit_name_slug]
self.logger.warning(f"Circuit '{circuit['circuitName']}' (slug: {circuit_name_slug}) not found in index")
def find_slugs_for_circuit(self, circuit: dict) -> tuple[Optional[str], Optional[str], Optional[str]]:
"""Resolve a Jolpica race's Circuit object to (country_slug, locality_slug, circuit_slug)."""
slugs = self._circuit_id_index.get(circuit.get('circuitId'))
if slugs:
return slugs
self.logger.warning(f"Circuit '{circuit.get('circuitName')}' (circuitId: {circuit.get('circuitId')}) "
f"has no circuit with that ergastId in circuits.json")
return None, None, None
+7 -3
View File
@@ -8,10 +8,12 @@
# graph builds f1-circuits from this branch.
#
# What the image ships, compiled before the merge: every Python file the service's image copies, and the
# models it imports.
# models it imports. Then the tests in tests/, which need the standard library only: every circuit in
# circuits/circuits.json carries one unique ergastId, and a race's circuit resolves by that id, never by
# its name.
#
# **Said, never passed silently**: the service's dependencies (service/requirements.txt) are the image's to
# install, so the service is not started, and the repository has no tests.
# install, so the service is not started.
set -eu
# Parsed, not compiled to files: a check leaves the tree as it found it.
@@ -20,4 +22,6 @@ find cdn-api.py circuits_service.py ergast_service.py posters_service.py models
for f in sys.argv[1:]:
ast.parse(open(f, encoding="utf-8").read(), f)
print(len(sys.argv) - 1, "Python file(s) parse")'
echo "NOT RUN HERE: the service (its dependencies are the image's to install); the repository has no tests"
# -B: no bytecode written, the tree stays as it was found.
python3 -B -m unittest discover -s tests -t .
echo "NOT RUN HERE: the service (its dependencies are the image's to install)"
+5 -1
View File
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import Optional, TYPE_CHECKING
from .track_layout import TrackLayout
if TYPE_CHECKING:
@@ -18,11 +18,14 @@ class Circuit:
urls: URLs
locality: 'Locality'
layouts: dict[str, TrackLayout]
# Jolpica's (Ergast's) circuitId: the stable key a race's circuit is matched on, never its name
ergast_id: Optional[str] = None
def to_dict(self) -> dict:
return {
"slug": self.slug,
"name": self.name,
"ergastId": self.ergast_id,
"urls": {"wikipedia": self.urls.wikipedia, "fandom": self.urls.fandom},
"layouts": {k: v.to_dict() for k, v in self.layouts.items()},
}
@@ -32,6 +35,7 @@ class Circuit:
circuit = cls(
slug=slug,
name=data["name"],
ergast_id=data.get("ergastId"),
urls=URLs(**data["urls"]),
locality=locality,
layouts={}
+4 -3
View File
@@ -142,7 +142,7 @@ class PostersService:
logger.warning("No bundled font found — poster text will use PIL's default bitmap font")
self.cache_dir = Path("cache/posters")
self.cache_dir.mkdir(parents=True, exist_ok=True)
# Pre-tuned zooms per circuit, keyed by slugified circuit name.
# Pre-tuned zooms per circuit, keyed by our circuit slug (the slugified name in f1-locations.json).
# Falls back to DEFAULT_ZOOM when not found.
self._zoom_by_circuit = self._load_zoom_lookup()
@@ -392,8 +392,9 @@ class PostersService:
if "lat" not in loc or "long" not in loc:
return None
lat, lon = float(loc["lat"]), float(loc["long"])
from ergast_service import slugify
entry = self._zoom_by_circuit.get(slugify(race["Circuit"].get("circuitName", "")))
# Our circuit slug, resolved from Jolpica's circuitId: a Jolpica name never keys a lookup
_, _, circuit_slug = self.ergast.find_slugs_for_circuit(race["Circuit"])
entry = self._zoom_by_circuit.get(circuit_slug)
zoom = entry["zoom"] if entry and "zoom" in entry else self.DEFAULT_ZOOM
return lat, lon, zoom
View File
Binary file not shown.
Binary file not shown.
+72
View File
@@ -0,0 +1,72 @@
"""A race's circuit is matched on Jolpica's circuitId, never on its name.
Standard library only (no models, no numpy), so the merge check runs it as it is.
"""
import json
import unittest
from pathlib import Path
from types import SimpleNamespace
from ergast_service import ErgastService
ROOT = Path(__file__).resolve().parent.parent
CIRCUITS_JSON = ROOT / "circuits" / "circuits.json"
def circuit_data_from_json() -> dict:
"""circuits.json in the shape ErgastService reads (country → localities → circuits)."""
data = json.loads(CIRCUITS_JSON.read_text(encoding="utf-8"))
return {
country_slug: SimpleNamespace(localities={
locality_slug: SimpleNamespace(circuits={
circuit_slug: SimpleNamespace(name=circuit["name"], ergast_id=circuit.get("ergastId"))
for circuit_slug, circuit in locality["circuits"].items()
})
for locality_slug, locality in country["localities"].items()
})
for country_slug, country in data.items()
}
def service_with_schedule(races: list[dict]) -> ErgastService:
service = ErgastService(SimpleNamespace(circuit_data=circuit_data_from_json()))
service._fetch_season_schedule = lambda season: races
return service
def race(name: str, circuit_id: str, circuit_name: str) -> dict:
return {"raceName": name, "Circuit": {"circuitId": circuit_id, "circuitName": circuit_name}}
class CircuitsJsonTest(unittest.TestCase):
def test_every_circuit_has_one_unique_ergast_id(self):
ids = {}
for country_slug, country in json.loads(CIRCUITS_JSON.read_text(encoding="utf-8")).items():
for locality_slug, locality in country["localities"].items():
for circuit_slug, circuit in locality["circuits"].items():
where = f"{country_slug}/{locality_slug}/{circuit_slug}"
ergast_id = circuit.get("ergastId")
self.assertTrue(ergast_id, f"{where} has no ergastId")
self.assertNotIn(ergast_id, ids, f"{where} and {ids.get(ergast_id)} share ergastId {ergast_id}")
ids[ergast_id] = where
class FindSlugsTest(unittest.TestCase):
def test_a_renamed_circuit_resolves_by_its_id(self):
# Jolpica names it Lusail; circuits.json keeps Losail, its slug and its URLs
service = service_with_schedule([race("Qatar Grand Prix", "losail", "Lusail International Circuit")])
self.assertEqual(service.find_slugs_for_grand_prix("Qatar Grand Prix", 2025),
("qatar", "al-daayen", "losail-international-circuit"))
def test_a_matching_name_with_an_unknown_id_resolves_to_nothing(self):
# Caesars Palace (1981-82) shares the Las Vegas name; only its id tells it apart from the Strip
service = service_with_schedule([race("Caesars Palace Grand Prix", "las_vegas", "Las Vegas Street Circuit")])
self.assertEqual(service.find_slugs_for_grand_prix("Caesars Palace Grand Prix", 1981), (None, None, None))
def test_an_unknown_race_resolves_to_nothing(self):
service = service_with_schedule([])
self.assertEqual(service.find_slugs_for_grand_prix("Qatar Grand Prix", 2025), (None, None, None))
if __name__ == "__main__":
unittest.main()