Ejemplo n.º 1
0
def get_team_stats(all_teams_list):

    team_overall_list = []

    for team_abbr in all_teams_list:

        current_team = TEAMS[team_abbr]

        print('Gathering overall data for {}'.format(current_team['name']))

        players_json = team.TeamPlayers(team_id=current_team['id']).json

        team_stats = players_json['resultSets'][0]

        team_overall_headers = team_stats['headers']
        team_overall_stats = team_stats['rowSet'][0]

        team_overall_dict = dict(zip(team_overall_headers, team_overall_stats))

        team_overall_list.append(team_overall_dict)

    df = pd.DataFrame(team_overall_list)

    df = df[team_overall_headers]

    df.to_csv('2016-17 Overall Team Stats.csv')
Ejemplo n.º 2
0
def test():
    team_id = TEAMS['ATL']['id']
    player_id = get_player('Lebron', 'James')
    assert team.TeamList()
    assert team.TeamSummary(team_id)
    team_details = team.TeamDetails(team_id)
    assert team_details
    assert team_details.background()
    assert team_details.history()
    assert team.TeamCommonRoster(team_id)
    assert team.TeamGeneralSplits(team_id)
    assert team.TeamOpponentSplits(team_id)
    assert team.TeamLastNGamesSplits(team_id)
    assert team.TeamInGameSplits(team_id)
    assert team.TeamClutchSplits(team_id)
    assert team.TeamShootingSplits(team_id)
    assert team.TeamPerformanceSplits(team_id)
    assert team.TeamLineups(team_id)
    assert team.TeamPlayers(team_id)
    assert team.TeamPlayerOnOffDetail(team_id)
    assert team.TeamPlayerOnOffSummary(team_id)
    assert team.TeamGameLogs(team_id)
    assert team.TeamShotTracking(team_id)
    assert team.TeamReboundTracking(team_id)
    assert team.TeamPassTracking(team_id)
    assert team.TeamVsPlayer(team_id, player_id)
Ejemplo n.º 3
0
def get_team_players(all_teams_list):

    all_players_list = []

    for team_abbr in all_teams_list:

        current_team = TEAMS[team_abbr]

        print('Gathering player data for {}'.format(current_team['name']))

        players_json = team.TeamPlayers(team_id=current_team['id']).json

        player_data = players_json['resultSets'][1]

        player_headers = player_data['headers']
        player_stats_list = player_data['rowSet']

        for player_stats in player_stats_list:
            player_stats_dict = dict(zip(player_headers, player_stats))
            all_players_list.append(player_stats_dict)

    df = pd.DataFrame(all_players_list)

    df = df[player_headers]

    df.to_csv('2016-17 Player Stats.csv')
Ejemplo n.º 4
0
def get_player_attributes(all_teams_list):

    player_ids = []

    for team_abbr in all_teams_list:

        current_team = TEAMS[team_abbr]
        players_json = team.TeamPlayers(team_id=current_team['id']).json
        player_data_list = players_json['resultSets'][1]
        for player_data in player_data_list['rowSet']:

            player_id = player_data[1]
            player_ids.append(player_id)

    player_summary_list = []

    for player_id in player_ids:

        player_summary_json = player.PlayerSummary(player_id).json
        player_info = player_summary_json['resultSets'][0]

        player_headers = player_info['headers']
        player_stats = player_info['rowSet'][0]

        player_summary_dict = dict(zip(player_headers, player_stats))
        player_summary_list.append(player_summary_dict)

        print("Gathered data for {}".format(player_stats[3]))

    df = pd.DataFrame(player_summary_list)

    df = df[player_headers]

    df.to_excel('2016-17 NBA Player Attributes.xlsx')
Ejemplo n.º 5
0
def get_team_best_rated_players(_team_id, _team_abbr, _nb_players, _injuries_report, _season, _season_type):

    player_ttfl_avg = []

    player_injury_status = []
    player_injury_type = []
    player_injury_date = []

    player_team_id = []
    player_team_abbr = []

    # ---

    # get players splits from team_id
    players = nba_team.TeamPlayers(_team_id, season=_season, season_type=_season_type).season_totals()

    # parse players df rows
    for index, row in players.iterrows():
        # add player ttfl score to list
        player_ttfl_avg.append(score.get_ttfl_score(players.iloc[[index]]))

        # add player injury status to list
        empty, info = injuries.check_player_injury(row['PLAYER_NAME'], _injuries_report)
        if not empty:
            player_injury_status.append('True')
            player_injury_type.append(info['Type'].values[0])
            player_injury_date.append(info['Date'].values[0])
        else:
            player_injury_status.append('False')
            player_injury_type.append('')
            player_injury_date.append('')

        # add player team id and abbr to list
        player_team_id.append(_team_id)
        player_team_abbr.append(_team_abbr)

    # add new series to players splits
    players['TTFL_SCORE'] = pandas.Series(player_ttfl_avg, index=players.index)
    players['INJ_STATUS'] = pandas.Series(player_injury_status, index=players.index)
    players['INJ_TYPE'] = pandas.Series(player_injury_type, index=players.index)
    players['INJ_DATE'] = pandas.Series(player_injury_date, index=players.index)
    players['TEAM_ID'] = pandas.Series(player_team_id, index=players.index)
    players['TEAM_ABBR'] = pandas.Series(player_team_abbr, index=players.index)

    # sort players splits per descending ttfl score
    players = players.sort_values('TTFL_SCORE', ascending=False)

    # fetch best N players from players splits
    players = players[0:_nb_players]

    # return data
    return players
Ejemplo n.º 6
0
 def testAll(self):
     assert team.TeamList()
     assert team.TeamSummary(self.teamId)
     team_details = team.TeamDetails(self.teamId)
     assert team_details
     # assert team_details.background()
     # assert team_details.history()
     assert team.TeamCommonRoster(self.teamId)
     assert team.TeamGeneralSplits(self.teamId)
     assert team.TeamOpponentSplits(self.teamId)
     assert team.TeamLastNGamesSplits(self.teamId)
     assert team.TeamInGameSplits(self.teamId)
     assert team.TeamClutchSplits(self.teamId)
     assert team.TeamShootingSplits(self.teamId)
     assert team.TeamPerformanceSplits(self.teamId)
     assert team.TeamLineups(self.teamId)
     assert team.TeamPlayers(self.teamId)
     assert team.TeamPlayerOnOffDetail(self.teamId)
     assert team.TeamPlayerOnOffSummary(self.teamId)
     assert team.TeamGameLogs(self.teamId)
     assert team.TeamShotTracking(self.teamId)
     assert team.TeamReboundTracking(self.teamId)
     assert team.TeamPassTracking(self.teamId)
     assert team.TeamVsPlayer(self.teamId, self.playerId)
Ejemplo n.º 7
0
def print_team_information(team_choice):
    # print(team_choice)
    try:
        team_id = team_ids[team_choice]
    except:
        print("Invalid team.")
        print()
        print()
        return
    # print(team_id)
    print('1. View Team Roster')
    print('2. View Team Coaches')
    print('3. View Championship History')
    print('4. View Hall of Fame History')
    print('5. View Retired Jerseys')
    print('6. View Season Totals for Team\'s Players')
    print('7. View Shooting Splits by Area')
    print('8. View Season Totals for 2017-18')
    print('9. Go back to main menu')

    team_info_choice = input("What information about " + team_choice + " would you like to view?\n")

    teamdetails = team.TeamDetails(team_id)

    if int(team_info_choice) == 1:
        teamcommonroster = team.TeamCommonRoster(team_id, season='2017-18')
        printer.pprint(teamcommonroster.roster())

    elif int(team_info_choice) == 2:
        teamcommonroster = team.TeamCommonRoster(team_id, season='2017-18')
        printer.pprint(teamcommonroster.coaches())

    elif int(team_info_choice) == 3:
        # teamdetails = team.TeamDetails(team_id)
        printer.pprint(teamdetails.awards_championships())

    elif int(team_info_choice) == 4:
        # teamdetails = team.TeamDetails(team_id)
        printer.pprint(teamdetails.hof())

    elif int(team_info_choice) == 5:
        # teamdetails == team.TeamDetails(team_id)
        printer.pprint(teamdetails.retired())

    elif int(team_info_choice) == 6:
        teamplayers = team.TeamPlayers(team_id, season='2017-18')
        printer.pprint(teamplayers.season_totals())
        # printer.pprint(teamdetails.social_sites())

    elif int(team_info_choice) == 7:
        shooting = team.TeamShootingSplits(team_id)
        printer.pprint(shooting.shot_areas())

    elif int(team_info_choice) == 8:
        sum = team.TeamSummary(team_id, season='2017-18')
        printer.pprint(sum.season_ranks())

    elif int(team_info_choice) == 9:
        return

    else:
        print("Invalid menu choice")