From 9ef7d95c7010351078a929f5144f5098d4142cd0 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Fri, 5 Apr 2024 16:55:07 +0200 Subject: Added the working version in dash --- src/match_up/model.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src/match_up/model.py') diff --git a/src/match_up/model.py b/src/match_up/model.py index 3a9990b..d27893d 100644 --- a/src/match_up/model.py +++ b/src/match_up/model.py @@ -1,6 +1,7 @@ from pathlib import PurePath from tinydb import TinyDB, where from dataclasses import dataclass +from random import randint MIN_SKILL = 1 MAX_SKILL = 10 @@ -10,9 +11,24 @@ class PlaySession: def __init__(self, database_location: PurePath): self.data = PlayerDatabase(database_location) - def start_round(self): ... - - def end_round(self): ... + def get_matches(self, number_of_courts: int = 4): + player_list = self.data.get_players() + game_list = [] + for i in range(number_of_courts): + game_list.append( + Game( + court_number=i + 1, + team_1=Team( + player_1=player_list[randint(0, len(player_list) - 1)], + player_2=player_list[randint(0, len(player_list) - 1)], + ), + team_2=Team( + player_1=player_list[randint(0, len(player_list) - 1)], + player_2=player_list[randint(0, len(player_list) - 1)], + ), + ) + ) + return game_list def end(self): self.data.close() @@ -35,6 +51,25 @@ class Player: status: bool = False wait_time: int = 0 + def get_name(self): + return self.first_name + " " + self.last_name + + +@dataclass +class Team: + player_1: Player + player_2: Player + + def __str__(self): + return self.player_1.get_name() + " & " + self.player_2.get_name() + + +@dataclass +class Game: + court_number: int + team_1: Team + team_2: Team + class PlayerDatabase: def __init__(self, database_location: PurePath = PurePath("storage.json")): -- cgit v1.3.1