diff options
| author | Karan Jayachandra <karan.jayachandra@nxp.com> | 2024-10-04 18:23:33 +0200 |
|---|---|---|
| committer | Karan Jayachandra <karan.jayachandra@nxp.com> | 2024-10-04 18:23:33 +0200 |
| commit | 88d7300021cd3963f2d6a6202609b0f6e956cdab (patch) | |
| tree | d9e9e186d86572e57253a188467ebb4084535039 /model.py | |
| parent | c58caf5b8b8801ba826b0ff6b241d7f25a333bc8 (diff) | |
Added the games view
Diffstat (limited to 'model.py')
| -rw-r--r-- | model.py | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -1,3 +1,4 @@ +from math import floor from csv import reader from pathlib import Path from dataclasses import dataclass @@ -10,7 +11,20 @@ class Player: status: bool +@dataclass +class Team: + player1: Player + player2: Player + + +@dataclass +class Game: + team1: Team + team2: Team + + class PlayerList: + def __init__(self, location: Path = "players.csv"): with open(location, newline="") as file: data_reader = reader(file) @@ -29,6 +43,9 @@ class PlayerList: def get_player(self, player_request: str): return [player for player in self.players if player.name == player_request] + def get_active_players(self): + return [player for player in self.players if player.status] + def toggle_player(self, player_request: Player): self.players = [ ( @@ -48,3 +65,26 @@ class PlayerList: for player in self.players: display_string += player.__str__() + "\n" return display_string + + +@dataclass +class GameList: + courts: int = 8 + + def create_games(self, players: list[Player]): + possible_games = floor(len(players) / 4) + games = [] + for i in range(possible_games): + team1 = Team(player1=players[4 * i + 0], player2=players[4 * i + 1]) + team2 = Team(player1=players[4 * i + 2], player2=players[4 * i + 3]) + game = Game(team1, team2) + games.append(game) + empty_courts = ( + self.courts - possible_games if self.courts > possible_games else 0 + ) + for i in range(empty_courts): + dummy_player = Player(name="-", skill=0, status=True) + dummy_team = Team(player1=dummy_player, player2=dummy_player) + game = Game(dummy_team, dummy_team) + games.append(game) + return games |
