From a0cb9b0e1214c8f399b013fc1b40316ec0b6f333 Mon Sep 17 00:00:00 2001 From: yann Date: Thu, 6 Feb 2025 10:26:48 +0100 Subject: [PATCH] delete unused old models --- models/match.py | 27 ---------------- models/participant.py | 46 --------------------------- models/player.py | 30 ------------------ models/tournament.py | 28 ---------------- models/turn.py | 74 ------------------------------------------- 5 files changed, 205 deletions(-) delete mode 100644 models/match.py delete mode 100644 models/participant.py delete mode 100644 models/player.py delete mode 100644 models/tournament.py delete mode 100644 models/turn.py diff --git a/models/match.py b/models/match.py deleted file mode 100644 index 81b6456..0000000 --- a/models/match.py +++ /dev/null @@ -1,27 +0,0 @@ -from player import Player - -class Match: - """Get two players - - print a string with both ids - return a tuple of list player, score - """ - def __init__(self, player1, player2): - self.name = None - self.player1 = player1 - self.player2 = player2 - self.score1 = 0 - self.score2 = 0 - self.data = ([self.player1, self.score1], [self.player2, self.score2]) - - def __str__(self): - return f"[{self.player1}, {self.player2}]" #pretty print for prompt - - def __repr__(self): - #return ([self.player1, self.score1], [self.player2, self.score2]) - return str(self) - - def update(self): - """Update tuple when attributs have change""" - self.data = ([self.player1, self.score1], [self.player2, self.score2]) - return self.data diff --git a/models/participant.py b/models/participant.py deleted file mode 100644 index 9e6f718..0000000 --- a/models/participant.py +++ /dev/null @@ -1,46 +0,0 @@ -from collections import UserDict -import json -from player import Player - - -class Participants(UserDict): - """Dict of players and score attending a tournament - - takes tournament's name and list of object Player - returns dict with player: score""" - def __init__(self, player_list): #player_list FOR TEST ; to feed when creating object - #self.tournament - self.player_list = player_list - self.data = {} - self.PLAYERS_FILE = "./data/players/player_list.json" #FOR TEST - - def create_participant_from_list(self, players): - for item in players: - self.data[item.chess_id] = 0 - return self.data - - def get_list_from_file(self): - with open(self.PLAYERS_FILE) as file: - self.data = json.load(file) - - - def get_players_from_file(self): - """create a Player list from the json file - - uses file in current folder - return a list of object Player - """ - players = [] - data = {} - with open(self.PLAYERS_FILE) as file: - data = json.load(file) - for i in data: - players.append( - Player(name=data[i][0], lastname=data[i][1], birthdate=data[i][2], gender=data[i][3], chess_id=i)) - # print(data[i][0]) - j = + 1 - return self.create_participant_from_list(players) - - def ask_for_new_participant(self): - pass - diff --git a/models/player.py b/models/player.py deleted file mode 100644 index 8fe54e6..0000000 --- a/models/player.py +++ /dev/null @@ -1,30 +0,0 @@ -import json -from datetime import datetime - -class Player: - """A chess player""" - def __init__(self, name, lastname, birthdate, ine=None, score = 0): - self.name = name - self.lastname = lastname - self.birthdate = birthdate - self.ine = ine - self.score = score - - def __str__(self): - """Used in print""" - return self.ine - - def __repr__(self): - return str(self) - - -joueur1 = Player("Bob", "Durand", "25/12/1995", "EF34924") -joueur2 = Player("Joe", "Bidjoba", "02/01/2001", "QS42622") -joueur3 = Player("Jeanine", "Mequesurton", "25/12/1995", "AB20022") -joueur4 = Player("Jean-Pierre", "Quiroul", "15/09/1992", "JF78739") -joueur5 = Player("René", "Nuphard", "25/12/1995", "ED22230") -joueur6 = Player("Sophie", "Fonfec", "24/05/1999", "EE49948") - - -liste = [joueur1, joueur2, joueur3, joueur4, joueur5, joueur6] -print(joueur1) \ No newline at end of file diff --git a/models/tournament.py b/models/tournament.py deleted file mode 100644 index a60071c..0000000 --- a/models/tournament.py +++ /dev/null @@ -1,28 +0,0 @@ -from ChessTournament.models.participant import Participants -from ChessTournament.models.turn import Turn - - -class Tournament: - """A competition with players and turns - - takes player_list - """ - def __init__(self, - name, - participants, - location = "Club", - date_start = "today", - date_end = 'today', - current_turn = 1, - total_turn = 4 ): - self.name = name - self.participants = participants - self.location = location - self.date_start = date_start - self.date_end = date_end - self.total_turn = total_turn - self.current_turn = current_turn - self.description = "Pas encore de description" - self.turn_list = [] - - diff --git a/models/turn.py b/models/turn.py deleted file mode 100644 index f2d0902..0000000 --- a/models/turn.py +++ /dev/null @@ -1,74 +0,0 @@ -from random import choice, shuffle -from datetime import datetime -from time import sleep -from participant import Participants -from match import Match - -class Turn: - """Round for tournament - - has name, dict of participant (object) - """ - def __init__(self, participants = None, name="Round 1"): - self.name = name - self.participants = participants - self.match_history = [] - self.match_list = [] - self.match_result = [] - self.player_list = [] - - def turn_time(self): - return(datetime.now()) - - def sort_players_by_score(self): - """orders dict on value and returns sorted list""" - return sorted(self.participants.items(), key=lambda t: t[1]) - - - - def create_match(self): - j = 0 - k = 0 - for i in range(0, len(self.player_list), 2): - j += 1 - match = Match(self.player_list[i][0], self.player_list[i+1][0]) - match.name = "match" + str(j) - while match in self.match_history: - k += 1# If match has already been made, choose the next player - match = Match(self.player_list[i][0], self.player_list[i+k][0]) - self.match_list.append(match) - else: - self.match_list.append(match) - #print(match) - - self.match_history.append([self.name, self.match_list]) - return self.match_list - # if i.index - - def input_scores(self): - for match in self.match_list: - print(match.name) - self.result = input(f"Vainqueur du {match.name} : 1.{match.player1}, 2.{match.player2}, 3.nul\n ? ") - if self.result == "1": - self.participants[match.player1] += 1 - match.score1 += 1 - if self.result == "2": - self.participants[match.player2] += 1 - match.score2 += 1 - if self.result == "3": - self.participants[match.player1] += 0.5 - match.score1 += 0.5 - self.participants[match.player2] += 0.5 - match.score2 += 0.5 - match.update() # update match then save it at the end of the turn - self.match_result.append(match.data) - return self.match_result - - - - -tour = Turn() - -tour.turn_time() -sleep(3) -tour.turn_time()