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

Ergast - results final position filter #494

Merged
merged 12 commits into from
Dec 28, 2023
25 changes: 20 additions & 5 deletions fastf1/ergast/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class ErgastRawResponse(ErgastResponseMixin, list):
auto_cast: Determines if values are automatically cast to the most
appropriate data type from their original string representation
"""

def __init__(self, *, query_result, category, auto_cast, **kwargs):
if auto_cast:
query_result = self._prepare_response(query_result, category)
Expand Down Expand Up @@ -351,6 +352,7 @@ class ErgastMultiResponse(ErgastResponseMixin):
auto_cast: Flag that enables or disables automatic casting from the
original string representation to the most suitable data type.
"""

def __init__(self, *args,
response_description: dict,
response_data: list,
Expand Down Expand Up @@ -409,6 +411,7 @@ class Ergast:
30 if not set. Maximum: 1000. See also "Response Paging" on
https://ergast.com/mrd/.
"""

def __init__(self,
result_type: Literal['raw', 'pandas'] = 'pandas',
auto_cast: bool = True,
Expand Down Expand Up @@ -459,10 +462,10 @@ def _build_url(
# string additionally
if standings_position is not None:
if endpoint == 'driverStandings':
selectors.append(f"/driverStandings/{standings_position}")
selectors.append(f"/driverStandings")
endpoint = None
elif endpoint == 'constructorStandings':
selectors.append(f"/constructorStandings/{standings_position}")
selectors.append(f"/constructorStandings")
endpoint = None

if lap_number is not None:
Expand All @@ -478,6 +481,9 @@ def _build_url(
if endpoint is not None:
selectors.append(f"/{endpoint}")

if standings_position is not None:
theOehrly marked this conversation as resolved.
Show resolved Hide resolved
selectors.append(f"/{standings_position}")

return BASE_URL + "".join(selectors) + ".json"

@classmethod
Expand Down Expand Up @@ -1002,6 +1008,7 @@ def get_race_results(
grid_position: Optional[int] = None,
fastest_rank: Optional[int] = None,
status: Optional[str] = None,
standings_position: Optional[int] = None,
result_type: Optional[Literal['pandas', 'raw']] = None,
auto_cast: Optional[bool] = None,
limit: Optional[int] = None,
Expand All @@ -1025,6 +1032,7 @@ def get_race_results(
grid_position: select a grid position by its number (default: all)
fastest_rank: select fastest by rank number (default: all)
status: select by finishing status (default: all)
standings_position: select a result by final position (default: all)
result_type: Overwrites the default result type
auto_cast: Overwrites the default value for ``auto_cast``
limit: Overwrites the default value for ``limit``
Expand All @@ -1044,7 +1052,8 @@ def get_race_results(
'driver': driver,
'grid_position': grid_position,
'fastest_rank': fastest_rank,
'status': status}
'status': status,
'standings_position': standings_position}

return self._build_default_result(endpoint='results',
table='RaceTable',
Expand All @@ -1067,6 +1076,7 @@ def get_qualifying_results(
results_position: Optional[int] = None,
fastest_rank: Optional[int] = None,
status: Optional[str] = None,
standings_position: Optional[int] = None,
result_type: Optional[Literal['pandas', 'raw']] = None,
auto_cast: Optional[bool] = None,
limit: Optional[int] = None,
Expand All @@ -1092,6 +1102,7 @@ def get_qualifying_results(
(default: all)
fastest_rank: select fastest by rank number (default: all)
status: select by finishing status (default: all)
standings_position: select a result by final position (default: all)
result_type: Overwrites the default result type
auto_cast: Overwrites the default value for ``auto_cast``
limit: Overwrites the default value for ``limit``
Expand All @@ -1112,7 +1123,8 @@ def get_qualifying_results(
'grid_position': grid_position,
'results_position': results_position,
'fastest_rank': fastest_rank,
'status': status}
'status': status,
'standings_position': standings_position}

return self._build_default_result(endpoint='qualifying',
table='RaceTable',
Expand All @@ -1133,6 +1145,7 @@ def get_sprint_results(
driver: Optional[str] = None,
grid_position: Optional[int] = None,
status: Optional[str] = None,
standings_position: Optional[int] = None,
result_type: Optional[Literal['pandas', 'raw']] = None,
auto_cast: Optional[bool] = None,
limit: Optional[int] = None,
Expand All @@ -1155,6 +1168,7 @@ def get_sprint_results(
driver: select a driver by its driver id (default: all)
grid_position: select a grid position by its number (default: all)
status: select by finishing status (default: all)
standings_position: select a result by final position (default: all)
result_type: Overwrites the default result type
auto_cast: Overwrites the default value for ``auto_cast``
limit: Overwrites the default value for ``limit``
Expand All @@ -1173,7 +1187,8 @@ def get_sprint_results(
'constructor': constructor,
'driver': driver,
'grid_position': grid_position,
'status': status}
'status': status,
'standings_position': standings_position}

return self._build_default_result(endpoint='sprint',
table='RaceTable',
Expand Down
Loading