Skip to content

Hack by Henry T, Anthony C, Shrihan Bolleni, Edgar Arevalo

Notifications You must be signed in to change notification settings

CodyGargar/PitPerfect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PitPerfect - AI Damage Intelligence

An AI-powered F1 damage detection and race strategy platform that analyzes race footage, generates telemetry data, and provides intelligent pit stop recommendations β€” all visualized in a stunning 3D interactive car model.

🌟 What's New

Comprehensive Video Analysis with Gemini 2.0 Flash

  • Upload race footage β†’ Get complete damage assessment
  • AI-generated synthetic telemetry showing crash impact
  • Automatic 3D model updates with highlighted damage
  • Natural language pit strategy recommendations

Features

  • πŸ€– AI-Powered Damage Detection: Uses Google Gemini 2.0 Flash to analyze race footage and detect damage with confidence scores
  • 🎨 3D Interactive Car Model: Real-time visualization of damaged parts with severity-based highlighting
  • πŸ“Š Synthetic Telemetry Generation: Creates realistic crash event data showing pre/during/post-crash performance
  • πŸ’‘ Intelligent Decision Engine: Computes lap time loss, cumulative impact, and AI-powered pit stop recommendations
  • πŸ’° Budget Analysis: Tracks repair costs against F1 budget cap constraints
  • 🧠 Gemini Reasoning: Natural language explanations for strategic recommendations
  • πŸŽ₯ Video Processing: Multi-frame analysis of uploaded race footage (MP4, MOV, AVI)

Tech Stack

Frontend

  • Next.js 15 - React framework
  • TypeScript - Type safety
  • Tailwind CSS - Styling with custom Williams x Atlassian theme
  • Three.js / React Three Fiber - 3D car visualization
  • Recharts - Telemetry graphs
  • Framer Motion - Animations

Backend

  • FastAPI - Python web framework
  • Google Gemini 2.0 Flash - Vision AI and reasoning
  • OpenCV - Video frame extraction
  • NumPy - Telemetry data generation
  • Uvicorn - ASGI server

Installation

Prerequisites

  • Node.js 20+
  • Python 3.9+
  • Google Gemini API key (Get one here)

Frontend Setup

# Install dependencies
npm install

# Create environment file
cp .env.example .env.local

# Add your Gemini API key to .env.local

# Run development server
npm run dev

Visit http://localhost:3000

Backend Setup

# Navigate to backend directory
cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Create environment file
cp ../.env.example .env

# Add your Gemini API key to .env

# Run backend server
python main.py

Backend API will be available at http://localhost:8000

Usage

  1. Start the backend server (see Backend Setup above)
  2. Start the frontend with npm run dev
  3. Upload race footage using the "Upload Video" button
  4. View damage detection results in real-time
  5. Analyze telemetry data in the bottom graph panel
  6. Review recommendations in the decision card
  7. Interact with 3D model to inspect damaged parts
  8. Simulate pit stops to see predicted outcomes

Design System

Williams x Atlassian Fusion Theme

  • Primary: #00205B (Williams Navy Blue)
  • Secondary: #00A3E0 (Cyan Blue)
  • Warning: #FFC300 (Medium damage)
  • Severe: #FF5733 (Critical damage)
  • Success: #2ECC71 (Fixed/optimized)
  • Neutral: #141414 (Background)

API Endpoints

POST /analyze_video_comprehensive ⭐ NEW

Comprehensive video analysis - Returns damage detection, telemetry data, and pit strategy in one call.

Request: multipart/form-data with video file

Response:

{
  "crash_description": "Contact with barrier in Turn 4 resulted in front wing damage",
  "impact_severity": "High",
  "damage_detection": {
    "timestamp": "2024-01-15T10:30:45",
    "car_id": "RB20",
    "detected_parts": [
      {"part": "front wing", "severity": 0.75, "confidence": 0.90},
      {"part": "left front tire", "severity": 0.45, "confidence": 0.85}
    ]
  },
  "telemetry_data": [
    {"lap": 1, "speed": 310.2, "throttle": 94.5, "temperature": 84.3, "damage_event": false},
    {"lap": 12, "speed": 217.1, "throttle": 47.2, "temperature": 93.8, "damage_event": true}
    // ... 50 laps total
  ],
  "decision": {
    "recommendation": "Pit Now",
    "Ξ”t_lap": 1.215,
    "cum_loss": 46.17,
    "pit_loss": 22.5,
    "budget_impact": 0.00164,
    "suggested_fix": "Replace front wing, left front tire",
    "reasoning": "With severe front wing damage causing 1.2s/lap loss..."
  }
}

POST /analyze_video

Legacy endpoint - damage detection only (see comprehensive endpoint above).

POST /compute_decision

Compute pit stop decision based on damage analysis.

Request:

{
  "damaged_parts": [...],
  "current_lap": 15,
  "total_laps": 58
}

Response:

{
  "Ξ”t_lap": 0.263,
  "cum_loss": 7.36,
  "pit_loss": 22.5,
  "budget_impact": 0.086,
  "recommendation": "Stay Out",
  "suggested_fix": "Replace front wing",
  "reasoning": "..."
}

POST /upload_telemetry

Upload telemetry CSV data for analysis.

Decision Engine Logic

The decision engine calculates:

  1. Lap Time Loss = baseline_lap_time Γ— damage_coefficient Γ— severity
  2. Cumulative Loss = lap_time_loss Γ— remaining_laps
  3. Budget Impact = (part_cost + pit_procedure_cost) / season_budget

Recommendations:

  • Pit Now: Cumulative loss > pit stop duration AND remaining laps > 5
  • Monitor: Lap time loss > 0.2s AND remaining laps > 10
  • Stay Out: Otherwise

Project Structure

HackTx25/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ globals.css
β”‚   β”œβ”€β”€ layout.tsx
β”‚   └── page.tsx
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ CarModel3D.tsx
β”‚   β”œβ”€β”€ CommandBar.tsx
β”‚   β”œβ”€β”€ DecisionCard.tsx
β”‚   β”œβ”€β”€ TelemetryGraph.tsx
β”‚   └── VideoPanel.tsx
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ decision-engine.ts
β”‚   └── types.ts
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py
β”‚   └── requirements.txt
β”œβ”€β”€ tailwind.config.ts
β”œβ”€β”€ next.config.ts
└── package.json

Demo Data

The application includes mock data for demonstration:

  • Pre-configured damaged parts (front wing, tire)
  • Simulated telemetry with damage events
  • Decision engine calculations

Documentation

Testing

Test the backend API:

cd backend
python test_api.py                    # Basic tests
python test_api.py path/to/video.mp4  # Test with video

Future Enhancements

  • Real-time live stream ingestion
  • Multi-car comparison
  • Official F1 telemetry API integration
  • Historical race analysis
  • Weather impact modeling
  • Advanced ML models for damage prediction
  • Gemini 2.5 Pro integration when available

License

MIT

Authors

Built for HackTX 2025

About

Hack by Henry T, Anthony C, Shrihan Bolleni, Edgar Arevalo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published