Real-time pit stop recommendations powered by machine learning
Validated on 59 real pit decisions from Race 2 (Jeddah 2024):
| Metric | Result |
|---|---|
| Expert Agreement | 50% within ยฑ2 laps (Grade B) |
| Time Saved | 7.5s per vehicle (~157.5s fleet-wide) |
| Position Equivalent | 2-3 positions in sprint racing |
| Damage Detection | 6/7 correct (85.7% precision) |
| Position-Aware Decisions | 30/59 (50.8%) used strategic context |
Grade Distribution:
- โ Grade A (Perfect Match): 25.4%
- โ Grade B (Close Match): 50.8%
โ ๏ธ Grade C (Different Approach): 23.7%
# Install dependencies
pip install -r requirements.txt
# Start web application
python3 webapp.py
# Open browser
open http://localhost:5002Features:
- ๐ฎ Live Demo - Interactive strategy recommender
- ๐ Data Explorer - Race 1 & 2 datasets with cleaning pipeline
- ๐ค ML Models - 7 integrated models with performance metrics
- ๐ Results - Validation charts and performance breakdown
- โน๏ธ About - Full project story and technical details
Port already in use?
# Kill existing server
pkill -f "python3 webapp.py"
# Or use a different port
python3 webapp.py # edit webapp.py line: app.run(port=5003)Missing dependencies?
pip install flask numpy pandas xgboost lifelines scikit-learnTo stop the server: Press Ctrl+C in the terminal
- XGBoost Tire Wear Model (776 KB) - Predicts degradation curves (MAE: 0.287s, Rยฒ: 0.842)
- Cox Hazard Safety Car Model (6.8 KB) - Estimates caution probability
- Damage Detector - Identifies tire/aero/mechanical issues (Precision: 0.89)
- Position Optimizer - Strategic decisions based on gaps and position
- Monte Carlo Engine - 5,000-10,000 simulations with variance reduction
- 51-Feature Pipeline - Weather + telemetry + race context
- Parallel Processor - 4-8x speedup for real-time decisions
Input โ Damage Detection โ Position Analysis โ Tire Wear Prediction
โ โ โ โ
Monte Carlo Simulations (1000+) with Variance Reduction
โ
Optimal Pit Lap + Confidence Interval + Strategy Type + Reasoning
Response Time: < 5 seconds
Toyota GR Cup (Race 1 & Race 2):
Race 1/vir_lap_time_R1.csv- 12,768 laps (after cleaning)Race 2/R2_telemetry_features.csv- 441 laps with 51 features- Cleaned 16-21% of rows (removed sentinel values, outliers, invalid laps)
Features Used:
- Weather: track temp, air temp, humidity, wind, rain
- Telemetry: sector times, top speed, tire age, stint length
- Context: position, gaps, flags, pit history
| Strategy | Description | Frequency | Success Rate |
|---|---|---|---|
| Aggressive Undercut | Pit early to gain position | 20.3% | 75.0% |
| Defensive Cover | Cover threat from behind | 30.5% | 83.3% |
| Hold Position | Stay out in pack racing | 13.6% | 62.5% |
| Optimal Stint | Maximize tire usage in clear air | 23.7% | 85.7% |
| Damage Pit | Emergency pit for repairs | 11.9% | 100% (necessary) |
HacktheTrack2025/
โโโ webapp.py # ๐ฎ Flask web application (main entry point)
โโโ requirements.txt # ๐ฆ Python dependencies
โโโ Makefile # โ๏ธ Build automation
โโโ CONTRIBUTING.md # ๐ Contribution guidelines
โ
โโโ data/ # ๐ Race datasets (Race 1 & 2)
โ โโโ race1/ # Training data (12,768 laps)
โ โโโ race2/ # Validation data (441 laps)
โ
โโโ models/ # ๐ค Trained ML models
โ โโโ wear_quantile_xgb.pkl # XGBoost tire wear (776 KB)
โ โโโ cox_hazard.pkl # Safety car predictor (6.8 KB)
โ โโโ ... # Overtake, Kalman, metadata
โ
โโโ src/grcup/ # ๐ง Core AI engine
โ โโโ models/ # Model implementations
โ โ โโโ wear_quantile_xgb.py # Tire degradation
โ โ โโโ sc_hazard.py # Safety car probability
โ โ โโโ damage_detector.py # Damage detection
โ โ โโโ overtake.py # Overtake prediction
โ โโโ strategy/ # Strategy optimization
โ โ โโโ optimizer_improved.py # Main optimizer
โ โ โโโ position_optimizer.py # Position-aware logic
โ โ โโโ monte_carlo.py # Simulation engine
โ โโโ features/ # Feature engineering
โ โโโ evaluation/ # Performance metrics
โ
โโโ templates_webapp/ # ๐จ Web UI (6 pages)
โ โโโ base.html # Base template + navbar
โ โโโ index.html # Homepage
โ โโโ live_demo.html # Interactive demo
โ โโโ data_explorer.html # Dataset viewer
โ โโโ ml_models.html # Model details
โ โโโ results.html # Validation charts
โ โโโ about.html # Full story
โ
โโโ scripts/ # ๐ง Utilities & validation
โ โโโ validate_race2_improved_full.py # Full validation
โ โโโ compare_production_vs_actual.py # Baseline comparison
โ โโโ ... # More analysis scripts
โ
โโโ reports/production/ # ๐ Validation results
โ โโโ race2_full_validation.json # 59 decisions analyzed
โ
โโโ notebooks/ # ๐ Training & experimentation
โ โโโ train_models.py # Model training pipeline
โ โโโ validate_walkforward.py # Walk-forward validation
โ
โโโ docs/ # ๐ Documentation (25+ guides)
โ โโโ IMPROVEMENTS_IMPLEMENTED.md # Technical details
โ โโโ WEBAPP_GUIDE.md # Web app usage
โ โโโ ... # Architecture, deployment, etc.
โ
โโโ modal_clean/ # โ๏ธ Cloud deployment (Modal)
โโโ grcup_modal.py # Serverless GPU functions
- Python 3.9+
- XGBoost - Quantile regression for tire wear
- lifelines - Cox proportional hazards for safety car
- NumPy/Pandas - Data processing
- scikit-learn - Model utilities
- Flask - Web framework
- Chart.js - Interactive visualizations
WEBAPP_GUIDE.md- Complete web app usage guideWEBAPP_FIXES_SUMMARY.md- Model integration detailsIMPROVEMENTS_IMPLEMENTED.md- Technical improvements (347 lines)FINAL_IMPROVEMENTS_SUMMARY.md- Production deployment summary
Current Lap: 21 | Tire Age: 19 | Position: P4
Gap Ahead: 1s | Gap Behind: 2s
โ AI recommends: Lap 35 (defensive_cover, 56% confidence)
Reasoning: Cover undercut threat while managing tire degradation
Lap Times: [91.2, 91.5, 92.1, 95.3, 96.8] (spike!)
Sector Drop: โ | Speed Loss: โ
โ AI recommends: Immediate pit (damage_pit, 80% confidence)
Reasoning: Lap time spike + sector drop + speed loss detected
What makes this Grade B:
- โ Matched crew decisions 50% of the time within 2 laps
- โ Position-aware reasoning in half the decisions
- โ Damage detection handled 40% of Race 2 pits
- โ Real-time capable (<5s response)
- โ Transparent reasoning with confidence intervals
Not Grade A because:
- Some decisions differ due to team-specific factors (fuel strategy, driver feedback)
- Conservative in traffic situations (prioritizes position defense)
- Calibration could be tighter (ยฑ80s confidence intervals)
Near-term (Grade B โ A):
- Track-specific calibration
- Live telemetry integration
- Multi-stint lookahead
Mid-term:
- iPad-friendly pit wall dashboard
- Driver feedback integration
- Real-time adjustments during race
Long-term:
- Reinforcement learning policy training
- Full-field strategic interactions
- Expand to IMSA, WEC, F1
MIT License
Built for the Toyota GR Cup AI Hackathon
Goal: Create an AI copilot that race engineers can trust at the track.
Status: Production-ready, Grade B, 50% expert agreement