From d05be232b93a6c8d495d7ed55b78c31bce9f8c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 9 Jan 2024 18:41:46 +0100 Subject: [PATCH] Add ELO charts to player pages --- src/render_site.py | 47 ++++++++++++++++++++++++++++++++++++++++++- templates/player.html | 19 +++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/render_site.py b/src/render_site.py index 9d48f9f..be63e2c 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -572,6 +572,49 @@ def get_variant_rating_progression(): return ret +def get_player_rating_progression(): + cur = conn_manager.get_new_cursor() + ret = {} + for rating_type in [utils.get_rating_type(False), utils.get_rating_type(True)]: + cur.execute( + "SELECT " + " id," + " player_name," + " array_agg(value_after ORDER BY rank ASC) " + "FROM" + "(" + " SELECT" + " users.id," + " users.player_name," + " user_ratings.value_after," + " RANK() OVER (PARTITION BY user_id ORDER BY league_id ASC) AS rank" + " FROM users" + " INNER JOIN user_ratings" + " ON users.id = user_ratings.user_id" + " WHERE user_ratings.rating_type = %s" + " UNION " + " SELECT" + " users.id," + " users.player_name," + " user_base_ratings.rating AS value_after," + " 0 AS rank" + " FROM users" + " INNER JOIN user_base_ratings" + " ON users.id = user_base_ratings.user_id" + " WHERE user_base_ratings.rating_type = %s" + ") AS t " + "GROUP BY id, player_name " + "ORDER BY id ", + (rating_type, rating_type) + ) + res = cur.fetchall() + for (_, player_name, rating_progression) in res: + if not player_name in ret.keys(): + ret[player_name] = {} + ret[player_name][rating_type] = rating_progression + return ret + + def get_total_games(): cur = conn_manager.get_new_cursor() cur.execute("SELECT COUNT(league_id) FROM games") @@ -711,6 +754,7 @@ def render_player_pages(env: jinja2.Environment, out_dir: Path): games = get_games() games_grouped_by_player = group_games_by_player(games) + player_rating_progression = get_player_rating_progression() player_template = env.get_template('player.html') for player_name, player_stat in player_stats.items(): @@ -720,7 +764,8 @@ def render_player_pages(env: jinja2.Environment, out_dir: Path): latest_run=datetime.datetime.now().isoformat(), player_name=player_name, player_stat=player_stat, - player_games=games_grouped_by_player.get(player_name, []) + player_games=games_grouped_by_player.get(player_name, []), + player_rating_progression=player_rating_progression.get(player_name, []) ) output_file = out_dir / 'player' / player_name / 'index.html' diff --git a/templates/player.html b/templates/player.html index 814bcf8..1af19ed 100644 --- a/templates/player.html +++ b/templates/player.html @@ -36,6 +36,7 @@ {{ stats_list(player_row.stats, True, True) }}
+ {% endfor %} @@ -55,5 +56,23 @@ table_{{rating_type}}.setFilter("rating_type", "=", {{rating_type}}); {% endfor %} + + {% endblock %}