A web application that allows users to simulate baseball games between teams from different eras, powered by advanced statistics and natural language processing.
- MLB StatsAPI for historical data
- Google's Gemini API for natural language processing
- Flask and Socket.IO for real-time web functionality
- Historical Matchups: Simulate games between any MLB teams from 1920 to present
- Real-time Simulation: Watch pitch-by-pitch with detailed statistics
- Live Scoreboard: Track inning-by-inning scoring and game state
- Base Runner System: Visual tracking of runners and scoring plays
- Pitch Sequences: Detailed pitch information including type, velocity, and outcome
- Batting Lineups: Batter lineup optimized using OBP, SLG, OPS and tracked and maintained for consistent batting order between innings.
- Google Gemini Analysis: Statistical analysis of era normalized player statistics by Google Gemini for creation of realistic play outcomes.
- Calculated Metrics: Each play uses sophisticated metrics calculations. Hit balls are calculated for expected distance. location, and exit velocity based on pitch velocity, venue factors, and historical player statistics (including launch angle and launch speed).
- Era Normalization: Historical stat adjustments for fair matchups
- Advanced Metrics:
- Exit velocity and launch angles
- Pitch velocity and movement
- BABIP and expected outcomes
- Park factors and elevation effects
- Pitcher Arsenal: Authentic pitch types and usage patterns
- Post-game Summary: Comprehensive game breakdown
- MVP Recognition: Top player and pitcher highlights
- AI Analysis: Natural language game commentary
- Performance Tracking: Notable player achievements
- Python 3.8+
- Node.js and npm
- Git- Clone the repository
git clone https://github.com/msamylea/bball.git
cd bball- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate- Install Python dependencies:
pip install -r requirements.txt- Start the Flask server:
python main.py- Open a web browser and navigate to:
http://localhost:8080- Select away team and year
- Select home team and year
- Click "Play Ball!"
- Watch real-time scoreboard updates
- Track base runners
- View pitch sequences
- Check player stats
- Follow fielding plays
- Review game summary
- Check MVP and top performers
- Read AI game analysis
- View final statistics
mlb-historical-simulator/
├── main.py # Flask application entry
├── calculations/ # Statistical modules
│ ├── gameplay_calcs.py
│ └── hit_distance_calc.py
├── data/ # Data processing
│ ├── data_loader.py
│ └── mlb_client.py
├── manager/ # Game state management
│ ├── batting_results.py
│ └── roster_manager.py
├── services/ # Core services
│ └── game_statistics_*.py
├── sim/ # Simulation engine
│ └── simulator.py
├── stats/ # Statistical processing
│ └── base_stats.py
├── templates/ # HTML templates
└── static/ # Static assets
Note
This simulator uses historical data and advanced statistics to create realistic game simulations. Player statistics are normalized across eras to ensure fair matchups. Game analysis is generated using AI but should not be considered official statistical records. The simulation focuses on regular season play and does not account for playoff-specific factors.