aboutsummaryrefslogtreecommitdiff
path: root/src/match_up/model.py
diff options
context:
space:
mode:
authorKaran Jayachandra <karan.jayachandra@nxp.com>2024-04-05 16:55:07 +0200
committerKaran Jayachandra <karan.jayachandra@nxp.com>2024-04-05 16:55:07 +0200
commit9ef7d95c7010351078a929f5144f5098d4142cd0 (patch)
tree57a33fc2bd915c4e9ed727356038537a7c5c719b /src/match_up/model.py
parentf48223b3d93e54cb9ed3f2174e9b6075719128bf (diff)
Added the working version in dash
Diffstat (limited to 'src/match_up/model.py')
-rw-r--r--src/match_up/model.py41
1 files changed, 38 insertions, 3 deletions
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")):