Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Feb 6, 2024
1 parent ac2e42d commit b5666bb
Show file tree
Hide file tree
Showing 7 changed files with 554 additions and 135 deletions.
58 changes: 58 additions & 0 deletions fastf1/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import warnings
from typing import (
Dict,
Optional
)

from fastf1.core import Session
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):
mapping = _get_driver_mapping()
return mapping.get_driver_color(identifier, _variants=True)


def get_driver_color(identifier: str, *, session: Optional[Session] = None):
mapping = _get_driver_mapping(session=session)
return mapping.get_driver_color(identifier)


def get_driver_name(identifier: str, *, session: Optional[Session] = None):
mapping = _get_driver_mapping(session=session)
return mapping.get_driver_name(identifier)


def get_team_name(identifier: str, *, session: Optional[Session] = None):
mapping = _get_driver_mapping(session=session)
return mapping.get_team_name(identifier)

def get_team_name_by_driver(identifier: str, *, short=False, session: Optional[Session] = None):
mapping = _get_driver_mapping(session=session)
return mapping.get_team_name_by_driver(identifier, short=short)


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)
33 changes: 33 additions & 0 deletions fastf1/plotting/_constants/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import (
Dict,
Type
)

from fastf1.plotting._constants.base import (
BaseSeason,
Colormaps
)
from fastf1.plotting._constants.season2023 import Season2023
from fastf1.plotting._constants.season2024 import Season2024


# Deprecated, will be removed for 2025
LEGACY_TEAM_TRANSLATE: Dict[str, str] = {
'MER': 'mercedes',
'FER': 'ferrari',
'RBR': 'red bull',
'MCL': 'mclaren',
'APN': 'alpine',
'AMR': 'aston martin',
'SAU': 'sauber',
'VIS': 'visa', # TODO: update
'HAA': 'haas',
'WIL': 'williams'
}


Constants: Dict[str, Type[BaseSeason]] = {
'2023': Season2023,
'2024': Season2024
}

25 changes: 25 additions & 0 deletions fastf1/plotting/_constants/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from enum import StrEnum
from typing import Dict


class Colormaps(StrEnum):
Classic = 'classic'
Default = 'default'
Official = 'official'


class Compounds(StrEnum):
Soft = "SOFT"
Medium = "MEDIUM"
Hard = "HARD"
Intermediate = "INTERMEDIATE"
Wet = "WET"
Unknown = "UNKNOWN"
TestUnknown = "TEST-UNKNOWN"


class BaseSeason:
Colormaps: Dict[Colormaps, dict]
CompoundColors: Dict[Compounds, str]
ShortTeamNames: Dict[str, str]
Teams: StrEnum
96 changes: 96 additions & 0 deletions fastf1/plotting/_constants/season2023.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from enum import StrEnum
from typing import (
Dict,
Sequence
)

from fastf1.plotting._constants.base import (
BaseSeason,
Colormaps,
Compounds
)


class Teams(StrEnum):
Mercedes = 'mercedes'
Ferrari = 'ferrari'
RedBull = 'red bull'
McLaren = 'mclaren'
Alpine = 'alpine'
AstonMartin = 'aston martin'
AlfaRomeo = 'alfa romeo'
AlphaTauri = 'alphatauri'
Haas = 'haas'
Williams = 'williams'


ShortTeamNames: Dict[Teams, str] = {
Teams.Mercedes: 'Mercedes',
Teams.Ferrari: 'Ferrari',
Teams.RedBull: 'Red Bull',
Teams.McLaren: 'McLaren',
Teams.Alpine: 'Alpine',
Teams.AstonMartin: 'Aston',
Teams.AlfaRomeo: 'Alfa Romeo',
Teams.AlphaTauri: 'AlphaTauri',
Teams.Haas: 'Haas',
Teams.Williams: 'Williams'
}


TeamColormaps: Dict[Colormaps, Dict[Teams, Sequence[str]]] = {
Colormaps.Classic: {
Teams.Mercedes: ['#00d2be', ],
Teams.Ferrari: ['#dc0000', ],
Teams.RedBull: ['#0600ef', ],
Teams.McLaren: ['#ff8700', ],
Teams.Alpine: ['#0090ff', ],
Teams.AstonMartin: ['#006f62', ],
Teams.AlfaRomeo: ['#900000', ],
Teams.AlphaTauri: ['#2b4562', ],
Teams.Haas: ['#ffffff', ],
Teams.Williams: ['#005aff', ]
},
Colormaps.Official: {
Teams.Mercedes: ['#6CD3BF', ],
Teams.Ferrari: ['#F91536', ],
Teams.RedBull: ['#3671C6', ],
Teams.McLaren: ['#F58020', ],
Teams.Alpine: ['#2293D1', ],
Teams.AstonMartin: ['#358C75', ],
Teams.AlfaRomeo: ['#900000', ],
Teams.AlphaTauri: ['#5E8FAA', ],
Teams.Haas: ['#B6BABD', ],
Teams.Williams: ['#37BEDD', ]
},
Colormaps.Default: {
Teams.Mercedes: ['#00f5d0', '#a8fff2'],
Teams.Ferrari: ['#da291c', '#e84d40'],
Teams.RedBull: ['#fcd700', '#ffec7b'],
Teams.McLaren: ['#ff8000', '#9d4d00'],
Teams.Alpine: ['#fe86bc', '#ff117c'],
Teams.AstonMartin: ['#00665e', '#00413b'],
Teams.AlfaRomeo: ['#900000', '#5f0000'],
Teams.AlphaTauri: ['#2b4562', '#406991'],
Teams.Haas: ['#ffffff', '#a7a7a7'],
Teams.Williams: ['#00a0dd', '#8cc8ff']
}
}


CompoundColors: Dict[Compounds, str] = {
Compounds.Soft: "#da291c",
Compounds.Medium: "#ffd12e",
Compounds.Hard: "#f0f0ec",
Compounds.Intermediate: "#43b02a",
Compounds.Wet: "#0067ad",
Compounds.Unknown: "#00ffff",
Compounds.TestUnknown: "#434649"
}


class Season2023(BaseSeason):
Colormaps = TeamColormaps
CompoundColors = CompoundColors
ShortTeamNames = ShortTeamNames
Teams = Teams
96 changes: 96 additions & 0 deletions fastf1/plotting/_constants/season2024.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from enum import StrEnum
from typing import (
Dict,
Sequence
)

from fastf1.plotting._constants.base import (
BaseSeason,
Colormaps,
Compounds
)


class Teams(StrEnum):
Mercedes = 'mercedes'
Ferrari = 'ferrari'
RedBull = 'red bull'
McLaren = 'mclaren'
Alpine = 'alpine'
AstonMartin = 'aston martin'
Sauber = 'sauber'
Visa = 'visa'
Haas = 'haas'
Williams = 'williams'


ShortTeamNames: Dict[Teams, str] = {
Teams.Mercedes: 'Mercedes',
Teams.Ferrari: 'Ferrari',
Teams.RedBull: 'Red Bull',
Teams.McLaren: 'McLaren',
Teams.Alpine: 'Alpine',
Teams.AstonMartin: 'Aston',
Teams.Sauber: 'Sauber',
Teams.Visa: 'Visa',
Teams.Haas: 'Haas',
Teams.Williams: 'Williams'
}


TeamColormaps: Dict[Colormaps, Dict[Teams, Sequence[str]]] = {
Colormaps.Classic: {
Teams.Mercedes: ['#00d2be', ],
Teams.Ferrari: ['#dc0000', ],
Teams.RedBull: ['#0600ef', ],
Teams.McLaren: ['#ff8700', ],
Teams.Alpine: ['#0090ff', ],
Teams.AstonMartin: ['#006f62', ],
Teams.Sauber: ['#00e701', ],
Teams.Visa: ['#1434CB', ], # TODO: update
Teams.Haas: ['#ffffff', ],
Teams.Williams: ['#005aff', ]
},
Colormaps.Official: {
Teams.Mercedes: ['#6CD3BF', ],
Teams.Ferrari: ['#F91536', ],
Teams.RedBull: ['#3671C6', ],
Teams.McLaren: ['#F58020', ],
Teams.Alpine: ['#2293D1', ],
Teams.AstonMartin: ['#358C75', ],
Teams.Sauber: ['#00e701', ],
Teams.Visa: ['#5E8FAA', ], # TODO: update
Teams.Haas: ['#B6BABD', ],
Teams.Williams: ['#37BEDD', ]
},
Colormaps.Default: {
Teams.Mercedes: ['#00f5d0', '#a8fff2'],
Teams.Ferrari: ['#da291c', '#8c1a11'],
Teams.RedBull: ['#fcd700', '#ffec7b'],
Teams.McLaren: ['#ff8700', '#9d4d00'],
Teams.Alpine: ['#fe86bc', '#ff117c'],
Teams.AstonMartin: ['#00665e', '#00413b'],
Teams.Sauber: ['#00e701', '#008d01'],
Teams.Visa: ['#1634cb', '#0c207e'], # TODO: update
Teams.Haas: ['#ffffff', '#a7a7a7'],
Teams.Williams: ['#00a0dd', '#8cc8ff']
}
}


CompoundColors: Dict[Compounds, str] = {
Compounds.Soft: "#da291c",
Compounds.Medium: "#ffd12e",
Compounds.Hard: "#f0f0ec",
Compounds.Intermediate: "#43b02a",
Compounds.Wet: "#0067ad",
Compounds.Unknown: "#00ffff",
Compounds.TestUnknown: "#434649"
}


class Season2024(BaseSeason):
Colormaps = TeamColormaps
CompoundColors = CompoundColors
ShortTeamNames = ShortTeamNames
Teams = Teams
Loading

0 comments on commit b5666bb

Please sign in to comment.