def get_shot_stats(playerID, n): num = randint(15, 40) print n, player_dict.keys()[player_dict.values().index( playerID)], 'getting shooting stats!' idx = players[players.id == playerID].index[0] player_shooting = nba.PlayerShotTracking(playerID).general_shooting() # catch and shoot 3 point shooting metric catchshoot = player_shooting[player_shooting.SHOT_TYPE == 'Catch and Shoot'] if catchshoot.empty: players.set_value(idx, '3catch_and_shoot', 0.0) return catch_and_shoot3 = catchshoot.FG3A_FREQUENCY[0] * catchshoot.FG3M[0] players.set_value(idx, '3catch_and_shoot', catch_and_shoot3) # pull-up shooting metric pullups = player_shooting[player_shooting.SHOT_TYPE == 'Pull Ups'] if pullups.empty: players.set_value(idx, 'pullupshoot', 0.0) return pullupshoot = pullups.EFG_PCT[1] * pullups.FGA[1] players.set_value(idx, 'pullupshoot', pullupshoot) sleep(num)
def get_player_shot_tracking_overall(id_list): res = [] player_shot_tracking_overall = {} for i in id_list: overall = player.PlayerShotTracking(player_id=i).overall().fillna(0) key = str(i) value = {} value.update({"PLAYER_NAME_LAST_FIRST":(str(overall["PLAYER_NAME_LAST_FIRST"].values[0].replace("'", '"'))),\ "FG2_PCT":(float(overall[["FG2_PCT"]].values[0])),\ "FG3_PCT":(float(overall[["FG3_PCT"]].values[0]))}) res.append(({key: value})) player_shot_tracking_overall.update({key: value}) print(res) sys.stdout.flush()
def generate_catch_shoot_df(player_id_lst, year): lst_of_dicts = [] for id in player_id_lst: print id shooting = player.PlayerShotTracking(id, season=year).general_shooting() if not shooting.empty and 'Catch and Shoot' in shooting.SHOT_TYPE.values: shooting.fillna(0, inplace=True) catch_shoot_freq = float(shooting.FGA_FREQUENCY[ shooting.SHOT_TYPE == 'Catch and Shoot']) lst_of_dicts.append({ 'player_id': str(id), 'catch_shoot_freq': catch_shoot_freq }) # time.sleep(1) else: lst_of_dicts.append({'player_id': str(id), 'catch_shoot_freq': 0}) catch_shoot_df = pd.DataFrame(lst_of_dicts) catch_shoot_df.set_index('player_id', inplace=True, drop=True) return catch_shoot_df
def test(): pid = get_player('Tim', 'Duncan') vs_pid = get_player('Stephen', 'Curry') assert player.PlayerList() assert player.PlayerSummary(pid) # assert player.PlayerGeneralSplits(pid) # assert player.PlayerOpponentSplits(pid) assert player.PlayerLastNGamesSplits(pid) assert player.PlayerInGameSplits(pid) assert player.PlayerClutchSplits(pid) # assert player.PlayerShootingSplits(pid) assert player.PlayerPerformanceSplits(pid) assert player.PlayerYearOverYearSplits(pid) assert player.PlayerCareer(pid) assert player.PlayerProfile(pid) assert player.PlayerGameLogs(pid) assert player.PlayerShotTracking(pid) assert player.PlayerReboundTracking(pid) assert player.PlayerPassTracking(pid) assert player.PlayerDefenseTracking(pid) # assert player.PlayerShotLogTracking(pid) # assert player.PlayerReboundLogTracking(pid) assert player.PlayerVsPlayer(pid, vs_pid)
def testAll(self): assert player.PlayerList() assert player.PlayerSummary(self.playerId) # assert player.PlayerGeneralSplits(self.playerId) # assert player.PlayerOpponentSplits(self.playerId) assert player.PlayerLastNGamesSplits(self.playerId) assert player.PlayerInGameSplits(self.playerId) assert player.PlayerClutchSplits(self.playerId) # assert player.PlayerShootingSplits(self.playerId) assert player.PlayerPerformanceSplits(self.playerId) assert player.PlayerYearOverYearSplits(self.playerId) assert player.PlayerCareer(self.playerId) assert player.PlayerProfile(self.playerId) assert player.PlayerGameLogs(self.playerId) assert player.PlayerShotTracking(self.playerId) assert player.PlayerReboundTracking(self.playerId) assert player.PlayerPassTracking(self.playerId) assert player.PlayerDefenseTracking(self.playerId) # assert player.PlayerShotLogTracking(self.playerId) # assert player.PlayerReboundLogTracking(self.playerId) assert player.PlayerVsPlayer(self.playerId, self.vs_playerId)