Пример #1
0
    def __init__(self, overview, data):
        time_format = data.config.time_format
        linescore = overview.linescore
        away = linescore.teams.away
        home = linescore.teams.home
        away_abbrev = data.teams_info[away.team.id].abbreviation
        home_abbrev = data.teams_info[home.team.id].abbreviation
        self.away_team = Team(away.team.id, away_abbrev, away.team.name,
                              away.goals, away.shotsOnGoal, away.powerPlay,
                              away.numSkaters, away.goaliePulled)
        self.home_team = Team(home.team.id, home_abbrev, home.team.name,
                              home.goals, home.shotsOnGoal, home.powerPlay,
                              home.numSkaters, home.goaliePulled)

        self.date = convert_time(overview.game_date).strftime("%Y-%m-%d")
        self.start_time = convert_time(
            overview.game_date).strftime(time_format)
        self.status = overview.status
        self.periods = Periods(overview)
        self.intermission = linescore.intermissionInfo.inIntermission

        if data.status.is_final(overview.status):
            self.winning_team = overview.w_team
            self.loosing_team = overview.l_team
Пример #2
0
    def __init__(self, overview, data):
        time_format = data.config.time_format
        linescore = overview.linescore

        away = linescore.teams.away
        away_abbrev = data.teams_info[away.team.id].abbreviation
        self.away_roster = data.teams_info[away.team.id].roster

        home = linescore.teams.home
        home_abbrev = data.teams_info[home.team.id].abbreviation
        self.home_roster = data.teams_info[home.team.id].roster

        away_goal_plays = []
        home_goal_plays = []

        away_penalties = []
        home_penalties = []

        if hasattr(overview, "plays"):
            plays = overview.plays
            away_scoring_plays, away_penalty_play, home_scoring_plays, home_penalty_play = filter_plays(
                plays, away.team.id, home.team.id)

            # Get the Away Goal details
            # If the request to the API fails or is missing who scorer and the assists are, return an empty list of goal plays
            # This method is there to prevent the goal board to display the wrong info
            for play in away_scoring_plays:
                try:
                    players = get_goal_players(play['players'],
                                               self.away_roster,
                                               self.home_roster)
                    away_goal_plays.append(Goal(play, players))
                except KeyError:
                    debug.error(
                        "Failed to get Goal details for current live game. will retry on data refresh"
                    )
                    away_goal_plays = []
                    break
            # Get the Home Goal details
            # If the request to the API fails or is missing who scorer and the assists are, return an empty list of goal plays
            # This method is there to prevent the goal board to display the wrong info
            for play in home_scoring_plays:
                try:
                    players = get_goal_players(play['players'],
                                               self.home_roster,
                                               self.away_roster)
                    home_goal_plays.append(Goal(play, players))
                except KeyError:
                    debug.error(
                        "Failed to get Goal details for current live game. will retry on data refresh"
                    )
                    home_goal_plays = []
                    break

            for play in away_penalty_play:
                try:
                    player = get_penalty_players(play['players'],
                                                 self.away_roster)
                    away_penalties.append(Penalty(play, player))
                except KeyError:
                    debug.error(
                        "Failed to get Goal details for current live game. will retry on data refresh"
                    )
                    away_penalties = []
                    break

            for play in home_penalty_play:
                try:
                    player = get_penalty_players(play['players'],
                                                 self.home_roster)
                    home_penalties.append(Penalty(play, player))
                except KeyError:
                    debug.error(
                        "Failed to get Goal details for current live game. will retry on data refresh"
                    )
                    home_penalties = []
                    break

        self.away_team = TeamScore(away.team.id, away_abbrev, away.team.name,
                                   away.goals, away.shotsOnGoal,
                                   away_penalties, away.powerPlay,
                                   away.numSkaters, away.goaliePulled,
                                   away_goal_plays)
        self.home_team = TeamScore(home.team.id, home_abbrev, home.team.name,
                                   home.goals, home.shotsOnGoal,
                                   home_penalties, home.powerPlay,
                                   home.numSkaters, home.goaliePulled,
                                   home_goal_plays)

        self.date = convert_time(overview.game_date).strftime("%Y-%m-%d")
        self.start_time = convert_time(
            overview.game_date).strftime(time_format)
        self.status = overview.status
        self.periods = Periods(overview)
        self.intermission = linescore.intermissionInfo.inIntermission
        if data.status.is_final(overview.status) and hasattr(
                overview, "w_score") and hasattr(overview, "l_score"):
            self.winning_team = overview.w_team
            self.winning_score = overview.w_score
            self.loosing_team = overview.l_team
            self.loosing_score = overview.l_score