Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Feb 4, 2024
1 parent dfdad13 commit 8a06bd5
Show file tree
Hide file tree
Showing 5 changed files with 491 additions and 135 deletions.
47 changes: 47 additions & 0 deletions dev/scripts/create_driver_translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json
import requests
import unicodedata


URL = 'https://ergast.com/api/f1/drivers.json?limit=1000'

NAMING_SCHEME_REVERSED = ['ZHO'] # last name is first


def _normalize_name(name: str) -> str:
# removes accents from a string and returns the closest possible
# ascii representation (https://stackoverflow.com/a/518232) in
# lowercase letters
stripped = ''.join(c for c in unicodedata.normalize('NFD', name)
if unicodedata.category(c) != 'Mn')
return stripped.lower()


response = requests.get(URL)
data = response.json()

if int(data['MRData']['total']) > int(data['MRData']['limit']):
raise ValueError


driver_mapping = dict()

for driver in data['MRData']['DriverTable']['Drivers']:
code = driver.get('code')
if not code:
continue

first_name = driver.get('givenName')
last_name = driver.get('familyName')

if code in NAMING_SCHEME_REVERSED:
name = last_name + ' ' + first_name
else:
name = first_name + ' ' + last_name

name = _normalize_name(name)

driver_mapping[code] = name


print(json.dumps(driver_mapping, indent=4))
44 changes: 44 additions & 0 deletions fastf1/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import warnings
from typing import Dict

from fastf1.plotting._drivers import _get_driver_mapping
from fastf1.plotting._plotting import (
_lapnumber_axis,
setup_mpl,
team_color,
)

COMPOUND_COLORS: Dict[str, str] = dict()
"""Mapping of tyre compound names to compound colors (hex color codes).
(current season only)"""

DRIVER_TRANSLATE: Dict[str, str] = dict()
"""Mapping of driver names to theirs respective abbreviations."""

TEAM_COLORS: Dict[str, str] = dict()
"""Mapping of team names to team colors (hex color codes).
(current season only)"""

TEAM_TRANSLATE: Dict[str, str] = dict()
"""Mapping of team names to theirs respective abbreviations."""


def driver_color(identifier):
return get_driver_color(identifier, season='current')


def get_driver_color(identifier: str,
*, season='current', round=None, session=None):
mapping = _get_driver_mapping(season)
return mapping.get_driver_color(identifier, round=round, session=session)


def list_drivers(*, season='current', round=None, session=None):
mapping = _get_driver_mapping(season)
return mapping.list_drivers(round=round, session=session)


def lapnumber_axis(ax, axis='xaxis'):
warnings.warn("``lapnumber_axis`` is deprecated and will be removed in"
"a future version.", FutureWarning)
return lapnumber_axis(ax, axis=axis)
208 changes: 208 additions & 0 deletions fastf1/plotting/_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
from typing import (
Dict
)


# Deprecated, will be removed for 2025
# TODO: update for 2024
LEGACY_TEAM_TRANSLATE: Dict[str, str] = {
'MER': 'mercedes',
'FER': 'ferrari',
'RBR': 'red bull',
'MCL': 'mclaren',
'APN': 'alpine',
'AMR': 'aston martin',
'ARR': 'alfa romeo',
'APT': 'alphatauri',
'HAA': 'haas',
'WIL': 'williams'
}

# Auto-generated from Ergast using dev/scripts/create_driver_translate.py
# This mapping needs to be updated for each new season.
# It provides a ready list of all historic driver abbreviations to names.
# It only includes drivers that were ever listed in an official classification.
# At runtime, data for the current season and specifically the current session
# is loaded additionally (that data includes development drivers).
DRIVER_ABB_TO_NORMALIZED_NAME = {
"AIT": "jack aitken",
"ALB": "alexander albon",
"ALG": "jaime alguersuari",
"ALO": "fernando alonso",
"BAD": "luca badoer",
"BAR": "rubens barrichello",
"BIA": "jules bianchi",
"BOT": "valtteri bottas",
"BOU": "sebastien bourdais",
"BUE": "sebastien buemi",
"BUT": "jenson button",
"CHA": "karun chandhok",
"CHI": "max chilton",
"COU": "david coulthard",
"DAM": "jerome d'ambrosio",
"DAV": "anthony davidson",
"DLR": "pedro de la rosa",
"DEV": "nyck de vries",
"DIG": "lucas di grassi",
"DIR": "paul di resta",
"DOO": "robert doornbos",
"ERI": "marcus ericsson",
"FIS": "giancarlo fisichella",
"FIT": "pietro fittipaldi",
"FRI": "patrick friesacher",
"GAS": "pierre gasly",
"GIO": "antonio giovinazzi",
"GLO": "timo glock",
"GRO": "romain grosjean",
"GUT": "esteban gutierrez",
"HAM": "lewis hamilton",
"HAR": "rio haryanto",
"HEI": "nick heidfeld",
"HUL": "nico hulkenberg",
"IDE": "yuji ide",
"KAR": "narain karthikeyan",
"KLI": "christian klien",
"KOB": "kamui kobayashi",
"KOV": "heikki kovalainen",
"KUB": "robert kubica",
"KVY": "daniil kvyat",
"LAT": "nicholas latifi",
"LAW": "liam lawson",
"LEC": "charles leclerc",
"LIU": "vitantonio liuzzi",
"LOT": "andre lotterer",
"MAG": "jan magnussen",
"MAL": "pastor maldonado",
"MAS": "felipe massa",
"MAZ": "nikita mazepin",
"MER": "roberto merhi",
"FMO": "franck montagny",
"TMO": "tiago monteiro",
"NAK": "kazuki nakajima",
"NAS": "felipe nasr",
"NOR": "lando norris",
"OCO": "esteban ocon",
"MON": "juan pablo montoya",
"PAL": "jolyon palmer",
"PER": "sergio perez",
"PET": "vitaly petrov",
"PIA": "oscar piastri",
"PIC": "charles pic",
"PIQ": "nelson piquet jr.",
"PIZ": "antonio pizzonia",
"RAI": "kimi raikkonen",
"RIC": "daniel ricciardo",
"ROS": "nico rosberg",
"RSS": "alexander rossi",
"RUS": "george russell",
"SAI": "carlos sainz",
"SAR": "logan sargeant",
"SAT": "takuma sato",
"MSC": "michael schumacher",
"SCH": "ralf schumacher",
"SEN": "bruno senna",
"SIR": "sergey sirotkin",
"SPE": "scott speed",
"STE": "will stevens",
"STR": "lance stroll",
"SUT": "adrian sutil",
"TRU": "jarno trulli",
"TSU": "yuki tsunoda",
"VDG": "giedo van der garde",
"VAN": "stoffel vandoorne",
"VER": "max verstappen",
"VET": "sebastian vettel",
"VIL": "jacques villeneuve",
"WEB": "mark webber",
"WEH": "pascal wehrlein",
"WIN": "markus winkelhock",
"WUR": "alexander wurz",
"YAM": "sakon yamamoto",
"ZHO": "zhou guanyu",
"ZON": "ricardo zonta"
}


COMPOUND_COLORS = {
'2023': {
"SOFT": "#da291c",
"MEDIUM": "#ffd12e",
"HARD": "#f0f0ec",
"INTERMEDIATE": "#43b02a",
"WET": "#0067ad",
"UNKNOWN": "#00ffff",
"TEST-UNKNOWN": "#434649"
}
}
"""Mapping of tyre compound names to compound colors (hex color codes).
(current season only)"""


DRIVER_COLORS: Dict[str, str] = {
"valtteri bottas": "#900000",
"zhou guanyu": "#500000",
"theo pourchaire": "#700000",

"nyck de vries": "#1e3d61",
"yuki tsunoda": "#356cac",
"daniel ricciardo": "#2b4562",
"liam lawson": "#2b4562",
"isack hadjar": "#1e6176",

"pierre gasly": "#0090ff",
"esteban ocon": "#70c2ff",
"jack doohan": "#0075c2",

"fernando alonso": "#006f62",
"lance stroll": "#25a617",
"felipe drugovich": "#2f9b90",

"charles leclerc": "#dc0000",
"carlos sainz": "#ff8181",
"robert shwartzman": "#9c0000",
"oliver bearman": "#c40000",

"kevin magnussen": "#ffffff",
"nico hulkenberg": "#cacaca",

"oscar piastri": "#ff8700",
"lando norris": "#eeb370",
"pato oward": "#ee6d3a",

"lewis hamilton": "#00d2be",
"george russell": "#24ffff",
"frederik vesti": "#00a6ff",

"max verstappen": "#0600ef",
"sergio perez": "#716de2",
"jake dennis": "#9f99e2",

"alexander albon": "#005aff",
"logan sargeant": "#012564",
"zak osullivan": "#1b3d97",
}



TEAM_COLORS = {
'2023': {
'classic': {
'mercedes': '#00d2be',
'ferrari': '#dc0000',
'red bull': '#0600ef',
'mclaren': '#ff8700',
'alpine': '#0090ff',
'aston martin': '#006f62',
'alfa romeo': '#900000',
'alphatauri': '#2b4562',
'haas': '#ffffff',
'williams': '#005aff'
},
'official': {

},
'default': {

}
}
}
Loading

0 comments on commit 8a06bd5

Please sign in to comment.