Beispiel #1
0
def get_player_stats(player_id):
    p = nba.Player(player_id)
    stats = p.get_stats()
    regular_season = stats["regularSeason"]
    post_season = stats["postSeason"]
    return jsonify({
        "regularSeason": regular_season,
        "postSeason": post_season
    })
Beispiel #2
0
def get_player(player_id):  # 201935 --> James Harden
    p = nba.Player(player_id)
    common_info, available_seasons, headline_stats = p.get_common_info()
    awards = p.get_awards()
    return jsonify({
        "commonInfo": common_info,
        "availableSeasons": available_seasons,
        "headlineStats": headline_stats[0],
        "awards": awards
    })
Beispiel #3
0
def process_stats(choice):
    if choice == 1:
        #print conference stats here
        conf = input("Enter conference name: (East/West)")
        scrape_conference(conf)
    elif choice == 2:
        #print team stats here
        team = input("Enter team name: ")
        url = build_team_url(team)
        scrape_team(url, team)
    elif choice == 3:
        #print player stats here
        player = input("Enter player name: (first name) (last name)")
        first, last = player.split()
        url = build_player_url(first, last)
        list_of_stats = scrape_player(url, team)
        player = n.Player(list_of_stats)
        player.display()
    elif choice == 4:
        pass
Beispiel #4
0
def process_csv_creation(choice):
    if choice == 1:
        #create csv file for conference
        conf = input("Enter conference name: (East/West)")
        myConf = n.Conference(conf, s.scrape_conference(conf))
        myConf.create_conf_csv()
    elif choice == 2:
        #create csv file for team
        team = input("Enter team name: ")
        url = build_team_url(team)
        myTeam = n.Team(team, s.scrape_team(url))
        myTeam.create_team_csv()
    elif choice == 3:
        #create csv file for player
        player = input("Enter player name: (first name) (last name) and year (2016-17)")
        first,last,year = player.split()
        url = build_player_url(first, last)
        myPlayer = n.Player(first + last,s.scrape_player(url,year))
        myPlayer.create_player_csv()
    elif choice == 4:
        pass
Beispiel #5
0
def process_csv_creation(choice):
    if choice == 1:
        #create csv file for conference
        conf = input("Enter conference name: (East/West)")
        myConf = n.Conference(conf, scrape_conference(conf))
    elif choice == 2:
        #create csv file for team
        team = input("Enter team name: ")
        url = build_team_url(team)
        myTeam = n.Team(team, scrape_team(url, team))
        myTeam.create_team_csv(team)
    elif choice == 3:
        #create csv file for player
        player = input("Enter player's full name: ")
        team = input("Enter team name: ")
        url = build_team_url(team)
        url = build_player_url(player, team)
        myPlayer = n.Player(scrape_player(url, team))
        myPlayer.create_player_csv()
    elif choice == 4:
        pass
Beispiel #6
0
def process_stats(choice):
    if choice == 1:
        #print conference stats here
        conf = input("Enter conference name: (East/West)")
        new_conf = n.Conference(conf, s.scrape_conference(conf))
        new_conf.display()
    elif choice == 2:
        #print team stats here
        team = input("Enter team name: ")
        url = build_team_url(team)
        if url:
            new_team = n.Team(team,s.scrape_team(url))
            new_team.display()
    elif choice == 3:
        #print player stats here
        player = input("Enter player name: (first name) (last name) and year (2016-17)")
        first,last,year = player.split()
        url = build_player_url(first, last)
        list_of_stats = s.scrape_player(url,year)
        player = n.Player(first + last,list_of_stats)
        player.display()
    elif choice == 4:
        pass
Beispiel #7
0
def graphStats(n_clicks, children, stat_list, selection, permode):
    if n_clicks is None:
        raise PreventUpdate
    else:
        ids = []
        start_dates = []
        end_dates = []
        dic = ''
        if (selection == 'team'):
            i = 1
            dic = team_stats
            while i < len(children):
                if "value" in children[i]['props'].keys(
                ) and "value" in children[i + 2]['props'].keys(
                ) and "value" in children[i + 4]['props'].keys():
                    ids.append(nba.Team(children[i]['props']['value'],
                                        permode))
                    start_dates.append(children[i + 2]['props']['value'])
                    end_dates.append(children[i + 4]['props']['value'])

                i += 6

        else:
            i = 1
            dic = player_stats
            while i < len(children):
                if "value" in children[i]['props'].keys(
                ) and "value" in children[i + 2]['props'].keys(
                ) and "value" in children[i + 4]['props'].keys():
                    ids.append(
                        nba.Player(children[i]['props']['value'], permode))
                    start_dates.append(children[i + 2]['props']['value'])
                    end_dates.append(children[i + 4]['props']['value'])
                i += 6

        same_dates = True
        for i in range(len(start_dates)):
            if (len(start_dates) != len(end_dates)
                    or start_dates[i] != start_dates[i - 1]
                    or end_dates[i] != end_dates[i - 1]):
                same_dates = False
                break

        graphs = []
        for j in stat_list:
            traces = []
            for i in range(len(ids)):
                df = ids[i].get_stats(j, str(start_dates[i]),
                                      str(end_dates[i]))
                if same_dates == False:
                    traces.append(
                        dict(x=(str(df.index)),
                             y=df,
                             name=ids[i].name,
                             text=df.index))
                    typ = ''
                else:
                    traces.append(dict(x=df.index, y=df, name=ids[i].name))
                    typ = 'category'

            graphs.append(
                dcc.Graph(
                    figure={
                        'data':
                        traces,
                        'layout':
                        dict(xaxis={
                            'title': 'Range',
                            'type': typ
                        },
                             yaxis={'title': dic[j]},
                             title=dic[j],
                             showlegend=True)
                    }))

        return html.Div(graphs)
Beispiel #8
0
def get_player_game_log(player_id, season, season_type):
    p = nba.Player(player_id)
    games = p.get_game_log(season, season_type)
    return jsonify(games)