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

Add warnings to users when identifier is fuzzy matched #574

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions fastf1/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import numpy as np
import pandas as pd

from fastf1.logger import get_logger


try:
import matplotlib
Expand All @@ -45,6 +47,7 @@
"Plotting of timedelta values will be restricted!",
UserWarning)

_logger = get_logger(__name__)

with warnings.catch_warnings():
warnings.filterwarnings('ignore',
Expand Down Expand Up @@ -286,6 +289,12 @@ 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]}."
Casper-Guo 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)):
# ensure that the best match has a minimum accuracy (35 out of
Expand Down Expand Up @@ -361,6 +370,12 @@ 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)):
# ensure that the best match has a minimum accuracy (35 out of
Expand Down
Loading