Models - livef1.models
¶
Classes
|
Represents a Formula 1 season, containing methods to load and manage the season's meetings and sessions. |
|
Represents a meeting in a specific season with relevant details and associated sessions. |
|
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:
- season
Season
The season this meeting belongs to.
- year
int
The year of the meeting.
- code
int
The unique code for the meeting.
- key
str
The unique identifier for the meeting.
- number
int
The sequential number of the meeting in the season.
- location
str
The location (e.g., circuit name) of the meeting.
- officialname
str
The official name of the meeting.
- name
str
The name of the meeting.
- country
dict
Details about the country where the meeting takes place (e.g., key, code, name).
- circuit
dict
Details about the circuit where the meeting takes place (e.g., key, short name).
- sessions
list
List of session objects associated with the meeting.
- loaded
bool
Indicates whether the meeting data has been loaded.
- season
Methods
load
([force])Load or reload meeting data from the API.
Parse session data to generate a detailed DataFrame of session metadata.
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.
- 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:
Methods
load
()Loads the season data from the API and populates the meetings attribute.
Parses session data from the meetings and organizes it into a DataFrame.
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:
- season
Season
The season the session belongs to.
- year
int
The year of the session.
- meeting
Meeting
The meeting the session is part of.
- key
int
Unique identifier for the session.
- name
str
Name of the session.
- type
str
Type of the session (e.g., practice, qualifying, race).
- number
int
The session number.
- startdate
str
Start date and time of the session.
- enddate
str
End date and time of the session.
- gmtoffset
str
GMT offset for the session’s timing.
- path
dict
Path information for accessing session data.
- loaded
bool
Indicates whether the session data has been loaded.
- season
Methods
check_data_name
(dataName)Validate and return the correct data name.
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.
Retrieve the timing data.
Retrieve information about available data topics for the session.
Retrieve the weather data.
load_data
(dataNames[, parallel, dataType, ...])Retrieve and parse data from feeds, either sequentially or in parallel.
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:
- dataName
str
The name of the data topic to validate.
- dataName
- 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.
- 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 NoneThe 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 NoneThe 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 NoneThe 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 NoneThe 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