From d06af0fc0bafc6aaa291fa648731979f72f75276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bratuli=C4=87?= Date: Mon, 23 Oct 2017 21:03:46 +0200 Subject: [PATCH 1/4] Added constants for tracking which are available at nba --- nba_py/constants.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nba_py/constants.py b/nba_py/constants.py index 7e2c317..9ca54d0 100644 --- a/nba_py/constants.py +++ b/nba_py/constants.py @@ -422,6 +422,18 @@ class MeasureType: class PtMeasureType: SpeedDistance = 'SpeedDistance' + Rebounding = 'Rebounding' + Possessions = 'Possessions' + CatchShoot = 'CatchShoot' + PullUpShot = 'PullUpShot' + Defense = 'Defense' + Drives = 'Drives' + Passing = 'Passing' + ElbowTouch = 'ElbowTouch' + PostTouch = 'PostTouch' + PaintTouch = 'PaintTouch' + Efficiency = 'Efficiency' + Default = SpeedDistance class GroupQuantity: From b694f73fca55684ab1012fe77d10d085ab8117b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bratuli=C4=87?= Date: Mon, 23 Oct 2017 21:04:18 +0200 Subject: [PATCH 2/4] Added pt_measure_type as parameter for player tracking stats, if not given, default is used --- nba_py/league.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/nba_py/league.py b/nba_py/league.py index 2aef748..d2ffdf8 100644 --- a/nba_py/league.py +++ b/nba_py/league.py @@ -257,7 +257,7 @@ def overall(self): return _api_scrape(self.json, 0) -class _PlayerTrackingStats: +class PlayerTrackingStats: """ Args: :league_id: ID for the league to look in (Default is 00) @@ -294,12 +294,12 @@ class _PlayerTrackingStats: :json: Contains the full json dump to play around with """ _endpoint = 'leaguedashptstats' - _pt_measure_type = '' def __init__(self, league_id=constants.League.Default, season_type=constants.SeasonType.Default, player_or_team=constants.PlayerOrTeam.Default, + pt_measure_type=constants.PtMeasureType.Default, per_mode=constants.PerMode.Default, season=constants.CURRENT_SEASON, playoff_round=constants.PlayoffRound.Default, @@ -330,7 +330,7 @@ def __init__(self, self.json = _get_json(endpoint=self._endpoint, params={'LeagueID': league_id, - 'PtMeasureType': self._pt_measure_type, + 'PtMeasureType': pt_measure_type, 'SeasonType': season_type, 'PlayerOrTeam': player_or_team, 'PerMode': per_mode, @@ -364,16 +364,6 @@ def __init__(self, def overall(self): return _api_scrape(self.json, 0) - -class PlayerSpeedDistanceTracking(_PlayerTrackingStats): - """ - Statistics that measure the distance covered and the average speed of all - movements (sprinting, jogging, standing, walking, backwards and forwards) - by a player while on the court. - """ - _pt_measure_type = constants.PtMeasureType.SpeedDistance - - class GameLog: _endpoint = 'leaguegamelog' From 76b75c358dcecb2f1b149ee82d9b89092ff28db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bratuli=C4=87?= Date: Mon, 23 Oct 2017 21:04:50 +0200 Subject: [PATCH 3/4] Changed test to fit refactored code and added another test to check whether passing and tracking stats are correct --- tests/test_nba_py_league.py | 3 ++- tests/test_nba_py_tracking.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/test_nba_py_tracking.py diff --git a/tests/test_nba_py_league.py b/tests/test_nba_py_league.py index ba0639c..01912cc 100644 --- a/tests/test_nba_py_league.py +++ b/tests/test_nba_py_league.py @@ -8,7 +8,8 @@ class TestPlayerSpeedDistanceTracking: def test_overall(self): - speed = league.PlayerSpeedDistanceTracking(date_from='03/05/2016', + # default is SpeedDistance tracking + speed = league.PlayerTrackingStats(date_from='03/05/2016', date_to='03/05/2016', season="2015-16") assert speed overall = speed.overall() diff --git a/tests/test_nba_py_tracking.py b/tests/test_nba_py_tracking.py new file mode 100644 index 0000000..641559b --- /dev/null +++ b/tests/test_nba_py_tracking.py @@ -0,0 +1,32 @@ +from nba_py import league +from nba_py import constants +try: + # python 2 compatability + from future_builtins import filter +except ImportError: + pass + +class TestPlayerTrackingStats: + + def __init__(self): + self.season = "2016-17" + self.target_player = "Aaron Gordon" + + def testPassing(self): + passing = league.PlayerTrackingStats(season=self.season, pt_measure_type=constants.PtMeasureType.Passing) + assert passing + overall = passing.overall() + stats = overall.iloc[2] + assert stats['PLAYER_NAME'] == self.target_player + assert stats['GP'] == 80 + assert stats['AST_TO_PASS_PCT_ADJ'] == 0.102 + assert stats['AST_ADJ'] == 2.6 + + def testDefense(self): + defense = league.PlayerTrackingStats(season=self.season, pt_measure_type=constants.PtMeasureType.Defense) + assert defense + overall = defense.overall() + stats = overall.iloc[2] + assert stats['PLAYER_NAME'] == self.target_player + assert stats['GP'] == 80 + assert stats['DREB'] == 3.6 \ No newline at end of file From a77b1f35bb575dc28d1a2775a95afa9a61d86386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bratuli=C4=87?= Date: Mon, 23 Oct 2017 22:13:17 +0200 Subject: [PATCH 4/4] Idented with extra line --- nba_py/league.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nba_py/league.py b/nba_py/league.py index d2ffdf8..2aec644 100644 --- a/nba_py/league.py +++ b/nba_py/league.py @@ -364,6 +364,7 @@ def __init__(self, def overall(self): return _api_scrape(self.json, 0) + class GameLog: _endpoint = 'leaguegamelog'