Please note: the video above is from when the project had a different UI but the majority of the functionality is the same. The only difference is that the project now is updated to include an MCP server for AI integration

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!

Built With

Share this project:

Updates