def getADVStats(gameList): df1 = pd.DataFrame() for a in gameList: print(a) boxscore_summary = game.BoxscoreSummary(a) sql_team_basic = boxscore_summary.game_summary() sql_team_basic = sql_team_basic[['GAME_DATE_EST', 'GAMECODE']] boxscore_advanced = game.BoxscoreAdvanced(a) sql_team_advanced = boxscore_advanced.sql_team_advanced() team_four_factors = game.BoxscoreFourFactors(a) sql_team_four_factors = team_four_factors.sql_team_four_factors() boxscore = game.Boxscore(a) sql_team_scoring = boxscore.team_stats() df = pd.concat([ sql_team_basic, sql_team_advanced, sql_team_four_factors, sql_team_scoring ], axis=1) df1 = pd.concat([df1, df], axis=0) df1.fillna(method='ffill', inplace=True) # print(df1.head()) print('Stats Compiled') return df1
def get_gameDataWithPlayersAndPoints(teamName, season): team_id = TEAMS[teamName]['id'] df = team.TeamGameLogs(team_id, season).info() print(df[:5]) # For each game get the players who played and the points and add them to the dataframe line for g in df["Game_ID"]: print(g) player_stats = game.BoxscoreAdvanced(g).sql_players_advanced() print("columns:::", list(player_stats)) print(player_stats) players = player_stats["PLAYER_NAME"].values minutes = player_stats["MIN"].values #points = player_stats["PTS"].values teamStartIndices = np.where( player_stats["START_POSITION"].values == 'F')[0] home_team_players = players[:teamStartIndices[2]] away_team_players = players[:teamStartIndices[2]] # Remove players who didn't play notPlayingPlayers = np.where(player_stats["MIN"].isnull())[0] players = np.delete(players, notPlayingPlayers) #points = np.delete(points, notPlayingPlayers) #player_stats["PLAYER_NAME"] = players #df = df.assign(player_stats=pd.Series(player_stats).values) print("------") break return df
def test(): gid = '0041400122' assert game.BoxscoreScoring(gid) assert game.BoxscoreUsage(gid) assert game.BoxscoreMisc(gid) assert game.BoxscoreAdvanced(gid) assert game.BoxscoreFourFactors(gid) assert game.PlayByPlay(gid)
def testAll(self): assert game.BoxscoreSummary(self.gameId) assert game.Boxscore(self.gameId) assert game.BoxscoreScoring(self.gameId) assert game.BoxscoreUsage(self.gameId) assert game.BoxscoreMisc(self.gameId) assert game.BoxscoreAdvanced(self.gameId) assert game.BoxscoreFourFactors(self.gameId) assert game.PlayByPlay(self.gameId) assert game.HustleStats(self.gameId)
def testBoxScoreAdvanced(self): boxscoreadvanced = game.BoxscoreAdvanced(self.gameId) playeradvanced = boxscoreadvanced.sql_players_advanced() self.assertTrue((26, 29), playeradvanced.shape) self.assertTrue( ('Aaron Gordon' == playeradvanced[1:2].PLAYER_NAME).all()) teamadvanced = boxscoreadvanced.sql_team_advanced() self.assertTrue((2, 27), teamadvanced.shape) self.assertTrue(('Celtics' == teamadvanced[1:2].TEAM_NAME).all())
def get_player_adv_logs(player_name, season='2016-17'): id = gf.get_player_id(player_name) try: player_info = pd.read_pickle('player_adv_game_logs/' + str(id) + '-' + season + '.pckl') except FileNotFoundError: print('File not found') player_info = game.BoxscoreAdvanced(id, season=season) player_info = player_info.sql_players_advanced() player_info.to_pickle('player_adv_game_logs/' + str(id) + '-' + season + '.pckl') return player_info
def test(): gid = '0041400122' print(game.BoxscoreSummary(gid).line_score()) assert game.BoxscoreSummary(gid) assert game.Boxscore(gid) assert game.BoxscoreScoring(gid) assert game.BoxscoreUsage(gid) assert game.BoxscoreMisc(gid) assert game.BoxscoreAdvanced(gid) assert game.BoxscoreFourFactors(gid) assert game.PlayByPlay(gid) assert game.HustleStats(gid)
recent_id = '00' + str(recent_id) foo = game.Boxscore(recent_id) foo = foo.team_stats() return '00' + str( int(recent_id) - 15 ) # Need to subtract 15 games because todays games are incomplete and will raise an error if included recent_id = most_recent(dataset_id) #%% # Collect and process data of the latest games played currently not used in the model g_id = '00' + str(int(dataset_id) + 1) trad = game.Boxscore(g_id) trad = trad.team_stats() adv = game.BoxscoreAdvanced(g_id) adv = adv.sql_team_advanced() ff = game.BoxscoreFourFactors(g_id) ff = ff.sql_team_four_factors() df = [] df.append(trad) df.append(adv) df.append(ff) merge0 = pd.concat(df, axis=1) df1, df2 = np.split(merge0, [1], axis=0) cols_A = [col + 'A' for col in df1.columns] cols_B = [col + 'B' for col in df2.columns] df1.columns = cols_A df2.columns = cols_B df2 = df2.reset_index(drop=True) summ = game.BoxscoreSummary(g_id)
from __future__ import print_function from nba_py import game # pbp = game.PlayByPlay('0041400122') # print pbp.info() box = game.Boxscore('0041400122') print(box.game_summary()) bss = game.BoxscoreScoring('0041400122') print(bss.sql_team_scoring()) bsu = game.BoxscoreUsage('0041400122') print(bsu.sql_team_usage()) bsa = game.BoxscoreAdvanced('0041400122') print(bsa.sql_team_advanced()) bsf = game.BoxscoreFourFactors('0041400122') print(bsf.sql_team_four_factors()) pt = game.PlayerTracking('0041400122') print(pt.info())
def boxscore_advanced(game_id, start_period, end_period, start_range, end_range, range_type): return game.BoxscoreAdvanced(game_id, start_period=start_period, end_period=end_period, start_range=start_range, end_range=end_range, range_type=range_type)