Formula 1 race strategy optimization powered by AI, Monte Carlo simulation, and real F1 telemetry data.
PitWall is a real-time Formula 1 race strategy optimization tool that answers: "When should I pit, and which tires should I use?"
- ποΈ Physics-Based Simulation - Models tire degradation, fuel effects, and pit stop timing
- π² Monte Carlo Analysis - 500 simulations per strategy to measure robustness under uncertainty
- π€ AI Race Engineer - Claude-powered strategy briefs in F1 team radio style
- π Interactive Visualization - Real-time charts and comparison tables
- π Real F1 Data - Built on FastF1 historical telemetry data
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β Next.js β ββββΆ β FastAPI β ββββΆ β FastF1 β
β Frontend β β Backend β β Data β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β
βββββΆ Strategy Optimizer
βββββΆ Monte Carlo Scorer
βββββΆ Claude AI (Anthropic)
- Python 3.9+
- Node.js 18+
- Anthropic API key (Get one here)
- OpenWeather API key (Get one here)
git clone <your-repo-url>
cd HackTAMScd backend
# Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Mac/Linux
# Install dependencies
pip install -r requirements.txt
# Configure environment
# Create backend/.env with:
ANTHROPIC_API_KEY=your_key_here
OPENWEATHER_API_KEY=your_key_hereThis downloads historical F1 data (~15-20 minutes):
cd data_prep
python fetch_reference_data.pycd backend
uvicorn main:app --reload --port 8000Backend will be available at http://localhost:8000
cd frontend
# Install dependencies
npm install
# Configure environment
# Create frontend/.env.local with:
NEXT_PUBLIC_API_URL=http://localhost:8000
# Start dev server
npm run devFrontend will be available at http://localhost:3000
- Select Track: Choose from Bahrain, Spain, Monaco, Silverstone, or Monza
- Configure Race: Set starting tire compound, rain probability, safety car probability
- Optimize: Click "Optimize Strategy" and wait 20-30 seconds
- Analyze Results:
- Top 3 strategies with robustness scores
- AI-generated race engineer brief
- Lap-by-lap visualization
- Monte Carlo robustness analysis
HackTAMS/
βββ backend/
β βββ main.py # FastAPI entry point
β βββ models/
β β βββ schemas.py # Pydantic data models
β β βββ tire.py # Tire degradation curves
β βββ engine/
β β βββ lap_sim.py # Lap time simulator
β β βββ optimizer.py # Strategy optimizer
β β βββ monte_carlo.py # Robustness scorer
β βββ ai/
β β βββ race_engineer.py # Claude AI integration
β βββ data/
β βββ tracks.json # Track metadata
β βββ cache/ # FastF1 cache (gitignored)
βββ frontend/
β βββ app/
β β βββ page.tsx # Main app page
β β βββ layout.tsx
β βββ components/
β β βββ ConfigPanel.tsx
β β βββ AIBrief.tsx
β β βββ StrategyChart.tsx
β β βββ ComparisonTable.tsx
β β βββ RobustnessChart.tsx
β βββ lib/
β βββ api.ts # Backend API client
βββ data_prep/
βββ fetch_reference_data.py # Data pre-caching script
Health check
Returns list of available tracks
Main optimization endpoint
Request Body:
{
"track": "bahrain",
"total_laps": 57,
"starting_compound": "SOFT",
"fuel_load_kg": 100,
"rain_probability": 0.0,
"safety_car_probability": 0.2
}Response:
{
"strategies": [
{
"stops": [{"lap": 18, "compound": "MEDIUM"}],
"total_race_time_seconds": 5234.5,
"robustness_score": 87.3,
"p50_time": 5235.1,
"p90_time": 5289.7
}
],
"ai_brief": "Box lap 18 for mediums...",
"config": { ... }
}Backend:
- FastAPI - High-performance Python web framework
- FastF1 - Official F1 telemetry library
- NumPy/SciPy - Numerical computation
- Anthropic Claude - AI strategy brief generation
Frontend:
- Next.js 14 - React framework with App Router
- TypeScript - Type safety
- TailwindCSS - Styling
- Recharts - Data visualization
- Optimization Time: ~10 seconds (deterministic optimizer)
- Monte Carlo Scoring: ~15 seconds (500 simulations)
- Total Response Time: ~25-30 seconds
- Strategy Space: ~5,000 candidate strategies per race
For a 2-minute demo:
- Set Bahrain, SOFT start, 0% rain, 20% SC
- Click "Optimize" β show 3 strategies + AI brief
- Adjust rain to 60% β re-optimize β strategies shift
- Explain robustness scores: "Strategy 2 is 0.8s slower but 12 points more robust"
- Close: "Real F1 teams have rooms full of engineers. PitWall puts it in a browser."
- Verify Python 3.9+ is installed:
python --version - Check all dependencies installed:
pip list - Ensure
.envfile exists with valid API keys
- Verify backend is running on port 8000
- Check
frontend/.env.localhas correct API URL - Check browser console for CORS errors
- Reduce Monte Carlo simulations in
backend/engine/monte_carlo.py(500 β 200) - Increase strategy search step size in
optimizer.py
- Run
data_prep/fetch_reference_data.pyfirst - Verify
backend/data/cache/folder exists and is populated - Check internet connection (FastF1 downloads data on first use)
This project was built for a 24-hour hackathon. Contributions welcome!
MIT License - see LICENSE file
- FastF1 library for F1 telemetry data
- Anthropic Claude for AI insights
- F1 community for inspiration
Built with β€οΈ for the racing strategy nerds