def __start_work(self, quest_name, timestamp): assert_person(quest_name in self.quests, f'quest named {quest_name} not found') assert_person(self.quests[quest_name]['start_timestamp'] is None, f'quest named {quest_name} is already started') quest = self.quests[quest_name] # проверить, что указанное время старта равно или позже последнего лога по этому квесту logs_obj = Logs(self.logs_path) logs = logs_obj.get_logs(select=['timestamp'], where=f'quest_id="{quest["id"]}" AND action="log_work"') if logs: last_log_timestamp = logs[-1][0] last_log_timestamp = parse_timestamp(last_log_timestamp) assert_person(last_log_timestamp <= timestamp, f'the given start datetime ({timestamp})' f' is before a last log of the quest ({last_log_timestamp})') quest['start_timestamp'] = timestamp logs_obj.log( timestamp=str(timestamp), quest_id=quest['id'], action='start_work', points={}, bookmark='') logs_obj.close()
def __log_work(self, quest_name, timestamp, points, bookmark): """ :param quest_name: 'name' :param timestamp: pandas.Timestamp object :param points: {'Minuten': 48, } :param bookmark: 'any text' """ assert_person(quest_name in self.quests, f'quest named {quest_name} not found') quest = self.quests[quest_name] assert_person(quest['start_timestamp'] is not None, f'quest named {quest_name} is not started') assert_person(quest['start_timestamp'] <= timestamp, f'the given log timestamp ({timestamp})' f' is after a start timestamp of the quest ({quest["start_timestamp"]})') for point_name in points: assert_person(point_name in quest['points'], f'point named {point_name} is not in quest {quest_name} points') quest['bookmark'] = bookmark for point_name in points: point = quest['points'][point_name] point['total_points'] += points[point_name] date = timestamp.date() if quest['first_date'] is None: quest['first_date'] = date quest['last_date'] = date quest['start_timestamp'] = None logs_obj = Logs(self.logs_path) logs_obj.log( timestamp=str(timestamp), quest_id=quest['id'], action='log_work', points=points, bookmark=bookmark) logs_obj.close()
person = Passenger(display_game, surface, "John", colors["BLACK"], int(display_width / 2), int(display_height / 2)) ticket = Ticket(display_game, surface, "Ticket", colors["BLACK"], display_width - 80, display_height - 80, 20, 20) cash_register = CashRegister(display_game, surface, "Cash Register", colors["GREEN"], 100, 10) objects = (person, ticket, cash_register) logs = Logs() active_key = "" while True: for event in pygame.event.get(): if event.type == QUIT: logs.close() pygame.quit() sys.exit() if event.type == KEYDOWN: temp = "" if event.key == K_LEFT: lead_x_change = -step_size active_key = "Left" temp = active_key + " " + person.current_pos() elif event.key == K_RIGHT: lead_x_change = step_size active_key = "Right" temp = active_key + " " + person.current_pos() elif event.key == K_UP: lead_y_change = -step_size active_key = "Up"