theOehrly / Fast-F1

FastF1 is a python package for accessing and analyzing Formula 1 results, schedules, timing data and telemetry
https://docs.fastf1.dev
MIT License
2.48k stars 259 forks source link

[BUG] Loading session data for Pre-Season Testing #316

Closed marlosb closed 1 year ago

marlosb commented 1 year ago

Describe the issue:

First, thanks for developing the library, it is very helpful. Great work.

As new season is approaching, I'm trying to get eyes on testing data and couldn't load pre-season test data. I'm using version 2.3.0. I tried to pass event name in several ways and none worked. I can't use session number as all testing sessions have round number 0. For event name "Pre-Season Testing" it tried to load "British Grand Prix"; for event name "FORMULA 1 ARAMCO PRE-SEASON TESTING 2023" it tried to load "Austrian Grand Prix and for event names "Sakhir" or "Bahrain" it tries to load "Bahrain Grand Prix" (this is expected as GP are more important than testing).

Any suggestion on how can I load data from pre-season tests?

Reproduce the code example:

print(f'library version is: {fastf1.__version__}')

event_name = 'Pre-Season Testing'
session_number = 1

event = fastf1.get_event(year=year, gp=event_name)
session = event.get_session(session_number)
session.load()

Error message:

library version is: 2.3.0
core           INFO     Loading data for British Grand Prix - Practice 1 [v2.3.0]
api            INFO     No cached data found for driver_info. Loading data...
api            INFO     Fetching driver list...
core        WARNING     Failed to load extended driver information!
core        WARNING     Failed to load data from Ergast API! (This is expected for recent sessions)
api            INFO     No cached data found for timing_data. Loading data...
api            INFO     Fetching timing data...
core        WARNING     Failed to load lap data!
api            INFO     No cached data found for car_data. Loading data...
api            INFO     Fetching car data...
core        WARNING     Failed to load telemetry data!
api            INFO     No cached data found for weather_data. Loading data...
api            INFO     Fetching weather data...
core        WARNING     Failed to load weather data!
api            INFO     No cached data found for race_control_messages. Loading data...
api            INFO     Fetching race control messages...
core        WARNING     Failed to load Race Control message data!
core           INFO     Finished loading data for 0 drivers: []
marlosb commented 1 year ago

I managed to solve it, see details below:

Cause: The _getevent() function generates an instance of EventSchedule class and then calls _get_event_byname() or _get_event_byround() methods from the instantiated object. While instantiating the object it sets _includetesting parameter to False. As search is not including testing sessions the fuzzy search can't find it.

You can see it in fastf1/events.py file at line 293. Extracted below.

    schedule = get_event_schedule(year=year, include_testing=False,
                                  force_ergast=force_ergast)

    if type(gp) is str:
        event = schedule.get_event_by_name(gp, strict_search=strict_search)
    else:
        event = schedule.get_event_by_round(gp)

    return event

Solution: Call _get_event_byname() method explicitly from an EventSchedule object created by you with _includetesting parameter as True. See below:

event_schedule = fastf1.get_event_schedule(year=2023, include_testing=True)

event_name = 'Pre-Season Testing'
session_number = 1

event = event_schedule.get_event_by_name(event_name)
session = event.get_session(session_number)
session.load()

Results:

core           INFO     Loading data for Pre-Season Testing - Practice 1 [v2.3.0]
api            INFO     No cached data found for driver_info. Loading data...
api            INFO     Fetching driver list...

Suggestion: to make the code more bullet proof maybe it should include an optional argument _includetesting in the _getevent() function and use it to instantiate EventSchedule object. Or maybe make _getevent() function a method of EventSchedule class.

theOehrly commented 1 year ago

Two separate functions get_testing_event and get_testing_session already exist and work as intended for today's test. See: https://theoehrly.github.io/Fast-F1/fastf1.html#fastf1.get_testing_session The reason for this is to avoid confusion, actually, because the supported call signature for get_event and get_testing_event differs slightly. Else there'd need to be clarifications in the docs that "option x does not work when option y is True" and stuff like that.

marlosb commented 1 year ago

Thanks for replying. I'm going to test get_testing_event() and get_testing_session(). Maybe call get_event_bt_name() method suits better for me because it works in both cases, testing and official events. But I'm going to give it a try anyway.