Beispiel #1
0
    def update_game(self, response):
        """ Use the livefeed to update game attributes.
            Including: game state, period attributes, etc.
        """

        logging.info("Updating all Game object attributes.")
        linescore = response.get("liveData").get("linescore")
        boxscore = response.get("liveData").get("boxscore")

        # Update Game State & Period related attributes
        # Don't update the game state if its final since we might have manually set it this way.
        lf_game_state = response.get("gameData").get("status").get("abstractGameState")

        if (
            lf_game_state == GameState.FINAL.value
            and not models.gameevent.GameEndEvent.cache.entries
        ):
            logging.warning(
                "Game State is FINAL, but no GameEndEvent recorded - don't update thie game state yet."
            )
        elif self.game_state != GameState.FINAL.value:
            self.game_state = lf_game_state
        else:
            logging.warning(
                "Game State is FINAL - do not update in case we manually set this via GameEndEvent."
            )

        self.game_state_code = int(response.get("gameData").get("status").get("codedGameState"))
        self.period.current = linescore.get("currentPeriod")
        self.period.current_ordinal = linescore.get("currentPeriodOrdinal")
        self.period.time_remaining = linescore.get("currentPeriodTimeRemaining")
        self.period.time_remaining_ss = utils.from_mmss(self.period.time_remaining)
        self.penalty_situation.current_ss = self.period.time_remaining_ss

        # TODO: Handle penalties that roll over periods
        if self.penalty_situation.current_ss == 0:
            logging.info("End of Period - resetting Penalty Situation.")
            self.penalty_situation = PenaltySituation()

        intermission = linescore.get("intermissionInfo")
        self.period.intermission = intermission.get("inIntermission")
        self.period.intermission_remaining = intermission.get("intermissionTimeRemaining")

        linescore_home = linescore.get("teams").get("home")
        boxscore_home = boxscore.get("teams").get("home")
        self.home_team.score = linescore_home.get("goals")
        self.home_team.shots = linescore_home.get("shotsOnGoal")

        linescore_away = linescore.get("teams").get("away")
        boxscore_away = boxscore.get("teams").get("away")
        self.away_team.score = linescore_away.get("goals")
        self.away_team.shots = linescore_away.get("shotsOnGoal")
        self.power_play_strength = linescore.get("powerPlayStrength")
        self.home_team.power_play = linescore_home.get("powerPlay")
        self.home_team.skaters = linescore_home.get("numSkaters")
        self.home_team.onice = boxscore_home.get("onIce")
        self.away_team.power_play = linescore_away.get("powerPlay")
        self.away_team.skaters = linescore_away.get("numSkaters")
        self.away_team.onice = boxscore_away.get("onIce")
Beispiel #2
0
    def current_ss(self, ss):
        # Convert a MM:SS to pure seconds if passed into the setter
        if ss in ("END", 0):
            self._current_ss = 0
            return

        if isinstance(ss, str) and ":" in ss:
            ss = utils.from_mmss(ss)

        if self.penalty_end >= ss:
            self._current_ss = ss
            self.penalty_killed = True
        else:
            self._current_ss = ss
Beispiel #3
0
def minute_remaining_check(game: Game):
    """ A function to check if there is approximately a minute remaining in the period. """

    if game.period.time_remaining == "END":
        game.period.current_oneminute_sent = True
        return

    period_remain_ss = utils.from_mmss(game.period.time_remaining)
    if 50 <= period_remain_ss <= 65:
        msg = f"One minute remaining in the {game.period.current_ordinal} period."
        socialhandler.send(msg=msg, game_hashtag=True)
        game.period.current_oneminute_sent = True
    elif period_remain_ss < 50:
        # Force the property to true if the period is below 50s
        game.period.current_oneminute_sent = True