diff --git a/src/render_site.py b/src/render_site.py index cb74b3e..db6039d 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -531,33 +531,44 @@ def get_player_list() -> List[Dict]: def get_variant_rating_progression(): cur = conn_manager.get_new_cursor() - cur.execute( - "SELECT " - " variants.rating_type," - " variants.name," - " variant_ratings.num_players," - " variant_ratings.value_after," - " games.datetime_finished," - " dense_rank() over (order by games.league_id desc) " - "FROM variants " - "INNER JOIN variant_ratings" - " ON variants.id = variant_ratings.variant_id " - "INNER JOIN games " - " ON variant_ratings.league_id = games.league_id" - ) ret = {} - for (rating_type, name, num_players, value_after, datetime_finished, rank) in cur.fetchall(): - if rating_type not in ret.keys(): - ret[rating_type] = {} - if name not in ret[rating_type].keys(): - ret[rating_type][name] = {} - if num_players not in ret[rating_type][name].keys(): - ret[rating_type][name][num_players] = [] - ret[rating_type][name][num_players].append({ - "value_after": value_after, - "datetime_finished": datetime_finished.astimezone(datetime.timezone.utc).isoformat(), - "rank": rank - }) + for rating_type in [utils.get_rating_type(False), utils.get_rating_type(True)]: + cur.execute( + "SELECT * FROM" + "(" + " SELECT " + " variants.name," + " variant_ratings.num_players," + " variant_ratings.value_after," + " DENSE_RANK() OVER (ORDER BY league_id ASC) AS rank" + " FROM variants " + " INNER JOIN variant_ratings" + " ON variants.id = variant_ratings.variant_id " + " WHERE variants.rating_type = %s " + " UNION " + " SELECT " + " variants.name," + " variant_base_ratings.num_players," + " variant_base_ratings.rating," + " 0 AS rank" + " FROM variants " + " INNER JOIN variant_base_ratings" + " ON variants.id = variant_base_ratings.variant_id " + " WHERE variants.rating_type = %s" + ") " + "ORDER BY rank", + (rating_type, rating_type) + ) + ret[rating_type] = {} + for (name, num_players, rating, rank) in cur.fetchall(): + if name not in ret[rating_type].keys(): + ret[rating_type][name] = {} + if num_players not in ret[rating_type][name].keys(): + ret[rating_type][name][num_players] = [] + ret[rating_type][name][num_players].append({ + "rating": rating, + "rank": rank + }) return ret diff --git a/templates/main.html b/templates/main.html index c06aa26..e74338a 100644 --- a/templates/main.html +++ b/templates/main.html @@ -124,6 +124,7 @@

List of played games

+

ELO progression

@@ -214,12 +215,13 @@ }, options: { parsing: { - xAxisKey: "datetime_finished", - yAxisKey: "value_after" + xAxisKey: "rank", + yAxisKey: "rating" }, scales: { x: { - type: 'time' + type: 'linear', + text: 'Number of games' } } }