Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Player Tracking Stats #109

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
781 changes: 781 additions & 0 deletions constants.py

Large diffs are not rendered by default.

476 changes: 476 additions & 0 deletions league.py

Large diffs are not rendered by default.

16 changes: 6 additions & 10 deletions nba_py/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from datetime import datetime, timedelta
import os

from requests import get
from datetime import datetime, timedelta
from nba_py.constants import League
import os

HAS_PANDAS = True
try:
Expand All @@ -22,13 +21,10 @@
# Constants
TODAY = datetime.today()
BASE_URL = 'http://stats.nba.com/stats/{endpoint}'
HEADERS = {
'user-agent': ('Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'), # noqa: E501
'Dnt': ('1'),
'Accept-Encoding': ('gzip, deflate, sdch'),
'Accept-Language': ('en'),
'origin': ('http://stats.nba.com')
}
HEADERS = {'user-agent': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/45.0.2454.101 Safari/537.36'),
}


def _api_scrape(json_inp, ndx):
Expand Down
24 changes: 13 additions & 11 deletions nba_py/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
from datetime import datetime

_curr_year = datetime.now().year
if datetime.now().month > 6:
CURRENT_SEASON = str(_curr_year) + "-" + str(_curr_year + 1)[2:]
else:
CURRENT_SEASON = str(_curr_year - 1) + "-" + str(_curr_year)[2:]
CURRENT_SEASON = '2017-18'

TEAMS = {
'ATL': {
Expand Down Expand Up @@ -419,10 +413,19 @@ class MeasureType:
Usage = 'Usage'
Default = Base


class PtMeasureType:
SpeedDistance = 'SpeedDistance'

Drives = 'Drives'
Defense = 'Defense'
CatchShoot = 'CatchShoot'
Passing = 'Passing'
Possessions = 'Possessions'
PullUpShot = 'PullUpShot'
Rebounding = 'Rebounding'
Efficiency = 'Efficiency'
ElbowTouch = 'ElbowTouch'
PostTouch = 'PostTouch'
PaintTouch = 'PaintTouch'

class GroupQuantity:
Default = 5
Expand Down Expand Up @@ -614,8 +617,7 @@ class StatCategory:


class ContextMeasure:
# Not sure if this is mapped correctly. Source:
# https://github.com/bradleyfay/NBAStats
# Not sure if this is mapped correctly. Source: https://github.com/bradleyfay/NBAStats
FGM = 'FGM'
FGA = 'FGA'
FG_PCT = 'FG_PCT'
Expand Down
17 changes: 4 additions & 13 deletions nba_py/draftcombine.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from nba_py import _api_scrape, _get_json
from nba_py import constants
from nba_py.constants import *


class Summary:
_endpoint = 'draftcombinestats'

def __init__(
self,
league_id=constants.League.Default,
season=constants.CURRENT_SEASON):
def __init__(self, league_id=League.Default, season=CURRENT_SEASON):
self.json = _get_json(endpoint=self._endpoint,
params={'LeagueID': league_id,
'SeasonYear': season})
Expand All @@ -20,10 +17,7 @@ def overall(self):
class DrillResults:
_endpoint = 'draftcombinedrillresults'

def __init__(
self,
league_id=constants.League.Default,
season=constants.CURRENT_SEASON):
def __init__(self, league_id=League.Default, season=CURRENT_SEASON):
self.json = _get_json(endpoint=self._endpoint,
params={'LeagueID': league_id,
'SeasonYear': season})
Expand All @@ -35,10 +29,7 @@ def overall(self):
class SpotShooting:
_endpoint = 'draftcombinespotshooting'

def __init__(
self,
league_id=constants.League.Default,
season=constants.CURRENT_SEASON):
def __init__(self, league_id=League.Default, season=CURRENT_SEASON):
self.json = _get_json(endpoint=self._endpoint,
params={'LeagueID': league_id,
'SeasonYear': season})
Expand Down
41 changes: 21 additions & 20 deletions nba_py/game.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from nba_py import _api_scrape, _get_json
from nba_py import constants
from nba_py.constants import *


class BoxscoreSummary:
_endpoint = 'boxscoresummaryv2'

def __init__(self,
game_id,
season=constants.CURRENT_SEASON,
season_type=constants.SeasonType.Default,
range_type=constants.RangeType.Default,
start_period=constants.StartPeriod.Default,
end_period=constants.EndPeriod.Default,
start_range=constants.StartRange.Default,
end_range=constants.EndRange.Default):
season=CURRENT_SEASON,
season_type=SeasonType.Default,
range_type=RangeType.Default,
start_period=StartPeriod.Default,
end_period=EndPeriod.Default,
start_range=StartRange.Default,
end_range=EndRange.Default):
self.json = _get_json(endpoint=self._endpoint,
params={'GameID': game_id,
'Season': season,
Expand Down Expand Up @@ -51,18 +51,17 @@ def season_series(self):
def available_video(self):
return _api_scrape(self.json, 8)


class _BaseBoxcore:

def __init__(self,
game_id,
season=constants.CURRENT_SEASON,
season_type=constants.SeasonType.Default,
range_type=constants.RangeType.Default,
start_period=constants.StartPeriod.Default,
end_period=constants.EndPeriod.Default,
start_range=constants.StartRange.Default,
end_range=constants.EndRange.Default):
season=CURRENT_SEASON,
season_type=SeasonType.Default,
range_type=RangeType.Default,
start_period=StartPeriod.Default,
end_period=EndPeriod.Default,
start_range=StartRange.Default,
end_range=EndRange.Default):
self.json = _get_json(endpoint=self._endpoint,
params={'GameID': game_id,
'Season': season,
Expand Down Expand Up @@ -154,8 +153,8 @@ class PlayByPlay:

def __init__(self,
game_id,
start_period=constants.StartPeriod.Default,
end_period=constants.EndPeriod.Default):
start_period=StartPeriod.Default,
end_period=EndPeriod.Default):
self.json = _get_json(endpoint=self._endpoint,
params={'GameID': game_id,
'StartPeriod': start_period,
Expand All @@ -166,8 +165,10 @@ def info(self):

def available_video(self):
return _api_scrape(self.json, 1)






class HustleStats:
_endpoint = 'hustlestatsboxscore'

Expand Down
Loading