25 Commits
Author SHA1 Message Date
nprasad2077 0b1814369b delete advanced data mgmt script 2023-09-20 02:51:13 -05:00
nprasad2077 39535055a5 model update and migration 2023-09-20 02:37:19 -05:00
nprasad2077 3ced0d278b Merge pull request #16 from nprasad2077/MBP
Mbp
2023-09-20 02:34:05 -05:00
nprasad2077 5eaa50f4e7 central teams list 2023-09-20 02:33:13 -05:00
nprasad2077 4b1d07353d 2009 done 2023-09-20 01:08:57 -05:00
nprasad2077 0701ef19d2 usage and readme 2023-09-20 00:00:01 -05:00
nprasad2077 3558b1c154 script update 2023-09-19 19:15:12 -05:00
nprasad2077 150bda67ca player name and season totals query; 2023-06-22 21:21:12 -05:00
nprasad2077 395f15683a player lookup changes 2023-06-22 21:06:39 -05:00
nprasad2077 8010111e82 Merge branch 'main' of github.com:nprasad2077/nbaStats into deploy 2023-06-22 20:59:42 -05:00
Nikhil Prasad caa97b109a Update README.md 2023-06-20 11:59:19 -05:00
nprasad2077 030cfcd1d9 updated playoffs limit 2023-05-24 22:00:26 -05:00
nprasad2077 ae1b6a49f8 updated top players limit 2023-05-24 21:54:33 -05:00
nprasad2077 405d3d0356 modify success message 2023-05-24 18:43:59 -05:00
Nikhil Prasad fcfb8eadbe Merge pull request #14 from nprasad2077/dev
Dev
2023-05-11 16:14:02 -05:00
Nikhil Prasad ff8084966a Merge pull request #12 from nprasad2077/dev
Dev
2023-05-10 15:33:30 -05:00
Nikhil Prasad 0e04f29d37 Merge pull request #10 from nprasad2077/dev
Dev
2023-05-08 18:54:16 -05:00
Nikhil Prasad 31ee84dfe8 Merge pull request #8 from nprasad2077/dev
Dev
2023-05-02 02:09:15 -05:00
Nikhil Prasad f7fceb12fa Merge pull request #7 from nprasad2077/dev
Dev
2023-04-27 13:41:43 -05:00
Nikhil Prasad 13132473b1 Merge pull request #6 from nprasad2077/dev
Dev
2023-04-27 11:01:08 -05:00
Nikhil Prasad 45206c38bb Merge pull request #5 from nprasad2077/dev
Dev
2023-04-21 20:28:20 -05:00
Nikhil Prasad 9117807179 Merge pull request #4 from nprasad2077/dev
env changes
2023-04-20 16:18:54 -05:00
Nikhil Prasad 84f449b1e4 Merge pull request #3 from nprasad2077/dev
working on data verification
2023-04-18 21:47:53 -05:00
Nikhil Prasad 01604850ce Merge pull request #2 from nprasad2077/dev
Dev
2023-04-18 16:14:56 -05:00
Nikhil Prasad 00d8fdcf23 Merge pull request #1 from nprasad2077/dev
Dev
2023-04-14 00:15:58 -05:00
13 changed files with 102 additions and 51 deletions

No files matched your search

+30 -22
View File
@@ -6,24 +6,29 @@ This documentation provides the necessary information to use the NBA Stats API.
---
# [View API Documentation](https://documenter.getpostman.com/view/24232555/2s93shzpR3)
---
### Base URL
All URLs referenced in this documentation use the following base URL:
> https://nba-stats-db.herokuapp.com/
> <https://nba-stats-db.herokuapp.com/>
### Endpoints
Top 20 Scorers by Season
Method: `Get`
> https://nba-stats-db.herokuapp.com/api/playerdata/topscorers/total/season/2023/
> <https://nba-stats-db.herokuapp.com/api/playerdata/topscorers/total/season/2023/>
Success Response:
`Code: 200`
Content:
```
{
"count": 20,
@@ -94,22 +99,23 @@ Content:
"team": "PHI",
"season": 2023
},
...
]
}
...
]
}
```
Top 20 Scorers in Playoffs
Method: `Get`
> https://nba-stats-db.herokuapp.com/api/playerdata/topscorers/playoffs/2022/
> <https://nba-stats-db.herokuapp.com/api/playerdata/topscorers/playoffs/2022/>
Success Response:
`Code: 200`
Content:
```
{
"count": 20,
@@ -180,22 +186,23 @@ Content:
"team": "GSW",
"season": 2022
},
...
]
}
...
]
}
```
Top 20 Assists by Season
Method: `Get`
> https://nba-stats-db.herokuapp.com/api/top_assists/totals/2023/
> <https://nba-stats-db.herokuapp.com/api/top_assists/totals/2023/>
Success Response:
`Code: 200`
Content:
```
{
"count": 20,
@@ -266,23 +273,23 @@ Content:
"team": "DEN",
"season": 2023
},
...
]
}
...
]
}
```
Top 20 Assists in Playoffs
Method: `Get`
> https://nba-stats-db.herokuapp.com/api/top_assists/playoffs/2022/
> <https://nba-stats-db.herokuapp.com/api/top_assists/playoffs/2022/>
Success Response:
`Code: 200`
Content:
```
{
"count": 20,
@@ -353,22 +360,23 @@ Content:
"team": "GSW",
"season": 2022
},
...
]
}
...
]
}
```
Top 20 Rebounders (Total Rebounds) by Season
Method: `Get`
> https://nba-stats-db.herokuapp.com/api/top_rebounds/totals/2023/
> <https://nba-stats-db.herokuapp.com/api/top_rebounds/totals/2023/>
Success Response:
`Code: 200`
Content:
```
{
"count": 20,
@@ -439,9 +447,9 @@ Content:
"team": "CHI",
"season": 2023
},
...
]
}
...
]
}
```
+5
View File
@@ -0,0 +1,5 @@
# Activate Python Shell
```
source venv/bin/activate
```
+1
View File
@@ -0,0 +1 @@
teams_data = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOK', 'DAL', 'SAS', 'DEN', 'MIN', 'SEA', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
@@ -0,0 +1,18 @@
from django.core.management.base import BaseCommand
from nba_data.models import PlayerAdvancedData
from django.db import connection
class Command(BaseCommand):
# Provides a description for use with the custom django management command (python manage.py help).
help = 'Delete all player ADVANCED data with season specified and reset primary key sequence in DB'
def handle(self, *args, **options):
# Delete player data with season
season = 2006
PlayerAdvancedData.objects.filter(season=season).delete()
# Reset the PK sequence
with connection.cursor() as cursor:
cursor.execute('ALTER SEQUENCE nba_data_playeradvanceddata_id_seq RESTART WITH 1;')
self.stdout.write(self.style.SUCCESS('Successfully deleted all players with season = {} in DB'.format(season)))
@@ -0,0 +1,18 @@
# Generated by Django 4.2 on 2023-09-20 07:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('nba_data', '0017_alter_playershotchartdata_result'),
]
operations = [
migrations.AlterField(
model_name='playeradvanceddata',
name='ft_attempt_rate',
field=models.DecimalField(decimal_places=3, max_digits=8, null=True),
),
]
+1 -1
View File
@@ -79,7 +79,7 @@ class PlayerAdvancedData(models.Model):
PER = models.DecimalField(max_digits=6, decimal_places=1, null=True)
TS_percent = models.DecimalField(max_digits=5, decimal_places=3, null=True)
three_p_attempt_rate = models.DecimalField(max_digits=5, decimal_places=3, null=True)
ft_attempt_rate = models.DecimalField(max_digits=5, decimal_places=3, null=True)
ft_attempt_rate = models.DecimalField(max_digits=8, decimal_places=3, null=True)
orb_percent = models.DecimalField(max_digits=5, decimal_places=2, null=True)
drb_percent = models.DecimalField(max_digits=5, decimal_places=2, null=True)
trb_percent = models.DecimalField(max_digits=5, decimal_places=2, null=True)
+4 -2
View File
@@ -6,6 +6,7 @@ from bs4 import BeautifulSoup
import csv
import json
import time
from data import teams_data
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -27,10 +28,11 @@ from nba_data.models import PlayerAdvancedData
# Change MEM to VAN for 2001 and prior.
# Change LAC to SDC for 1984 and prior.
teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'DAL', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'DAL', 'SAS', 'DEN', 'MIN', 'SEA', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
season = input('What season? ')
for team in teams:
for team in teams_data:
url_make = 'https://www.basketball-reference.com/teams/' + team + '/' + season + '.html'
response = requests.get(url_make)
+4 -5
View File
@@ -6,6 +6,7 @@ from bs4 import BeautifulSoup
import csv
import json
import time
from data import teams_data
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -29,13 +30,11 @@ from nba_data.models import PlayerPlayoffAdvancedData
teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'DAL', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
teams2 = ['HOU' ,'PHI', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
team_abbreviations = ['ATL', 'BOS', 'BRK', 'CHI', 'CHO', 'CLE', 'DAL', 'DEN', 'DET', 'GSW', 'HOU', 'IND', 'LAC', 'LAL', 'MEM', 'MIA', 'MIL', 'MIN', 'NOP', 'NYK', 'OKC', 'ORL', 'PHI', 'PHO', 'POR', 'SAC', 'SAS', 'TOR', 'UTA', 'WAS']
season = input('What season? ')
for team in teams:
teams2 = 'PHI'
for team in teams_data:
url_make = 'https://www.basketball-reference.com/teams/' + team + '/' + season + '.html'
response = requests.get(url_make)
@@ -27,7 +27,7 @@ from nba_data.models import PlayerPlayoffAdvancedData
# Change LAC to SDC for 1984 and prior.
teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'BRK', 'TOR', 'MEM', 'NOP', 'DAL', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
teams = ['ATL', 'BOS', 'BRK', 'CHI', 'CHO', 'CLE', 'DAL', 'DEN', 'DET', 'GSW', 'HOU', 'IND', 'LAC', 'LAL', 'MEM', 'MIA', 'MIL', 'MIN', 'NOP', 'NYK', 'OKC', 'ORL', 'PHI', 'PHO', 'POR', 'SAC', 'SAS', 'TOR', 'UTA', 'WAS']
single_team = ['GSW']
+3 -5
View File
@@ -6,6 +6,7 @@ from bs4 import BeautifulSoup
import csv
import json
import time
from data import teams_data
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -27,14 +28,11 @@ from nba_data.models import PlayerPlayoffTotalsData
# Change LAC to SDC for 1984 and prior.
teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'DAL', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
team_abbreviations = ['ATL', 'BOS', 'BRK', 'CHI', 'CHO', 'CLE', 'DAL', 'DEN', 'DET', 'GSW', 'HOU', 'IND', 'LAC', 'LAL', 'MEM', 'MIA', 'MIL', 'MIN', 'NOP', 'NYK', 'OKC', 'ORL', 'PHI', 'PHO', 'POR', 'SAC', 'SAS', 'TOR', 'UTA', 'WAS']
teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'DAL', 'SAS', 'DEN', 'MIN', 'SEA', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
season = input('What season? ')
for team in teams:
for team in teams_data:
url_make = 'https://www.basketball-reference.com/teams/' + team + '/' + season + '.html'
response = requests.get(url_make)
+6 -5
View File
@@ -12,10 +12,11 @@ django.setup()
from nba_data.models import PlayerShotChartData
player_name = 'LeBron James'
season = 2014
# team = 'LAL' # You might want to find a way to get this from the webpage
url = 'https://www.basketball-reference.com/players/j/jamesle01/shooting/' + \
player_name = 'Damian Lillard'
season = 2013
# Player name and season will be inserted into DB. Modify before running script.
url = 'https://www.basketball-reference.com/players/l/lillada01/shooting/' + \
str(season)
response = requests.get(url)
@@ -110,4 +111,4 @@ try:
except Exception as e:
print(f"Error inserting data into database: {e}")
print('success')
print(f"success {player_name} {season}")
+3 -2
View File
@@ -6,6 +6,7 @@ from bs4 import BeautifulSoup
import csv
import json
import time
from data import teams_data
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -26,14 +27,14 @@ from nba_data.models import PlayerTotalsData
# Change MEM to VAN for 2001 and prior.
# Change LAC to SDC for 1984 and prior.
teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'DAL', 'SAS', 'DEN', 'MIN', 'OKC', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
teams = ['HOU' ,'PHI', 'BOS', 'NYK', 'NJN', 'TOR', 'MEM', 'NOH', 'DAL', 'SAS', 'DEN', 'MIN', 'SEA', 'UTA', 'POR', 'MIL', 'CLE', 'CHI', 'IND', 'DET', 'SAC', 'PHO', 'GSW', 'LAC', 'LAL', 'MIA', 'ATL', 'WAS', 'ORL', 'CHA']
# team = input('What team? ')
# OMIT above. Will now only ask for season and iterate thru teams list.
season = input('What season? ')
for team in teams:
for team in teams_data:
url_make = 'https://www.basketball-reference.com/teams/' + team + '/' + season + '.html'
response = requests.get(url_make)
+8 -8
View File
@@ -30,22 +30,22 @@ class PlayerDataByTeamList(generics.ListAPIView):
return PlayerData.objects.filter(team=team)
# Fetch player data by season
# Fetch player totals data by season
class PlayerDataBySeasonList(generics.ListAPIView):
serializer_class = PlayerDataSerializer
serializer_class = PlayerTotalsDataSerializer
def get_queryset(self):
season = self.kwargs['season']
return PlayerData.objects.filter(season=season)
return PlayerTotalsData.objects.filter(season=season)
# Fetch player data by player name
# Fetch player totals data by player name
class PlayerDataByNameList(generics.ListAPIView):
serializer_class = PlayerDataSerializer
serializer_class = PlayerTotalsDataSerializer
def get_queryset(self):
name = self.kwargs['name']
return PlayerData.objects.filter(name__icontains=name)
return PlayerTotalsData.objects.filter(player_name__icontains=name)
# Fetch Top 20 players by PTS DESC for the season specified.
@@ -62,7 +62,7 @@ class TopScorersbySeasonTotalsList(generics.ListAPIView):
def get_queryset(self):
season = self.kwargs['season']
return PlayerTotalsData.objects.filter(season=season).order_by('-PTS')[:20]
return PlayerTotalsData.objects.filter(season=season).order_by('-PTS')[:200]
# Fetch and calculate the average 3P made, 3P attemps, 2P made, 2P attempts for all players in each season.
@@ -631,7 +631,7 @@ class TopScorersbySeasonListPlayoffs(generics.ListAPIView):
def get_queryset(self):
season = self.kwargs['season']
return PlayerPlayoffTotalsData.objects.filter(season=season).order_by('-PTS')[:20]
return PlayerPlayoffTotalsData.objects.filter(season=season).order_by('-PTS')[:200]
class TopAssistsBySeasonListPlayoffs(generics.ListAPIView):