add variant page to website
This commit is contained in:
parent
97f5a8459a
commit
74a2bd7d50
2 changed files with 80 additions and 1 deletions
|
@ -26,6 +26,15 @@ class Leader:
|
|||
entry: PlayerEntry
|
||||
|
||||
|
||||
@dataclass
|
||||
class VariantStats:
|
||||
name: str
|
||||
num_players: int
|
||||
rating: int
|
||||
games_played: int
|
||||
games_won: int
|
||||
|
||||
|
||||
def get_rating_lists() -> Dict[int, List[PlayerEntry]]:
|
||||
cur = conn_manager.get_connection().cursor()
|
||||
rating_types = [utils.get_rating_type(x) for x in [False, True]]
|
||||
|
@ -105,6 +114,43 @@ def get_streak_lists():
|
|||
return leaderboard
|
||||
|
||||
|
||||
def get_variant_ratings():
|
||||
cur = conn_manager.get_new_cursor()
|
||||
cur.execute(
|
||||
"SELECT"
|
||||
" ratings.name,"
|
||||
" ratings.num_players,"
|
||||
" current_rating,"
|
||||
" COUNT(games.id) AS games_played,"
|
||||
" COUNT(games.id) FILTER (WHERE ratings.num_suits * 5 = games.score) AS games_won "
|
||||
"FROM "
|
||||
" ("
|
||||
" SELECT DISTINCT ON (variants.id, variant_base_ratings.num_players)"
|
||||
" variants.id,"
|
||||
" variants.num_suits,"
|
||||
" name,"
|
||||
" variant_base_ratings.num_players,"
|
||||
" COALESCE(variant_ratings.value_after, variant_base_ratings.rating) AS current_rating "
|
||||
" FROM variants "
|
||||
" LEFT OUTER JOIN variant_base_ratings"
|
||||
" ON variants.id = variant_base_ratings.variant_id "
|
||||
" LEFT OUTER JOIN variant_ratings "
|
||||
" ON variant_ratings.variant_id = variant_base_ratings.variant_id AND variant_ratings.num_players = variant_base_ratings.num_players "
|
||||
" GROUP BY (variants.id, name, variant_base_ratings.num_players, variant_base_ratings.rating, variant_ratings.league_id, variant_ratings.value_after) "
|
||||
" ORDER BY variants.id, variant_base_ratings.num_players, league_id DESC"
|
||||
" ) AS ratings "
|
||||
"LEFT OUTER JOIN games "
|
||||
" ON games.variant_id = ratings.id AND games.num_players = ratings.num_players "
|
||||
"GROUP BY (ratings.id, ratings.name, ratings.num_players, ratings.current_rating)"
|
||||
"ORDER BY (ratings.id, ratings.num_players)"
|
||||
""
|
||||
)
|
||||
return [
|
||||
VariantStats(variant_name, num_players, rating, games_played, games_won)
|
||||
for (variant_name, num_players, rating, games_played, games_won) in cur.fetchall()
|
||||
]
|
||||
|
||||
|
||||
def get_total_games():
|
||||
cur = conn_manager.get_new_cursor()
|
||||
cur.execute("SELECT COUNT(league_id) FROM games")
|
||||
|
@ -137,7 +183,8 @@ def render_leaderboard():
|
|||
leaderboards=leaderboards,
|
||||
total_games_played=get_total_games(),
|
||||
total_players=get_num_players(),
|
||||
latest_run=datetime.datetime.now().isoformat()
|
||||
latest_run=datetime.datetime.now().isoformat(),
|
||||
variants=get_variant_ratings()
|
||||
# variants=variants,
|
||||
)
|
||||
output_file = Path(constants.WEBSITE_OUTPUT_DIRECTORY) / 'index.html'
|
||||
|
@ -145,4 +192,5 @@ def render_leaderboard():
|
|||
with open(output_file, 'w') as f:
|
||||
f.write(rendered_html)
|
||||
|
||||
|
||||
render_leaderboard()
|
||||
|
|
|
@ -49,5 +49,36 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
<!-- Variants -->
|
||||
<div class="tab-pane fade" id="variants">
|
||||
<div class="container my-5">
|
||||
<table class="table table-hover table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="text-center">Variant</th>
|
||||
<th scope="col" class="text-center">Player count</th>
|
||||
<th scope="col" class="text-center">Rating</th>
|
||||
<th scope="col" class="text-center">Games Played</th>
|
||||
<th scope="col" class="text-center">Max Scores</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for variant in variants %}
|
||||
<tr>
|
||||
<td class="text-center"><strong>{{ variant.name }}</strong></td>
|
||||
<td class="text-center">{{ variant.num_players }}</td>
|
||||
<td class="text-center variant-rating">{{ variant.rating | int }}</td>
|
||||
<td class="text-center">{{ variant.games_played }}</td>
|
||||
<td class="text-center">{{ variant.games_won }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue