def get_pilot_data(self): log_file = open("log.txt", "r") first_line = True list_of_pilots = {} for line in log_file: if first_line: first_line = not first_line continue log_line = LogLine(line) if log_line.get_pilot_code() in list_of_pilots: pilot = list_of_pilots.get(log_line.get_pilot_code()) else: pilot = Pilot(log_line.get_pilot_code(), log_line.get_pilot_name()) list_of_pilots[pilot.get_code()] = pilot lap = Lap(log_line.get_lap_number(), log_line.get_lap_time(), log_line.get_lap_average_speed(), log_line.get_lap_hour()) pilot.add_lap(lap) log_file.close() return list_of_pilots
def process_input(self): """ Begins processing the input file, extracting the desired access attempt entries and building the document model. """ with open(self._ifile) as f: lines = f.readlines() for line in lines: LogLine.process(line, self)
class TestLogLine(unittest.TestCase): @classmethod def setUp(self): self.__log_line = LogLine( "23:49:08.277 038 – F.MASSA 1 1:02.852" " 44,275") def test_get_lap_hour(self): self.assertEqual("23:49:08.277", self.__log_line.get_lap_hour()) def test_get_pilot(self): self.assertEqual("038 – F.MASSA", self.__log_line.get_pilot()) def test_get_pilot_code(self): self.assertEqual("038", self.__log_line.get_pilot_code()) def test_get_pilot_name(self): self.assertEqual("F.MASSA", self.__log_line.get_pilot_name()) def test_get_lap_number(self): self.assertEqual("1", self.__log_line.get_lap_number()) def test_get_lap_time(self): self.assertEqual("1:02.852", self.__log_line.get_lap_time()) def test_get_lap_average_speed(self): self.assertEqual("44,275", self.__log_line.get_lap_average_speed())
def _create_colonize_log(log_type, kwargs): player_name = kwargs["player1"].get_name() fighter = kwargs["squad1"].get_fighter() hex_id = kwargs["hex1"].get_id() new_log_line = LogLine(log_type, player_name=player_name, fighter=fighter, hex_id=hex_id) return new_log_line
def _create_move_log(log_type, kwargs): player_name = kwargs["player1"].get_name() fighter = kwargs["squad1"].get_fighter() from_hex = kwargs["hex1"].get_id() to_hex = kwargs["hex2"].get_id() new_log_line = LogLine(log_type, player_name=player_name, fighter=fighter, from_hex=from_hex, to_hex=to_hex) return new_log_line
def _create_attack_log(log_type, kwargs): atk_player = kwargs["player1"].get_name() def_player = kwargs["player2"].get_name() fighter = kwargs["squad1"].get_fighter() from_hex = kwargs["hex1"].get_id() to_hex = kwargs["hex2"].get_id() new_log_line = LogLine(log_type, atk_player=atk_player, def_player=def_player, fighter=fighter, from_hex=from_hex, to_hex=to_hex) return new_log_line
def _create_combat_log(log_type, kwargs): atk_player = kwargs["player1"].get_name() def_player = kwargs["player2"].get_name() atk_fighter = kwargs["squad1"].get_fighter() def_fighter = kwargs["squad2"].get_fighter() victor = kwargs["victor"].get_name() hex_id = kwargs["hex1"].get_id() new_log_line = LogLine(log_type, atk_player=atk_player, def_player=def_player, atk_fighter=atk_fighter, def_fighter=def_fighter, victor=victor, hex_id=hex_id) return new_log_line
def _create_build_log(log_type, kwargs): player_name = kwargs["player1"].get_name() fighter = kwargs["squad1"].get_fighter() hex_id = kwargs["hex1"].get_id() structure = kwargs["hex1"].get_structure() # FIXME: Add code to display when squad build is random if "is_random" in kwargs: is_random = kwargs["is_random"] else: is_random = False new_log_line = LogLine(log_type, player_name=player_name, fighter=fighter, hex_id=hex_id, structure=structure, is_random=is_random) return new_log_line
def setUp(self): self.__log_line = LogLine( "23:49:08.277 038 – F.MASSA 1 1:02.852" " 44,275")
def _create_new_turn_log(log_type, kwargs): turn_num = kwargs["turn_num"] new_log_line = LogLine(log_type, turn_num=turn_num) return new_log_line