add list of games to variant pages

This commit is contained in:
Maximilian Keßler 2023-12-27 18:39:51 +01:00
parent 1481817a72
commit 5af11b9134
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 36 additions and 7 deletions

View file

@ -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()

View file

@ -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 %}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
@ -70,11 +70,20 @@
</div>
</div>
<script>
let tabledata = [
{% for game in games %}
{{- game -}},
{% endfor %}
];
</script>
{% for rating_type, leaders in leaders.items() %}
<div class="tab-pane fade" id="leaderboards-{{rating_type}}">
<div class="container my-5">
<!-- Leaderboards -->
<h3>Leaderboards</h3>
<div id="leaderboards-{{rating_type}}-data" class="accordion">
{% for category, leaderboard in leaderboards.items() %}
<div class="card">
@ -107,10 +116,17 @@
{% endfor %}
</div>
<br>
<!-- List of games -->
<h3>List of played games</h3>
<div id="table-{{rating_type}}"></div>
</div>
</div>
{% endfor %}
<div class="tab-pane fade" id="players">
<div class="container my-5">
<div id="table-players"></div>
@ -163,4 +179,12 @@
</div>
</div>
<script>
{% for rating_type in leaders %}
{{ games_table_js("tabledata", rating_type, True, False, False) }}
table_{{rating_type}}.setFilter("rating_type", "=", {{rating_type}});
{% endfor %}
</script>
{% endblock %}