diff --git a/src/render_site.py b/src/render_site.py index dd15b82..d6a5ab0 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -616,6 +616,57 @@ def get_player_rating_progression(): return ret +def get_global_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) AS ratings, " + " array_agg(rank ORDER BY rank ASC) AS ranks," + " (array_agg(value_after ORDER BY rank DESC))[1] AS current_rating " + "FROM" + "(" + " SELECT" + " users.id," + " users.player_name," + " user_ratings.value_after," + " DENSE_RANK() OVER (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 current_rating DESC " + "LIMIT 20 ", + (rating_type, rating_type) + ) + res = cur.fetchall() + ret[rating_type] = {} + for (_, player_name, rating_progression, ranks, _) in res: + assert len(rating_progression) == len(ranks) + ret[rating_type][player_name] = [ + { + "rating": rating, + "rank": rank + } + for (rating, rank) in zip(rating_progression, ranks) + ] + return ret + def get_total_games(): cur = conn_manager.get_new_cursor() cur.execute("SELECT COUNT(league_id) FROM games") @@ -677,6 +728,7 @@ def render_main_site(env: jinja2.Environment, out_dir: Path): games = get_games() variant_ratings = get_variant_rating_progression() + player_ratings = get_global_player_rating_progression() template = env.get_template('main.html') rendered_html = template.render( @@ -690,7 +742,8 @@ def render_main_site(env: jinja2.Environment, out_dir: Path): players=players, games=[dataclasses.asdict(game) for game in games], variant_stats=var_stats, - variant_ratings=variant_ratings + variant_ratings=variant_ratings, + player_ratings=player_ratings ) output_file = out_dir / 'index.html' diff --git a/templates/main.html b/templates/main.html index 09c547c..bea40c5 100644 --- a/templates/main.html +++ b/templates/main.html @@ -125,9 +125,12 @@

-

ELO progression

+

Variant ELO progression

+

Player ELO progression

+ + {% endfor %} @@ -230,6 +233,39 @@ new Chart(ctx_{{rating_type}}, config_{{rating_type}}); {% endfor %} + {% for rating_type, rating_map in player_ratings.items() %} + let datasets_players_{{rating_type}} = []; + {% for player_name, data in rating_map.items() %} + datasets_players_{{rating_type}}.push({ + data: {{ data }}, + label: "{{player_name}}" + }); + {% endfor %} + + const config_players_{{rating_type}} = { + type: 'line', + data: { + datasets: datasets_players_{{rating_type}} + }, + options: { + parsing: { + xAxisKey: "rank", + yAxisKey: "rating" + }, + scales: { + x: { + type: 'linear', + text: 'Number of games' + } + } + } + } + const ctx_players_{{rating_type}} = document.getElementById('chart-players-{{rating_type}}'); + new Chart(ctx_players_{{rating_type}}, config_players_{{rating_type}}); + + {% endfor %} + + {% endblock %}