Beispiel #1
0
def choice_display_contests():
    # display contests list
    contests_list = Contest.get_contests()
    if not contests_list:
        view.print_msg_error_1()
    else:
        view.print_contests_list(contests_list)
        view.clear_screen()
Beispiel #2
0
def choice_display_players_for_a_contest():
    contest_query = Contest()
    contest_name = input('Enter the contest name: ')
    view.clear_screen_without_msg()
    if contest_query.get_players_contest(contest_name) == 0:
        view.print_players_sorting_by_name(contest_query.players)
        view.clear_screen()
        view.print_players_sorting_by_ranking(contest_query.players)
        view.clear_screen()
    else:
        view.print_msg_error_2()
Beispiel #3
0
def choice_update_rank_player():
    input_control = ReadInformation()
    id_player = input_control.read_id2()
    ranking = input_control.read_ranking()
    player = Player()
    ret = player.update_ranking2(id_player, ranking)
    if ret == 1:
        view.print_player_updated(player)
    else:
        view.print_msg_error_4()
    view.clear_screen()
Beispiel #4
0
def choice_display_players(type_sorting):
    players_list = Player.get_players()
    # print(type(players_list))
    # print((players_list))
    if not players_list:
        view.print_msg_error_3()
    elif type_sorting == 1:
        view.print_players_sorting_by_name(players_list)
        view.clear_screen()
    else:
        view.print_players_sorting_by_ranking(players_list)
        view.clear_screen()
Beispiel #5
0
    def read_contest_information(self):
        players_table = Contest.get_size_players_table()
        if not players_table:
            view.print_msg_error_17()
            view.clear_screen()
            return None
        read_input = ReadInformation()
        contest_list = []
        contest_list.append(read_input.read_name(3))
        contest_list.append(read_input.read_name(4))
        contest_list.append(read_input.read_date(0))
        contest_list.append(read_input.read_time_control())
        contest_list.append(read_input.read_comments())
        view.clear_screen_without_msg()

        view.infos_3()
        players_ids = []
        players_obj = []

        players = []
        for player_item in players_table:
            player = Player()
            player.deserializing_player(player_item)
            players.append(player)

        while len(players_ids) != 8:
            # view.display_players(players)
            view.print_players_list2(players)
            id = ReadInformation.read_id(len(players_ids))
            ret = Player.player_exists(players_table, id)
            if ret is False:
                view.print_msg_error_18()
            elif id in players_ids:
                view.print_msg_error_19()
            else:
                players_ids.append(id)
                player = Player()
                player_dict = player.get_player_from_id(id)
                player.deserializing_player(player_dict)
                view.infos_5(player)
                players_obj.append(player)
            view.clear_screen()
        view.infos_4()
        contest_list.append(players_obj)
        return contest_list
Beispiel #6
0
def choice_display_matches():
    contest_query = Contest()
    contest_name = input('Enter the contest name: ')
    view.clear_screen_without_msg()
    if contest_query.get_players_contest(contest_name) == 0:
        for round in range(4):
            if not contest_query.rounds[round].matches:
                print('the contest is not finished, '
                      'we cannot display the following matches')
                view.clear_screen()
                return
            contest_query.display_scores_matches(round, 4, 0)
            view.clear_screen()
    else:
        view.print_msg_error_2()
        view.clear_screen()
Beispiel #7
0
def restore_contest():
    name_contest = input("Type contest name: ")
    # print(name_contest)
    db = TinyDB('db.json')
    contests_table = db.table('contests')
    User = Query()
    ret = contests_table.contains(User.name == name_contest)
    contest_dict = contests_table.get(User.name == name_contest)
    # json_object = json.loads(contest_dict)
    # json_formatted_str = json.dumps(contest_dict, indent=4)
    if ret is True:
        # print(f"The contest {name_contest} exists in DB")
        contest = Contest()
        contest.deserializing_contest(contest_dict)
        # print("name:", contest.name)
        # print("location:", contest.location)
        # print(contest.rounds)
        # print(contest.rounds[3].matches)
        # print(len(contest.rounds[3].matches))
        if not contest.rounds[3].matches:
            print('You can continue this contest')
            view.clear_screen()
        else:
            print("The contest is already completed")
            view.clear_screen()
            return contest
        # input()
        for round in range(4):
            # print(f"round {round}:", contest.rounds[round].matches)
            if not contest.rounds[round].matches:
                current_round = round
                # print(f"round {round} don't begin")
                break
        # view.display_players(contest.players)
        # print(f"current_round: {current_round}")
        nb_rounds = 4 - current_round
        nb_matches = 4
        # contest.create_rounds(nb_rounds)
        contest.create_matches(nb_rounds, nb_matches)

        choice_add_new_contest(1, current_round, contest)
        view.clear_screen()
        # TODO check if statement is completed or no
    else:
        print("the contest don't exists")
Beispiel #8
0
def choice_add_new_contest(is_restore, current_round, contest):
    nb_matches = 4
    if is_restore == 0:
        contest_list = ReadInformation.read_contest_information()
        if not contest_list:
            return None
        db = TinyDB('db.json')
        contests_table = db.table('contests')
        User = Query()
        ret = contests_table.contains(User.name == contest_list[0])
        if ret is True:
            print("You cannot create this contest "
                  "because the name is already used !")
            view.clear_screen()
            return
        contest = Contest(contest_list[0], contest_list[1], contest_list[2],
                          contest_list[3], contest_list[4], contest_list[5])
        view.infos_contest(contest)
        view.clear_screen()
        nb_rounds = 4
        nb_matches = 4

        contest.create_rounds(nb_rounds)
        contest.create_matches(nb_rounds, nb_matches)
        contest.serialization_contest()
        contest.save()
    nb_rounds = 4 - current_round
    for n in range(nb_rounds):
        view.infos_9(current_round)
        contest.rounds[current_round].start_datetime = \
            datetime.datetime.now()
        # print("datetime: ", contest.rounds[current_round].start_datetime)

        contest.rounds[current_round].end_datetime = \
            contest.rounds[current_round].start_datetime + \
            datetime.timedelta(hours=1)
        # print("datetime: ", contest.rounds[current_round].end_datetime)

        Tour.matches_generator(contest, current_round)
        contest.display_assignement_players(current_round, nb_matches)
        view.clear_screen()
        result_matches = []
        for n in range(4):
            view.infos_6()
            view.infos_10(n)
            name_player_1 = Player.get_name_player(
                contest.rounds[current_round].matches[n][0][0])
            name_player_2 = Player.get_name_player(
                contest.rounds[current_round].matches[n][1][0])
            view.infos_11(name_player_1, name_player_2)
            result_matches.append(ReadInformation.read_score())
            view.clear_screen_without_msg()
        contest.save_scores2(current_round, nb_matches, result_matches)
        view.display_round(contest, current_round, nb_matches)
        view.clear_screen()
        contest.players = Player.sort_players_by_point(contest.players)
        current_round += 1
        contest.serialization_contest()
        contest.update_contest()

        # print("current_round:", current_round)
        if current_round < 4:
            ret = ReadInformation.read_choice_exit_contest()
            if ret == '1':
                view.clear_screen_without_msg()
                pass
            elif ret == '2':
                view.clear_screen_without_msg()
                return contest
            elif ret == '3':
                exit()
            # else:
    for player in contest.players:
        view.display_players(contest.players)
        view.infos_7(player)
        input_control = ReadInformation()
        player.ranking = input_control.read_ranking()
        player.update_ranking()
        view.clear_screen_without_msg()
        view.infos_8()
        view.infos_7(player)
        view.clear_screen()
    return contest