def create_game_logs_file(team_id): """Creates file for each NBA team containing game info from last season :param team_id: ID number of the team """ # team game log path = os.path.join(TEAM_BASE_PATH, TEAM_DICT[team_id] + '.json') if not os.path.exists(path): print("Retrieving team " + TEAM_DICT[team_id] + " game log, season stats ... Please wait.") game_logs = team.TeamGameLogs(team_id, '2016-17').json with open(path, 'w') as outfile: json.dump(game_logs, outfile) # playoff game log playoff_path = os.path.join(TEAM_PLAYOFF_PATH, TEAM_DICT[team_id] + '.json') if not os.path.exists(playoff_path): playoff_games = team.TeamGameLogs(team_id, '2016-17', constants.SeasonType.Playoffs).json if len(playoff_games['resultSets'][0]['rowSet']): with open(playoff_path, 'w') as playoff_files: json.dump(playoff_games, playoff_files) # season stats season_path = os.path.join(TEAM_SEASON_PATH, TEAM_DICT[team_id] + '.json') if not os.path.exists(season_path): season_stats = team.TeamSeasons(team_id).json with open(season_path, 'w') as season_files: json.dump(season_stats, season_files)
def load_team_season(): header = ['TEAM_ID', 'YEAR', 'WINS', 'LOSSES', 'WIN_PCT', 'CONF_RANK', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A', 'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'OREB', 'DREB', 'REB', 'AST', 'PF', 'STL', 'TOV', 'BLK', 'PTS'] resDF = pd.DataFrame() for teamName in teamToIndex: print(teamName) teamId = TEAMS[teamName]["id"] seasonInfo = team.TeamSeasons(teamId).info() seasonInfo = seasonInfo[header] resDF = resDF.append(seasonInfo) time.sleep(2) resDF.to_csv("data/team/team-season.csv", index=False)
def teams(teamid): """Specific team pages. """ team_summary = team.TeamSummary(teamid) team_summary_info = team_summary.info() team_season_ranks = team_summary.season_ranks() team_common_roster = team.TeamCommonRoster(teamid) roster = team_common_roster.roster() coaches = team_common_roster.coaches() season = team_summary_info[0]["SEASON_YEAR"] team_game_log = team.TeamGameLogs(teamid, season=season) team_games = team_game_log.info() playoffs_teamgamelogs = team.TeamGameLogs(teamid, season=season, season_type="Playoffs") playoffs_team_games = playoffs_teamgamelogs.info() team_season = team.TeamSeasons(teamid) team_season_info = team_season.info() for i in team_season_info: if (i["YEAR"] == season): current_season_info = i return render_template("teams.html", title=team_summary_info[0]["TEAM_CITY"] + " " + team_summary_info[0]["TEAM_NAME"], teamid=teamid, team_summary_info=team_summary_info, team_season_ranks=team_season_ranks, season=season, team_games=team_games, playoffs_team_games=playoffs_team_games, team_season=team_season_info, roster=roster, coaches=coaches, current_season_info=current_season_info, team_img=TEAM_ID_DATA)
def teams_and_season(teamid, season): # season example: "2016-17" # type example: "Regular Season" or "Playoffs" team_game_log = team.TeamGameLogs(teamid, season=season) team_games = team_game_log.info() playoffs_teamgamelogs = team.TeamGameLogs(teamid, season=season, season_type="Playoffs") playoffs_team_games = playoffs_teamgamelogs.info() team_summary = team.TeamSummary(teamid, season=season) team_summary_info = team_summary.info() team_season_ranks = team_summary.season_ranks() team_common_roster = team.TeamCommonRoster(teamid) roster = team_common_roster.roster() coaches = team_common_roster.coaches() team_season = team.TeamSeasons(teamid) team_season_info = team_season.info() for i in team_season_info: if (i["YEAR"] == season): current_season_info = i return render_template("teams.html", title=team_summary_info[0]["TEAM_CITY"] + " " + team_summary_info[0]["TEAM_NAME"], teamid=teamid, team_summary_info=team_summary_info, team_season_ranks=team_season_ranks, season=season, team_games=team_games, playoffs_team_games=playoffs_team_games, current_season_info=current_season_info, team_img=TEAM_ID_DATA)
def test_TeamSeasons(self): teamstats = team.TeamSeasons(self.teamId) info = teamstats.info() self.assertTrue((70, 34), info.shape)