aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKaran Jayachandra <mail@karanjayachandra.com>2024-10-16 21:42:22 +0000
committerKaran Jayachandra <mail@karanjayachandra.com>2024-10-16 21:42:22 +0000
commit7643486d7122b322a052bfca8ec83326c48053d0 (patch)
tree096d2b629818f79674d22a14eff124f082449b6e /src
parent9ef7d95c7010351078a929f5144f5098d4142cd0 (diff)
parent36cc7d82a55cbd8167e1f52637dd1938497dd8cc (diff)
Merge branch 'develop' into 'main'
Full functionality available See merge request KaranJayachandra/match_up!3
Diffstat (limited to 'src')
-rw-r--r--src/match_up/__init__.py33
-rw-r--r--src/match_up/__main__.py4
-rw-r--r--src/match_up/model.py153
-rw-r--r--src/match_up/templates/index.html14
-rw-r--r--src/match_up/tests/__init__.py44
-rw-r--r--src/match_up/view.py96
6 files changed, 0 insertions, 344 deletions
diff --git a/src/match_up/__init__.py b/src/match_up/__init__.py
deleted file mode 100644
index 04c2f12..0000000
--- a/src/match_up/__init__.py
+++ /dev/null
@@ -1,33 +0,0 @@
-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,
-)
-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._dashboard = Dash("Match Up!", external_stylesheets=[ZEPHYR])
- self._layout = MainLayout(
- self._session.data.get_players(), self._session.get_matches()
- )
- self._dashboard.layout = self._layout.get()
-
- def run(self):
- self._dashboard.run(debug=self._debug)
-
-
-def main():
- a = Application(debug=True)
- a.run()
diff --git a/src/match_up/__main__.py b/src/match_up/__main__.py
deleted file mode 100644
index 3500cdb..0000000
--- a/src/match_up/__main__.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from match_up import main
-
-if __name__ == "__main__":
- main()
diff --git a/src/match_up/model.py b/src/match_up/model.py
deleted file mode 100644
index d27893d..0000000
--- a/src/match_up/model.py
+++ /dev/null
@@ -1,153 +0,0 @@
-from pathlib import PurePath
-from tinydb import TinyDB, where
-from dataclasses import dataclass
-from random import randint
-
-MIN_SKILL = 1
-MAX_SKILL = 10
-
-
-class PlaySession:
- def __init__(self, database_location: PurePath):
- self.data = PlayerDatabase(database_location)
-
- 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()
-
- def __str__(self):
- display_string = ""
- for player in self.data.get_players():
- display_string = display_string + player.__str__() + "\n"
- return display_string.rstrip()
-
- def __del__(self):
- self.end()
-
-
-@dataclass
-class Player:
- first_name: str
- last_name: str
- skill: int = 1
- 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")):
- print(f"Using database location: {database_location.name}")
- self._database = TinyDB(database_location.name)
-
- def get_players(self) -> list[Player]:
- player_list = []
- for row in self._database:
- player_list.append(
- Player(
- first_name=row["first_name"],
- last_name=row["last_name"],
- skill=row["skill"],
- status=row["status"],
- wait_time=row["wait_time"],
- )
- )
- return player_list
-
- def activate_player(self, player: Player):
- self._database.update(
- {"status": True},
- where("first_name") == player.first_name
- and where("last_name") == player.last_name,
- )
-
- def deactivate_player(self, player: Player):
- self._database.update(
- {"wait_time": False},
- where("first_name") == player.first_name
- and where("last_name") == player.last_name,
- )
-
- def increment_player_wait(self, player: Player):
- self._database.update(
- {"wait_time": 1},
- where("first_name") == player.first_name
- and where("last_name") == player.last_name,
- )
-
- def reset_player_wait(self, player: Player):
- self._database.update(
- {"wait_time": 0},
- where("first_name") == player.first_name
- and where("last_name") == player.last_name,
- )
-
- def deactivate_all_players(self) -> bool:
- for row in self._database:
- row["status"] = False
-
- def add_player(self, player: Player) -> bool:
- self._database.insert(
- {
- "first_name": player.first_name,
- "last_name": player.last_name,
- "skill": player.skill,
- "status": player.status,
- "wait_time": player.wait_time,
- }
- )
-
- def remove_player(self, player: Player) -> bool:
- self._database.remove(
- where("first_name") == player.first_name
- and where("last_name") == player.last_name
- )
-
- def update_player_skill(self, player: Player):
- self._database.update(
- {"skill": player.skill},
- where("first_name") == player.first_name
- and where("last_name") == player.last_name,
- )
-
- def close(self) -> None:
- self._database.close()
-
- def __del__(self):
- self.close()
diff --git a/src/match_up/templates/index.html b/src/match_up/templates/index.html
deleted file mode 100644
index 23bba20..0000000
--- a/src/match_up/templates/index.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<!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/tests/__init__.py b/src/match_up/tests/__init__.py
deleted file mode 100644
index 3166746..0000000
--- a/src/match_up/tests/__init__.py
+++ /dev/null
@@ -1,44 +0,0 @@
-from os import remove
-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, MIN_SKILL, MAX_SKILL
-
-TEST_DATABASE_LOCATION = PurePath("test_storage.json")
-
-
-def generate_test_database(total_players: int = 20) -> None:
- try:
- if isfile(TEST_DATABASE_LOCATION):
- remove(TEST_DATABASE_LOCATION)
- db = PlayerDatabase(TEST_DATABASE_LOCATION)
- for _ in range(total_players):
- db.add_player(
- Player(
- first_name=get_first_name(),
- last_name=get_last_name(),
- skill=randint(MIN_SKILL, MAX_SKILL),
- )
- )
- finally:
- db.close()
-
-
-def activate_random_players(activate_players: int = 17) -> None:
- try:
- db = PlayerDatabase(TEST_DATABASE_LOCATION)
- player_list = db.get_players()
- for index, player in enumerate(player_list):
- if index < activate_players:
- db.activate_player(player)
- finally:
- db.close()
-
-
-def main():
- pass
-
-
-if __name__ == "__main__":
- main()
diff --git a/src/match_up/view.py b/src/match_up/view.py
deleted file mode 100644
index 8fa1c54..0000000
--- a/src/match_up/view.py
+++ /dev/null
@@ -1,96 +0,0 @@
-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 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="Game List", style={"textAlign": "center"}),
- Table(table_header + table_body, bordered=True),
- ]
- )
-
- def get(self):
- return self._layout
-
-
-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], 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([self._game_layout.get()], width=9),
- Col([self._player_layout.get()], width=3),
- ],
- style={"margin": "15px"},
- )
- ]
- ),
- ]
- )
- # full_layout = Div([Div(children="Hello World")])
- return full_layout