NBA Database- A Flask-based Web Application
- Introduction
- Key Features
- Technologies Used
- Project Structure
- Installation & Setup
- Usage & Screenshots
- Database Structure
- API Endpoints
NBA Database is a mini framework that fetches information from different endpoints of nba_api, storing information in a database and visualizing these information in different sections of webpage.
- Real-time data fetching from NBA API
- Efficient data storage using SQLAlchemy (Object Relational Mapping-ORM)
- Interactive data visualizations with Plotly
- Responsive front-end design using HTML, CSS, and JavaScript
Python, Flask, SQLAlchemy, Plotly, NBA API, HTML, CSS, JavaScript, SQLite. (You can browse requirements.txt for details)
- Models: SQL Alchemy Database Models - databasemodels.py
- Views: HTML files in templates folder
- Controllers: Flask Routes - Between lines of 109-236 in app.py
- CLI Commands: Custom Flask CLI commands for database operations and data fetching - Between lines of 27-104 in app.py
After obtaining the files in repository or [cloning the repository](git clone https://github.com/alper-sayin/NBA-Database.git) to desired folder, setting up virtual environment and satisfying the requirements requirements.txt, you should run flask CLI commands in your terminal to create then update the database (Database will be automatically created in your project folder directory)
After opening the terminal in your IDE, you should apply:
flask db_create
for creating the databaseflask db_drop
for dropping the databaseflask db_seed_teams
for seeding the database with teamsflask db_seed_players
for seeding the database with playersflask db_extend_player_info
for updating the players table with country, jersey, weight, height and position informationflask db_add_career_stats
for updating the players table with career stats.- After flask CLI commands, you can run the app.py file and experience all the functionality which is explained in details in usage (screenshots of application in action) by going to http://127.0.0.1:5000 address in your internet browser
***I separated flask CLI commands for seeding the players table on purpose. So you can arbitrarily add the desired information.
Also you may want to add more columns of the current players or teams tables after the initial database creation. In this case, you should update database models in code snippet and then you should create other flask CLI commands for seeding the database.
But between seeding the database and updating database models, you should apply:
flask db init
flask db migrate
flask db upgrade
to update the current database. That's why I used flask-migrate package in this project. But you don't need to use these flask CLI commands in final code in order to test out current functionality. If you want to add more columns or add more tables to current database after creation then you should apply these flask CLI commands.
Players section. Players are grouped by surnames.
Switching radio button to filter only active players
Search bar is searching for the word both in name and surname
You can use “toggle graph” if you want to view some essential stats in graph
Download database section. Functionality to fetch database in both excel, csv or json(API) formats
Database structure and tables in SQLite
- nba_api.stats.static/players
- nba_api.stats.static/teams
- nba_api.stats.endpoints/commonplayerinfo*
- nba_api.stats.endpoints/playercareerstats*
*It takes a while fetching information from these endpoints for all players. So I saved as json files (nba_players.json, career_stats_of_all_players.json), added to repository and implemented the code in this way.