summaryrefslogtreecommitdiff
path: root/src
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
parentf48223b3d93e54cb9ed3f2174e9b6075719128bf (diff)
Added the working version in dash
Diffstat (limited to 'src')
-rw-r--r--src/match_up/__init__.py4
-rw-r--r--src/match_up/model.py41
-rw-r--r--src/match_up/templates/index.html14
-rw-r--r--src/match_up/view.py107
4 files changed, 118 insertions, 48 deletions
diff --git a/src/match_up/__init__.py b/src/match_up/__init__.py
index c41394a..04c2f12 100644
--- a/src/match_up/__init__.py
+++ b/src/match_up/__init__.py
@@ -19,7 +19,9 @@ class Application:
database_location = DATABASE_LOCATION
self._session = PlaySession(PurePath(database_location))
self._dashboard = Dash("Match Up!", external_stylesheets=[ZEPHYR])
- self._layout = MainLayout(self._session.data.get_players())
+ self._layout = MainLayout(
+ self._session.data.get_players(), self._session.get_matches()
+ )
self._dashboard.layout = self._layout.get()
def run(self):
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")):
diff --git a/src/match_up/templates/index.html b/src/match_up/templates/index.html
new file mode 100644
index 0000000..23bba20
--- /dev/null
+++ b/src/match_up/templates/index.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<html>
+ <head>
+ <title>{{ title }}</title>
+ </head>
+ <body>
+ <h1>{{ title }}</h1>
+ <ul>
+ {% for person in people %}
+ <li>{{ person.first_name }}</li>
+ {% endfor %}
+ </ul>
+ </body>
+</html> \ No newline at end of file
diff --git a/src/match_up/view.py b/src/match_up/view.py
index 9da82a9..8fa1c54 100644
--- a/src/match_up/view.py
+++ b/src/match_up/view.py
@@ -1,45 +1,37 @@
-from dash.html import Div, H4
-from match_up.model import Player
-from dash.dash_table import DataTable
-from dash_bootstrap_components import Row, Col, Container, Input, Select
+from dash.html import Div, H4, Thead, Tbody, Tr, Td, Th
+from match_up.model import Player, Game
+from dash_bootstrap_components import (
+ Row,
+ Col,
+ Container,
+ Input,
+ Select,
+ Table,
+ NavbarSimple,
+)
-class PlayerLayout:
- def __init__(self, player_list: list[Player]):
+class GameLayout:
+ def __init__(self, game_list: list[Game]):
+ table_header = [Thead(Tr([Th("Court"), Th("Team 1"), Th("Team 2")]))]
+ table_body = [
+ Tbody(
+ [
+ Tr(
+ [
+ Td(children=game.court_number),
+ Td(children=game.team_1.__str__()),
+ Td(children=game.team_2.__str__()),
+ ]
+ )
+ for game in game_list
+ ]
+ )
+ ]
self._layout = Div(
[
- H4(children="Player List"),
- DataTable(
- data=[
- {
- "Player": player.first_name + " " + player.last_name,
- "Status": "Active" if player.status else "Inactive",
- }
- for player in player_list
- ],
- columns=[
- {"name": "Player", "id": "Player", "type": "text"},
- ],
- style_data_conditional=[
- {
- "if": {
- "column_id": "Player",
- "filter_query": "{Status} = Active",
- },
- "backgroundColor": "green",
- "color": "white",
- },
- {
- "if": {
- "column_id": "Player",
- "filter_query": "{Status} = Inactive",
- },
- "backgroundColor": "tomato",
- "color": "white",
- "fontWeight": "bold",
- },
- ],
- ),
+ H4(children="Game List", style={"textAlign": "center"}),
+ Table(table_header + table_body, bordered=True),
]
)
@@ -47,30 +39,57 @@ class PlayerLayout:
return self._layout
-class GameLayout:
- def __init__(): ...
+class PlayerLayout:
+ def __init__(self, player_list: list[Player]):
+ table_header = [Thead(Tr([Th("Player Name")]))]
+ table_body = [
+ Tbody(
+ [
+ Tr(
+ [
+ Td(
+ children=player.first_name + " " + player.last_name,
+ style={"color": ("green" if player.status else "red")},
+ )
+ ]
+ )
+ for player in player_list
+ ]
+ )
+ ]
+ self._layout = Div(
+ [
+ H4(children="Player List", style={"textAlign": "center"}),
+ Table(table_header + table_body, bordered=True),
+ ]
+ )
+
+ def get(self):
+ return self._layout
class MainLayout:
- def __init__(self, player_list: list[Player]):
+ def __init__(self, player_list: list[Player], game_list: list[Game]):
self._player_layout = PlayerLayout(player_list)
+ self._game_layout = GameLayout(game_list)
def refresh(): ...
def get(self):
full_layout = Div(
[
+ NavbarSimple(brand="Match Up!"),
Container(
[
Row(
[
- Col(["Total Samples"], width=1),
- Col([self._player_layout.get()], width=10),
+ Col([self._game_layout.get()], width=9),
+ Col([self._player_layout.get()], width=3),
],
style={"margin": "15px"},
)
]
- )
+ ),
]
)
# full_layout = Div([Div(children="Hello World")])