def add_game(self, home_team_name, away_team_name, match_time, field, main_referee_id, referees=[], user_id=""): try: home_team = self.__team_DB.get(home_team_name) away_team = self.__team_DB.get(away_team_name) # Checking for collision self.collision_game_check(home_team, match_time) self.collision_game_check(away_team, match_time) game = Game(self.__game_id_counter, home_team.name, away_team.name, match_time, field) home_team.add_game(game.game_id) away_team.add_game(game.game_id) for referee_id in referees: referee = self.__user_DB.get_signed_user(referee_id) game.add_referee(referee.user_id) referee.add_game(game.game_id) self.__user_DB.update_signed_user(referee) main_referee = self.__user_DB.get_signed_user(main_referee_id) game.main_referee = main_referee.user_id main_referee.add_game(game.game_id) self.__game_DB.add(game) self.update_game_counter() self.__team_DB.update(home_team) self.__team_DB.update(away_team) self.__user_DB.update_signed_user(main_referee) Logger.info_log("{0}:".format(user_id) + "Created new game between home:{0} and away:{1} ". format(home_team.name, away_team.name)) except Exception as err: Logger.error_log("{0}:".format(user_id) + err.__str__()) raise err
def test_add_remove_event(self): r = Referee(RefereeQualificationEnum.MAIN, 'Dor123', '12345678', 'Dor', datetime(1990, 8, 8), '1.1.1.1', '') self.game.add_referee(r) game_event = GameEvent(self.game, r, "type", "des", datetime(2020, 5, 5), 89) g = Game(self.home_team, self.away_team, self.d, self.field) g.main_referee = Referee(RefereeQualificationEnum.MAIN, 'Dor12', '12345678', 'Dor', datetime(1990, 8, 8), '1.1.1.1', '') not_game_event = GameEvent(g, g.main_referee, EventTypeEnum.GOAL, "des", datetime(2020, 5, 5), 89) self.assertRaises(ValueError, self.game.add_event, event=not_game_event) self.assertNotIn(not_game_event, self.game._Game__events) self.assertIn(game_event, self.game._Game__events) self.assertRaises(ValueError, self.game.add_event, event=game_event) self.game.remove_event(r) self.assertNotIn(r, self.game._Game__events) self.game.remove_event(game_event) self.assertNotIn(game_event, self.game._Game__events)
def game_dict_to_object(self, game_dict): match_time_str = game_dict['_Game__match_time'] date_split = match_time_str.split('.') match_time_object = datetime(int(date_split[2]), int(date_split[1]), int(date_split[0])) game_object = Game(game_dict['_Game__game_id'], game_dict['_Game__home_team'], game_dict['_Game__away_team'], match_time_object, game_dict['_Game__field']) game_object.home_score = game_dict['_Game__home_score'] game_object.away_score = game_dict['_Game__away_score'] game_object.main_referee = game_dict['_Game__main_referee'] game_object.referees = game_dict['_Game__referees'] game_object.events = game_dict['_Game__events'] game_object.is_game_on = game_dict['_Game__is_game_on'] game_object.is_game_finished = game_dict['_Game__is_game_finished'] game_object.fan_following = game_dict['fan_following'] return game_object