Skip to content

bokiiiiiii/Formula-1-Data-Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

111 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Formula 1 Data Analysis

Python FastF1 License

Project Description

A comprehensive Formula 1 data analysis and visualization tool that automatically downloads telemetry data, generates insightful analytical plots, and optionally posts them to Instagram. This project leverages the FastF1 API to provide in-depth analysis of F1 races, qualifying sessions, and practice sessions.

Project Start Date: January 2024

Instagram

๐Ÿ“ธ Follow our analysis: @f1.data.analysis

Key Features

๐Ÿ–ฅ๏ธ Modern GUI Interface

  • Intuitive event selection interface built with CustomTkinter
  • Dark mode design for comfortable viewing
  • Real-time progress tracking and logging

๐Ÿ“Š Comprehensive Data Analysis

  • Event Selection: Interactive GUI for selecting specific Grand Prix events from any F1 season
  • Data Acquisition: Automatic download of telemetry data, lap times, and session information via FastF1 API
  • Advanced Caching: Built-in FastF1 cache management for faster subsequent loads
  • Retry Logic: Network error handling with automatic retry mechanism

๐Ÿ“ˆ Visualization Features

The project generates a wide variety of analytical plots:

Track & Lap Analysis

  • ๐Ÿ—บ๏ธ Track map with annotated corners - Visual representation of circuit layouts
  • ๐ŸŽ๏ธ Qualifying flying lap analysis - Detailed telemetry breakdown
  • ๐Ÿ Sprint Qualifying flying lap analysis - Sprint session insights
  • ๐Ÿš€ Race fastest lap analysis - Complete telemetry data visualization

Performance Metrics

  • โฑ๏ธ Driver lap time distribution - Statistical lap time analysis
  • ๐Ÿ“‰ Driver lap time scatter plots - Lap-by-lap performance visualization
  • โ›ฝ Fuel-corrected lap times (Scatterplot) - Performance adjusted for fuel load
  • ๐Ÿงฎ Fuel-corrected lap times (Gaussian Processes) - Advanced ML-based analysis
  • ๐ŸŒก๏ธ Driver race evolution heatmap - Race pace visualization over time

Strategic Analysis

  • ๐Ÿ† Team pace ranking - Comparative team performance
  • ๐ŸŽฒ Monte Carlo race strategy simulation - Probabilistic strategy analysis

Vehicle Dynamics

  • ๐ŸŽฏ G-G diagram (friction circle) - Longitudinal vs lateral acceleration with speed-mapped colours

๐Ÿ’พ Output Management

  • High-quality PNG image export
  • Automatic caption generation for social media
  • Organized file structure with timestamped outputs

๐Ÿ“ฑ Social Media Integration

  • Automatic Instagram posting capability
  • Custom caption generation for each plot type
  • Configurable posting options

Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager
  • Git (for cloning the repository)

Setup Instructions

  1. Clone the Repository

    git clone https://github.com/bokiiiiiii/Formula-1-Data-Analysis.git
    cd Formula-1-Data-Analysis
  2. Create Virtual Environment (Recommended)

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install Dependencies

    pip install -r requirements.txt
  4. Configure Instagram (Optional)

    • If you want to use the auto-posting feature, create a config.json file
    • Add your Instagram credentials (refer to config.py for structure)
  5. Run FastF1 Cache Setup

    # The first run will create a cache directory for faster subsequent loads
    python main.py

Usage

Quick Start

  1. Launch the Application

    python main.py
  2. Select Your Event

    • A GUI window will appear showing available F1 events
    • Choose the Grand Prix you want to analyze
    • Click "Start Analysis" to begin
  3. View Results

    • Plots will be automatically generated and saved
    • Check the output folder (default: ../Pic) for images and captions

Configuration Options

The project uses a flexible configuration system. Key settings in main.py:

Basic Settings

YEAR = 2024                    # F1 season year
SESSION_NAME = "Q"             # Session(s): "FP1", "FP2", "FP3", "Q", "S", "R", or "FP1+Q+R"
FOLDER_PATH = "../Pic"         # Output directory for plots

Plot Function Control

ENABLE_ALL = True              # Enable all plotting functions
FUNC_PARAMS = {
    "plot_annotated_qualifying_flying_lap": {"enable": True, "session": "Q"},
    "plot_annotated_race_fastest_lap": {"enable": True, "session": "R"},
    "plot_team_pace_ranking": {"enable": True, "session": "Q"},
    # ... more plot functions
}

Available Sessions

  • FP1, FP2, FP3 - Free Practice sessions
  • Q - Qualifying
  • S - Sprint Qualifying
  • R - Race
  • Combined: FP1+Q+R (processes multiple sessions)

Project Structure

Formula-1-Data-Analysis/
โ”‚
โ”œโ”€โ”€ main.py                          # Main application entry point
โ”œโ”€โ”€ config.py                        # Configuration management
โ”œโ”€โ”€ config.json                      # User configuration file (create manually)
โ”œโ”€โ”€ logger_config.py                 # Logging setup
โ”œโ”€โ”€ performance_monitor.py           # Performance tracking utilities
โ”œโ”€โ”€ retry_utils.py                   # Network retry logic
โ”œโ”€โ”€ auto_ig_post.py                  # Instagram posting module
โ”œโ”€โ”€ requirements.txt                 # Python dependencies
โ”œโ”€โ”€ README.md                        # Project documentation
โ”‚
โ”œโ”€โ”€ plot_functions/                  # Plotting modules
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ plot_runner.py              # Plot execution coordinator
โ”‚   โ”œโ”€โ”€ utils.py                    # Shared utilities
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ annotated_qualifying_flying_lap.py
โ”‚   โ”œโ”€โ”€ annotated_race_fatest_lap.py
โ”‚   โ”œโ”€โ”€ annotated_sprint_qualifying_flying_lap.py
โ”‚   โ”œโ”€โ”€ driver_fuel_corrected_laptimes_gaussian_processes.py
โ”‚   โ”œโ”€โ”€ driver_fuel_corrected_laptimes_scatterplot.py
โ”‚   โ”œโ”€โ”€ driver_laptimes_distribution.py
โ”‚   โ”œโ”€โ”€ driver_laptimes_scatterplot.py
โ”‚   โ”œโ”€โ”€ driver_g_g_diagram.py
โ”‚   โ”œโ”€โ”€ driver_race_evolution_heatmap.py
โ”‚   โ”œโ”€โ”€ monte_carlo_race_strategy.py
โ”‚   โ”œโ”€โ”€ plot_track_with_annotated_corners.py
โ”‚   โ”œโ”€โ”€ race_fatest_lap_telemetry_data.py
โ”‚   โ””โ”€โ”€ team_pace_ranking.py
โ”‚
โ””โ”€โ”€ logs/                            # Application logs (auto-generated)

Dependencies

Core Libraries

  • FastF1 (โ‰ฅ3.5): F1 data acquisition and analysis
  • Matplotlib (โ‰ฅ3.8): Plotting and visualization
  • Pandas (โ‰ฅ2.0): Data manipulation
  • NumPy (โ‰ฅ2.0): Numerical computing
  • SciPy (โ‰ฅ1.10): Scientific computing

UI & Automation

  • CustomTkinter (โ‰ฅ5.2): Modern GUI framework
  • Playwright (โ‰ฅ1.40): Browser automation for Instagram

Machine Learning

  • Scikit-learn (โ‰ฅ1.3): ML algorithms (Gaussian Processes)
  • Seaborn (โ‰ฅ0.13): Statistical data visualization

Utilities

  • Pillow (โ‰ฅ10.0): Image processing
  • python-dotenv (โ‰ฅ1.0): Environment variable management
  • pydantic (โ‰ฅ2.0): Data validation

See requirements.txt for complete dependency list.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Formula 1 Data Analysis and Visualisations

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages