Skip to content

niraj4rl/Laliga_gin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

La Liga Analytics & Match Prediction System

A machine learning-powered system to predict La Liga football match outcomes with real-time injury data integration.

🎯 Features

  • Match Predictions: Real-time predictions for upcoming La Liga matches using ML models
  • Injury Integration: Real-time player injury data enrichment
  • Historical Analysis: Team statistics and performance trends
  • Key Player Impact: Identifies key players and their performance metrics
  • Interactive Dashboard: React-based UI for exploring predictions and standings
  • REST API: FastAPI backend for seamless data access

πŸ›  Tech Stack

Backend:

  • Python 3.x with FastAPI
  • SQLAlchemy ORM for database operations
  • PostgreSQL for data persistence
  • Scikit-learn for ML model training

Frontend:

  • React with Vite bundler
  • Tailwind CSS for styling
  • Axios for API communication

πŸ“‹ Prerequisites

  • Python 3.8+
  • Node.js 16+
  • PostgreSQL 12+
  • Git

πŸš€ Setup & Installation

1. Clone the Repository

git clone https://github.com/niraj4rl/Laliga_gin.git
cd Laliga_gin

2. Backend Setup

Create Virtual Environment

python -m venv .venv

# On Windows
.venv\Scripts\activate

# On Linux/Mac
source .venv/bin/activate

Install Dependencies

cd backend
pip install -r requirements.txt
cd ..

Configure Environment Variables

# Copy the example file
cp backend/.env.example backend/.env

# Edit .env and add your API keys
# Required:
#   - FOOTBALL_API_KEY: Get from https://www.football-data.org/
# Optional:
#   - RAPIDAPI_KEY: For enhanced injury data from RapidAPI
#   - APIFOOTBALL_API_KEY: Alternative data provider
# Database:
#   - DATABASE_URL: PostgreSQL connection string

Setup Database

# Create database
createdb laliga_analytics

# Run migrations
cd backend
python -c "from database.db import Base, engine; Base.metadata.create_all(bind=engine)"

# Seed initial data (optional)
python database/seed.py
cd ..

3. Frontend Setup

cd frontend
npm install
cd ..

4. Run the Application

# Start both backend and frontend
python run.py

The application will be available at:

  • Frontend: http://localhost:8002
  • Backend API: http://localhost:8001

πŸ“‘ API Endpoints

Predictions

  • GET /predict/upcoming - Get upcoming match predictions
  • GET /predict/upcoming?include_injuries=true - Include injury data
  • GET /predict/upcoming?include_injuries=false - Fast predictions without injury data

Query Parameters

  • include_injuries (boolean): Include player injury data (default: true)
  • Response time varies: ~30s with injuries, ~5s without

πŸ—‚ Project Structure

β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── main.py          # FastAPI endpoints
β”‚   β”œβ”€β”€ database/
β”‚   β”‚   β”œβ”€β”€ db.py            # SQLAlchemy models & connection
β”‚   β”‚   β”œβ”€β”€ schema.sql       # Database schema
β”‚   β”‚   β”œβ”€β”€ seed.py          # Initial data setup
β”‚   β”‚   └── download_real_data.py
β”‚   β”œβ”€β”€ ml/
β”‚   β”‚   β”œβ”€β”€ feature_engineering.py
β”‚   β”‚   └── train_model.py
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── data_service.py
β”‚   β”œβ”€β”€ .env.example         # Environment variables template
β”‚   β”œβ”€β”€ .env                 # Local secrets (gitignored)
β”‚   └── requirements.txt
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ App.js
β”‚   β”‚   └── index.css
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ features.csv
β”‚   └── laliga_matches.csv
β”œβ”€β”€ models/
β”‚   └── model_meta.json
β”œβ”€β”€ run.py                   # Main entry point
└── README.md

πŸ” Security Notes

  • Never commit .env file - It's gitignored for security
  • Use .env.example as reference for required variables
  • Rotate API keys if accidentally exposed
  • All secrets are loaded from environment variables, not hardcoded

Environment Variables

# Database (Required)
DATABASE_URL=postgresql://username:password@localhost:5432/laliga_analytics

# API Keys
FOOTBALL_API_KEY=your_key_here          # Required - https://www.football-data.org/
RAPIDAPI_KEY=                            # Optional - for injury data
APIFOOTBALL_API_KEY=                     # Optional - alternative provider

# Features
ENABLE_INJURY_LOOKUP=1                  # 1 to enable, 0 to disable
UPCOMING_MATCH_LIMIT=5                  # Number of upcoming matches to fetch

🧹 Cleanup & Logs

Stop Running Servers

# PowerShell (Windows)
Get-NetTCPConnection -LocalPort 8001,8002 -State Listen | Stop-Process -Force

# Bash (Linux/Mac)
lsof -ti:8001,8002 | xargs kill -9

☁️ Deployment

This project is ready to deploy with:

  • Backend on Render
  • Frontend on Vercel

Backend (Render)

  1. Go to Render and create a Web Service from this GitHub repo.
  2. Render will detect render.yaml automatically.
  3. Set required environment variables in Render:
    • DATABASE_URL
    • FOOTBALL_API_KEY
  4. Optional variables:
    • RAPIDAPI_KEY
    • APIFOOTBALL_API_KEY
    • ENABLE_INJURY_LOOKUP (1 or 0)
    • UPCOMING_MATCH_LIMIT
  5. Deploy and copy your backend URL (example: https://laliga-api.onrender.com).

Frontend (Vercel)

  1. Import the same repo in Vercel.
  2. Vercel will use vercel.json from project root.
  3. Add env var in Vercel project settings:
    • VITE_API_BASE_URL=https://<your-render-backend-url>
  4. Deploy.

Final Production CORS Step

After frontend is deployed, add this variable in Render backend:

  • FRONTEND_URL=https://<your-vercel-domain>

Then redeploy backend once so CORS allows your live frontend domain.

πŸ“Š Model Information

  • Training Data: Historical La Liga match data (2017-present)
  • Features: Team form, head-to-head records, player injuries, home/away advantage
  • Model: Ensemble learning approach (Random Forest + Gradient Boosting)
  • Accuracy: ~68% on test set

πŸ› Troubleshooting

Port Already in Use

# Find and stop process using port 8001 or 8002
netstat -ano | findstr :8001  # Windows
lsof -i :8001                 # Linux/Mac

Database Connection Failed

  • Ensure PostgreSQL is running
  • Verify DATABASE_URL is correct in .env
  • Check database name matches: laliga_analytics

API Key Errors

  • Verify FOOTBALL_API_KEY is valid at https://www.football-data.org/
  • Injury data fails gracefully if RAPIDAPI_KEY is missing
  • Use include_injuries=false for faster responses if API limits hit

🀝 Contributing

  1. Create a feature branch: git checkout -b feature/YourFeature
  2. Commit changes: git commit -m 'Add YourFeature'
  3. Push to branch: git push origin feature/YourFeature
  4. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see LICENSE file for details.

πŸ“§ Contact

Author: Niraj
GitHub: @niraj4rl
Email: pashte.niraj2005@gmail.com


Last Updated: March 26, 2026
Repository: github.com/niraj4rl/Laliga_gin

About

A machine learning-powered system to predict La Liga football match outcomes using machine learning and with real-time injury data integration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors