コード例 #1
0
    def load(cls, save_id: int):
        """
        Method of loading a backup tournament
        """
        Player.initialise_players_data()
        Player.load_players()
        Player.all_players_inactive()
        data_load = cls.table_tournoi.get(doc_id=save_id)

        # data_load = data_load[-1]

        t = {}
        # --------- Load Objet Tournament ----------

        t['identity'] = data_load['id']
        t['name'] = data_load['name']
        t['location'] = data_load['location']
        t['tournament_date'] = data_load['tournament_date']
        t['timer'] = data_load['timer']
        t['description'] = data_load['description']
        t['max_rounds_number'] = data_load['max_rounds_number']

        tournament = Tournament(t['identity'], t['name'], t['location'], t['tournament_date'], t['description'],
                                t['timer'], max_rounds_number=t['max_rounds_number'])

        # --------- Load Objet Player ---------------

        t['players'] = data_load['players']
        for player in t['players']:
            # 1 - Search for the player with uuid stored in player[0].
            # 2 - Assign the number of points stored in player[1]
            # 3 - Fill in the existing matches store in player[2]
            p_found = [p for p in Player.PLAYERS if player[0] == p.uuid]

            assert p_found          # Raises an exception if the player is not found

            p_found = p_found[0]

            p_found.status = True
            # p_found.switch_player_tournament()
            p_found.point = player[1]
            for meet in player[2]:
                p_found.add_meet(meet)

        # --------- Load Objet Round ----------------

        t['rounds'] = data_load['rounds']
        for n, round in enumerate(t['rounds']):
            # 1 - We scan the saved rounds.
            # 2 - We extract the information from the rounds.
            # 3 - We extract the matches and the scores.
            if n % 2 == 0:
                tournament.rounds.append(Round(round['number'],
                                         Player.list_player_tournament(),
                                         round['start'],
                                         round['end'],
                                         t['rounds'][n+1]['matches'],
                                         round['id']))

        return tournament
コード例 #2
0
 def add_round(self):
     """
     Method to add a round in tournament
     Returns: Object Round
     """
     r = Round(round_number=len(self.rounds) + 1, players=Player.list_player_tournament())
     self.rounds.append(r)
     return r
コード例 #3
0
 def list_tournament_players_sort_elo(self):
     """
     Function that will print the list of players in the tournament sorted by ELO
     """
     title = "Bienvenue dans le gestionnaire de tournois d'échec."
     subtitle = "Listing des joueurs du tournoi :"
     data = Player.list_player_tournament()
     data.sort(reverse=True, key=lambda x: int(x.elo))
     self.view_menu.display_data(title, subtitle, data)
コード例 #4
0
 def list_tournament_players_sort_alpha(self):
     """
     Function that will print the list of players in the tournament sorted alphabetically
     """
     title = "Bienvenue dans le gestionnaire de tournois d'échec."
     subtitle = "Listing des joueurs du tournoi :"
     data = Player.list_player_tournament()
     data.sort(key=lambda x: (x.name, x.first_name))
     self.view_menu.display_data(title, subtitle, data)
コード例 #5
0
    def view_result(self):
        """
        Méthode qui affiche le résultat du tournoi.

        Returns:

        """

        p = Player.list_player_tournament()
        p.sort(reverse=True, key=lambda x: (int(x.point), int(x.elo)))
        data = []
        for n, player in enumerate(p):
            data.append(
                f"{n + 1} - {player.fullname} ({player.age} ans) avec {player.point} points,"
                f" classement ELO : {player.elo}")

        title = "Bienvenue dans le gestionnaire de tournois d'échec.\n"
        subtitle = "Classement du tournoi."

        self.view_menu.display_data(title, subtitle, data)