Modules¶
tracking¶
-
nba_stats_tracking.tracking.
add_to_tracking_totals
(totals, item)[source]¶ Adds totals from item to totals
Parameters: - totals (dict) – Totals to be added to
- item (dict) – Item to be added to totals dict
Returns: totals dict
Return type: dict
-
nba_stats_tracking.tracking.
aggregate_full_season_tracking_stats_for_seasons
(stat_measure, seasons, season_types, entity_type, **kwargs)[source]¶ Aggregates full season stats for stat measure for desired filters. Returns list of dicts for stats for each team/player and dict with league totals.
Parameters: - stat_measure (str) – Options: Drives, Defense, CatchShoot, Passing, Possessions, PullUpShot, Rebounding, Efficiency, SpeedDistance, ElbowTouch, PostTouch, PaintTouch
- seasons (list[str]) – List of seasons.Format YYYY-YY ex 2019-20
- season_types (list[str]) – List of season types. Options are Regular Season or Playoffs
- entity_type (str) – Options are player or team
- opponent_team_id (str) – (optional) nba.com team id
Returns: tuple with list of dicts for stats for each player/team and dict with league totals
Return type: tuple(list[dict], dict)
-
nba_stats_tracking.tracking.
generate_tracking_game_logs
(stat_measure, entity_type, date_from, date_to, **kwargs)[source]¶ Generates game logs for all games between two dates for desired filters
Parameters: - stat_measure (str) – Options: Drives, Defense, CatchShoot, Passing, Possessions, PullUpShot, Rebounding, Efficiency, SpeedDistance, ElbowTouch, PostTouch, PaintTouch
- entity_type (str) – Options are player or team
- date_from (str) – Format - MM/DD/YYYY
- date_to (str) – Format - MM/DD/YYYY
- team_id_game_id_map (dict) – (optional) dict mapping team id to game id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times
- team_id_opponent_team_id_map (dict) – (optional) dict mapping team id to opponent team id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times
- player_id_team_id_map (dict) – (optional) dict mapping player id to team id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times
Returns: list of game log dicts
Return type: list[dict]
-
nba_stats_tracking.tracking.
get_tracking_response_json_for_stat_measure
(stat_measure, season, season_type, entity_type, **kwargs)[source]¶ Makes API call to NBA Advanced Stats and returns JSON response
Parameters: - stat_measure (str) – Options: Drives, Defense, CatchShoot, Passing, Possessions, PullUpShot, Rebounding, Efficiency, SpeedDistance, ElbowTouch, PostTouch, PaintTouch
- season (str) – Format YYYY-YY ex 2019-20
- season_type (str) – Options are Regular Season or Playoffs
- entity_type (str) – Options are player or team
- date_from (str) – (optional) Format - MM/DD/YYYY
- date_to (str) – (optional) Format - MM/DD/YYYY
- opponent_team_id (str) – (optional) nba.com team id
Returns: response json
Return type: dict
-
nba_stats_tracking.tracking.
get_tracking_stats
(stat_measure, seasons, season_types, entity_type, **kwargs)[source]¶ Gets stat measure tracking stats for filter
Parameters: - stat_measure (str) – Options: Drives, Defense, CatchShoot, Passing, Possessions, PullUpShot, Rebounding, Efficiency, SpeedDistance, ElbowTouch, PostTouch, PaintTouch
- seasons (list[str]) – List of seasons.Format YYYY-YY ex 2019-20
- season_types (list[str]) – List of season types. Options are Regular Season or Playoffs
- entity_type (str) – Options are player or team
- date_from (str) – (optional) Format - MM/DD/YYYY
- date_to (str) – (optional) Format - MM/DD/YYYY
- opponent_team_id (str) – (optional) nba.com team id
Returns: list of dicts with stats for each player/team
Return type: list[dict]
-
nba_stats_tracking.tracking.
sum_tracking_totals
(entity_type, *args)[source]¶ Sums totals for given dicts and grouped by entity type
Parameters: - entity_type (str) – Options are player, team, opponent or league
- *args (dict) – Variable length argument list of dicts to be summed up
Returns: list of dicts with totals for each entity
Return type: list[dict]
tracking_shots¶
Module containing functions for accessing tracking shot stats
-
nba_stats_tracking.tracking_shots.
add_to_tracking_shot_totals
(totals, item)[source]¶ Adds shot totals from item to totals and updates percentages
Parameters: - totals (dict) – Totals to be added to
- item (dict) – Item to be added to totals dict
Returns: totals dict
Return type: dict
-
nba_stats_tracking.tracking_shots.
aggregate_full_season_tracking_shot_stats_for_seasons
(entity_type, seasons, season_types, **kwargs)[source]¶ Aggregates full season stats for desired filters. Returns list of dicts for stats for each team/player and dict with league totals.
Parameters: - entity_type (str) – Options are player, team or opponent
- seasons (list[str]) – List of seasons.Format YYYY-YY ex 2019-20
- season_types (list[str]) – List of season types. Options are Regular Season or Playoffs
- close_def_dists (list[str]) – (optional) Options: ‘’, ‘0-2 Feet - Very Tight’, ‘2-4 Feet - Tight’,‘4-6 Feet - Open’,‘6+ Feet - Wide Open’
- shot_clocks (list[str]) – (optional) - Options: ‘’, ‘24-22’, ‘22-18 Very Early’, ‘18-15 Early’, ‘15-7 Average’, ‘7-4 Late’, ‘4-0 Very Late’
- shot_dists (list[str]) – (optional) - Options: ‘’, ‘>=10.0’
- touch_times (list[str]) – (optional) - Options: ‘’, ‘Touch < 2 Seconds’, ‘Touch 2-6 Seconds’, ‘Touch 6+ Seconds’
- dribble_ranges (list[str]) – (optional) - Options: ‘’, ‘0 Dribbles’, ‘1 Dribble’, ‘2 Dribbles’, ‘3-6 Dribbles’, ‘7+ Dribbles’
- general_ranges (list[str]) – (optional) - Options: ‘Overall’, ‘Catch and Shoot’, ‘Pullups’, ‘Less Than 10 ft’
- periods (list[int]) – (optional) Only get stats for specific periods
- location (str) – (optional) - Options: ‘Home’ or ‘Road’
Returns: tuple with list of dicts for stats for each player/team and dict with league totals
Return type: tuple(list[dict], dict)
-
nba_stats_tracking.tracking_shots.
generate_tracking_shot_game_logs
(entity_type, date_from, date_to, **kwargs)[source]¶ Generates game logs for all games between two dates for desired filters
Parameters: - entity_type (str) – Options are player, team or opponent
- date_from (str) – Format - MM/DD/YYYY
- date_to (str) – Format - MM/DD/YYYY
- team_id_game_id_map (dict) – (optional) dict mapping team id to game id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times
- team_id_opponent_team_id_map (dict) – (optional) dict mapping team id to opponent team id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times
- player_id_team_id_map (dict) – (optional) dict mapping player id to team id. When getting game logs for multiple separate filters for the same date it is recommended that you pass this in to avoid making the same request multiple times
- close_def_dists (list[str]) – (optional) Options: ‘’, ‘0-2 Feet - Very Tight’, ‘2-4 Feet - Tight’,‘4-6 Feet - Open’,‘6+ Feet - Wide Open’
- shot_clocks (list[str]) – (optional) - Options: ‘’, ‘24-22’, ‘22-18 Very Early’, ‘18-15 Early’, ‘15-7 Average’, ‘7-4 Late’, ‘4-0 Very Late’
- shot_dists (list[str]) – (optional) - Options: ‘’, ‘>=10.0’
- touch_times (list[str]) – (optional) - Options: ‘’, ‘Touch < 2 Seconds’, ‘Touch 2-6 Seconds’, ‘Touch 6+ Seconds’
- dribble_ranges (list[str]) – (optional) - Options: ‘’, ‘0 Dribbles’, ‘1 Dribble’, ‘2 Dribbles’, ‘3-6 Dribbles’, ‘7+ Dribbles’
- general_ranges (list[str]) – (optional) - Options: ‘Overall’, ‘Catch and Shoot’, ‘Pullups’, ‘Less Than 10 ft’
- periods (list[int]) – (optional) Only get stats for specific periods
- location (str) – (optional) - Options: ‘Home’ or ‘Road’
Returns: list of game log dicts
Return type: list[dict]
-
nba_stats_tracking.tracking_shots.
get_tracking_shot_stats
(entity_type, seasons, season_types, **kwargs)[source]¶ Gets tracking shot stats for filters
Parameters: - entity_type (str) – Options are player, team or opponent
- seasons (list[str]) – List of seasons.Format YYYY-YY ex 2019-20
- season_types (list[str]) – List of season types. Options are Regular Season or Playoffs
- close_def_dists (list[str]) – (optional) Options: ‘’, ‘0-2 Feet - Very Tight’, ‘2-4 Feet - Tight’,‘4-6 Feet - Open’,‘6+ Feet - Wide Open’
- shot_clocks (list[str]) – (optional) - Options: ‘’, ‘24-22’, ‘22-18 Very Early’, ‘18-15 Early’, ‘15-7 Average’, ‘7-4 Late’, ‘4-0 Very Late’
- shot_dists (list[str]) – (optional) - Options: ‘’, ‘>=10.0’
- touch_times (list[str]) – (optional) - Options: ‘’, ‘Touch < 2 Seconds’, ‘Touch 2-6 Seconds’, ‘Touch 6+ Seconds’
- dribble_ranges (list[str]) – (optional) - Options: ‘’, ‘0 Dribbles’, ‘1 Dribble’, ‘2 Dribbles’, ‘3-6 Dribbles’, ‘7+ Dribbles’
- general_ranges (list[str]) – (optional) - Options: ‘Overall’, ‘Catch and Shoot’, ‘Pullups’, ‘Less Than 10 ft’
- date_from (str) – (optional) Format - MM/DD/YYYY
- date_to (str) – (optional) Format - MM/DD/YYYY
- periods (list[int]) – (optional) Only get stats for specific periods
- location (str) – (optional) - Options: ‘Home’ or ‘Road’
Returns: list of dicts with stats for each player/team
Return type: list[dict]
-
nba_stats_tracking.tracking_shots.
get_tracking_shots_response
(entity_type, season, season_type, **kwargs)[source]¶ Makes API call to NBA Advanced Stats and returns JSON response
Parameters: - entity_type (str) – Options are player, team or opponent
- season (str) – Format YYYY-YY ex 2019-20
- season_type (str) – Options are Regular Season or Playoffs
- date_from (str) – (optional) Format - MM/DD/YYYY
- date_to (str) – (optional) Format - MM/DD/YYYY
- close_def_dist (str) – (optional) Defaults to “”. Options: ‘’, ‘0-2 Feet - Very Tight’, ‘2-4 Feet - Tight’,‘4-6 Feet - Open’,‘6+ Feet - Wide Open’
- shot_clock (str) – (optional) - Defaults to “”. Options: ‘’, ‘24-22’, ‘22-18 Very Early’, ‘18-15 Early’, ‘15-7 Average’, ‘7-4 Late’, ‘4-0 Very Late’
- shot_dist (str) – (optional) - Defaults to “”. Options: ‘’, ‘>=10.0’
- touch_time (str) – (optional) - Defaults to “”. Options: ‘’, ‘Touch < 2 Seconds’, ‘Touch 2-6 Seconds’, ‘Touch 6+ Seconds’
- dribbles (str) – (optional) - Defaults to “”. Options: ‘’, ‘0 Dribbles’, ‘1 Dribble’, ‘2 Dribbles’, ‘3-6 Dribbles’, ‘7+ Dribbles’
- general_range (str) – (optional) - Defaults to “Overall”. Options: ‘Overall’, ‘Catch and Shoot’, ‘Pullups’, ‘Less Than 10 ft’
- period (int) – (optional) Only get stats for specific period
- location (str) – (optional) - Options: ‘Home’ or ‘Road’
Returns: response json
Return type: dict
-
nba_stats_tracking.tracking_shots.
sum_tracking_shot_totals
(entity_type, *args)[source]¶ Sums totals for given dicts and grouped by entity type
Parameters: - entity_type (str) – Options are player, team, opponent or league
- *args (dict) – Variable length argument list of dicts to be summed up
Returns: list of dicts with totals for each entity
Return type: list[dict]
utils¶
-
nba_stats_tracking.utils.
get_boxscore_response_for_game
(game_id)[source]¶ Gets response from boxscore endpoint
Parameters: game_id (str) – nba.com game id Returns: response json Return type: dict
-
nba_stats_tracking.utils.
get_game_ids_for_date
(date)[source]¶ Gets game ids for all games played on a given date
Parameters: date (str) – Format - MM/DD/YYYY Returns: list of game ids Return type: list
-
nba_stats_tracking.utils.
get_json_response
(url, params)[source]¶ Helper function to get json response for request
Parameters: - url (str) – base url for api endpoint
- params (dict) – params for request
Returns: response json
Return type: dict
-
nba_stats_tracking.utils.
get_player_team_map_for_date
(date)[source]¶ Creates a dict mapping player id to team id for all games on a given date
Parameters: date (str) – Format - MM/DD/YYYY Returns: player id team id dict Return type: dict
-
nba_stats_tracking.utils.
get_scoreboard_response_json_for_date
(date)[source]¶ Gets response from scoreboard endpoint
Parameters: date (str) – Format - MM/DD/YYYY Returns: response json Return type: dict
-
nba_stats_tracking.utils.
get_season_from_game_id
(game_id)[source]¶ Gets season from nba.com game id 4th and 5th digits of game id represent year season started ex 0021900001 is for the 2019-20 season
Parameters: game_id (str) – nba.com game id Returns: season - Format YYYY-YY ex 2019-20 Return type: string
-
nba_stats_tracking.utils.
get_season_type_from_game_id
(game_id)[source]¶ Gets season type from nba.com game id Season type is represented in 3rd digit of game id 2 is Regular Season, 4 is Playoffs
Parameters: game_id (str) – nba.com game id Returns: season type - Regular Season or Playoffs Return type: string
-
nba_stats_tracking.utils.
get_team_id_maps_for_date
(date)[source]¶ Creates dicts mapping team id to game id and team id to opponent team id for games on a given date
Parameters: date (str) – Format - MM/DD/YYYY Returns: team id game id dict, team id opponent id dict Return type: tuple(dict, dict)
-
nba_stats_tracking.utils.
make_array_of_dicts_from_response_json
(response_json, index)[source]¶ Makes array of dicts from stats.nba.com response json
Parameters: - response_json (dict) – dict with response from request
- index (int) – index that holds results in resultSets array
Returns: list of dicts with data for each row
Return type: list[dict]