示例#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 __init__(self):
     super().__init__()
     Player.load_players()