def delete_finished_games(): current_time = datetime.datetime.now() finished_games = Database.get_finished_games(current_time) if len(finished_games) is not 0: list_finished_games = ProgramManager.extract_to_list( finished_games) Database.delete_finished_games(list_id_games=list_finished_games)
def create_game(type, pitch_id, year, month, day, start_hour, max_participants): ProgramManager.delete_finished_games() id_game = Database.get_max_game_id() + 1 start_game = datetime.datetime(year, month, day, start_hour) end_game = datetime.datetime(year, month, day, start_hour + 2) Database.create_game(id_game, type, pitch_id, start_game, end_game, max_participants)
def get_full_data_on_games(list_games): games_full_data = [] for game in list_games: pitch_db = Database.get_pitch(game.pitch_id) pitch_object = Pitch(pitch_db[0], pitch_db[1], pitch_db[2], pitch_db[3], pitch_db[4], pitch_db[5]) distance = pitch_object.calculate_distance(ProgramManager.location) games_full_data.append([game, distance, pitch_object]) return games_full_data
def get_available_games(type, year, month, day, start_hour, requested_distance): ProgramManager.delete_finished_games() start_game = datetime.datetime(year, month, day, start_hour) games = Database.get_available_games(type=type, start_game=start_game) list_games = ProgramManager.build_games_objects(games) games_full_data = ProgramManager.get_full_data_on_games(list_games) games_full_data = [ item for item in games_full_data if item[1] <= requested_distance ] return sorted(games_full_data, key=lambda x: x[1])
def create_db(): if not isfile(ProgramManager.db_name): list_pitches = OSM.get_pitches() Database.create_db(list_pitches) else: print('DB already exist')
def join_to_game(id_game): num_participants = Database.get_current_participants_in_game( id_game=id_game) Database.joining_to_game(id_game=id_game, num_participants=num_participants)