diff options
Diffstat (limited to 'src/match_up')
| -rw-r--r-- | src/match_up/__init__.py | 18 | ||||
| -rw-r--r-- | src/match_up/model.py | 3 | ||||
| -rw-r--r-- | src/match_up/tests/__init__.py | 14 | ||||
| -rw-r--r-- | src/match_up/view.py | 77 |
4 files changed, 100 insertions, 12 deletions
diff --git a/src/match_up/__init__.py b/src/match_up/__init__.py index 2b1e42b..c41394a 100644 --- a/src/match_up/__init__.py +++ b/src/match_up/__init__.py @@ -1,25 +1,31 @@ +from dash import Dash from pathlib import PurePath from match_up.model import PlaySession +from match_up.view import MainLayout from match_up.tests import ( TEST_DATABASE_LOCATION, - generate_test_database, - activate_random_players, ) +from dash_bootstrap_components.themes import ZEPHYR DATABASE_LOCATION = "storage.json" class Application: def __init__(self, debug=False): + self._debug = debug if debug: database_location = TEST_DATABASE_LOCATION else: database_location = DATABASE_LOCATION - self.session = PlaySession(PurePath(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._dashboard.layout = self._layout.get() + + def run(self): + self._dashboard.run(debug=self._debug) def main(): - generate_test_database() - activate_random_players() a = Application(debug=True) - print(a.session) + a.run() diff --git a/src/match_up/model.py b/src/match_up/model.py index 181b698..3a9990b 100644 --- a/src/match_up/model.py +++ b/src/match_up/model.py @@ -2,6 +2,9 @@ from pathlib import PurePath from tinydb import TinyDB, where from dataclasses import dataclass +MIN_SKILL = 1 +MAX_SKILL = 10 + class PlaySession: def __init__(self, database_location: PurePath): diff --git a/src/match_up/tests/__init__.py b/src/match_up/tests/__init__.py index 4dbd883..3166746 100644 --- a/src/match_up/tests/__init__.py +++ b/src/match_up/tests/__init__.py @@ -3,17 +3,15 @@ from os.path import isfile from random import randint from pathlib import PurePath from names import get_first_name, get_last_name -from match_up.model import Player, PlayerDatabase +from match_up.model import Player, PlayerDatabase, MIN_SKILL, MAX_SKILL TEST_DATABASE_LOCATION = PurePath("test_storage.json") -MIN_SKILL = 1 -MAX_SKILL = 10 def generate_test_database(total_players: int = 20) -> None: try: if isfile(TEST_DATABASE_LOCATION): - remove_test_database() + remove(TEST_DATABASE_LOCATION) db = PlayerDatabase(TEST_DATABASE_LOCATION) for _ in range(total_players): db.add_player( @@ -38,5 +36,9 @@ def activate_random_players(activate_players: int = 17) -> None: db.close() -def remove_test_database() -> None: - remove(TEST_DATABASE_LOCATION) +def main(): + pass + + +if __name__ == "__main__": + main() diff --git a/src/match_up/view.py b/src/match_up/view.py new file mode 100644 index 0000000..9da82a9 --- /dev/null +++ b/src/match_up/view.py @@ -0,0 +1,77 @@ +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 + + +class PlayerLayout: + def __init__(self, player_list: list[Player]): + 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", + }, + ], + ), + ] + ) + + def get(self): + return self._layout + + +class GameLayout: + def __init__(): ... + + +class MainLayout: + def __init__(self, player_list: list[Player]): + self._player_layout = PlayerLayout(player_list) + + def refresh(): ... + + def get(self): + full_layout = Div( + [ + Container( + [ + Row( + [ + Col(["Total Samples"], width=1), + Col([self._player_layout.get()], width=10), + ], + style={"margin": "15px"}, + ) + ] + ) + ] + ) + # full_layout = Div([Div(children="Hello World")]) + return full_layout |
