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
16 changes: 14 additions & 2 deletions fastf1/ergast/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ def _build_url(
selectors.append(f"/{round}")
if grid_position is not None:
selectors.append(f"/grid/{grid_position}")
if results_position is not None:
selectors.append(f"/results/{results_position}")
if fastest_rank is not None:
selectors.append(f"/fastest/{fastest_rank}")

Expand Down Expand Up @@ -482,6 +480,12 @@ def _build_url(
elif endpoint == 'constructorStandings':
endpoint = f"constructorStandings/{standings_position}"

if results_position is not None:
if endpoint in ('results', 'qualifying', 'sprint'):
endpoint = f"{endpoint}/{results_position}"
else:
selectors.append(f"/results/{results_position}")

if lap_number is not None:
if endpoint == 'laps':
endpoint = f"laps/{lap_number}"
Expand Down Expand Up @@ -1019,6 +1023,7 @@ def get_race_results(
constructor: Optional[str] = None,
driver: Optional[str] = None,
grid_position: Optional[int] = None,
results_position: Optional[int] = None,
fastest_rank: Optional[int] = None,
status: Optional[str] = None,
result_type: Optional[Literal['pandas', 'raw']] = None,
Expand All @@ -1042,6 +1047,8 @@ def get_race_results(
(default: all)
driver: select a driver by its driver id (default: all)
grid_position: select a grid position by its number (default: all)
results_position: select a finishing result by its position
(default: all)
fastest_rank: select fastest by rank number (default: all)
status: select by finishing status (default: all)
result_type: Overwrites the default result type
Expand All @@ -1062,6 +1069,7 @@ def get_race_results(
'constructor': constructor,
'driver': driver,
'grid_position': grid_position,
'results_position': results_position,
'fastest_rank': fastest_rank,
'status': status}

Expand Down Expand Up @@ -1151,6 +1159,7 @@ def get_sprint_results(
constructor: Optional[str] = None,
driver: Optional[str] = None,
grid_position: Optional[int] = None,
results_position: Optional[int] = None,
status: Optional[str] = None,
result_type: Optional[Literal['pandas', 'raw']] = None,
auto_cast: Optional[bool] = None,
Expand All @@ -1173,6 +1182,8 @@ def get_sprint_results(
(default: all)
driver: select a driver by its driver id (default: all)
grid_position: select a grid position by its number (default: all)
results_position: select a finishing result by its position
(default: all)
status: select by finishing status (default: all)
result_type: Overwrites the default result type
auto_cast: Overwrites the default value for ``auto_cast``
Expand All @@ -1192,6 +1203,7 @@ def get_sprint_results(
'constructor': constructor,
'driver': driver,
'grid_position': grid_position,
'results_position': results_position,
'status': status}

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