api reference - VforVitorio/F1_Strat_Manager GitHub Wiki
API Reference
- Overview
- System Architecture
- Installation and Setup
- Streamlit Dashboard
- Strategy Recommendations View
- Gap Analysis View
- Radio Analysis View
- Time Predictions View
- Strategy Chat Interface
- Machine Learning Models
- Lap Time Prediction
- Tire Degradation Modeling
- Vision-based Gap Calculation
- NLP Pipeline
- Radio Transcription
- Sentiment and Intent Analysis
- Named Entity Recognition
- Expert System
- Degradation Rules
- Gap Analysis Rules
- Radio Message Rules
- Integrated Rule Engine
- Developer Guide
- API Reference
- Integration Guide
API Reference
- scripts/IS_agent/N06_rule_merging.ipynb
- scripts/IS_agent/utils/N06_rule_merging.py
- scripts/ML_tyre_pred/ML_utils/N00_model_lap_prediction.py
- scripts/ML_tyre_pred/N00_model_lap_prediction.ipynb
- scripts/app/app.py
- scripts/app/components/degradation_view.py
- scripts/app/utils/processing.py
- scripts/app/utils/visualization.py
- scripts/lap_prediction.ipynb
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 datamodel_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 modelvalidate_lap_data(input_data)
: Validates input telemetry dataadd_sequential_features(df)
: Adds features based on previous lapsprepare_features_for_prediction(df, feature_names)
: Prepares model inputsformat_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:
- Loading data from all sources
- Transforming data into facts for the rule engine
- Running the integrated engine with all rule systems
- Returning prioritized strategy recommendations
Supporting functions:
transform_all_facts()
: Converts data into expert system factsload_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:
- Add new data sources: Implement a data loader function and add to
utils/data_loader.py
- Add new processing: Implement processing function in
utils/processing.py
- Add new models: Create a prediction module following the pattern in
ML_tyre_pred/ML_utils/
- Add new rules: Extend one of the rule classes or create a new rule class
- Add new visualizations: Add functions to
utils/visualization.py
- Add new UI components: Create new component files in
components/
For detailed guidance on extending the system, see the Integration Guide.
On this page
- API Reference
- 1. Core API Structure
- 2. Data Loading and Processing APIs
- 2.1 Data Loading Functions
- 2.2 Data Processing Functions
- 3. Machine Learning Model APIs
- 3.1 Lap Time Prediction API
- 3.2 Tire Degradation Prediction API
- 4. Expert System API
- 4.1 Class Hierarchy
- 4.2 Expert System Fact Classes
- 4.3 Rule Engine API
- 4.4 Integrated Analysis Functions
- 5. Visualization API
- 5.1 Degradation Visualization Functions
- 5.2 Gap Analysis Visualization Functions
- 6. UI Component APIs
- 7. Main Application Flow
- 8. Extending the System