Skip to content

Python/SQLITE3 based project which scrapes data from ATP Rankings website and uses Matplotlib for data visualization. Also updated to include FastAPI and MCP server deployment on render

License

Notifications You must be signed in to change notification settings

Jupiterian/ATP-Rankings-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Logo

ATP Rankings Data Visualization

A comprehensive Python project for ATP tennis rankings data collection, analysis, and visualization. Features include web scraping, database management, interactive web interface, and AI integration via Model Context Protocol (MCP).

🌟 Features

  • πŸ“Š Data Collection: Automated scraping from atptour.com
  • πŸ—„οΈ Database: 2,600+ weeks of historical ATP rankings (1973-2025)
  • 🌐 Web Interface: Modern FastAPI application with interactive charts
  • πŸ“ˆ CLI Analysis: Command-line tools for player statistics and comparisons
  • πŸ€– AI Integration: MCP server for AI assistant access
  • 🎨 Visualizations: Matplotlib (CLI) and Chart.js (web) graphs
  • πŸ§ͺ Testing: Comprehensive test suite with pytest

πŸš€ Quick Start

Installation

  1. Clone the repository

    git clone https://github.com/Jupiterian/ATP-Rankings-Data-Visualization.git
    cd ATP-Rankings-Data-Visualization
  2. Install dependencies

    pip install -r requirements.txt
  3. Run the web application

    uvicorn src.main:app --reload

    Open your browser to http://localhost:8000

Update Database

To get the latest rankings data:

python scripts/filler.py

πŸ“ Project Structure

ATP-Rankings-Data-Visualization/
β”œβ”€β”€ src/                      # Core application code
β”‚   β”œβ”€β”€ main.py              # FastAPI web application
β”‚   β”œβ”€β”€ services.py          # Business logic layer
β”‚   β”œβ”€β”€ mcp_router.py        # MCP API endpoints
β”‚   └── mcp_manifest.json    # MCP schema definition
β”œβ”€β”€ scripts/                  # Utility scripts
β”‚   β”œβ”€β”€ generate.py          # Regenerate entire database
β”‚   β”œβ”€β”€ filler.py            # Update database with latest data
β”‚   β”œβ”€β”€ analyze.py           # CLI data analysis tool
β”‚   β”œβ”€β”€ debug.py             # Database debugging utility
β”‚   β”œβ”€β”€ test_mcp.sh          # Quick MCP endpoint tests
β”‚   β”œβ”€β”€ test_render_mcp.py   # Production deployment tests
β”‚   β”œβ”€β”€ keep_alive.py        # Render free tier keep-alive
β”‚   └── deploy.sh            # Deployment helper
β”œβ”€β”€ docs/                     # Documentation
β”‚   β”œβ”€β”€ MCP_README.md        # MCP server documentation
β”‚   β”œβ”€β”€ MCP_DEPLOYMENT.md    # Deployment guide
β”‚   β”œβ”€β”€ MCP_IMPLEMENTATION_SUMMARY.md
β”‚   └── MCP_QUICK_REFERENCE.md
β”œβ”€β”€ templates/                # HTML templates (Jinja2)
β”‚   β”œβ”€β”€ index.html           # Home page
β”‚   β”œβ”€β”€ week.html            # Weekly rankings
β”‚   β”œβ”€β”€ comparison.html      # Player comparison
β”‚   β”œβ”€β”€ weeks_at_no1.html    # Histogram visualization
β”‚   └── api_docs.html        # API documentation
β”œβ”€β”€ tests/                    # Test suite
β”‚   └── test_mcp.py          # MCP endpoint tests
β”œβ”€β”€ Examples/                 # Example visualizations
β”œβ”€β”€ rankings.db              # SQLite database (2,600+ tables)
β”œβ”€β”€ Dockerfile               # Container image
β”œβ”€β”€ docker-compose.yml       # Docker Compose config
β”œβ”€β”€ Procfile                 # Render/Heroku deployment
β”œβ”€β”€ runtime.txt              # Python version
└── requirements.txt         # Python dependencies

🌐 Web Application

Features

  • Browse Rankings: View all 2,600+ weeks organized by year
  • Player Search: Autocomplete search across all players
  • Player Comparison: Side-by-side statistics with career graphs
  • Weeks at #1: Interactive histogram of world #1 rankings
  • API Access: RESTful API with comprehensive documentation
  • Keyboard Navigation: Arrow keys to navigate between weeks

Running Locally

uvicorn src.main:app --reload

Access at http://localhost:8000

API Endpoints

  • GET / - Home page
  • GET /week/{week_id} - Weekly rankings
  • GET /comparison - Player comparison tool
  • GET /weeks-at-no1 - Weeks at #1 histogram
  • GET /api-docs - API documentation
  • GET /api/weeks - List all available weeks
  • GET /api/week/{week_id} - Get week data
  • GET /api/search-players?q={query} - Search players
  • POST /api/player-factfile - Player statistics
  • POST /api/player-career - Career time-series data

πŸ€– MCP Server (AI Integration)

The MCP server allows AI assistants like Claude to query ATP rankings data.

MCP Endpoints

Base URL: http://localhost:8000/mcp

  • GET /mcp/health - Health check
  • GET /mcp/manifest - Server capabilities
  • POST /mcp/tools/search_players - Search for players
  • POST /mcp/tools/get_player_factfile - Player statistics
  • POST /mcp/tools/get_player_career - Career history
  • GET /mcp/tools/get_weeks_at_no1 - Weeks at #1 leaderboard
  • GET /mcp/tools/get_all_weeks - Available weeks list
  • POST /mcp/tools/get_week_rankings - Specific week data

Testing MCP

# Run test suite
pytest tests/test_mcp.py -v

# Quick smoke test
bash scripts/test_mcp.sh

# Test production deployment
python scripts/test_render_mcp.py https://your-app.onrender.com

Full Documentation: See docs/MCP_README.md

πŸ“Š CLI Analysis Tools

analyze.py

Analyze player data and generate matplotlib visualizations.

# Show player statistics
python scripts/analyze.py -f Roger_Federer

# Plot ranking history
python scripts/analyze.py -r Roger_Federer Rafael_Nadal

# Plot points history
python scripts/analyze.py -p Novak_Djokovic

# Weeks at #1 histogram
python scripts/analyze.py -n

Options:

  • -h - Show help menu
  • -f - Player factfile (statistics)
  • -r - Ranking history plot
  • -p - Points history plot
  • -n - Weeks at #1 bar graph

Examples: See Examples/Examples.md

πŸ—„οΈ Database Management

Update Database (Recommended)

Add latest rankings data:

python scripts/filler.py

Regenerate Database

Complete database rebuild (takes ~1 hour):

python scripts/generate.py

Debug Database

Find and fix problematic tables:

python scripts/debug.py

Browse Database

Recommended GUI tool: DB Browser for SQLite

πŸš€ Deployment

Deploy to Render (Free)

  1. Push to GitHub

    git add .
    git commit -m "Deploy ATP Rankings"
    git push origin main
  2. Connect to Render

    • Go to render.com
    • Click "New Web Service"
    • Connect your GitHub repository
    • Render auto-detects settings from Procfile
  3. Deploy

    • Click "Create Web Service"
    • Wait 2-3 minutes for deployment
  4. Keep Alive (Optional)

    python scripts/keep_alive.py https://your-app.onrender.com

Full Guide: See docs/MCP_DEPLOYMENT.md for Railway, Fly.io, Heroku, Docker, and VPS options.

πŸ§ͺ Testing

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=src --cov-report=html

# Test specific module
pytest tests/test_mcp.py::TestMCPHealth -v

πŸ› οΈ Technologies

Backend:

  • Python 3.12
  • FastAPI (web framework)
  • SQLite3 (database)
  • Uvicorn (ASGI server)
  • Pydantic (validation)

Frontend:

  • Jinja2 (templates)
  • Chart.js (interactive charts)
  • HTML5/CSS3

Scraping & Analysis:

  • BeautifulSoup4 (web scraping)
  • Matplotlib (static visualizations)

Testing & Deployment:

  • Pytest (testing framework)
  • Docker (containerization)
  • Render/Railway/Fly.io (hosting)

πŸ“ License

See LICENSE file for details.

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“§ Contact

For questions or issues, please open a GitHub issue.


⭐ If you find this project useful, please star the repository!

About

Python/SQLITE3 based project which scrapes data from ATP Rankings website and uses Matplotlib for data visualization. Also updated to include FastAPI and MCP server deployment on render

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published