forked from Hanabi/hanabi-league
interactive tables for game history on variants
This commit is contained in:
parent
31f71c6d5c
commit
de146b779a
2 changed files with 47 additions and 19 deletions
|
@ -150,6 +150,17 @@ def get_games():
|
||||||
return [GameRow(**row) for row in cur.fetchall()]
|
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]]:
|
def get_rating_lists() -> Dict[int, List[PlayerEntry]]:
|
||||||
cur = conn_manager.get_connection().cursor()
|
cur = conn_manager.get_connection().cursor()
|
||||||
rating_types = [utils.get_rating_type(x) for x in [False, True]]
|
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:
|
with open(output_file, 'w') as f:
|
||||||
f.write(rendered_html)
|
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')
|
variant_template = env.get_template('variant.html')
|
||||||
for variant_id, stats in variant_stats.items():
|
for variant_id, stats in variant_stats.items():
|
||||||
rendered_var = variant_template.render(
|
rendered_var = variant_template.render(
|
||||||
|
@ -346,7 +360,7 @@ def render_leaderboard():
|
||||||
latest_run=datetime.datetime.now().isoformat(),
|
latest_run=datetime.datetime.now().isoformat(),
|
||||||
variant_stats=stats,
|
variant_stats=stats,
|
||||||
variant_name=variant_names[variant_id],
|
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'
|
output_file = out_dir / 'variant' / str(variant_id) / 'index.html'
|
||||||
|
|
|
@ -89,28 +89,42 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="table-{{num_players}}p"></div>
|
<div id="table-{{num_players}}p"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- JavaScript part for the interactive tables -->
|
||||||
<script>
|
<script>
|
||||||
|
{% for num_players, games in variant_games.items() %}
|
||||||
let tabledata_{{num_players}} = [
|
let tabledata_{{num_players}} = [
|
||||||
{% for game in games %}
|
{% for game in games %}
|
||||||
{{game }},
|
{{game }},
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
];
|
];
|
||||||
|
|
||||||
var table = new Tabulator("#table-{{num_players}}p", {
|
var table_{{num_players}} = new Tabulator("#table-{{num_players}}p", {
|
||||||
height: 205,
|
height: 205,
|
||||||
data:tabledata_{{num_players}},
|
data:tabledata_{{num_players}},
|
||||||
layout:"fitColumns",
|
layout:"fitColumns",
|
||||||
columns: [
|
columns: [
|
||||||
{title: "Game", field: "game_id", width: 150},
|
{title: "id", field: "league_id"},
|
||||||
{title: "# Players", field: "num_players", width:200},
|
{title: "Game", field: "game_id", formatter: "link", formatterParams:{
|
||||||
{title: "Seed", field: "seed"},
|
urlPrefix: "https://hanab.live/replay/",
|
||||||
|
target:"_blank"
|
||||||
|
}},
|
||||||
|
{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: "Result", field: "game_outcomes"}
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</script>
|
||||||
|
|
||||||
<footer class="footer mt-auto py-3 bg-light">
|
<footer class="footer mt-auto py-3 bg-light">
|
||||||
<div class="container text-center">
|
<div class="container text-center">
|
||||||
|
|
Loading…
Reference in a new issue