Example #1
0
def scrape_matchups():

    df = pd.read_pickle('./player_game_table.pkl')
    seasons = ["2017-2018", "2016-2017", "2015-2016"]
    #print(df.head(1))
    game_ids = df.loc[(df.player_id == "2544") & (df.season.isin(seasons))]
    player_ids = set([])
    count = 0
    for idx, row in game_ids.iterrows():
        if not count % 10:
            print(count, " out of ", game_ids.shape)
        count += 1

        all_games = df.loc[(df.game_id == row.game_id)
                           & (df.team_id != row.team_id)]
        #print(all_games)
        for idx, game_row in all_games.iterrows():
            player_ids.add(game_row.player_id)

    print(len(player_ids))
    print(player_ids)
    api_seasons = ["2017-18", "2016-17", "2015-16"]
    headers = [
        'player_id', 'min', 'fgm', 'fga', 'fg3m', 'fg3a', 'ftm', 'fta', 'oreb',
        'dreb', 'reb', 'ast', 'tov', 'stl', 'blk', 'pts', 'season',
        'player_vs_id', 'fp'
    ]
    not_input = {}
    for header in headers:
        not_input[header] = []

    count = 0
    for player_id in player_ids:
        count += 1
        if ~count % 10:
            print(count, " out of ", len(player_ids))
        for season in api_seasons:
            response = player.PlayerVsPlayer(2544, player_id,
                                             season=season).json
            for header in headers:
                if header.upper() in response['resultSets'][0]['headers']:
                    idx = response['resultSets'][0]['headers'].index(
                        header.upper())
                    not_input[header].append(
                        str(response['resultSets'][0]['rowSet'][0][idx]))

            #add FP
            not_input['season'].append(season)
            not_input['player_vs_id'].append(player_id)
            not_input['fp'].append('meme')

    #pp.pprint(response['resultSets'][0])
    df = pd.DataFrame(data=not_input)
    df.to_pickle('./player_vs_table.pkl')
Example #2
0
def find_on_off_rating():
    player_oo_dict = {}
    for player1 in player_ids:
        player_oo_dict[player1] = {}
        for player2 in player_ids:
            if player1 != player2:
                p = player.PlayerVsPlayer(player_ids[player1],
                                          player_ids[player2])
                try:
                    dataframe = p.on_off_court()
                    oo_rating = dataframe["PLUS_MINUS"][
                        1]  # dataframe["PLUS_MINUS"][0]
                    player_oo_dict[player1][player2] = oo_rating
                except:
                    print(player1, player2)

    return player_oo_dict
Example #3
0
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)
Example #4
0
    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)
Example #5
0
def print_player_information(first_name, last_name):
    print("What information about the player would you like to view?")
    print("1. Basic Info (Vitals)")
    print("2. View Season Averages")
    print("3. Compare to Another Player")
    print("9. Go back to main menu")
    choice = input("Pick a number from the list above.\n")

    # getting basic info
    if int(choice) == 1:
        first_name.strip()
        last_name.strip()
        id = player_functions.get_player_id(first_name, last_name) # the id of the player requested
        if id is None:
            print("The player was not found")
        else:
            # getting the basic player summary
            player_summary = player.PlayerSummary(id)
            vitals = player_summary.info()
            printer.pprint(vitals)
    # submenu for season averages
    elif int(choice) == 2:
        first_name.strip()
        last_name.strip()
        id = player_functions.get_player_id(first_name, last_name)  # the id of the player requested
        if id is None:
            print("The player was not found")
        else:
            print("1. View Headline Stats for this Season")
            print("2. View Regular Season Totals")
            print("3. View Career Regular Season Totals")
            print("4. View Post Season Totals")
            print("5. View Career Post Season Totals")
            print("6. View All Star Season Totals")
            print("7. View Career All Star Season Totals")
            print("8. View College Season Totals")
            print("9. View Career College Season Totals")
            player_career = player.PlayerCareer(id)
            choice = input("Pick a number from the list above.\n")
            num = int(choice)

            print()
            print()

            if num == 1:
                player_summary = player.PlayerSummary(id)
                printer.pprint(player_summary.headline_stats())
            elif num == 2:
                # view regular season totals
                printer.pprint(player_career.regular_season_totals())
            elif num == 3:
                printer.pprint(player_career.regular_season_career_totals())
            elif num == 4:
                printer.pprint(player_career.post_season_totals())
            elif num == 5:
                printer.pprint(player_career.post_season_career_totals())
            elif num == 6:
                printer.pprint(player_career.all_star_season_totals())
            elif num == 7:
                printer.pprint(player_career.career_all_star_season_totals())
            elif num == 8:
                printer.pprint(player_career.college_season_totals())
            elif num == 9:
                printer.pprint(player_career.college_season_career_totals())

            print()
            print()

    elif int(choice) == 3:
        vs_player_first_name = input("What is the first name of the player you'd like to compare against?\n")
        vs_player_last_name = input("What is their last name?\n")

        id = player_functions.get_player_id(first_name, last_name)
        vs_player_id = player_functions.get_player_id(vs_player_first_name, vs_player_last_name)  # the id of the player to be compared against
        printer.pprint(player.PlayerVsPlayer(id, vs_player_id, season='2017-18').overall())



    #tryna dip
    elif int(choice) == 9:
        return

    elif int(choice) == 100:
        printer.pprint(player.get_player(first_name, last_name, season='2017-18', just_id=False))
    else:
        print("Invalid menu choice")