From 1b3ca35dd66cf32af080376a0c6d99c3d1d11e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 5 Dec 2023 16:02:08 +0100 Subject: [PATCH] use string representations for game outcomes --- requirements.txt | 1 + src/render_site.py | 8 ++++++-- src/stats.py | 19 ++++++++++--------- templates/variant.html | 4 ++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1f30fd8..bbee653 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ requests requests_cache termcolor jinja2 +aenum diff --git a/src/render_site.py b/src/render_site.py index c196a4c..0e9b455 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -91,7 +91,7 @@ class GameRow: league_id: int num_bdrs: int num_crits_lost: int - game_outcomes: List[stats.GameOutcome] + game_outcomes: List[str] def get_games(): @@ -147,7 +147,11 @@ def get_games(): " ) " "ORDER BY league_id DESC" ) - return [GameRow(**row) for row in cur.fetchall()] + res = [] + for row in cur.fetchall(): + row['game_outcomes'] = [stats.GameOutcome(outcome).string for outcome in row['game_outcomes']] + res.append(GameRow(**row)) + return res def group_games_by_var_id_and_num_players(games: List[GameRow]): diff --git a/src/stats.py b/src/stats.py index ad8907c..de763a8 100644 --- a/src/stats.py +++ b/src/stats.py @@ -1,4 +1,4 @@ -import enum +import aenum from typing import List, Tuple, Set import psycopg2.extras @@ -10,14 +10,15 @@ import games_db_interface from log_setup import logger -class GameOutcome(enum.Enum): - win = 0 - discard_crit = 1 - bomb_crit = 2 - strikeout = 3 - bottom_deck = 4 - vote_to_kill = 5 - out_of_pace = 6 +class GameOutcome(aenum.Enum): + _init_ = 'value string' + win = 0, 'Win' + discard_crit = 1, 'Discard Critical' + bomb_crit = 2, 'Bomb Critical' + strikeout = 3, 'Strikeout' + bottom_deck = 4, 'Bottom Deck' + vote_to_kill = 5, 'Vote to Kill' + out_of_pace = 6, 'Out of Pace' class GameAnalysisResult: diff --git a/templates/variant.html b/templates/variant.html index 1b9c2c2..269db89 100644 --- a/templates/variant.html +++ b/templates/variant.html @@ -104,9 +104,9 @@ ]; var table_{{num_players}} = new Tabulator("#table-{{num_players}}p", { - height: 205, + height: 400, data:tabledata_{{num_players}}, - layout:"fitColumns", + layout:"fitDataStretch", columns: [ {title: "id", field: "league_id"}, {title: "Game", field: "game_id", formatter: "link", formatterParams:{