Add ELO charts to player pages
This commit is contained in:
parent
1d07cf67b1
commit
d05be232b9
2 changed files with 65 additions and 1 deletions
|
@ -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'
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
</h4>
|
||||
{{ stats_list(player_row.stats, True, True) }}
|
||||
<div id="table-{{rating_type}}"></div>
|
||||
<canvas id="chart-{{rating_type}}"></canvas>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -55,5 +56,23 @@
|
|||
table_{{rating_type}}.setFilter("rating_type", "=", {{rating_type}});
|
||||
{% endfor %}
|
||||
</script>
|
||||
<!-- JavaScript part for the rating chart -->
|
||||
<script>
|
||||
{% for rating_type, progression in player_rating_progression.items() %}
|
||||
rating_progression_{{rating_type}} = {{progression}};
|
||||
const config_{{rating_type}} = {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: Array.from({length: rating_progression_{{rating_type}}.length}, (_, i) => i),
|
||||
datasets: [{
|
||||
label: 'Rating',
|
||||
data: rating_progression_{{rating_type}}
|
||||
}]
|
||||
}
|
||||
};
|
||||
const ctx_{{rating_type}} = document.getElementById('chart-{{rating_type}}');
|
||||
new Chart(ctx_{{rating_type}}, config_{{rating_type}});
|
||||
{% endfor %}
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue