simply variant tables: less data repetition

This commit is contained in:
Maximilian Keßler 2023-12-07 16:37:55 +01:00
parent f90a98765b
commit 29e0e9b189
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 56 additions and 45 deletions

View file

@ -169,17 +169,6 @@ def get_games():
return res return res
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 group_games_by_var_id(games: List[GameRow]): def group_games_by_var_id(games: List[GameRow]):
ret = {} ret = {}
for game in games: for game in games:
@ -382,7 +371,6 @@ def render_leaderboard():
f.write(rendered_html) f.write(rendered_html)
games = get_games() games = get_games()
grouped_games_var_players = group_games_by_var_id_and_num_players(games)
grouped_games_var = group_games_by_var_id(games) grouped_games_var = group_games_by_var_id(games)
variant_template = env.get_template('variant.html') variant_template = env.get_template('variant.html')
@ -394,7 +382,6 @@ def render_leaderboard():
variant_stats_by_player=by_player_stats, variant_stats_by_player=by_player_stats,
variant_stats=variant_stats.get(variant_id, VariantStats), variant_stats=variant_stats.get(variant_id, VariantStats),
variant_name=variant_names[variant_id], variant_name=variant_names[variant_id],
variant_games_by_player=grouped_games_var_players.get(variant_id, {}),
variant_games=grouped_games_var.get(variant_id, []) variant_games=grouped_games_var.get(variant_id, [])
) )

View file

@ -50,4 +50,36 @@
</li> </li>
</ul> </ul>
</div> </div>
{% endmacro %}} {% endmacro %}
{% macro games_table_js(data, div_id, show_player_num, show_var_rating) %}
var table_{{div_id}} = new Tabulator("#table-{{div_id}}", {
height: 400,
data: {{data}},
layout: "fitDataStretch",
columns: [
{title: "id", field: "league_id"},
{title: "Game", field: "game_id", formatter: "link", formatterParams:{
urlPrefix: "https://hanab.live/replay/",
target:"_blank"
}},
{% if show_player_num %}
{title: "# Players", field: "num_players"},
{% endif %}
{% if show_var_rating %}
{title: "Rating Change", field: "variant_rating_change"},
{title: "Rating After", field: "variant_rating_after"},
{% endif %}
{title: "Players", field: "users"},
{title: "Seed", field: "seed", formatter: "link", formatterParams: {
urlPrefix: "https://hanab.live/seed/",
target:"_blank"
}},
{title: "Score", field: "score"},
{title: "BDR", field: "num_bdrs"},
{title: "Turns", field: "num_turns"},
{title: "Result", field: "game_outcomes"}
],
});
{% endmacro %}

View file

@ -1,5 +1,5 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% from "stats_table.html" import stats_list %} {% from "stats_table.html" import stats_list, games_table_js %}
{% block navbar %} {% block navbar %}
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <nav class="navbar navbar-expand-lg navbar-light bg-light">
@ -33,6 +33,14 @@
League Statistics for {{variant_name}} League Statistics for {{variant_name}}
</h3> </h3>
{{ stats_list(variant_stats, False) }} {{ stats_list(variant_stats, False) }}
<h4>
List of Played Games
</h4>
{% if variant_stats.games_played == 0 %}
There have been no games played on this variant so far.
{% else %}
<div id="table-overview"></div>
{% endif %}
</div> </div>
</div> </div>
@ -49,7 +57,7 @@
{% if num_player_stats.games_played == 0 %} {% if num_player_stats.games_played == 0 %}
There have been no games played on this variant with {{num_players}} players so far. There have been no games played on this variant with {{num_players}} players so far.
{% else %} {% else %}
<div id="table-{{num_players}}p"></div> <div id="table-{{num_players}}"></div>
{% endif %} {% endif %}
</div> </div>
</div> </div>
@ -58,36 +66,20 @@
<!-- JavaScript part for the interactive tables --> <!-- JavaScript part for the interactive tables -->
<script> <script>
{% for num_players, games in variant_games_by_player.items() %} // Tabledata
let tabledata_{{num_players}} = [ let tabledata = [
{% for game in games %} {% for game in variant_games %}
{{game }}, {{- game -}},
{% endfor %} {% endfor %}
]; ];
var table_{{num_players}} = new Tabulator("#table-{{num_players}}p", { // Main table
height: 400, {{ games_table_js("tabledata", "overview", True, False) }}
data:tabledata_{{num_players}},
layout:"fitDataStretch", {% for num_players in variant_stats_by_player.keys() %}
columns: [ {{ games_table_js("tabledata", num_players, False, True) }}
{title: "id", field: "league_id"}, // Filter table on corresponding page to only display games with corresponding player number
{title: "Game", field: "game_id", formatter: "link", formatterParams:{ table_{{num_players}}.setFilter("num_players", "=", {{num_players}});
urlPrefix: "https://hanab.live/replay/",
target:"_blank"
}},
{title: "Rating Change", field: "variant_rating_change"},
{title: "Rating After", field: "variant_rating_after"},
{title: "Players", field: "users"},
{title: "Seed", field: "seed", formatter: "link", formatterParams: {
urlPrefix: "https://hanab.live/seed/",
target:"_blank"
}},
{title: "Score", field: "score"},
{title: "BDR", field: "num_bdrs"},
{title: "Turns", field: "num_turns"},
{title: "Result", field: "game_outcomes"}
],
});
{% endfor %} {% endfor %}
</script> </script>
{% endblock %} {% endblock %}