From de146b779ad390a56123921bca55765fafb935c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 5 Dec 2023 15:44:08 +0100 Subject: [PATCH] interactive tables for game history on variants --- src/render_site.py | 16 +++++++++++++- templates/variant.html | 50 +++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/render_site.py b/src/render_site.py index bf0a7c9..c196a4c 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -150,6 +150,17 @@ def get_games(): return [GameRow(**row) for row in cur.fetchall()] +def group_games_by_var_id_and_num_players(games: List[GameRow]): + ret = {} + for game in games: + if game.variant_id not in ret.keys(): + ret[game.variant_id] = {} + if game.num_players not in ret[game.variant_id].keys(): + ret[game.variant_id][game.num_players] = [] + ret[game.variant_id][game.num_players].append(dataclasses.asdict(game)) + return ret + + def get_rating_lists() -> Dict[int, List[PlayerEntry]]: cur = conn_manager.get_connection().cursor() rating_types = [utils.get_rating_type(x) for x in [False, True]] @@ -338,6 +349,9 @@ def render_leaderboard(): with open(output_file, 'w') as f: f.write(rendered_html) + games = get_games() + grouped_games = group_games_by_var_id_and_num_players(games) + variant_template = env.get_template('variant.html') for variant_id, stats in variant_stats.items(): rendered_var = variant_template.render( @@ -346,7 +360,7 @@ def render_leaderboard(): latest_run=datetime.datetime.now().isoformat(), variant_stats=stats, variant_name=variant_names[variant_id], - games=[dataclasses.asdict(game) for game in get_games()] + variant_games=grouped_games.get(variant_id,{}) ) output_file = out_dir / 'variant' / str(variant_id) / 'index.html' diff --git a/templates/variant.html b/templates/variant.html index 7870136..1b9c2c2 100644 --- a/templates/variant.html +++ b/templates/variant.html @@ -89,29 +89,43 @@
- {% endfor %} + + +