forked from Hanabi/hanabi-league
Add charts with player elo progression
This commit is contained in:
parent
7e1d0d4b7c
commit
869598a886
2 changed files with 91 additions and 2 deletions
|
@ -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'
|
||||
|
|
|
@ -125,9 +125,12 @@
|
|||
<div id="table-{{rating_type}}"></div>
|
||||
|
||||
<br>
|
||||
<h3>ELO progression</h3>
|
||||
<h3>Variant ELO progression</h3>
|
||||
<canvas id="chart-{{rating_type}}"></canvas>
|
||||
|
||||
<h3>Player ELO progression</h3>
|
||||
<canvas id="chart-players-{{rating_type}}"></canvas>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% 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 %}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue