Ejemplo n.º 1
0
    def test_nba_boxscore_string_representation(self):
        expected = ('Boxscore for Houston Rockets at Utah Jazz '
                    '(9:00 PM, February 22, 2020)')

        boxscore = Boxscore(BOXSCORE)

        assert boxscore.__repr__() == expected
Ejemplo n.º 2
0
    def test_nba_boxscore_string_representation(self):
        expected = ('Boxscore for Detroit Pistons at Los Angeles Lakers '
                    '(10:30 PM, October 31, 2017)')

        boxscore = Boxscore(BOXSCORE)

        assert boxscore.__repr__() == expected
Ejemplo n.º 3
0
    def test_invalid_url_yields_empty_class(self):
        flexmock(Boxscore) \
            .should_receive('_retrieve_html_page') \
            .and_return(None)

        boxscore = Boxscore(BOXSCORE)

        for key, value in boxscore.__dict__.items():
            if key == '_uri':
                continue
            assert value is None
Ejemplo n.º 4
0
def get_day_stats(date, games_dict):
    df = pd.DataFrame()
    for i in range(len(games_dict[date])):
        stats = Boxscore(games_dict[date][i]['boxscore'])
        game_df = pd.DataFrame(games_dict[date][i], index=[0])
        away_team, home_team = game_data(game_df, stats)
        away_team['date'] = pd.to_datetime(away_team['date'],
                                           format='%I:%M %p, %B %d, %Y')
        home_team['date'] = pd.to_datetime(home_team['date'],
                                           format='%I:%M %p, %B %d, %Y')
        df = pd.concat([df, away_team])
        df = pd.concat([df, home_team])
    return df
Ejemplo n.º 5
0
    def test_game_summary_with_no_scores_returns_none(self):
        result = Boxscore(None)._parse_summary(
            pq("""<table id="line_score">
    <tbody>
        <tr>
            <td class="center"></td>
            <td class="center"></td>
        </tr>
        <tr>
            <td class="center"></td>
            <td class="center"></td>
        </tr>
    </tbody>
</table>"""))

        assert result == {'away': [None], 'home': [None]}
Ejemplo n.º 6
0
    def setup_method(self, *args, **kwargs):
        self.results = {
            'date': '10:30 PM, October 31, 2017',
            'location': 'STAPLES Center, Los Angeles, California',
            'winner': HOME,
            'winning_name': 'Los Angeles Lakers',
            'winning_abbr': 'LAL',
            'losing_name': 'Detroit Pistons',
            'losing_abbr': 'DET',
            'pace': 97.4,
            'away_wins': 5,
            'away_losses': 3,
            'away_minutes_played': 240,
            'away_field_goals': 41,
            'away_field_goal_attempts': 94,
            'away_field_goal_percentage': .436,
            'away_two_point_field_goals': 31,
            'away_two_point_field_goal_attempts': 61,
            'away_two_point_field_goal_percentage': .508,
            'away_three_point_field_goals': 10,
            'away_three_point_field_goal_attempts': 33,
            'away_three_point_field_goal_percentage': .303,
            'away_free_throws': 1,
            'away_free_throw_attempts': 3,
            'away_free_throw_percentage': .333,
            'away_offensive_rebounds': 10,
            'away_defensive_rebounds': 34,
            'away_total_rebounds': 44,
            'away_assists': 21,
            'away_steals': 7,
            'away_blocks': 3,
            'away_turnovers': 12,
            'away_personal_fouls': 11,
            'away_points': 93,
            'away_true_shooting_percentage': .488,
            'away_effective_field_goal_percentage': .489,
            'away_three_point_attempt_rate': .351,
            'away_free_throw_attempt_rate': .032,
            'away_offensive_rebound_percentage': 19.2,
            'away_defensive_rebound_percentage': 75.6,
            'away_total_rebound_percentage': 45.4,
            'away_assist_percentage': 51.2,
            'away_steal_percentage': 7.2,
            'away_block_percentage': 4.6,
            'away_turnover_percentage': 11.2,
            'away_offensive_rating': 95.5,
            'away_defensive_rating': 116.0,
            'home_wins': 3,
            'home_losses': 4,
            'home_minutes_played': 240,
            'home_field_goals': 45,
            'home_field_goal_attempts': 91,
            'home_field_goal_percentage': .495,
            'home_two_point_field_goals': 33,
            'home_two_point_field_goal_attempts': 65,
            'home_two_point_field_goal_percentage': .508,
            'home_three_point_field_goals': 12,
            'home_three_point_field_goal_attempts': 26,
            'home_three_point_field_goal_percentage': .462,
            'home_free_throws': 11,
            'home_free_throw_attempts': 14,
            'home_free_throw_percentage': .786,
            'home_offensive_rebounds': 11,
            'home_defensive_rebounds': 42,
            'home_total_rebounds': 53,
            'home_assists': 30,
            'home_steals': 9,
            'home_blocks': 5,
            'home_turnovers': 14,
            'home_personal_fouls': 14,
            'home_points': 113,
            'home_true_shooting_percentage': .582,
            'home_effective_field_goal_percentage': .560,
            'home_three_point_attempt_rate': .286,
            'home_free_throw_attempt_rate': .154,
            'home_offensive_rebound_percentage': 24.4,
            'home_defensive_rebound_percentage': 80.8,
            'home_total_rebound_percentage': 54.6,
            'home_assist_percentage': 66.7,
            'home_steal_percentage': 9.2,
            'home_block_percentage': 8.2,
            'home_turnover_percentage': 12.6,
            'home_offensive_rating': 116.0,
            'home_defensive_rating': 95.5
        }
        flexmock(utils) \
            .should_receive('_todays_date') \
            .and_return(MockDateTime(YEAR, MONTH))

        self.boxscore = Boxscore(BOXSCORE)
Ejemplo n.º 7
0
    def setup_method(self, *args, **kwargs):
        self.results = {
            'date': '9:00 PM, February 22, 2020',
            'location': 'Vivint Smart Home Arena, Salt Lake City, Utah',
            'winner': AWAY,
            'winning_name': 'Houston Rockets',
            'winning_abbr': 'HOU',
            'losing_name': 'Utah Jazz',
            'losing_abbr': 'UTA',
            'pace': 103.2,
            'away_wins': 36,
            'away_losses': 20,
            'away_minutes_played': 240,
            'away_field_goals': 45,
            'away_field_goal_attempts': 92,
            'away_field_goal_percentage': .489,
            'away_two_point_field_goals': 25,
            'away_two_point_field_goal_attempts': 44,
            'away_two_point_field_goal_percentage': .568,
            'away_three_point_field_goals': 20,
            'away_three_point_field_goal_attempts': 48,
            'away_three_point_field_goal_percentage': .417,
            'away_free_throws': 10,
            'away_free_throw_attempts': 14,
            'away_free_throw_percentage': .714,
            'away_offensive_rebounds': 6,
            'away_defensive_rebounds': 36,
            'away_total_rebounds': 42,
            'away_assists': 20,
            'away_steals': 9,
            'away_blocks': 5,
            'away_turnovers': 10,
            'away_personal_fouls': 25,
            'away_points': 120,
            'away_true_shooting_percentage': .611,
            'away_effective_field_goal_percentage': .598,
            'away_three_point_attempt_rate': .522,
            'away_free_throw_attempt_rate': .152,
            'away_offensive_rebound_percentage': 13.0,
            'away_defensive_rebound_percentage': 85.7,
            'away_total_rebound_percentage': 47.7,
            'away_assist_percentage': 44.4,
            'away_steal_percentage': 8.7,
            'away_block_percentage': 8.5,
            'away_turnover_percentage': 9.2,
            'away_offensive_rating': 116.3,
            'away_defensive_rating': 106.6,
            'home_wins': 0,
            'home_losses': 0,
            'home_minutes_played': 240,
            'home_field_goals': 42,
            'home_field_goal_attempts': 90,
            'home_field_goal_percentage': .467,
            'home_two_point_field_goals': 35,
            'home_two_point_field_goal_attempts': 59,
            'home_two_point_field_goal_percentage': .593,
            'home_three_point_field_goals': 7,
            'home_three_point_field_goal_attempts': 31,
            'home_three_point_field_goal_percentage': .226,
            'home_free_throws': 19,
            'home_free_throw_attempts': 24,
            'home_free_throw_percentage': .792,
            'home_offensive_rebounds': 6,
            'home_defensive_rebounds': 40,
            'home_total_rebounds': 46,
            'home_assists': 18,
            'home_steals': 1,
            'home_blocks': 2,
            'home_turnovers': 13,
            'home_personal_fouls': 14,
            'home_points': 110,
            'home_true_shooting_percentage': .547,
            'home_effective_field_goal_percentage': .506,
            'home_three_point_attempt_rate': .344,
            'home_free_throw_attempt_rate': .267,
            'home_offensive_rebound_percentage': 14.3,
            'home_defensive_rebound_percentage': 87.0,
            'home_total_rebound_percentage': 52.3,
            'home_assist_percentage': 42.9,
            'home_steal_percentage': 1.0,
            'home_block_percentage': 4.5,
            'home_turnover_percentage': 11.4,
            'home_offensive_rating': 106.6,
            'home_defensive_rating': 116.3
        }
        flexmock(utils) \
            .should_receive('_todays_date') \
            .and_return(MockDateTime(YEAR, MONTH))

        self.boxscore = Boxscore(BOXSCORE)
Ejemplo n.º 8
0
def main():

    file_path = os.getcwd()

    with open(file_path + '/nbaScraperModelData.csv', "r") as f:
        last_line = f.readlines()[-1].strip().split(",")
        last_recorded_date = last_line[-1]

    datetime_object = datetime.strptime(last_recorded_date,
                                        '%I:%M%p, %B %d, %Y')
    start_date = datetime_object + timedelta(days=1)
    start_date = date(2021, 10, 19)
    end_date = date.today()
    game_dates = Boxscores(start_date, end_date)
    for date_key in game_dates.games.keys():
        for game_key in game_dates.games[date_key]:
            game_df = Boxscore(game_key['boxscore'])
            game_Stats = {}
            # winning team (not always home) -- home team on top
            winningTeam = game_df.winner
            if winningTeam == 'Home':
                game_Stats['Home'] = game_df.winning_name
                game_Stats['winningScore'] = game_df.home_points
                game_Stats['losingScore'] = game_df.away_points

            else:
                game_Stats['Home'] = game_df.losing_name
                game_Stats['winningScore'] = game_df.away_points
                game_Stats['losingScore'] = game_df.home_points

            game_Stats['winningTeam'] = game_df.winning_name
            game_Stats['losingTeam'] = game_df.losing_name

            game_Stats['Pace_Home'] = game_df.pace
            game_Stats['Pace_AWAY'] = game_df.pace

            game_Stats[
                'FG_PpercentHome'] = game_df.home_effective_field_goal_percentage
            game_Stats[
                'FG_PpercentAWAY'] = game_df.away_effective_field_goal_percentage

            game_Stats['TOV_Home'] = game_df.home_turnovers
            game_Stats['TOV_AWAY'] = game_df.away_turnovers

            game_Stats['ORB_Home'] = game_df.home_offensive_rebounds
            game_Stats['ORB_AWAY'] = game_df.away_offensive_rebounds

            game_Stats['FT_Rate_Home'] = game_df.home_free_throw_attempt_rate
            game_Stats['FT_Rate_AWAY'] = game_df.away_free_throw_attempt_rate

            game_Stats['Off_Rat_Home'] = game_df.home_offensive_rating
            game_Stats['Off_Rat_AWAY'] = game_df.away_offensive_rating

            # get date
            game_Stats['date'] = game_df.date

            df = pd.DataFrame(game_Stats, index=[0])

            df.to_csv(file_path + '/nbaScrapermodelData.csv',
                      mode='a',
                      header=False)
Ejemplo n.º 9
0
    def setup_method(self, *args, **kwargs):
        flexmock(Boxscore) \
            .should_receive('_parse_game_data') \
            .and_return(None)

        self.boxscore = Boxscore(None)
Ejemplo n.º 10
0
    def test_invalid_url_returns_none(self):
        result = Boxscore(None)._retrieve_html_page('')

        assert result is None
Ejemplo n.º 11
0
 def boxscore(self):
     """
     Returns an instance of the Boxscore class containing more detailed
     stats on the game.
     """
     return Boxscore(self._boxscore)