Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename visa_rb key to rb #645

Merged
merged 3 commits into from
Oct 27, 2024
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
9 changes: 3 additions & 6 deletions fastf1/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
LEGACY_DRIVER_COLORS as _LEGACY_DRIVER_COLORS
from fastf1.plotting._constants import \
LEGACY_DRIVER_TRANSLATE as _LEGACY_DRIVER_TRANSLATE
from fastf1.plotting._constants import \
LEGACY_TEAM_COLORS as _LEGACY_TEAM_COLORS
from fastf1.plotting._constants import \
LEGACY_TEAM_TRANSLATE as _LEGACY_TEAM_TRANSLATE
from fastf1.plotting._constants import Constants as _Constants
Expand Down Expand Up @@ -134,12 +136,7 @@ def __getattr__(name):
future version. Use :func:`~fastf1.plotting.get_driver_name` instead.
"""

_DEPR_TEAM_COLORS: dict[str, str] = {
# str(key.value): val for key, val
# in _Constants['2024'].Colormaps[_Colormaps.Default].items()
name.replace("kick ", ""): team.TeamColor.FastF1 for name, team
in _Constants['2024'].Teams.items()
}
_DEPR_TEAM_COLORS: dict[str, str] = _LEGACY_TEAM_COLORS.copy()
TEAM_COLORS: dict[str, str]
"""
Mapping of team names to team colors (hex color codes).
Expand Down
2 changes: 1 addition & 1 deletion fastf1/plotting/_constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'APN': 'alpine',
'AMR': 'aston martin',
'SAU': 'sauber',
'RB': 'rb',
'RB' : 'visa rb',
'HAA': 'haas',
'WIL': 'williams'
}
Expand Down
41 changes: 25 additions & 16 deletions fastf1/plotting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,23 @@ def driver_color(identifier: str) -> str:
ratio = fuzz.ratio(identifier, existing_key)
key_ratios.append((ratio, existing_key))
key_ratios.sort(reverse=True)
if key_ratios[0][0] != 100:
_logger.warning(
"Correcting invalid user input "
f"'{identifier}' to '{key_ratios[0][1]}'."

theOehrly marked this conversation as resolved.
Show resolved Hide resolved
)
if ((key_ratios[0][0] < 35)
or (key_ratios[0][0] / key_ratios[1][0] < 1.2)):
if (key_ratios[0][0] < 35) or (
key_ratios[0][0] / key_ratios[1][0] < 1.2
):
# ensure that the best match has a minimum accuracy (35 out of
# 100) and that it has a minimum confidence (at least 20% better
# than second best)
raise KeyError
raise KeyError(
f"Cannot find a good match for user input: {identifier}"
)

if key_ratios[0][0] != 100:
_logger.warning(
"Correcting invalid user input "
f"'{identifier}' to '{key_ratios[0][1]}'."
)

best_matched_key = key_ratios[0][1]
return LEGACY_DRIVER_COLORS[best_matched_key]

Expand Down Expand Up @@ -263,18 +268,22 @@ def team_color(identifier: str) -> str:
ratio = fuzz.ratio(identifier, existing_key)
key_ratios.append((ratio, existing_key))
key_ratios.sort(reverse=True)
if key_ratios[0][0] != 100:
_logger.warning(
"Correcting invalid user input "
f"'{identifier}' to '{key_ratios[0][1]}'."

)
if ((key_ratios[0][0] < 35)
or (key_ratios[0][0] / key_ratios[1][0] < 1.2)):
if (key_ratios[0][0] < 35) or (
key_ratios[0][0] / key_ratios[1][0] < 1.2
):
# ensure that the best match has a minimum accuracy (35 out of
# 100) and that it has a minimum confidence (at least 20% better
# than second best)
raise KeyError
raise KeyError(
f"Cannot find a good match for user input: {identifier}"
)

if key_ratios[0][0] != 100:
_logger.warning(
"Correcting invalid user input "
f"'{identifier}' to '{key_ratios[0][1]}'."
)
best_matched_key = key_ratios[0][1]
return LEGACY_TEAM_COLORS[best_matched_key]

Expand Down
17 changes: 13 additions & 4 deletions fastf1/tests/test_plotting_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,20 @@ def test_driver_color():

def test_team_color():
with pytest.warns(FutureWarning, match="is deprecated"):
color = fastf1.plotting.team_color('ferrari')
color_ferrari = fastf1.plotting.team_color('ferrari')

assert color.startswith('#')
assert len(color) == 7
_ = int(color[1:], base=16) # ensure that it's a valid hex color
assert color_ferrari.startswith('#')
assert len(color_ferrari) == 7
_ = int(color_ferrari[1:], base=16) # ensure that it's a valid hex color

with pytest.warns(FutureWarning, match="is deprecated"):
Casper-Guo marked this conversation as resolved.
Show resolved Hide resolved
color_visa = fastf1.plotting.team_color("visa")
color_rb = fastf1.plotting.team_color("rb")
color_visa_rb = fastf1.plotting.team_color("visa rb")
color_rbr = fastf1.plotting.team_color("RBR")

assert color_visa == color_rb == color_visa_rb
assert color_visa_rb != color_rbr


def test_lapnumber_axis():
Expand Down
Loading