def test_get_team_scores(self):
     DBSetup().g62_status_empty()
     lastGame = Gameinfo.objects.last()
     Gameresult.objects.filter(gameinfo=lastGame, isHome=True).update(fh=3,
                                                                      sh=2)
     gameresult_wrapper = GameresultWrapper(lastGame)
     assert gameresult_wrapper.get_home_score() == 5
     assert gameresult_wrapper.get_away_score() == 0
 def test_saves_score(self):
     DBSetup().g62_status_empty()
     firstGame = Gameinfo.objects.first()
     gameresult_wrapper = GameresultWrapper(firstGame)
     gameresult_wrapper.save_home_first_half(12, 9)
     gameresult_wrapper.save_away_first_half(9, 12)
     gameresult_wrapper.save_home_second_half(8, 16)
     gameresult_wrapper.save_away_second_half(16, 8)
     first_home = Gameresult.objects.get(gameinfo=firstGame, isHome=True)
     first_away = Gameresult.objects.get(gameinfo=firstGame, isHome=False)
     assert first_home.fh == 12
     assert first_home.sh == 8
     assert first_home.pa == 25
     assert first_away.fh == 9
     assert first_away.sh == 16
     assert first_away.pa == 20
Exemplo n.º 3
0
 def __init__(self, game_id):
     self.game_id = game_id
     self.gameinfo: GameinfoWrapper = GameinfoWrapper(game_id)
     self.gameresult: GameresultWrapper = GameresultWrapper(self.gameinfo.gameinfo)
 def test_get_team_fullnames(self):
     DBSetup().g62_status_empty()
     lastGame = Gameinfo.objects.last()
     gameresult_wrapper = GameresultWrapper(lastGame)
     assert gameresult_wrapper.get_home_fullname() == 'AAAAAAA1'
     assert gameresult_wrapper.get_away_fullname() == 'BBBBBBB1'
Exemplo n.º 5
0
 def __init__(self, game):
     self.number_of_ticks = 5
     self.game: Gameinfo = game
     self.gameresult_wrapper = GameresultWrapper(game)
     self.home_name = self.gameresult_wrapper.get_home_name()
     self.away_name = self.gameresult_wrapper.get_away_name()
Exemplo n.º 6
0
class Liveticker(object):

    def __init__(self, game):
        self.number_of_ticks = 5
        self.game: Gameinfo = game
        self.gameresult_wrapper = GameresultWrapper(game)
        self.home_name = self.gameresult_wrapper.get_home_name()
        self.away_name = self.gameresult_wrapper.get_away_name()

    def as_json(self):
        return dict(
            gameId=self.game.id,
            status=self.get_status(),
            standing=self.game.standing,
            time=self.get_time(),
            home={
                "name": self.gameresult_wrapper.get_home_fullname(),
                "score": self.gameresult_wrapper.get_home_score(),
                "isInPossession": self.is_home_in_possession(),
            },
            away={
                "name": self.gameresult_wrapper.get_away_fullname(),
                "score": self.gameresult_wrapper.get_away_score(),
                "isInPossession": self.is_away_in_possession(),
            },
            ticks=self.get_ticks())

    def get_status(self):
        return self.game.status

    def get_time(self):
        if self.game.gameStarted is None:
            time = self.game.scheduled
        else:
            time = self.game.gameStarted
        return time.strftime("%H:%M")

    def get_ticks(self):
        ticks = []
        relevant_ticks = TeamLog.objects.filter(gameinfo=self.game).order_by('-created_time')[
            slice(None, self.number_of_ticks)]
        tick: TeamLog
        for tick in relevant_ticks:
            if tick.team is None or tick.event == 'Spielzeit':
                is_home = None
            else:
                is_home = 'home' if tick.team.name == self.home_name else 'away'
            ticks.append(Tick(tick, is_home).as_json())
        return ticks

    def __repr__(self):
        self.as_json()

    def is_home_in_possession(self):
        return self.game.in_possession == self.home_name

    def is_away_in_possession(self):
        return self.game.in_possession == self.away_name

    def collect_all_ticks(self):
        self.number_of_ticks = None