예제 #1
0
    def __init__(self, team_nickname, n_games):
        if team_nickname is None and n_games is None:
            return

        self.team_nickname = team_nickname
        self.team_dict = find_teams_by_nickname(self.team_nickname)
        self.n_games = n_games
        self.team_id = 0
        self.gl = None
        self.game_ids = list()
        self.box_scores = list()
        self.n_games_found = False
        self.analyze_found = False
        self.totals = list()
        self.wins = 0
        self.losses = 0
        self.teams_beaten = list()
        self.teams_lost = list()
        self.team_found = False
        self.n_ids = list()
        self.roster = None

        self.keys = ["FGM", "FGA", "FG_PCT",
                     "FG3M", "FG3A", "FG3_PCT",
                     "FTM", "FTA", "FT_PCT",
                     "REB", "AST", "STL",
                     "BLK", "TO", "PTS"]  # Keys are used for BoxScoreTraditionalV2

        self.home_team_w = {key: 0 for key in self.keys}
        self.home_team_l = {key: 0 for key in self.keys}
        self.away_team_w = {key: 0 for key in self.keys}
        self.away_team_l = {key: 0 for key in self.keys}
        self.diff = {key: 0 for key in self.keys}

        if not len(self.team_dict):
            raise Exception
        else:
            self.team_id = self.team_dict[0]['id']
            self.team_nickname = self.team_dict[0]['nickname']
            self.gl = TeamGameLog(self.team_id).get_normalized_dict()['TeamGameLog']
            self.gl = self.gl[0:int(self.n_games)]

            for l in self.gl:
                tmp = l['Game_ID'], l['MATCHUP'], l['WL']
                self.game_ids.append(tmp)

            for game in self.game_ids:
                self.box_scores.append(BoxScoreTraditionalV2(game).get_normalized_dict()['TeamStats'])
                if self.box_scores[len(self.box_scores) -1][0]['TEAM_NAME'] != self.team_nickname:
                    self.box_scores[0].append(self.box_scores[len(self.box_scores) - 1][0])
                    del self.box_scores[0][0]

            self.initialize_data()
            self.team_found = True
예제 #2
0
def get_todays_high_player_stats(sixers_scores):

    # Each player in the box score is iterated over and checked to see if they had the highest
    # of any stat for that day.
    
    high_default = [0, "No Games", 0, 0, 0, 0, 0, "Nobody", "H", "0000", "https://www.basketball-reference.com"]
    points_high = high_default
    assists_high = high_default
    rebounds_high = high_default
    steals_high = high_default
    blocks_high = high_default
 
    
    for game_list in sixers_scores:
      
        box_score = game_list[0]
    
        for player in box_score['data']:
            #if they're not a sixers player, continue
            if player[1] != sixers_id:
                continue
            else:
                #build a list of all important data about the player
                #game_id, player name, points, assists, rebounds, steals, blocks, opponent, home/away, year
                player_info = [player[0], player[5], player[26],player[21],player[20],player[22],player[23], teams.find_team_name_by_id(game_list[1])['nickname'], game_list[2], game_list[3]]
                #append basketball reference URL
                if player_info[8] == "H":
                    player_info.append("https://www.basketball-reference.com/boxscores/" + player_info[9] + "0" + str(month) + url_day_format(day) + "0" + "PHI.html")
                else:
                    player_info.append("https://www.basketball-reference.com/boxscores/" + player_info[9] + "0" + str(month) + url_day_format(day) + "0" + (teams.find_teams_by_nickname(player_info[7])[0]["abbreviation"]) +".html")
                    
                #check if player has highest points. If None type replace with 0
                if player_info[2] != None:
                    if player_info[2] > points_high[2]: 
                        points_high = player_info
                    #check for ties
                    elif player_info[2] == points_high[2]:
                        points_high.append(player_info)
                else:
                    player_info[2] = 0;
            
                #check for highest assists
                if player_info[3] != None:
                    if player_info[3] > assists_high[3]: 
                        assists_high = player_info
                    elif player_info[3] == assists_high[3]: 
                        assists_high.append(player_info)
                else:
                    player_info[3] = 0;
     
                #check for highest rebounds
                if player_info[4] != None:
                    if player_info[4] > rebounds_high[4]:
                        rebounds_high = player_info
                    elif player_info[4] == rebounds_high[4]: 
                        rebounds_high.append(player_info)
                else:
                    player_info[4] = 0;
        
                #check for highest steals
                if player_info[5] != None:
                    if player_info[5] > steals_high[5]:
                        steals_high = player_info
                    elif player_info[5] == steals_high[5]:
                        steals_high.append(player_info)
                else:
                    player_info[5] = 0;
            
                #check for highest blocks
                if player_info[6] != None:
                    if player_info[6] > blocks_high[6]:
                        blocks_high = player_info
                    elif player_info[6] == blocks_high[6]:
                        blocks_high.append(player_info)
                else:
                    player_info[6] = 0;
    #  f.close()
    write_javascript_file(date, points_high, assists_high, rebounds_high, steals_high, blocks_high)
    print("Points High:", points_high)
    print("Assists High:", assists_high)
    print("Rebounds High:", rebounds_high)
    print("Steals High:", steals_high)
    print("Blocks High:", blocks_high)
예제 #3
0
import numpy as np
import pandas as pd
from matplotlib import pyplot
import json
# import nba_api
from nba_api.stats.endpoints import shotchartdetail
from nba_api.stats.static import teams, players

l = players.find_players_by_first_name("LeBron")
print(l)
z = teams.find_teams_by_nickname("LAL")
print(z)


res = shotchartdetail.ShotChartDetail(0, 2544)
content = json.loads(res.get_json())

results = content['resultSets'][0]
headers = results['headers']
rows = results['rowSet']
df = pd.DataFrame(rows)
df.columns = headers

df.to_csv("f.csv", index=False)



custom_headers = {
    'Host': 'stats.nba.com',
    'Connection': 'keep-alive',
    'Cache-Control': 'max-age=0',
예제 #4
0
def teamID(teamName):
    # find team ID by team name
    teamDict = teams.find_teams_by_full_name(teamName)
    if len(teamDict) == 0:
        teamDict = teams.find_teams_by_nickname(teamName)
    return teamDict[0]['id']