From 5af11b91345b19ad1fdd36992705b60ba31e5261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Wed, 27 Dec 2023 18:39:51 +0100 Subject: [PATCH] add list of games to variant pages --- src/render_site.py | 17 +++++++++++------ templates/main.html | 26 +++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/render_site.py b/src/render_site.py index f397693..67b8f88 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -97,6 +97,7 @@ class VariantRow: variant_id: int name: str num_players: int + rating_type: int stats: VariantStats @@ -375,6 +376,7 @@ def get_variant_rows() -> List[VariantRow]: " ratings.name," " ratings.num_players," " current_rating," + " rating_type," " COUNT(games.id) AS games_played," " COUNT(games.id) FILTER (WHERE ratings.num_suits * 5 = games.score) AS games_won," " COALESCE(SUM(game_statistics.num_bottom_deck_risks), 0) AS total_bdr," @@ -386,6 +388,7 @@ def get_variant_rows() -> List[VariantRow]: " variants.id," " variants.num_suits," " variants.clue_starved," + " variants.rating_type," " name," " variant_base_ratings.num_players," " COALESCE(variant_ratings.value_after, variant_base_ratings.rating) AS current_rating " @@ -397,7 +400,7 @@ def get_variant_rows() -> List[VariantRow]: " AND variant_ratings.num_players = variant_base_ratings.num_players " " GROUP BY (" " variants.id, name, variant_base_ratings.num_players, variant_base_ratings.rating," - " variant_ratings.league_id, variant_ratings.value_after" + " variant_ratings.league_id, variant_ratings.value_after, variants.rating_type" " ) " " ORDER BY variants.id, variant_base_ratings.num_players, league_id DESC" " ) AS ratings " @@ -405,13 +408,13 @@ def get_variant_rows() -> List[VariantRow]: " ON games.variant_id = ratings.id AND games.num_players = ratings.num_players " "LEFT OUTER JOIN game_statistics" " ON games.id = game_statistics.game_id " - "GROUP BY (ratings.id, ratings.name, ratings.clue_starved, ratings.num_players, ratings.current_rating, ratings.num_suits)" + "GROUP BY (ratings.id, ratings.name, ratings.clue_starved, ratings.num_players, ratings.current_rating, ratings.num_suits, rating_type)" "ORDER BY (ratings.clue_starved, ratings.num_suits, ratings.num_players)" "" ) return [ - VariantRow(variant_id, variant_name, num_players, VariantStats(games_played, games_won, total_bdr, total_crits_lost, total_turns, round(rating))) - for (variant_id, variant_name, num_players, rating, games_played, games_won, total_bdr, total_crits_lost, total_turns) in cur.fetchall() + VariantRow(variant_id, variant_name, num_players, rating_type, VariantStats(games_played, games_won, total_bdr, total_crits_lost, total_turns, round(rating))) + for (variant_id, variant_name, num_players, rating, rating_type, games_played, games_won, total_bdr, total_crits_lost, total_turns) in cur.fetchall() ] @@ -573,6 +576,8 @@ def render_main_site(env: jinja2.Environment, out_dir: Path): 'Maximum Streak (Current Streak)': streak_lists, } + games = get_games() + template = env.get_template('main.html') rendered_html = template.render( leaders=leaders, @@ -582,7 +587,8 @@ def render_main_site(env: jinja2.Environment, out_dir: Path): latest_run=datetime.datetime.now().isoformat(), variants_with_player_nums=variant_rows, unique_variants=build_unique_variants(variant_rows), - players=players + players=players, + games=[dataclasses.asdict(game) for game in games] # variants=variants, ) @@ -674,6 +680,5 @@ def render_all(): if __name__ == "__main__": - get_player_list() render_all() diff --git a/templates/main.html b/templates/main.html index 1f2ebf5..f930e6b 100644 --- a/templates/main.html +++ b/templates/main.html @@ -1,5 +1,5 @@ {% extends "layout.html" %} -{% from "stats_table.html" import player_table_js %} +{% from "stats_table.html" import player_table_js, games_table_js %} {% block navbar %}