예제 #1
0
def get_team_shots(plays, game_id, periods=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]):
    """Gets the number of shots attempted by each team and their types
    returned as a list of lists"""
    # [[[away 2 atts, away 2s made],
    # [away 3 atts, away 3s made],
    # [total away atts, total away made]],
    # [[home 2 atts, home 2s made],
    # [home 3 atts, home 3s made],
    # [total home atts, total home made]]]

    teams = espn.get_teams("", game_id)
    away_two_atts, away_three_atts, away_shot_atts = 0, 0, 0
    home_two_atts, home_three_atts, home_shot_atts = 0, 0, 0

    away_twos_made, away_threes_made, away_shots_made = 0, 0, 0
    home_twos_made, home_threes_made, home_shots_made = 0, 0, 0

    for play in plays:
        if (
            ("miss" in play[7] or "make" in play[7])
            and "free throw" not in play[8]
            and play[4] in periods
        ):
            if play[8] == "two":
                if play[10] == teams[0]:
                    away_two_atts += 1
                    if play[7] == "make":
                        away_twos_made += 1
                if play[10] == teams[1]:
                    home_two_atts += 1
                    if play[7] == "make":
                        home_twos_made += 1
            if play[8] == "three":
                if play[10] == teams[0]:
                    away_three_atts += 1
                    if play[7] == "make":
                        away_threes_made += 1
                if play[10] == teams[1]:
                    home_three_atts += 1
                    if play[7] == "make":
                        home_threes_made += 1
    away_shot_atts = away_two_atts + away_three_atts
    home_shot_atts = home_two_atts + home_three_atts
    away_shots_made = away_twos_made + away_threes_made
    home_shots_made = home_twos_made + home_threes_made
    shot_list = [
        [
            [away_two_atts, away_twos_made],
            [away_three_atts, away_threes_made],
            [away_shot_atts, away_shots_made],
        ],
        [
            [home_two_atts, home_twos_made],
            [home_three_atts, home_threes_made],
            [home_shot_atts, home_shots_made],
        ],
    ]
    return shot_list
예제 #2
0
def get_team_fts(plays, game_id, periods=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]):
    """Gets the free throws taken and made by each team"""
    teams = espn.get_teams("", game_id)
    away_ft_atts, away_fts_made = 0, 0
    home_ft_atts, home_fts_made = 0, 0

    for play in plays:
        if (
            ("miss" in play[7] or "make" in play[7])
            and "free throw" in play[8]
            and play[4] in periods
        ):
            if play[10] == teams[0]:
                away_ft_atts += 1
                if play[7] == "make":
                    away_fts_made += 1
            if play[10] == teams[1]:
                home_ft_atts += 1
                if play[7] == "make":
                    home_fts_made += 1
    ft_shot_list = [[away_ft_atts, away_fts_made], [home_ft_atts, home_fts_made]]
    return ft_shot_list
예제 #3
0
import espn_scraper as espn
import json
''' Pretty print json helper '''


def ppjson(data):
    print(json.dumps(data, indent=2, sort_keys=True))


leagues = espn.get_leagues()
print(leagues)
for league in leagues:
    teams = espn.get_teams(league)
    print(league, len(teams))

# print nfl 2016 postseason scores
scoreboard_urls = espn.get_all_scoreboard_urls("nfl", 2017)
for scoreboard_url in scoreboard_urls:
    data = espn.get_url(scoreboard_url, cached_path="cached_json")
    for event in data['content']['sbData']['events']:
        if event['season']['type'] == 3:
            print(
                event['season']['type'], event['season']['year'],
                event['competitions'][0]['competitors'][0]['team']
                ['abbreviation'],
                event['competitions'][0]['competitors'][0]['score'],
                event['competitions'][0]['competitors'][1]['team']
                ['abbreviation'],
                event['competitions'][0]['competitors'][1]['score'])

url = espn.get_game_url("boxscore", "nba", 400900498)
예제 #4
0
 def test_get_num_nhl_teams(self):
     self.assertEqual(len(espn.get_teams("nhl")), 31)
예제 #5
0
 def test_get_num_wnba_teams(self):
     self.assertEqual(len(espn.get_teams("wnba")), 12)
예제 #6
0
 def test_get_num_ncw_teams(self):
     assert(len(espn.get_teams("ncw")) > 300)
예제 #7
0
 def test_get_num_ncb_teams(self):
     self.assertEqual(len(espn.get_teams("ncb")), 353)
예제 #8
0
 def test_get_num_ncf_teams(self):
     self.assertEqual(len(espn.get_teams("ncf")), 256)
예제 #9
0
 def test_get_num_mlb_teams(self):
     self.assertEqual(len(espn.get_teams("mlb")), 30)
예제 #10
0
import espn_team_stats as espn_team
import pygal
import plotly.express as px
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html


game_id = "401301254"
plays = espn.play_by_play_builder(game_id)
shot_type_list = espn_team.get_team_shots(plays, game_id)
ft_list = espn_team.get_team_fts(plays, game_id)
team_fg_pcts = espn_team.get_team_fg_pcts(plays, game_id)
team_ft_pcts = espn_team.get_team_ft_pcts(plays, game_id)
teams = espn.get_teams("", game_id)
print(teams)

# print(team_ft_pcts)
# print(team_fg_pcts)

away_shot_pcts = team_fg_pcts[0]
away_shot_pcts.append(team_ft_pcts[0])
home_shot_pcts = team_fg_pcts[1]
home_shot_pcts.append(team_ft_pcts[1])

x_labels = ["3 pt Percentage", "2 pt Percentage", "Fg Percentage", "FT Percentage"]
team_shot_pcts_chart = pygal.Radar()
team_shot_pcts_chart.title = "Shooting Percentages by Team"
team_shot_pcts_chart.x_labels = x_labels
team_shot_pcts_chart.add(teams[0], away_shot_pcts)