Exemplo n.º 1
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)
def get_splits(TEAMABR, ten=False, twenty=False, regseason=True):
    """returns the splits of a team over the past N days. Will consider changing this to a from - to thing for different dates. 
    
    Parameters
    ----------
    TEAMABR : str
    	Abbreviation of the desired team. Ex: Atlanta = ATL.  

    Returns 
    -------
    teamsplits : array	
    	Array of desired team's statistics over the previous N games. 

    """
    import numpy as np
    from nba_py import team
    teams = team.TeamList()
    teamids = teams.info()
    teamids = teamids[:-15]
    teamids = teamids[['TEAM_ID', 'ABBREVIATION']]

    teamids = teamids.rename(index=str, columns={"ABBREVIATION": "Team"})
    teamids = teamids.replace('BKN', 'BRK')
    teamids = teamids.sort_values('Team')

    TEAM_ID = teamids.loc[teamids['Team'] == TEAMABR].values[0, 0]
    teamids = pd.get_dummies(teamids)
    teamarray = teamids.loc[teamids['TEAM_ID'] == TEAM_ID].values[0, 1:]

    TEAM = team.TeamLastNGamesSplits(team_id=TEAM_ID, season='2017-18')
    if ten:
        df = TEAM.last10()
    if twenty:
        df = TEAM.last20()
    if regseason:
        TEAM = team.TeamGeneralSplits(team_id=TEAM_ID, season='2017-18')
        df = TEAM.overall()

# if five:
#df = TEAM

    df = df[[
        'OREB', 'DREB', 'REB', 'PF', 'STL', 'TOV', 'BLK', 'FG3_PCT', 'FG_PCT',
        'FT_PCT'
    ]].values

    teamsplits = np.concatenate((df[0], teamarray))
    return teamsplits
 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)
Exemplo n.º 4
0
def create_todays_data():
    """Creates a dataset identical to the one used for the ML modeling. This is done by scraping the ngames averages
    of the teams just listed, along with the spread, and cominbing. 
    
    Returns 
    -------
    
    today_matchups : arr
        In accordance with the designated format of how these team statistics will be shaped, I did that here. 
        For further explanation, please refer to the "relevant stats" and "splits_optimizer" repo's which explain why I 
        use certain values, this function simply puts them in that shape for the games I want to predict. 
    
    
    home_teams : arr
        Array of the home teams. Since I next have to obtain the spread of these games, I'll line them up based on the 
        name of the home team. 
    """
    today = datetime.now()
    day = today.day
    month = today.month
    year = today.year

    matchups = get_todays_games()

    #matchups
    import numpy as np
    from nba_py import team
    teams = team.TeamList()
    teamids = teams.info()
    #print('predicting matchups of ', teamids)
    #  print()
    teamids = teamids[:-15]
    # print(teamids)
    teamids = teamids[['TEAM_ID', 'ABBREVIATION']]
    teamids = teamids.rename(index=str, columns={"ABBREVIATION": "Team"})
    teamids = teamids.replace('BKN', 'BRK')
    teamids = teamids.sort_values('Team')
    # print(teamids)
    todays_matchups = []
    home_teams = []
    road_teams = []
    for matchup in matchups:
        home_teams.append(matchup[1])
        road_teams.append(matchup[0])
        game_array = []
        for team_ in matchup:
            TEAM_ID = teamids.loc[teamids['Team'] == team_].values[0, 0]
            #   print(team_,TEAM_ID)

            TEAM_splits = team.TeamLastNGamesSplits(team_id=TEAM_ID,
                                                    season='2018-19')
            # print(TEAM_splits.last20())
            df = TEAM_splits.last20()

            #retain (and create) the columns proven to be correlated to outcome.
            df['AST/TO'] = df['AST'] / df['TOV']

            df = df[[
                'FGM', 'FG3M', 'FTM', 'DREB', 'AST', 'STL', 'TOV', 'BLK',
                'PTS', 'AST/TO', 'FG3_PCT', 'FG_PCT', 'FT_PCT'
            ]]
            # df['AST/TO'] = df['AST']/df['TOV']
            game_array.append(df.values)

        matchup_array = np.concatenate((game_array[0], game_array[1]), axis=1)
        todays_matchups.append(matchup_array)

    #quick formating!
    todays_matchups = np.array(todays_matchups)
    todays_matchups = todays_matchups[:, 0, :]
    return todays_matchups, home_teams, road_teams