api reference - VforVitorio/F1_Strat_Manager GitHub Wiki

API Reference

VforVitorio/F1_Strat_Manager

powered by

Devin

API Reference

This document provides a comprehensive reference for the programmatic interfaces available in the F1 Strategy Manager application. It covers the core APIs for data loading, processing, machine learning models, expert system integration, and visualization components.

For information about extending the system with new data sources or rules, see Integration Guide.

1. Core API Structure

The F1 Strategy Manager system is organized into several interconnected API layers that handle different aspects of F1 strategy analysis.

2. Data Loading and Processing APIs

2.1 Data Loading Functions

The system provides functions to load race data, recommendations, and driver information.

These functions handle the acquisition of data from various sources, including CSV/parquet files.

2.2 Data Processing Functions

These functions transform raw data into formats suitable for analysis and visualization.

Key processing functions:

Function Description Parameters
get_processed_race_data(driver_number=None) Loads race data and applies fuel adjustment and degradation metrics driver_number: Optional driver to filter for
get_processed_recommendations(driver_number=None) Loads and filters strategic recommendations driver_number: Optional driver to filter for
get_processed_gap_data(driver_number=None) Loads and processes gap data with consistency metrics driver_number: Optional driver to filter for
get_lap_time_predictions(race_data, model_path=None) Runs lap time prediction models race_data: Race telemetry, model_path: Path to model file
calculate_gap_consistency(gap_df) Calculates consistency of gaps between cars gap_df: DataFrame with gap data

3. Machine Learning Model APIs

3.1 Lap Time Prediction API

The lap time prediction API provides functionality to predict lap times based on telemetry data.

Main function:

Parameters:

  • input_data: DataFrame or path to CSV with telemetry data
  • model_path: Path to the model file (defaults to project standard location)
  • include_next_lap: Whether to include prediction for the next lap

Returns a DataFrame with lap time predictions and relevant metrics.

Supporting functions:

  • load_lap_prediction_model(model_path=None): Loads the XGBoost model
  • validate_lap_data(input_data): Validates input telemetry data
  • add_sequential_features(df): Adds features based on previous laps
  • prepare_features_for_prediction(df, feature_names): Prepares model inputs
  • format_lap_predictions(df, predictions): Formats prediction results

3.2 Tire Degradation Prediction API

Functions to predict tire degradation over time.

4. Expert System API

The expert system provides the strategic intelligence of the application through a rule-based engine.

4.1 Class Hierarchy

4.2 Expert System Fact Classes

These classes represent the knowledge used by the rule engine:

4.3 Rule Engine API

The F1CompleteStrategyEngine class is the main interface for generating strategy recommendations.

Key methods:

Method Description Parameters
F1CompleteStrategyEngine() Constructor for the integrated rule engine None
reset() Reinitializes the engine's working memory None
declare(fact) Adds a fact to the knowledge base fact: Fact object
run() Executes all rules against the knowledge base None
get_recommendations() Returns strategy recommendations with conflicts resolved None
record_rule_fired(rule_name) Tracks which rules have fired rule_name: Name of rule

4.4 Integrated Analysis Functions

High-level functions for running the complete strategy analysis:

This function coordinates:

  1. Loading data from all sources
  2. Transforming data into facts for the rule engine
  3. Running the integrated engine with all rule systems
  4. Returning prioritized strategy recommendations

Supporting functions:

  • transform_all_facts(): Converts data into expert system facts
  • load_all_data(): Loads data from various sources

5. Visualization API

The visualization module provides functions to create standardized visualizations for the various dashboards.

5.1 Degradation Visualization Functions

Key functions:

Function Description Key Parameters
st_plot_degradation_rate() Plots tire degradation rate processed_race_data, driver_number
st_plot_regular_vs_adjusted_degradation() Compares raw vs. fuel-adjusted degradation tire_deg_data, compound_names, compound_colors
st_plot_speed_vs_tire_age() Shows sector speeds vs. tire age processed_race_data, driver_number, compound_id
st_plot_fuel_adjusted_degradation() Shows fuel-adjusted degradation processed_race_data, driver_number

5.2 Gap Analysis Visualization Functions

Key functions:

Function Description Key Parameters
st_plot_gap_evolution() Shows gap evolution over time gap_data, driver_number
st_plot_undercut_opportunities() Visualizes undercut windows gap_data, driver_number
st_plot_gap_consistency() Shows consistency of gaps gap_data, driver_number

6. UI Component APIs

The Streamlit dashboard components provide high-level interfaces for rendering different views.

Key rendering functions:

Function Description File
render_overview() Main dashboard overview components/overview_view.py
render_degradation_view() Tire degradation analysis components/degradation_view.py
render_gap_analysis() Gap analysis visualization components/gap_analysis_view.py
render_time_predictions_view() Lap time predictions components/time_predictions_view.py
render_radio_analysis() Team radio analysis components/radio_analysis_view.py
render_recommendations_view() Strategy recommendations components/recommendations_view.py
render_strategy_chat() LLM-powered strategy chat components/strategy_chat.py

7. Main Application Flow

The main application flow in app.py coordinates all the APIs:

8. Extending the System

To extend the system with new capabilities:

  1. Add new data sources: Implement a data loader function and add to utils/data_loader.py
  2. Add new processing: Implement processing function in utils/processing.py
  3. Add new models: Create a prediction module following the pattern in ML_tyre_pred/ML_utils/
  4. Add new rules: Extend one of the rule classes or create a new rule class
  5. Add new visualizations: Add functions to utils/visualization.py
  6. Add new UI components: Create new component files in components/

For detailed guidance on extending the system, see the Integration Guide.

On this page