A Python-backed D3.js web application for F1 enthusiasts to visualize lap times, tire strategies, driver/team performance, telemetry, and race analytics with ML-powered race predictions.
π Live Demo: https://f1-dash.live/
- π Lap Time Analysis - Scatter plots, box plots, lap-by-lap progression with outlier filtering
- π Tire Strategy Visualization - Stint bars with compound colors, pit stop timing
- π Telemetry Overlays - Speed traces, throttle/brake, gear shifts, multi-channel comparison
- π Driver Comparisons - Head-to-head lap times, sector comparisons
- π Race Progression - Position changes over laps, gap analysis
- β±οΈ Stint Analysis - Tire degradation curves, compound performance
- π€ Race Predictions (ML) - XGBoost-powered race predictions based on practice session data
flowchart TB
subgraph Frontend["π₯οΈ Frontend (Static Site)"]
UI[D3.js Visualizations]
API_Client[API Client]
end
subgraph Backend["βοΈ Backend (FastAPI)"]
Routes[API Routes]
Services[Service Layer]
Repos[Repository Layer]
ML[ML Prediction Service]
end
subgraph External["π External Data"]
FastF1[FastF1 API]
F1_Official[F1 Timing Data]
end
subgraph Storage["πΎ Storage"]
FileStore[File Storage JSON]
Cache[FastF1 Cache]
Models[ML Models]
end
UI --> API_Client
API_Client -->|REST API| Routes
Routes --> Services
Services --> Repos
Services --> ML
Repos --> FileStore
Services -->|Data Ingestion| FastF1
FastF1 --> F1_Official
FastF1 --> Cache
ML --> Models
sequenceDiagram
participant User
participant Frontend
participant API
participant Service
participant FastF1
participant Storage
User->>Frontend: Select Session
Frontend->>API: POST /ingest/session
API->>Service: Ingest Request
Service->>FastF1: Fetch Session Data
FastF1-->>Service: Lap Times, Telemetry
Service->>Storage: Save JSON
Service-->>API: Session Created
API-->>Frontend: Session ID
Frontend->>API: GET /laps/{session_id}
API->>Storage: Read Laps
Storage-->>API: Lap Data
API-->>Frontend: JSON Response
Frontend->>User: Render D3 Chart
- β‘ FastAPI - Modern Python web framework with async support
- ποΈ FastF1 - F1 data access library (2018+ seasons)
- β Pydantic - Data validation and serialization
- π€ XGBoost - Machine learning for race predictions
- ποΈ Repository Pattern - Pluggable storage (file-based JSON, ready for DynamoDB)
- π D3.js - Data visualization library
- π Vanilla JavaScript - No framework dependencies
- π¦ ES Modules - Modern JavaScript architecture
- Security headers middleware (CSP, X-Frame-Options, etc.)
- Rate limiting (100 req/min API, 5 req/min ingestion)
- CORS configuration with explicit origins
- API key authentication for sensitive endpoints
- XSS prevention (safe DOM manipulation)
- Path traversal protection
- π Python 3.11+
- π¦ Node.js (optional, for frontend development server)
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment (optional)
cp .env.example .env
# Run the server
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000
- π API Documentation:
http://localhost:8000/docs - π OpenAPI Schema:
http://localhost:8000/openapi.json - π Health Check:
http://localhost:8000/health
cd frontend
# Option 1: Python simple server
python -m http.server 3000
# Option 2: Any static file server
npx serve -l 3000The frontend will be available at http://localhost:3000
This project includes a render.yaml blueprint for easy deployment:
- π€ Push your code to GitHub
- π Go to render.com and create a new Blueprint
- π Connect your GitHub repository
- β¨ Render will auto-detect the
render.yamland create both services
After deployment, configure environment variables in the Render dashboard:
F1_CORS_ORIGINS- Your frontend URL (e.g.,https://f1-dash.live)F1_API_KEYS- Optional API keys for protected endpoints
Update frontend/config.js with your backend URL:
window.F1_API_URL = 'https://f1-dash-api.onrender.com/api/v1';| Variable | Description | Default |
|---|---|---|
F1_ENVIRONMENT |
development, staging, or production |
development |
F1_CORS_ORIGINS |
Comma-separated allowed origins | http://localhost:3000 |
F1_API_KEYS |
Comma-separated API keys | (none) |
F1_API_KEY_AUTH_ENABLED |
Enable API key auth | false |
F1_RATE_LIMIT_ENABLED |
Enable rate limiting | true |
F1_TRUSTED_HOSTS |
Allowed hosts (production) | localhost |
GET /api/v1/schedule/years- Get available yearsGET /api/v1/schedule/events/{year}- Get events for a yearGET /api/v1/schedule/sessions/{year}/{round}- Get sessions for an event
GET /api/v1/sessions- List sessions (filterable by year)GET /api/v1/sessions/years- Get available yearsGET /api/v1/sessions/events/{year}- Get events for a yearGET /api/v1/sessions/id/{session_id}- Get specific sessionGET /api/v1/sessions/{year}/{round}- Get event sessions
GET /api/v1/laps/{session_id}- Get session lapsGET /api/v1/laps/{session_id}/fastest- Get fastest lapsGET /api/v1/laps/{session_id}/distribution- Lap time distributionGET /api/v1/laps/{session_id}/compound-performance- Compound analysis
GET /api/v1/strategy/{session_id}/stints- Get tire stintsGET /api/v1/strategy/{session_id}/summary- Strategy summary
GET /api/v1/telemetry/{session_id}/{driver}/{lap}- Get lap telemetryPOST /api/v1/telemetry/{session_id}/compare- Compare multiple laps
GET /api/v1/predictions/race/{year}/{round}- Get race predictionGET /api/v1/predictions/backtest/{year}/{round}- Backtest with actual resultsGET /api/v1/predictions/model/info- Model status and infoPOST /api/v1/predictions/train- Train the prediction model
GET /api/v1/ingest/status/{year}/{round}/{session}- Check ingestion statusPOST /api/v1/ingest/session- Ingest session dataPOST /api/v1/ingest/telemetry- Ingest telemetry data
cd backend
source venv/bin/activate
# Run all tests
pytest
# Run with coverage
pytest --cov=app
# Run specific test file
pytest tests/unit/test_services.py -vf1-dash/
βββ README.md
βββ render.yaml # Render deployment blueprint
βββ backend/
β βββ app/
β β βββ api/ # FastAPI routes
β β β βββ schemas/ # Request/Response schemas
β β β βββ v1/ # API version 1 endpoints
β β βββ config.py # Settings management
β β βββ dependencies.py # Dependency injection
β β βββ domain/ # Domain models and enums
β β β βββ enums/
β β β βββ models/
β β βββ ingestion/ # FastF1 data fetching
β β βββ main.py # Application entry point
β β βββ middleware/ # Security middleware
β β βββ repositories/
β β β βββ file/ # File-based implementations
β β β βββ interfaces/ # Abstract repository interfaces
β β βββ services/ # Business logic layer
β βββ data/
β β βββ models/ # Pre-trained ML models
β βββ tests/
β βββ requirements.txt
βββ frontend/
βββ index.html
βββ config.js # API URL configuration
βββ css/
βββ js/
βββ api/ # API client
βββ charts/ # D3.js chart components
βββ utils/ # Utilities (colors, formatters, security)
The prediction model uses XGBoost trained on historical race data (2023-2024 seasons):
π Features (15 total):
- Best lap delta, average pace delta, consistency (std dev) for FP1, FP2, FP3
- Session positions for each practice session
- Long run pace delta for each session
π Model Performance:
- MAE: ~0.49 positions (training data)
- 87% of predictions within 1 position
Pre-trained model files are included in backend/data/models/ for production deployment.
Data is fetched from the official F1 timing system via the FastF1 library. Available data includes:
- π Sessions from 2018 onwards
- β±οΈ Lap timing and sector times
- π Tire compound and stint information
- π Car telemetry (speed, throttle, brake, gear)
- π€οΈ Weather conditions
- π© Race control messages
For production deployment:
- Set
F1_ENVIRONMENT=production - Configure
F1_CORS_ORIGINSto your specific frontend domain - Enable API key authentication for ingestion endpoints
- Use HTTPS (handled automatically by Render)
- Review and configure
F1_TRUSTED_HOSTS
If you find this project useful, consider supporting its development:
MIT