Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Docs.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# OpenFPL Scout API – Backend Documentation

Version: 2.3.1

Description: AI-powered Fantasy Premier League (FPL) Scout API providing optimal team selection, player projections, and gameweek analysis.
**Version:** 4.5.0
**Description:** AI-powered Fantasy Premier League (FPL) Scout API – optimal team selection, player projections, and gameweek analysis.

---

Expand Down
193 changes: 50 additions & 143 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
# OpenFPL-Scout-AI

<img src="assets/openfpl-scout-preview.png" alt="OpenFPL Scout AI" width="400"/>
<img src="assets/openfpl-scout-preview.png" alt="OpenFPL Scout AI – AI-powered Fantasy Premier League team selector" width="400"/>

*Image credits: Generated with GPT-4o*

OpenFPL-Scout-AI is an AI-powered Fantasy Premier League Scout that uses ensemble machine learning (Linear Regression, XGBoost, CatBoost) to predict player points and optimize FPL team selection. It features a beautiful web interface for visualizing your optimal team in a football pitch layout.
**OpenFPL-Scout-AI** is an AI-powered Fantasy Premier League (FPL) scout that uses an ensemble of machine learning models (Linear Regression, XGBoost, CatBoost) to predict player points and build your optimal FPL squad each gameweek.

## 🚀 Live Demo & API Access

**Web Interface:** **[https://openfpl-scout-ai-186049008266.europe-west1.run.app](https://openfpl-scout-ai-186049008266.europe-west1.run.app)**

**🔥 API Access via RapidAPI:** **[Subscribe on RapidAPI Marketplace](https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api)**
- Free tier: 10 requests/hour
- Professional support and documentation
- Easy integration with RapidAPI headers
| | Link |
|---|---|
| **Web Interface** | [https://openfpl-scout-ai-186049008266.europe-west1.run.app](https://openfpl-scout-ai-186049008266.europe-west1.run.app) |
| **RapidAPI** | [Subscribe on RapidAPI Marketplace](https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api) – free tier: 10 req/hr |

## Features

- 🎯 **AI-Powered Predictions**: Ensemble ML models (Linear Regression, XGBoost, CatBoost)
- ⚽ **Interactive Web UI**: Beautiful pitch visualization with player cards
- 📊 **Real-time Data**: Live fixture and match data integration
- 🚀 **Fast Performance**: Async player predictions and caching
- 🏆 **Smart Team Selection**: Automated optimal team selection by position
- 👑 **Captain Assignment**: Intelligent captain/vice-captain selection
- 📱 **Mobile Responsive**: Works perfectly on all devices
- 📸 **Screenshot Feature**: Download your team lineup as PNG
- 🎨 **Professional Design**: FPL-themed UI with gradient backgrounds
- 🔌 **RapidAPI Integration**: Professional API marketplace access
- 🎯 **AI Predictions** – Ensemble ML models (Linear Regression, XGBoost, CatBoost)
- ⚽ **Pitch Visualization** – Interactive football-pitch team layout
- 🏆 **Smart Selection** – Optimal team + captain/vice-captain assignment
- 📊 **Live Data** – Real-time fixtures and match data
- 📱 **Mobile Responsive** – Works on all screen sizes
- 📸 **PNG Export** – Download your lineup as an image
- 🔌 **RapidAPI** – Production-ready API marketplace integration

## Installation

Expand All @@ -36,166 +31,78 @@ docker build -t openfpl-scout-ai .
docker run -d -p 8000:8000 --name openfpl-api openfpl-scout-ai
```

## Usage

### Web Interface
Visit the [live demo](https://openfpl-scout-ai-186049008266.europe-west1.run.app) or [http://localhost:8000](http://localhost:8000) for local development:

- **Visual Team Display**: See your optimal team laid out on a football pitch
- **Player Cards**: Detailed cards showing player stats, fixtures, and expected points
- **Gameweek Selection**: Navigate between different gameweeks
- **Screenshot Export**: Download your team lineup as a high-quality image
- **Interactive Elements**: Click on player cards for detailed information

### API Access via RapidAPI

**🔥 Primary API Access:** [Subscribe on RapidAPI Marketplace](https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api)
## API

**Base URL:** `https://openfpl-api.p.rapidapi.com`

**Authentication:**
**Authentication (RapidAPI):**
```http
X-RapidAPI-Key: YOUR_RAPIDAPI_KEY
X-RapidAPI-Host: openfpl-api.p.rapidapi.com
```

### Endpoints

| Method | Path | Description |
|--------|------|-------------|
| GET | `/api/health` | Health check |
| GET | `/api/gameweeks` | Available gameweeks |
| GET | `/api/gw/scout` | Optimal FPL team for a gameweek |
| GET | `/api/gw/playerpoints` | Filtered player point predictions |
| GET | `/api` | API info and metadata |

**Quick Example:**
```javascript
const options = {
method: 'GET',
fetch('https://openfpl-api.p.rapidapi.com/api/gw/scout?gameweek=7', {
headers: {
'X-RapidAPI-Key': 'YOUR_RAPIDAPI_KEY',
'X-RapidAPI-Host': 'openfpl-api.p.rapidapi.com'
}
};

fetch('https://openfpl-api.p.rapidapi.com/api/gw/scout?gameweek=7', options)
.then(response => response.json())
.then(data => console.log(data));
}).then(r => r.json()).then(console.log);
```

### API Documentation
- **RapidAPI Docs:** [https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api](https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api)

### Main Endpoints

- `GET /api/health` — Health check
- `GET /api/gameweeks` — Available gameweeks with saved data
- `GET /api/gw/scout` — Get optimal FPL team for specific gameweek
- `GET /api/gw/playerpoints` — Get filtered player point predictions
- `GET /api` — API information and metadata

**Sample `/api/gw/scout` response:**
```json
{
"scout_team": [
{
"element_type": "Goalkeeper",
"web_name": "Alisson",
"team_name": "Liverpool",
"expected_points": 5.2,
"role": "",
"now_cost": 55,
"selected_by_percent": 15.5
},
{
"element_type": "Defender",
"web_name": "Alexander-Arnold",
"team_name": "Liverpool",
"expected_points": 8.1,
"role": "captain",
"now_cost": 70,
"selected_by_percent": 45.2
}
],
"gameweek": 7,
"version": "4.0.0",
"credits": "OpenFPL-Scout AI - Team Predictions | Developed by Kassem @elcaiseri, 2025"
}
```
Full docs: [RapidAPI Marketplace](https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api)

## Screenshots

The web interface provides a beautiful visualization of your optimal FPL team:

![Team Visualization](assets/FPL-Scout-Team-GW1-2025-08-07.png)

Features of the UI:
- **Football Pitch Layout**: Players arranged in realistic formation
- **Color-Coded Positions**: Goalkeepers (Orange), Defenders (Blue), Midfielders (Light Blue), Forwards (Green)
- **Captain Badges**: Golden 'C' for captain, Silver 'VC' for vice-captain
- **Fixture Information**: Opponent teams and home/away indicators
- **Expected Points**: AI-predicted points for each player
- **Team Statistics**: Total expected points and player count
- **Responsive Design**: Works on desktop, tablet, and mobile devices

## Model Overview

| Model | Version | Description |
|-------------------|---------|--------------------------------|
| Linear Regression | v4.0 | Baseline linear model |
| XGBoost | v4.0 | Gradient boosting ensemble |
| CatBoost | v3.0 | Categorical boosting model |
The pitch layout shows players in formation with color-coded positions (GK orange, DEF blue, MID light-blue, FWD green), captain/vice-captain badges, AI-predicted points, and fixture information.

- Ensemble predictions for accuracy
- Feature importance analysis
- Optimized for FPL player performance
## ML Models

## API Integration

Integrates with Football Data API for:
- Live fixtures and matchups
- Home/away status
- Gameweek info

**For RapidAPI Users:** All data is pre-processed and cached for optimal performance.
| Model | Version | Notes |
|-------------------|---------|-------|
| Linear Regression | v4.0 | Baseline |
| XGBoost | v4.0 | Gradient boosting |
| CatBoost | v3.0 | Handles categorical features |

## Code Structure

- `main.py`: FastAPI app and endpoints
- `src/scout.py`: FPLScout class (predictions, team selection)
- `src/models.py`: Pydantic response models
- `src/utils.py`: Config and helpers
- `src/logger.py`: Logging
- `main.py`FastAPI app and route handlers
- `src/scout.py`FPLScout (predictions & team selection)
- `src/models.py` Pydantic response models
- `src/utils.py` Config and helpers
- `src/logger.py` Logging

## What's New

- **🔌 RapidAPI Marketplace**: Now available on RapidAPI with professional support
- **📈 Enhanced API**: New endpoints for gameweeks and player filtering
- **🌐 Live Deployment**: Available on Google Cloud Platform
- **🎨 Beautiful Web Interface**: Interactive team visualization with football pitch layout
- **📸 Screenshot Feature**: Export your team lineup as high-quality PNG images
- **📱 Mobile Responsive**: Perfect experience on all devices
- **2024/2025 Season**: Models updated with latest data
- **CatBoost Integration**: Improved ML pipeline ([Issue #1](https://github.com/elcaiseri/Fantasy-Premier-League-LTX/issues/1))
- **RESTful API**: FastAPI endpoints for team selection and predictions
- **Rebranding**: Now OpenFPL-Scout-AI
- **Refactored Code**: Improved modularity and maintainability
- **AI-Powered Predictions**: Advanced ensemble models
- **Async Processing**: Fast parallel predictions
- **Live Data**: Real-time match integration
- **Docker Support**: Easy deployment
- **RapidAPI Marketplace** – Professional API access with free tier
- **New endpoints** – Gameweeks listing and player filtering
- **Live deployment** – Google Cloud Platform
- **Web UI** – Interactive pitch visualization + PNG export
- **2024/2025 models** – CatBoost added; latest season data ([#1](https://github.com/elcaiseri/Fantasy-Premier-League-LTX/issues/1))

## Contributing

Contributions welcome! Ideas for improvement:
- Enhanced algorithms and selection logic
- Additional UI features and visualizations
- Player injury/form tracking
- Better documentation
- Mobile app development

Fork, branch, and submit a pull request.
Contributions welcome! Fork, branch, and open a pull request.
Ideas: improved algorithms, UI features, injury/form tracking, mobile app.

## License

MIT License — see [LICENSE](LICENSE) for details.

## API Support & Contact
MIT – see [LICENSE](LICENSE).

**For API Support:**
- **RapidAPI Marketplace:** [https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api](https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api)
- **Email:** [support@openfpl.kassem.dev](mailto:iqasem4444@gmail.com)
## Contact

**General Questions:**
- **API support / RapidAPI:** [https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api](https://rapidapi.com/elcaiseri-elcaiseri-default/api/openfpl-api)
- **Email:** [iqasem4444@gmail.com](mailto:iqasem4444@gmail.com)
18 changes: 9 additions & 9 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description"
content="OpenFPL Scout AI Team - Get the best Fantasy Premier League team recommendations powered by artificial intelligence. Optimize your FPL squad with data-driven player selections and maximize your points.">
content="OpenFPL Scout AI – AI-powered Fantasy Premier League team selector. Get data-driven FPL squad recommendations, player point predictions, and captain picks every gameweek.">
<meta name="keywords"
content="Fantasy Premier League, FPL, AI team selection, football predictions, premier league fantasy, FPL scout, fantasy football AI, player recommendations">
content="FPL scout, Fantasy Premier League AI, FPL team selector, FPL predictions, FPL captain picks, fantasy football AI, premier league fantasy, FPL points optimizer">
<meta name="author" content="@elcaiseri">
<meta name="robots" content="index, follow">
<link rel="canonical" href="https://openfpl-scout-ai-186049008266.europe-west1.run.app/">
Expand All @@ -19,9 +19,9 @@
content="https://openfpl-scout-ai-186049008266.europe-west1.run.app/assets/openfpl-scout-preview.png">

<!-- Open Graph Meta Tags -->
<meta property="og:title" content="OpenFPL Scout AI Team - Fantasy Premier League AI Recommendations">
<meta property="og:title" content="OpenFPL Scout AI – FPL Team Predictions">
<meta property="og:description"
content="Get the best Fantasy Premier League team recommendations powered by AI. Optimize your FPL squad with data-driven selections.">
content="AI-powered Fantasy Premier League team selector. Get data-driven FPL squad picks and player point predictions every gameweek.">
<meta property="og:image"
content="https://openfpl-scout-ai-186049008266.europe-west1.run.app/assets/openfpl-scout-preview.png">
<meta property="og:image:secure_url"
Expand All @@ -34,9 +34,9 @@

<!-- Twitter Card Meta Tags -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="OpenFPL Scout AI Team - Fantasy Premier League AI">
<meta name="twitter:title" content="OpenFPL Scout AI – FPL Team Predictions">
<meta name="twitter:description"
content="AI-powered Fantasy Premier League team recommendations to maximize your points.">
content="AI-powered FPL team selector: data-driven squad picks and player point predictions every gameweek.">
<meta name="twitter:image"
content="https://openfpl-scout-ai-186049008266.europe-west1.run.app/assets/openfpl-scout-preview.png">
<meta name="twitter:creator" content="@elcaiseri">
Expand All @@ -46,8 +46,8 @@
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "OpenFPL Scout AI Team",
"description": "AI-powered Fantasy Premier League team recommendations",
"name": "OpenFPL Scout AI",
"description": "AI-powered Fantasy Premier League team selector with data-driven player predictions",
"url": "https://openfpl-scout-ai-186049008266.europe-west1.run.app/",
"applicationCategory": "SportsApplication",
"operatingSystem": "Web Browser",
Expand All @@ -61,7 +61,7 @@

<link rel="icon" type="image/png"
href="https://openfpl-scout-ai-186049008266.europe-west1.run.app/assets/openfpl-scout-preview.png">
<title>OpenFPL Scout AI Team - Fantasy Premier League AI Recommendations | FPL Scout</title>
<title>OpenFPL Scout AI – FPL Team Predictions & AI Scout</title>

<!-- Local Styles -->
<link rel="stylesheet" href="static/style.css">
Expand Down