def test_teams_string_representation(self, *args, **kwargs):
        expected = """Washington Capitals (WSH)
Pittsburgh Penguins (PIT)
Chicago Blackhawks (CHI)
Columbus Blue Jackets (CBJ)
Minnesota Wild (MIN)
Anaheim Ducks (ANA)
Montreal Canadiens (MTL)
Edmonton Oilers (EDM)
New York Rangers (NYR)
St. Louis Blues (STL)
San Jose Sharks (SJS)
Ottawa Senators (OTT)
Toronto Maple Leafs (TOR)
Boston Bruins (BOS)
Tampa Bay Lightning (TBL)
New York Islanders (NYI)
Nashville Predators (NSH)
Calgary Flames (CGY)
Philadelphia Flyers (PHI)
Winnipeg Jets (WPG)
Carolina Hurricanes (CAR)
Los Angeles Kings (LAK)
Florida Panthers (FLA)
Dallas Stars (DAL)
Detroit Red Wings (DET)
Buffalo Sabres (BUF)
Arizona Coyotes (ARI)
New Jersey Devils (NJD)
Vancouver Canucks (VAN)
Colorado Avalanche (COL)"""

        teams = Teams()

        assert teams.__repr__() == expected
예제 #2
0
    def test_invalid_default_year_reverts_to_previous_year(
            self, *args, **kwargs):
        flexmock(utils) \
            .should_receive('_find_year_for_season') \
            .and_return(2018)

        teams = Teams()

        for team in teams:
            assert team._year == '2017'
예제 #3
0
    def test_nhl_empty_page_returns_no_teams(self):
        flexmock(utils) \
            .should_receive('_no_data_found') \
            .once()
        flexmock(utils) \
            .should_receive('_get_stats_table') \
            .and_return(None)

        teams = Teams()

        assert len(teams) == 0
예제 #4
0
    def create_league(self, year: int):
        """
        Generates NHL teams using web scraper and stores them in a dictionary

        :param year: Year of the season to be analyzed
        """
        # Getting information for each team from sportsreference library
        teams = Teams(year)

        # Putting Hockey_Team objects for each team in our dictionary
        for team in teams:
            self._teams[team.name.upper()] = HockeyTeam(team)
예제 #5
0
    def setup_method(self, *args, **kwargs):
        self.results = {
            'rank': 25,
            'abbreviation': 'DET',
            'name': 'Detroit Red Wings',
            'average_age': 28.4,
            'games_played': 82,
            'wins': 33,
            'losses': 36,
            'overtime_losses': 13,
            'points': 79,
            'points_percentage': .482,
            'goals_for': 207,
            'goals_against': 244,
            'simple_rating_system': -0.41,
            'strength_of_schedule': 0.04,
            'total_goals_per_game': 5.50,
            'power_play_goals': 38,
            'power_play_opportunities': 252,
            'power_play_percentage': 15.08,
            'power_play_goals_against': 45,
            'power_play_opportunities_against': 235,
            'penalty_killing_percentage': 80.85,
            'short_handed_goals': 3,
            'short_handed_goals_against': 9,
            'shots_on_goal': 2335,
            'shooting_percentage': 8.5,
            'shots_against': 2507,
            'save_percentage': .903,
            'pdo_at_even_strength': 99.6
        }
        self.abbreviations = [
            'WSH', 'PIT', 'CHI', 'CBJ', 'MIN', 'ANA', 'MTL', 'EDM', 'NYR',
            'STL', 'SJS', 'OTT', 'TOR', 'BOS', 'TBL', 'NYI', 'NSH', 'CGY',
            'PHI', 'WPG', 'CAR', 'LAK', 'FLA', 'DAL', 'DET', 'BUF', 'ARI',
            'NJD', 'VAN', 'COL'
        ]
        html_contents = read_file('NHL_%s.html' % YEAR)

        flexmock(utils) \
            .should_receive('_todays_date') \
            .and_return(MockDateTime(YEAR, MONTH))

        self.teams = Teams()
        print(" Points Percentage: {:.1%}".format(
            self.team.points_percentage()))
        # League standing
        print(" League Standing: {}/31\n".format(self.team.league_standing()))

        print("Key Takeaways:")

        # If key_takeaways is empty their stats are average
        if len(self.takeaways) == 0:
            print(" (+/-) Pretty average team all around the board")
            # Output takeaways found earlier
        else:
            # Outputting contents of key_takeaways
            for point in self.takeaways:
                print(point)


if __name__ == '__main__':
    teams = Teams(2020)

    teams_dictionary = {}

    for team in teams:
        teams_dictionary[team.name.upper()] = HockeyTeam(team)

    nhl_team = teams_dictionary["PITTSBURGH PENGUINS"]

    report = GeneralTeamReport(nhl_team)

    report.display_report()
예제 #7
0
from sportsreference.nhl.teams import Teams

print("Team  |    Wins   |    Losses   |   Points")
for team in Teams():
    print(team.name, team.wins, team.losses, team.points)
예제 #8
0
from sportsreference.nhl.teams import Teams

year_start = 1999  #starting year, don't include 2005
year_end = 2019
sport = 'NHL'

while year_start <= year_end:  #ending year, doesn't include 2005
    if year_start == 2005:
        year_start += 1
    teams = Teams(year_start)
    for team in teams:
        losses = team.losses
        otl = team.overtime_losses
        if type(otl) == type(losses):
            combined_losses = losses + otl
        else:
            combined_losses = losses

        zscore = (team.wins - (0.5 * (team.wins + combined_losses))) / (
            (team.wins + combined_losses) * 0.5 * 0.5)**(0.5)
        zscoreabs = abs(zscore)
        print(
            f'{sport},{team.name},{team.wins},{combined_losses},{year_start},{zscore},{zscoreabs}'
        )
    year_start += 1