Exemplo n.º 1
0
 def get_game_summary_response(self):
     """
     gets game summary response from stats.nba.com for game id
     returns request response (error if response status is not 200)
     """
     parameters = {'GameId': self.GameId}
     return utils.get_json_response(self.SummaryBaseUrl, parameters, self.SummaryFilePath)
Exemplo n.º 2
0
 def get_pbp_events(self):
     """
     Sets:
     Periods - list of DataPeriod objects
     """
     response_json = utils.get_json_response(self.PbpUrl, {}, self.PbpFilePath)
     game_periods = response_json['g']['pd']
     # verify pbp is complete
     last_period = game_periods[-1]
     last_event = last_period['pla'][-1]
     if last_event['de'] not in ['Game End', 'End Period']:
         raise Exception(f"Last event is not game end: GameId: {self.GameId}")
     self.Periods = [DataPeriod(period['pla'], self.GameId, period['p']) for period in game_periods]
Exemplo n.º 3
0
 def get_pbp_response(self, start_period=0, end_period=10, range_type=2, start_range=0, end_range=55800):
     """
     gets play by play response from stats.nba.com for game id
     returns request response (error if response status is not 200)
     """
     parameters = {
         'GameId': self.GameId,
         'StartPeriod': start_period,
         'EndPeriod': end_period,
         'RangeType': range_type,
         'StartRange': start_range,
         'EndRange': end_range
     }
     return utils.get_json_response(self.PbpBaseUrl, parameters, self.PbpFilePath)
Exemplo n.º 4
0
 def get_game_data(self, **kwargs):
     """
     gets and cleans game data from data.nba.com
     kwargs:
     ignore_rebound_and_shot_order, default False, set to True to avoid raising possession_details.PbpEventOrderErrorException
         - do this if you don't want to fix issues with pbp and don't care about rebound stats
     period_starters_override - dict with missing period starters
     """
     game_summary_json = utils.get_json_response(self.GameDetailUrl, {}, self.GameSummaryFilePath)
     self.get_pbp_events()
     self.instantiate_team_and_player_data(game_summary_json)
     if 'period_starters_override' in kwargs:
         self.set_period_starters(missing_period_starters=kwargs.get('period_starters_override'))
     else:
         self.set_period_starters()
     self.add_players_on_floor()
     self.add_possession_details(ignore_rebound_and_shot_order=kwargs.get('ignore_rebound_and_shot_order', False))
Exemplo n.º 5
0
 def get_shots_response(self, team_id, file_path):
     """
     gets shots response from stats.nba.com for game id
     returns request response (error if response status is not 200)
     """
     if self.League == pbpstats.NBA_STRING:
         league_id = pbpstats.NBA_GAME_ID_PREFIX
     elif self.League == pbpstats.G_LEAGUE_STRING:
         league_id = pbpstats.G_LEAGUE_GAME_ID_PREFIX
     elif self.League == pbpstats.WNBA_STRING:
         league_id = pbpstats.WNBA_GAME_ID_PREFIX
     parameters = {
         'GameID': self.GameId,
         'Season': self.Season,
         'SeasonType': self.SeasonType,
         'TeamID': team_id,
         'PlayerID': 0,
         'Outcome': '',
         'Location': '',
         'Month': 0,
         'SeasonSegment': '',
         'DateFrom': '',
         'DateTo': '',
         'OpponentTeamID': 0,
         'VsConference': '',
         'VsDivision': '',
         'Position': '',
         'RookieYear': '',
         'GameSegment': '',
         'Period': 0,
         'LastNGames': 0,
         'ContextMeasure': 'FG_PCT',
         'PlayerPosition': '',
         'LeagueID': league_id,
     }
     return utils.get_json_response(self.ShotsBaseUrl, parameters, file_path)