AI-Powered NRL Fantasy Predictions & Optimization
A comprehensive web application that helps NRL Fantasy coaches predict player scores, optimize their squads, and make data-driven decisions using advanced machine learning and statistical analysis.
- β Fantasy Scoring Engine: Accurate implementation of 2024 NRL Fantasy scoring rules
- β Basic Predictions: Weighted average predictions using last 3-5 games
- β Captain Suggestions: AI-powered captain and vice-captain recommendations
- β Trade Optimizer: Smart trade suggestions based on value and projected points
- β Value Picks: Find the best points-per-dollar players by position
- β REST API: Fast, documented FastAPI with auto-generated OpenAPI docs
- β Web Interface: Clean, responsive UI for testing and exploring predictions
- β Real Data Ingestion: Import from NRL-Data GitHub repository
- β ML Predictions: Gradient Boosting model with opponent/venue context
- β Opponent Analysis: Defensive strength ratings by team and position
- β Home/Away Adjustments: Venue-specific advantage calculations
- β Bye Round Planner: Multi-week optimization for rounds 13-17
- β PostgreSQL Support: Production-ready database with migration path
- β Automated Tests: Pytest suite for scoring accuracy and predictions
- β Logging & Monitoring: Centralized logging with file and console output
python -m nrl_fantasy.init_dbpython -m nrl_fantasy.utils.sample_datafrom nrl_fantasy.data.storage.database import get_db
from nrl_fantasy.models.predictor import PlayerPredictor
with get_db() as db:
predictor = PlayerPredictor(db)
count = predictor.generate_all_projections(2024, 6)
print(f"Generated {count} projections")The app automatically runs on port 5000:
- Frontend UI: http://localhost:5000
- API Docs: http://localhost:5000/docs
- Health Check: http://localhost:5000/health
GET /api/players/{player_id}/projection?round=6POST /api/team/project
{
"players": [
{"player_id": 1, "position": "FRF"},
{"player_id": 2, "position": "HOK"}
],
"bank_balance": 100.0,
"trades_remaining": 2
}GET /api/players/value-picks?position=HLF&limit=5POST /api/advanced/predict
{
"player_id": 1,
"round": 15,
"opponent": "Melbourne Storm",
"is_home": true,
"venue": "Penrith Stadium"
}POST /api/advanced/train-model?season=2024GET /api/advanced/defensive-strength/Melbourne%20Storm?position=HLFPOST /api/advanced/bye-plan
{
"squad": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
"current_round": 10,
"trades_available": 10
}POST /api/advanced/import-data/2024nrl_fantasy/
βββ api/ # API schemas and advanced endpoints
β βββ schemas.py # Pydantic models
β βββ advanced_endpoints.py # Phase 2 endpoints
βββ config/ # Configuration
β βββ database_config.py # DB connection management
βββ data/ # Data layer
β βββ ingestion/ # External data fetchers
β βββ storage/ # Database models & connection
βββ models/ # Prediction engines
β βββ predictor.py # Basic weighted average
β βββ advanced_predictor.py # ML with context
βββ optimization/ # Team optimization
β βββ team_optimizer.py # Captain & trade suggestions
β βββ bye_planner.py # Multi-week bye planning
βββ scoring/ # Fantasy scoring
β βββ engine.py # Points calculator
βββ tests/ # Automated tests
β βββ test_scoring_engine.py
β βββ test_predictor.py
βββ utils/ # Utilities
β βββ sample_data.py # Sample data generator
β βββ logger.py # Centralized logging
βββ main.py # FastAPI application
- Uses last 3-5 games with exponential weighting
- Adjusts for minutes played
- Confidence based on consistency
- MAE: ~8-10 fantasy points
- 16 engineered features including:
- Recent form (last 3, 5, 10 games)
- Consistency and trend analysis
- Minutes, tackles, metres averages
- Opponent defensive strength
- Home/away venue factors
- MAE: ~5-7 fantasy points (when trained)
- Sklearn GradientBoostingRegressor with 100 estimators
- beauhobba/NRL-Data - Player stats, match results
- uselessnrlstats - Historical data (1908-present)
- nrlR Package - R package for live stats
- FootyStatistics.com - Prices, break-evens, ownership
- Unofficial NRL Fantasy JSON endpoints (undocumented)
See DATA_SOURCES.md for detailed research.
# All tests
python -m pytest nrl_fantasy/tests/ -v
# Specific test
python -m pytest nrl_fantasy/tests/test_scoring_engine.py -v
# With coverage
python -m pytest nrl_fantasy/tests/ --cov=nrl_fantasy --cov-report=html- β Scoring engine accuracy tests
- β Prediction logic tests
- β Edge cases (no history, negative scores, premium scorers)
# Automatic - just run init_db
python -m nrl_fantasy.init_dbOption 1: Replit PostgreSQL
# Enable in Replit, then:
export NRL_DATABASE_URL=$DATABASE_URL
python -m nrl_fantasy.init_dbOption 2: External (Neon, Supabase, etc.)
export NRL_DATABASE_URL="postgresql://user:pass@host:5432/dbname"
python -m nrl_fantasy.init_dbSee nrl_fantasy/config/database_config.py for migration guide.
The app includes a realistic sample data generator with:
- 128 players across 16 NRL teams
- 40 matches over 5 rounds (2024 season)
- 320 player performances with detailed stats
- 640 price history records
- Realistic stat distributions by position (forwards, backs, playmakers)
| Component | Technology |
|---|---|
| Backend | Python 3.11 + FastAPI |
| Database | SQLite (dev) / PostgreSQL (prod) |
| ORM | SQLAlchemy 2.0 |
| ML | scikit-learn, NumPy, Pandas |
| Server | Uvicorn with auto-reload |
| Testing | Pytest |
| Frontend | HTML/CSS/JavaScript (vanilla) |
# Database (optional - defaults to SQLite)
NRL_DATABASE_URL="sqlite:///nrl_fantasy.db"
# API Configuration
API_HOST="0.0.0.0"
API_PORT=5000
# Season
CURRENT_SEASON=2024
# Logging
LOG_LEVEL="INFO"- User authentication (JWT tokens)
- Saved teams and watchlists
- Email/push notifications for price changes
- Historical performance analytics dashboard
- Automated weekly data updates (cron jobs)
- Advanced ensemble models (XGBoost + LightGBM)
- Full season optimization with integer programming
- Mobile app (React Native / Flutter)
- Live score tracking during matches
- League analysis & competitor modeling
- Weather impact analysis
- Injury probability modeling
- Custom scoring league support
- Transfer market trends
- Social features (leagues, challenges)
MIT License - see LICENSE file
- NRL-Data by beauhobba - Historical match statistics
- uselessnrlstats - Comprehensive historical data
- FootyStatistics.com - Community fantasy tools
- Rugby League Project - Match data archive
For questions or issues:
- Check
/docsfor interactive API documentation - Review
replit.mdfor project details - See
DATA_SOURCES.mdfor data information
Built with β€οΈ for the NRL Fantasy community