diff --git a/src/render_site.py b/src/render_site.py index a29c1c2..db87361 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -26,6 +26,15 @@ class Leader: entry: PlayerEntry +@dataclass +class VariantStats: + name: str + num_players: int + rating: int + games_played: int + games_won: int + + 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]] @@ -105,6 +114,43 @@ def get_streak_lists(): return leaderboard +def get_variant_ratings(): + cur = conn_manager.get_new_cursor() + cur.execute( + "SELECT" + " ratings.name," + " ratings.num_players," + " current_rating," + " COUNT(games.id) AS games_played," + " COUNT(games.id) FILTER (WHERE ratings.num_suits * 5 = games.score) AS games_won " + "FROM " + " (" + " SELECT DISTINCT ON (variants.id, variant_base_ratings.num_players)" + " variants.id," + " variants.num_suits," + " name," + " variant_base_ratings.num_players," + " COALESCE(variant_ratings.value_after, variant_base_ratings.rating) AS current_rating " + " FROM variants " + " LEFT OUTER JOIN variant_base_ratings" + " ON variants.id = variant_base_ratings.variant_id " + " LEFT OUTER JOIN variant_ratings " + " ON variant_ratings.variant_id = variant_base_ratings.variant_id 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) " + " ORDER BY variants.id, variant_base_ratings.num_players, league_id DESC" + " ) AS ratings " + "LEFT OUTER JOIN games " + " ON games.variant_id = ratings.id AND games.num_players = ratings.num_players " + "GROUP BY (ratings.id, ratings.name, ratings.num_players, ratings.current_rating)" + "ORDER BY (ratings.id, ratings.num_players)" + "" + ) + return [ + VariantStats(variant_name, num_players, rating, games_played, games_won) + for (variant_name, num_players, rating, games_played, games_won) in cur.fetchall() + ] + + def get_total_games(): cur = conn_manager.get_new_cursor() cur.execute("SELECT COUNT(league_id) FROM games") @@ -137,7 +183,8 @@ def render_leaderboard(): leaderboards=leaderboards, total_games_played=get_total_games(), total_players=get_num_players(), - latest_run=datetime.datetime.now().isoformat() + latest_run=datetime.datetime.now().isoformat(), + variants=get_variant_ratings() # variants=variants, ) output_file = Path(constants.WEBSITE_OUTPUT_DIRECTORY) / 'index.html' @@ -145,4 +192,5 @@ def render_leaderboard(): with open(output_file, 'w') as f: f.write(rendered_html) + render_leaderboard() diff --git a/templates/content.html b/templates/content.html index c7a98dd..4233da6 100644 --- a/templates/content.html +++ b/templates/content.html @@ -49,5 +49,36 @@ {% endfor %} + + + +
Variant | +Player count | +Rating | +Games Played | +Max Scores | +
---|---|---|---|---|
{{ variant.name }} | +{{ variant.num_players }} | +{{ variant.rating | int }} | +{{ variant.games_played }} | +{{ variant.games_won }} | +