Models - livef1.models

Classes

Season(year, meetings)

Represents a Formula 1 season, containing methods to load and manage the season's meetings and sessions.

Meeting([season, year, code, key, number, ...])

Represents a meeting in a specific season with relevant details and associated sessions.

Session([season, year, meeting, key, name, ...])

Represents a Formula 1 session, containing methods to retrieve live timing data and process it.

class livef1.models.Meeting(season: Season = None, year: int = None, code: int = None, key: str = None, number: int = None, location: str = None, officialname: str = None, name: str = None, country: Dict = None, circuit: Dict = None, sessions: List = None, loaded: bool = False, **kwargs)[source]

Represents a meeting in a specific season with relevant details and associated sessions.

Attributes:
seasonSeason

The season this meeting belongs to.

yearint

The year of the meeting.

codeint

The unique code for the meeting.

keystr

The unique identifier for the meeting.

numberint

The sequential number of the meeting in the season.

locationstr

The location (e.g., circuit name) of the meeting.

officialnamestr

The official name of the meeting.

namestr

The name of the meeting.

countrydict

Details about the country where the meeting takes place (e.g., key, code, name).

circuitdict

Details about the circuit where the meeting takes place (e.g., key, short name).

sessionslist

List of session objects associated with the meeting.

loadedbool

Indicates whether the meeting data has been loaded.

Methods

load([force])

Load or reload meeting data from the API.

parse_sessions()

Parse session data to generate a detailed DataFrame of session metadata.

set_sessions()

Create session objects for the meeting using the session JSON data.

load(force=False)[source]

Load or reload meeting data from the API.

Note

Reloading is useful when updated data is required.

Parameters:
forcebool, optional

If True, forces the reload of meeting data even if already loaded. Defaults to False.

parse_sessions()[source]

Parse session data to generate a detailed DataFrame of session metadata.

Note

The resulting DataFrame is stored in the sessions_table attribute and indexed by season year, meeting location, and session type.

set_sessions()[source]

Create session objects for the meeting using the session JSON data.

Note

This method populates the sessions attribute with Session objects derived from sessions_json.

class livef1.models.Season(year, meetings)[source]

Represents a Formula 1 season, containing methods to load and manage the season’s meetings and sessions.

Attributes:
yearint

The year of the season.

meetingslist of Meeting

A list of Meeting objects for the season.

Methods

load()

Loads the season data from the API and populates the meetings attribute.

parse_sessions()

Parses session data from the meetings and organizes it into a DataFrame.

set_meetings()

Creates Meeting objects for each meeting in the meetings_json attribute and adds them to the meetings list.

load()[source]

Loads the season data from the API and populates the meetings attribute.

parse_sessions()[source]

Parses session data from the meetings and organizes it into a DataFrame.

The resulting DataFrame is stored in the meetings_table attribute, indexed by season_year, meeting_location, and session_type.

set_meetings()[source]

Creates Meeting objects for each meeting in the meetings_json attribute and adds them to the meetings list.

class livef1.models.Session(season: Season = None, year: int = None, meeting: Meeting = None, key: int = None, name: str = None, type: str = None, number: int = None, startdate: str = None, enddate: str = None, gmtoffset: str = None, path: Dict = None, loaded: bool = False, **kwargs)[source]

Represents a Formula 1 session, containing methods to retrieve live timing data and process it.

Attributes:
seasonSeason

The season the session belongs to.

yearint

The year of the session.

meetingMeeting

The meeting the session is part of.

keyint

Unique identifier for the session.

namestr

Name of the session.

typestr

Type of the session (e.g., practice, qualifying, race).

numberint

The session number.

startdatestr

Start date and time of the session.

enddatestr

End date and time of the session.

gmtoffsetstr

GMT offset for the session’s timing.

pathdict

Path information for accessing session data.

loadedbool

Indicates whether the session data has been loaded.

Methods

check_data_name(dataName)

Validate and return the correct data name.

get_car_telemetry()

Retrieve the car telemetry data.

get_data(dataNames[, parallel, force])

Retrieve one or multiple data topics from cache or load them, with optional parallel processing.

get_laps()

Retrieve the laps data.

get_timing()

Retrieve the timing data.

get_topic_names()

Retrieve information about available data topics for the session.

get_weather()

Retrieve the weather data.

load_data(dataNames[, parallel, dataType, ...])

Retrieve and parse data from feeds, either sequentially or in parallel.

print_topic_names()

Print the topic names and their descriptions.

generate

generate_car_telemetry_table

generate_laps_table

check_data_name(dataName: str)[source]

Validate and return the correct data name.

This method checks if the provided data name exists in the topic_names_info attribute. If it does, it returns the corresponding topic name.

Parameters:
dataNamestr

The name of the data topic to validate.

Returns:
str

The validated data name.

Notes

  • The method ensures that the provided data name exists in the topic_names_info attribute.

  • If the data name is found, it returns the corresponding topic name.

generate(silver=True, gold=False)[source]
generate_car_telemetry_table()[source]
generate_laps_table()[source]
get_car_telemetry()[source]

Retrieve the car telemetry data.

This method returns the car telemetry data if it has been generated. If not, it logs an informational message indicating that the car telemetry table is not generated yet.

Returns:
CarTelemetry or None

The car telemetry data if available, otherwise None.

Notes

  • The method checks if the carTelemetry attribute is populated.

  • If the carTelemetry attribute is not populated, it logs an informational message.

get_data(dataNames, parallel: bool = False, force: bool = False)[source]

Retrieve one or multiple data topics from cache or load them, with optional parallel processing.

Parameters:
data_namesUnion[str, List[str]]

Single data topic name or list of data topic names to retrieve

parallelbool, optional

Whether to use parallel processing when fetching multiple topics. Defaults to False.

forcebool, optional

Whether to force download data even if it exists in cache. Defaults to False.

Returns:
Union[BasicResult, Dict[str, BasicResult]]

If a single topic is requested, returns its BasicResult object. If multiple topics are requested, returns a dictionary mapping topic names to their BasicResult objects.

Notes

  • Automatically handles both single and multiple data requests

  • Checks cache (data lake) before loading new data unless force=True

  • Uses parallel processing for multiple topics when parallel=True

  • Returns same format as input: single result for str input, dict for list input

Examples

# Get single topic >>> telemetry = session.get_data(“CarData.z”)

# Get multiple topics in parallel (default) >>> data = session.get_data([“CarData.z”, “Position.z”, “SessionStatus”])

# Get multiple topics sequentially >>> data = session.get_data([“CarData.z”, “Position.z”], parallel=False)

# Force download data even if cached >>> data = session.get_data(“CarData.z”, force=True)

get_laps()[source]

Retrieve the laps data.

This method returns the laps data if it has been generated. If not, it logs an informational message indicating that the laps table is not generated yet.

Returns:
Laps or None

The laps data if available, otherwise None.

Notes

  • The method checks if the laps attribute is populated.

  • If the laps attribute is not populated, it logs an informational message.

get_timing()[source]

Retrieve the timing data.

This method returns the timing data if it has been generated. If not, it logs an informational message indicating that the timing table is not generated yet.

Returns:
Timing or None

The timing data if available, otherwise None.

Notes

  • The method checks if the timing attribute is populated.

  • If the timing attribute is not populated, it logs an informational message.

get_topic_names()[source]

Retrieve information about available data topics for the session.

This method fetches details about the available data topics for the session from the live timing feed and enriches the data with descriptions and keys from a predefined TOPICS_MAP.

Returns:
dict

A dictionary containing information about available data topics. Each key represents a topic, and its value is another dictionary with the following keys: - description (str): A description of the topic. - key (str): A unique key identifying the topic. - Other metadata provided by the live timing feed.

Notes

  • The data is fetched from a URL formed by appending “Index.json” to the session’s

full_path. - The fetched data is enriched with additional information from the TOPICS_MAP dictionary. - The topic_names_info attribute is set to the resulting dictionary for later use.

Examples

The returned dictionary would be:

{
    "Topic1": {
        "KeyFramePath": "Topic1.json",
        "StreamPath": "Topic1.jsonStream"
        "description": "Description for Topic1",
        "key": "T1"
    },
    "Topic2": {
        "KeyFramePath": "Topic2.json",
        "StreamPath": "Topic2.jsonStream"
        "description": "Description for Topic2",
        "key": "T2"
    }
}
get_weather()[source]

Retrieve the weather data.

This method returns the weather data if it has been generated. If not, it logs an informational message indicating that the weather table is not generated yet.

Returns:
Weather or None

The weather data if available, otherwise None.

Notes

  • The method checks if the weather attribute is populated.

  • If the weather attribute is not populated, it logs an informational message.

load_data(dataNames, parallel: bool = False, dataType: str = 'StreamPath', stream: bool = True)[source]

Retrieve and parse data from feeds, either sequentially or in parallel.

Parameters:
dataNamesUnion[str, List[str]]

Single data name or list of data names to retrieve

parallelbool, optional

Whether to load data in parallel (True) or sequentially (False), by default True

dataTypestr, optional

The type of the data to fetch, by default “StreamPath”

streambool, optional

Whether to fetch as stream, by default True

Returns:
Union[BasicResult, dict]

If single data name provided: BasicResult object with parsed data If multiple data names: Dictionary mapping names to BasicResult objects

Notes

  • For parallel loading, uses multiprocessing Pool with (CPU count - 1) processes

  • Saves all loaded data to bronze lake before returning

  • Returns same format as input: single result for str input, dict for list input

print_topic_names()[source]

Print the topic names and their descriptions.

This method prints the key and description for each topic available in the topic_names_info attribute. If the topic_names_info attribute is not already populated, it fetches the data using the get_topic_names method.

Notes

  • The method assumes the topic_names_info attribute is a dictionary

where each key represents a topic, and its value is another dictionary containing key and description. - The get_topic_names method is called if topic_names_info is not already populated.

Examples

The output would be:

T1 : 
    Description for topic 1
T2 : 
    Description for topic 2