summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.py40
-rw-r--r--model.py11
-rw-r--r--tools/generate_dummy_data.py (renamed from dummy_data_generation.py)0
3 files changed, 13 insertions, 38 deletions
diff --git a/app.py b/app.py
index c4e4d89..6c1609a 100644
--- a/app.py
+++ b/app.py
@@ -26,38 +26,26 @@ def home():
def get_random_games():
print("Creating new games...")
GAME_GENERATOR.create_random_games(COURT_LIST, PLAYER_LIST)
- return render_template(
- "games.j2",
- games=GAME_GENERATOR.games,
- )
+ return render_template("games.j2", games=GAME_GENERATOR.games)
@app.route("/skilled-games", methods=["POST"])
def get_skilled_games():
print("Creating new games...")
GAME_GENERATOR.create_skilled_games(COURT_LIST, PLAYER_LIST)
- return render_template(
- "games.j2",
- games=GAME_GENERATOR.games,
- )
+ return render_template("games.j2", games=GAME_GENERATOR.games)
@app.route("/clear-games", methods=["POST"])
def clear_games():
print("Clearing games...")
GAME_GENERATOR.clear(COURT_LIST)
- return render_template(
- "games.j2",
- games=GAME_GENERATOR.games,
- )
+ return render_template("games.j2", games=GAME_GENERATOR.games)
@app.route("/game-list", methods=["GET"])
def get_list_of_games():
- return render_template(
- "games.j2",
- games=GAME_GENERATOR.games,
- )
+ return render_template("games.j2", games=GAME_GENERATOR.games)
@app.route("/player-toggle/<player_request>", methods=["POST"])
@@ -67,18 +55,12 @@ def toggle_player(player_request):
abort(404)
PLAYER_LIST.toggle_player(player_request)
selection = PLAYER_LIST.get_player(player_request)
- return render_template(
- "player.j2",
- player=selection[0],
- )
+ return render_template("player.j2", player=selection[0])
@app.route("/player-list", methods=["GET"])
def get_list_of_players():
- return render_template(
- "players.j2",
- players=PLAYER_LIST.players,
- )
+ return render_template("players.j2", players=PLAYER_LIST.players)
@app.route("/court-toggle/<court_number>", methods=["POST"])
@@ -89,15 +71,9 @@ def toggle_court(court_number):
abort(404, f"Multiple courts requested: {len(selection)}")
COURT_LIST.toggle_court(court_number)
selection = COURT_LIST.get_court(court_number)
- return render_template(
- "court.j2",
- court=selection[0],
- )
+ return render_template("court.j2", court=selection[0])
@app.route("/court-list", methods=["GET"])
def get_list_of_courts():
- return render_template(
- "courts.j2",
- courts=COURT_LIST.courts,
- )
+ return render_template("courts.j2", courts=COURT_LIST.courts)
diff --git a/model.py b/model.py
index a623d0a..c83bcfd 100644
--- a/model.py
+++ b/model.py
@@ -18,7 +18,6 @@ class CourtList:
def __post_init__(self):
self.courts = [Court(i + 1, True) for i in range(self.total)]
- self.active = self.total
def get_court(self, court_number: int):
return [court for court in self.courts if court.number == court_number]
@@ -35,7 +34,6 @@ class CourtList:
)
for court in self.courts
]
- self.active = sum([court.status for court in self.courts])
@dataclass
@@ -45,16 +43,17 @@ class Player:
status: bool = True
+def create_player_from_row(row: list[str]) -> Player:
+ return Player(name=row[0], skill=row[1], status=(row[2] == "True"))
+
+
class PlayerList:
def __init__(self, location: Path = "players.csv"):
- players = []
with open(location, newline="") as file:
data_reader = reader(file)
next(data_reader, None)
- for row in data_reader:
- player = Player(name=row[0], skill=row[1], status=(row[2] == "True"))
- players.append(player)
+ players = [create_player_from_row(row) for row in data_reader]
players.sort(key=attrgetter("name"))
self.players = players
diff --git a/dummy_data_generation.py b/tools/generate_dummy_data.py
index 3d6d116..3d6d116 100644
--- a/dummy_data_generation.py
+++ b/tools/generate_dummy_data.py