Where Luck Meets Science
A comprehensive statistical analysis platform for lottery draws
Features β’ Installation β’ Usage β’ API β’ Contributing
Lottery Lab is a research and educational platform for statistical analysis of lottery draws. It provides comprehensive tools to analyze randomness, detect patterns, and visualize correlations in historical lottery data.
β οΈ Disclaimer: This is a research/educational tool. Lottery outcomes are truly random and cannot be predicted. This software does NOT claim to predict winning numbers.
- Frequency Analysis β Hot/cold numbers, expected vs actual distributions
- Randomness Tests β Chi-square, Kolmogorov-Smirnov, Runs test, Autocorrelation
- Pattern Detection β Consecutive numbers, arithmetic sequences, digit analysis
- Correlation Heatmaps β Number co-occurrence patterns and relationships
- Number Generator β Generate sets based on statistical analysis
- Shannon Entropy β Measure randomness/unpredictability
- Historical Data β Browse and filter past lottery draws
- Clean, responsive UI inspired by Google ML Crash Course
- Real-time updates with HTMX
- Interactive Plotly.js charts
- Bilingual support (Polish/English)
- RESTful API with OpenAPI documentation
- Comprehensive test suite (79% coverage)
- Automatic data updates from MBNet
- Makefile for common tasks
| Category | Technology |
|---|---|
| Backend | Python 3.11+, FastAPI, SQLAlchemy |
| Frontend | Jinja2, HTMX, Plotly.js |
| Database | SQLite (dev), PostgreSQL (prod) |
| Analysis | NumPy, Pandas, SciPy |
| Testing | pytest, pytest-cov |
- Python 3.11 or higher
- pip or pipenv
# Clone the repository
git clone https://github.com/bartoszclapinski/LotteryLAB.git
cd LotteryLAB/lotterylab
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
.\venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Initialize database
make db-init
# Import historical data (optional)
python scripts/update_mbnet.py
# Start the server
make serverThe application will be available at http://127.0.0.1:8000
Navigate to http://127.0.0.1:8000 and explore:
- Frequency Analysis β View number frequency distributions
- Randomness Tests β Run statistical tests on draw data
- Pattern Analysis β Detect sequences and patterns
- Correlation Heatmap β Visualize number relationships
- Number Generator β Generate weighted number sets
make help # Show all available commands
make server # Start development server
make test # Run all tests
make test-cov # Run tests with coverage report
make update # Fetch latest draws from MBNet
make db-upgrade # Run database migrations
make clean # Clean build artifacts| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/health |
Health check |
| GET | /api/v1/draws |
List draws with filters |
| GET | /api/v1/analysis/frequency |
Frequency analysis |
| GET | /api/v1/analysis/randomness |
Randomness tests |
| GET | /api/v1/analysis/patterns |
Pattern detection |
| GET | /api/v1/analysis/correlation |
Correlation analysis |
curl "http://127.0.0.1:8000/api/v1/analysis/frequency?game_type=lotto&window_days=365"{
"game_type": "lotto",
"window_days": 365,
"num_draws": 156,
"frequency": {"1": 18, "2": 21, ...},
"expected_each": 19.1,
"hot_numbers": [7, 23, 34, 45],
"cold_numbers": [3, 11, 28, 39]
}LotteryLAB/
βββ lotterylab/
β βββ src/
β β βββ api/ # FastAPI endpoints
β β βββ analysis/ # Statistical analysis modules
β β β βββ frequency.py # Frequency analysis
β β β βββ randomness.py # Randomness tests
β β β βββ patterns.py # Pattern detection
β β β βββ visualizations.py
β β βββ database/ # SQLAlchemy models
β β βββ data_acquisition/ # Data import/update
β β βββ repositories/ # Data access layer
β β βββ utils/ # Helpers, i18n, logging
β βββ templates/ # Jinja2 templates
β βββ static/ # CSS, JS, images
β βββ tests/ # Test suite
β βββ scripts/ # CLI utilities
β βββ alembic/ # Database migrations
β βββ .ai/ # Sprint docs, PRD
βββ alembic.ini
βββ README.md
# Run all tests
make test
# Run with coverage
make test-cov
# Run specific test file
pytest tests/test_randomness.py -vThe UI supports multiple languages:
- π΅π± Polish (default)
- π¬π§ English
Switch languages using the toggle in the header.
Tests if observed number frequencies match expected uniform distribution.
Compares empirical distribution against theoretical uniform distribution.
Analyzes sequence randomness by counting "runs" of consecutive values.
Detects temporal dependencies between successive draws.
Quantifies randomness/uncertainty in the number distribution.
Contributions are welcome! Please read our contributing guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Data source: MBNet for historical Polish Lotto data
- UI inspiration: Google ML Crash Course
- Statistical methods: SciPy documentation
Lottery Lab β Research & Education
Made with β€οΈ for data science enthusiasts