forked from Hanabi/hanabi-league
simply variant tables: less data repetition
This commit is contained in:
parent
f90a98765b
commit
29e0e9b189
3 changed files with 56 additions and 45 deletions
|
@ -169,17 +169,6 @@ def get_games():
|
|||
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]):
|
||||
ret = {}
|
||||
for game in games:
|
||||
|
@ -382,7 +371,6 @@ def render_leaderboard():
|
|||
f.write(rendered_html)
|
||||
|
||||
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)
|
||||
|
||||
variant_template = env.get_template('variant.html')
|
||||
|
@ -394,7 +382,6 @@ def render_leaderboard():
|
|||
variant_stats_by_player=by_player_stats,
|
||||
variant_stats=variant_stats.get(variant_id, VariantStats),
|
||||
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, [])
|
||||
)
|
||||
|
||||
|
|
|
@ -50,4 +50,36 @@
|
|||
</li>
|
||||
</ul>
|
||||
</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 %}
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "layout.html" %}
|
||||
{% from "stats_table.html" import stats_list %}
|
||||
{% from "stats_table.html" import stats_list, games_table_js %}
|
||||
|
||||
{% block navbar %}
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
|
@ -33,6 +33,14 @@
|
|||
League Statistics for {{variant_name}}
|
||||
</h3>
|
||||
{{ 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>
|
||||
|
||||
|
@ -49,7 +57,7 @@
|
|||
{% if num_player_stats.games_played == 0 %}
|
||||
There have been no games played on this variant with {{num_players}} players so far.
|
||||
{% else %}
|
||||
<div id="table-{{num_players}}p"></div>
|
||||
<div id="table-{{num_players}}"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -58,36 +66,20 @@
|
|||
|
||||
<!-- JavaScript part for the interactive tables -->
|
||||
<script>
|
||||
{% for num_players, games in variant_games_by_player.items() %}
|
||||
let tabledata_{{num_players}} = [
|
||||
{% for game in games %}
|
||||
{{game }},
|
||||
// Tabledata
|
||||
let tabledata = [
|
||||
{% for game in variant_games %}
|
||||
{{- game -}},
|
||||
{% endfor %}
|
||||
];
|
||||
|
||||
var table_{{num_players}} = new Tabulator("#table-{{num_players}}p", {
|
||||
height: 400,
|
||||
data:tabledata_{{num_players}},
|
||||
layout:"fitDataStretch",
|
||||
columns: [
|
||||
{title: "id", field: "league_id"},
|
||||
{title: "Game", field: "game_id", formatter: "link", formatterParams:{
|
||||
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"}
|
||||
],
|
||||
});
|
||||
// Main table
|
||||
{{ games_table_js("tabledata", "overview", True, False) }}
|
||||
|
||||
{% for num_players in variant_stats_by_player.keys() %}
|
||||
{{ games_table_js("tabledata", num_players, False, True) }}
|
||||
// Filter table on corresponding page to only display games with corresponding player number
|
||||
table_{{num_players}}.setFilter("num_players", "=", {{num_players}});
|
||||
{% endfor %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue