From 66a08496d8a58b0b0073c2edb1cf453f6cf4b57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 26 Dec 2023 13:47:31 +0100 Subject: [PATCH] stats page: add list of variant ratings --- src/render_site.py | 13 ++++++++----- templates/stats_table.html | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/render_site.py b/src/render_site.py index c859db0..211c202 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -79,13 +79,17 @@ class GeneralStats: def __iadd__(self, other): for field in dataclasses.fields(self): - setattr(self, field.name, getattr(self, field.name) + getattr(other, field.name)) + # This is a slight hack: For lists, we left-fold into lists on concatenation + if type(getattr(self, field.name)) == list: + setattr(self, field.name, getattr(self, field.name) + [getattr(other, field.name)]) + else: + setattr(self, field.name, getattr(self, field.name) + getattr(other, field.name)) return self @dataclass class VariantStats(GeneralStats): - rating: int = 0 + rating: int | List[int] = 0 @dataclass @@ -360,7 +364,6 @@ def get_streak_list() -> Dict[int, List[PlayerStreakEntry]]: ) for (player_name, rank, user_accounts, max_streak, current_streak) in cur.fetchall(): leaderboard[rating_type].append(PlayerStreakEntry(player_name, user_accounts, max_streak, rank, current_streak)) - print(leaderboard) return leaderboard @@ -544,12 +547,13 @@ def build_variant_stats_by_variant(variant_rows: List[VariantRow]): if row.variant_id not in variant_stats_per_player.keys(): variant_stats_per_player[row.variant_id] = {} if row.variant_id not in variant_stats.keys(): - variant_stats[row.variant_id] = VariantStats() + variant_stats[row.variant_id] = VariantStats(rating=[]) if row.variant_id not in variant_names.keys(): variant_names[row.variant_id] = {} variant_stats_per_player[row.variant_id][row.num_players] = row.stats variant_names[row.variant_id] = row.name variant_stats[row.variant_id] += row.stats + print(variant_stats) return variant_stats, variant_stats_per_player, variant_names @@ -638,7 +642,6 @@ def render_player_pages(env: jinja2.Environment, out_dir: Path): games = get_games() games_grouped_by_player = group_games_by_player(games) - print(games_grouped_by_player) player_template = env.get_template('player.html') for player_name, player_stat in player_stats.items(): diff --git a/templates/stats_table.html b/templates/stats_table.html index 5b0699d..df063ec 100644 --- a/templates/stats_table.html +++ b/templates/stats_table.html @@ -7,7 +7,7 @@ {% if show_rating %} {{stats.rating}} {% else %} - - + {{ stats.rating|join(", ")}} {% endif %} {% if show_streaks %}