예제 #1
0
 def test_get_roster_stats(self):
     df = get_roster_stats('GSW', 2019)
     expected_columns = [
         'PLAYER', 'POS', 'AGE', 'TEAM', 'G', 'GS', 'MP', 'FG', 'FGA',
         'FG%', '3P', '3PA', '3P%', '2P', '2PA', '2P%', 'eFG%', 'FT', 'FTA',
         'FT%', 'ORB', 'DRB', 'TRB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
         'PTS', 'SEASON'
     ]
     self.assertCountEqual(list(df.columns), expected_columns)
예제 #2
0
def roster_stats(team, year, data_format, playoffs):

    print("Saving into excel sheet... ")
    writer = ExcelWriter("./Excel-Sheets/%s-%d_Roster_Stats_%s.xlsx" % (team, year, data_format))
    roster_stats_df = get_roster_stats(team, year, data_format, playoffs)

    roster_stats_df.to_excel(writer, sheet_name=team, startrow=0, startcol=0, index=False, header=True)

    writer.save()
예제 #3
0
 def test_get_roster_stats(self):
     df = get_roster_stats('GSW',
                           2019,
                           data_format='ADVANCED',
                           playoffs=True)
     expected_columns = [
         'Name', 'Age', 'G', 'MP', 'PER', 'TS%', '3PAr', 'FTr', 'ORB%',
         'DRB%', 'TRB%', 'AST%', 'STL%', 'BLK%', 'TOV%', 'USG%', 'OWS',
         'DWS', 'WS', 'WS/48', 'OBPM', 'DBPM', 'BPM', 'VORP'
     ]
     self.assertListEqual(list(df.columns), expected_columns)
예제 #4
0
def user_input():
    team_or_player = input("What stats would you like to see: (1)Team or (2)Player ")

    if team_or_player == '1':
        user_team = input("What team would you like to view? ")
        user_season = int(input("Enter the desired season: "))

        user_stats = input("Enter the number for what stat you would like to see: \n1.) Roster List\n"
                           "2.) Team Stats\n"
                           "3.) Team Opponent Stats\n"
                           "4.) Roster Stats\n"
                           "5.) Misc Stats\n")

        print_or_excel = input("Would you like to save information in an excel sheet (Y/N)? ").upper()

        if user_stats == '1':

            if print_or_excel == 'Y':
                roster_list(user_team, user_season)
                print("Saved")

            elif print_or_excel == 'N':
                print(get_roster(user_team, user_season))

        elif user_stats == '2':
            data_format = input("Enter data format: (TOTAL | PER_GAME): ").upper()

            if print_or_excel == 'Y':
                team_stats(user_team, user_season, data_format)
                print(get_team_stats(user_team, user_season, data_format))

            elif print_or_excel == 'N':
                print(get_team_stats(user_team, user_season, data_format))

        elif user_stats == '3':
            data_format = input("Enter data format: (TOTAL | PER_GAME: ").upper()

            if print_or_excel == 'Y':
                team_opp_stats(user_team, user_season, data_format)
                print(get_opp_stats(user_team, user_season, data_format))

            elif print_or_excel == 'N' or 'n':
                print(get_opp_stats(user_team, user_season, data_format))

        elif user_stats == '4':
            user_playoffs = input("Would you like playoff roster stats? (Y/N) ")
            data_format = input("Enter data format: (TOTAL | PER_GAME): ").upper()
            playoffs = False

            if user_playoffs == 'Y':
                playoffs = True
            if print_or_excel == 'Y':
                roster_stats(user_team, user_season, data_format, playoffs)
                print(get_roster_stats(user_team, user_season, data_format, playoffs))
            elif print_or_excel == 'N':
                print(get_roster_stats(user_team, user_season, data_format, playoffs))

        elif user_stats == '5':
            if print_or_excel == 'Y':
                team_misc(user_team, user_season)
                print(get_team_misc(user_team, user_season))
            elif print_or_excel == 'N':
                print(get_team_misc(user_team, user_season))

    elif team_or_player == '2':
        user_player = input('What player do you like to view? ')
        print_or_excel = input("Save into excel sheet? (Y/N): ").upper()

        user_stats = input("Enter the number for what stat you would like to see: \n"
                           "1.) Player Stats\n"
                           "2.) Game Logs\n")
        user_playoffs = input("Playoff Stats? (Y/N): ").upper()

        if user_stats == '1':
            stat_type = input("Enter stat type: (PER_GAME | PER_MINUTE | PER_POSS | ADVANCED): ").upper()
            user_career = input("Career Stats? (Y/N): ").upper()

            if user_playoffs == 'Y':
                playoffs = True
            else:
                playoffs = False

            if user_career == 'Y':
                career = True
            else:
                career = False

            if print_or_excel == "Y":
                player_stats(user_player, stat_type, playoffs, career)
                print(get_stats(user_player, stat_type, playoffs, career))
            elif print_or_excel == "N":
                print(get_stats(user_player, stat_type, playoffs, career))

        elif user_stats == '2':
            user_start_date = input("Enter start date: (YYYY-MM-DD): ").upper()
            user_end_date = input("Enter end date: (YYYY-MM-DD): ")
            if user_playoffs == 'Y':
                playoffs = True
            else:
                playoffs = False

            if print_or_excel == "Y":
                player_game_logs(user_player, user_start_date, user_end_date, playoffs)
                print(get_game_logs(user_player, user_start_date, user_end_date, playoffs))
            elif print_or_excel == "N":
                print(get_game_logs(user_player, user_start_date, user_end_date, playoffs))
예제 #5
0
"""
Created on Sat Sep 19 18:46:31 2020


@author: B Hoover
"""

from basketball_reference_scraper.teams import get_roster, get_team_stats, get_opp_stats, get_roster_stats, get_team_misc

from basketball_reference_scraper.players import get_stats, get_game_logs, get_player_headshot

from basketball_reference_scraper.shot_charts import get_shot_chart

import os
#Get team roster stats
bulls_2020 = get_roster_stats('CHI', 2020)

#Select individual player
bulls_2020[bulls_2020.PLAYER == "Coby White"]
''' Get individual players 

name - Player full name (e.g. 'LaMarcus Aldridge')
stat_type - One of 'PER_GAME', 'PER_MINUTE', 'PER_POSS', 'ADVANCED'
playoffs - Whether to return Playoff stats or not. One of True|False. Default value is False
career - Whether to return career stats or not. One of True|False. Default value is False

'''

coby = get_stats("Coby White",
                 stat_type='ADVANCED',
                 playoffs=False,
예제 #6
0
from basketball_reference_scraper.teams import get_roster, get_team_stats, get_opp_stats, get_roster_stats, get_team_misc

df = get_roster('GSW', 2019)
print(df)

s = get_team_stats('GSW', 2019, data_format='PER_GAME')
print(s)

s = get_opp_stats('GSW', 2019, data_format='PER_GAME')
print(s)

s = get_roster_stats('GSW', 2019, data_format='PER_GAME', playoffs=False)
print(s)

s = get_team_misc('GSW', 2019)
print(s)

from basketball_reference_scraper.players import get_stats, get_game_logs

s = get_stats('Stephen Curry',
              stat_type='PER_GAME',
              playoffs=False,
              career=False)
print(s)

df = get_game_logs('LeBron James', '2010-01-19', '2014-01-20', playoffs=False)
print(df)

from basketball_reference_scraper.seasons import get_schedule, get_standings

s = get_schedule(2018, playoffs=False)
예제 #7
0
def get_info(team, year):
  try: 
    return get_roster_stats(team, year)
  except:
    return None
예제 #8
0
playoffs2020 = [
    'BOS', 'BRK', 'DAL', 'DEN', 'HOU', 'IND', 'LAC', 'LAL', 'MIA', 'MIL',
    'OKC', 'ORL', 'PHI', 'POR', 'TOR', 'UTA'
]
years = [2020, 2019]

# Loop for pulling roster data
output = []

#for year in years:
for team in playoffs2020:
    # For Reg Season
    #df1 = get_roster(team, 2021)

    # For Playoffs
    df1 = get_roster_stats(team, 2020, data_format='PER_GAME', playoffs=False)
    #df1 = df1[['PLAYER','TEAM']]

    #Team Misc
    #df1 = get_team_misc(team,2019)
    #df1 = df1.to_frame().T
    output.append(df1)
    print(team)
#print(year)
results = pd.concat(output, ignore_index=True)
#results.drop_duplicates(subset=['PLAYER'],keep='last',inplace=True)
#results['TS%'] = round(results['PTS']/(2*(results['FGA']+0.44*results['FTA'])),3)
results.to_csv('2020 Regular Season Avgs (Playoff Teams).csv')

#Print Testing
# data_format = 'TOTALS'|'PER_GAME'|'PER_MINUTE'|'PER_POSS'|'ADVANCED'