Skip to content

Arnie016/HacktheTrack2025

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AI Pit Strategy Optimizer - Toyota GR Cup

Real-time pit stop recommendations powered by machine learning

Grade B Expert Agreement Time Saved


๐Ÿ† Results

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%

๐Ÿš€ Quick Start

Run the Interactive Demo

# Install dependencies
pip install -r requirements.txt

# Start web application
python3 webapp.py

# Open browser
open http://localhost:5002

Features:

  • ๐ŸŽฎ 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

Troubleshooting

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-learn

To stop the server: Press Ctrl+C in the terminal


๐Ÿง  How It Works

7 Integrated ML Models

  1. XGBoost Tire Wear Model (776 KB) - Predicts degradation curves (MAE: 0.287s, Rยฒ: 0.842)
  2. Cox Hazard Safety Car Model (6.8 KB) - Estimates caution probability
  3. Damage Detector - Identifies tire/aero/mechanical issues (Precision: 0.89)
  4. Position Optimizer - Strategic decisions based on gaps and position
  5. Monte Carlo Engine - 5,000-10,000 simulations with variance reduction
  6. 51-Feature Pipeline - Weather + telemetry + race context
  7. Parallel Processor - 4-8x speedup for real-time decisions

Decision Process

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


๐Ÿ“Š Datasets

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 Types

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)

๐Ÿ“ Project Structure

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

๐Ÿ”ง Technical Stack

  • 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

๐Ÿ“– Documentation

  • WEBAPP_GUIDE.md - Complete web app usage guide
  • WEBAPP_FIXES_SUMMARY.md - Model integration details
  • IMPROVEMENTS_IMPLEMENTED.md - Technical improvements (347 lines)
  • FINAL_IMPROVEMENTS_SUMMARY.md - Production deployment summary

๐ŸŽฅ Demo Scenarios

Scenario 1: Defensive Cover

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

Scenario 2: Damage Detection

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

๐Ÿ Validation Highlights

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)

๐Ÿ”ฎ Future Work

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

๐Ÿ“„ License

MIT License


๐Ÿ™ Acknowledgments

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

Deployment ready

Deployment ready

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors