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

Fix/tracking #94

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions nba_py/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 3 additions & 12 deletions nba_py/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -365,15 +365,6 @@ 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'

Expand Down
3 changes: 2 additions & 1 deletion tests/test_nba_py_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
32 changes: 32 additions & 0 deletions tests/test_nba_py_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from nba_py import league
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, rewriting it to UnitTests usage would be a great idea.

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