Skip to content

CricOptima is an advanced fantasy cricket optimization platform designed to help users build winning teams using data science and linear programming.

License

Notifications You must be signed in to change notification settings

millenniumsingha/CricOptima

Repository files navigation

🏏 CricOptima

Streamlit App Python FastAPI Streamlit Docker

CricOptima is an advanced, AI-powered fantasy cricket team optimizer. I designed and built this system to move beyond simple heuristics, implementing Gradient Boosting for player performance prediction and mathematical constraint satisfaction for optimal team selection.

πŸ”΄ LIVE DEMO - Experience the AI optimizer in action!


πŸ“š Documentation


πŸš€ Key Features

Build optimal fantasy cricket teams using machine learning predictions and constraint optimization algorithms.

πŸ“Έ Screenshots

Dashboard Constraints Setup Player Analytics
Dashboard Constraints Analytics
Optimization Results Head-to-Head Simulation
Results Head-to-Head Simulation

✨ Features

Feature Description
πŸ€– ML Predictions Gradient Boosting model predicts player fantasy points
🎯 Smart Optimization Builds best team within budget and role constraints
πŸ“Š Analytics Dashboard Explore player stats, value scores, and predictions
πŸ”Œ REST API Full-featured FastAPI backend with Swagger docs
🐳 Docker Ready One-command deployment with docker-compose

πŸš€ Quick Start

Option 1: Docker (Recommended)

# Clone repository
git clone https://github.com/millenniumsingha/CricOptima.git
cd CricOptima

# Train ML model and start services
docker-compose --profile training up train
docker-compose up -d

# Access:
# - Dashboard: http://localhost:8501
# - API Docs:  http://localhost:8000/docs

Option 2: Local Installation

# Install dependencies
pip install -r requirements.txt

# Train ML model
python -m src.ml.train

# Start API (terminal 1)
uvicorn api.main:app --reload

# Start Dashboard (terminal 2)
streamlit run app/streamlit_app.py

πŸ“Š How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Player Data   │────▢│   ML Predictor  │────▢│   Predictions   β”‚
β”‚   (Stats/Form)  β”‚     β”‚ (Gradient Boost)β”‚     β”‚  (Points/Conf)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                         β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
                        β”‚    Optimizer    β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚  (Constraints)  β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚   Optimal XI    β”‚
                        β”‚ (Best Team)     β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

ML Features Used

  • Recent batting/bowling averages
  • Strike rate & economy rate
  • Form trend (improving/declining)
  • Consistency score
  • Matches played (experience)

Optimization Constraints

  • Budget limit (default: 1000 points)
  • Team size: 11 players
  • Min 3 batsmen, 3 bowlers, 1 all-rounder, 1 wicket-keeper
  • Max 7 players from same team

πŸ”Œ API Reference

Method Endpoint Description
GET /players List all players with filters
GET /players/{id} Get single player details
POST /optimize Build optimal team
GET /predictions Get ML predictions
POST /teams/validate Validate team selection
GET /health Health check

Example: Get Optimal Team

curl -X POST "http://localhost:8000/optimize" \
  -H "Content-Type: application/json" \
  -d '{"budget": 1000, "team_name": "My Dream XI"}'

πŸ“ Project Structure

CricOptima/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ models/          # Data models (Player, Team, Match)
β”‚   β”œβ”€β”€ scoring/         # Fantasy points calculator
β”‚   β”œβ”€β”€ optimizer/       # Team optimization algorithm
β”‚   β”œβ”€β”€ ml/              # ML prediction model
β”‚   └── data/            # Data layer & sample data
β”œβ”€β”€ api/                 # FastAPI backend
β”œβ”€β”€ app/                 # Streamlit dashboard
β”œβ”€β”€ tests/               # Test suite
└── ml_models/           # Trained models

πŸ§ͺ Testing

# Run all tests
pytest tests/ -v

# With coverage
pytest tests/ --cov=src --cov=api

🎯 Fantasy Scoring Rules

Category Points
Run 0.5
Four +1 bonus
Six +2 bonus
50 runs +10 bonus
100 runs +20 bonus
Wicket 10
3-wicket haul +5 bonus
5-wicket haul +10 bonus
Catch/Stumping/Run-out 10

✨ What's New in v2.0

  • πŸ”Œ Live Integration: Real-time player data fetching via CricAPI.
  • πŸ” User Auth: Secure JWT-based authentication with bcrypt hashing.
  • πŸ’Ύ Team Management: Save, load, and manage your optimized teams.
  • βš–οΈ Smart Comparison: Head-to-Head win probability predictions.
  • 🎲 Monte Carlo Simulation: 1000x match simulation for variance analysis.
  • πŸ“± Mobile First: Fully responsive Streamlit UI for all devices.
  • πŸš€ DevOps Ready: CI/CD pipeline with GitHub Actions.

πŸ—ΊοΈ Roadmap (v3.0 & Beyond)

Phase 1: Advanced Analytics (Q1 2026)

  • Player Consistency Ratings: New metric based on coefficient of variation.
  • ROI Analysis: Cost vs. Points historical trend analysis.
  • Venue Impact: Adjust predictions based on pitch conditions.

Phase 2: Social & Real-time (Q2 2026)

  • Private Leagues: Compete with friends in custom leaderboards.
  • Live Tracking: Real-time point updates via WebSocket during matches.
  • Historical Backtesting: Validate model against past 5 years of IPL data.

πŸ™ Acknowledgments

  • Original project from Internshala Python Training
  • IPL teams and player data
  • scikit-learn, FastAPI, and Streamlit communities

Built with ❀️ for cricket fans and data enthusiasts

About

CricOptima is an advanced fantasy cricket optimization platform designed to help users build winning teams using data science and linear programming.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages