add more stats to webpage
This commit is contained in:
parent
d272c4f549
commit
230d96ae1b
1 changed files with 17 additions and 9 deletions
|
@ -85,7 +85,7 @@ def get_leaders(rating_lists: Dict, streak_lists: Dict) -> Dict[int, Dict[str, L
|
|||
return leaders
|
||||
|
||||
|
||||
def get_streak_lists():
|
||||
def get_stat_lists(stat_type: str, order_type: str = 'DESC', precision: int = 0, default: float | int = 0, percents: bool = False):
|
||||
cur = conn_manager.get_connection().cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||
rating_types = [utils.get_rating_type(x) for x in [False, True]]
|
||||
leaderboard = {
|
||||
|
@ -98,19 +98,24 @@ def get_streak_lists():
|
|||
" SELECT "
|
||||
" player_name,"
|
||||
" string_agg(user_accounts.username, %s ORDER BY user_accounts.username) AS user_accounts,"
|
||||
" COALESCE(maximum_streak, %s) AS maximum_streak"
|
||||
f" COALESCE({stat_type}, %s) AS value"
|
||||
" FROM users "
|
||||
" LEFT OUTER JOIN user_statistics"
|
||||
" ON users.id = user_statistics.user_id AND variant_type = %s"
|
||||
" LEFT OUTER JOIN user_accounts "
|
||||
" ON users.id = user_accounts.user_id "
|
||||
" GROUP BY (user_accounts.user_id, player_name, maximum_streak) "
|
||||
f" GROUP BY (user_accounts.user_id, player_name, {stat_type}) "
|
||||
" ) AS streaks "
|
||||
"ORDER BY maximum_streak DESC",
|
||||
(", ", 0, rating_type)
|
||||
f"ORDER BY value {order_type}",
|
||||
(", ", default, rating_type)
|
||||
)
|
||||
for (player_name, user_accounts, maximum_streak) in cur.fetchall():
|
||||
leaderboard[rating_type].append(PlayerEntry(player_name, user_accounts, maximum_streak))
|
||||
for (player_name, user_accounts, value) in cur.fetchall():
|
||||
if percents:
|
||||
value = round(100 * value, precision)
|
||||
value = str(value) + ' %'
|
||||
else:
|
||||
value = round(value, precision)
|
||||
leaderboard[rating_type].append(PlayerEntry(player_name, user_accounts, value))
|
||||
return leaderboard
|
||||
|
||||
|
||||
|
@ -167,12 +172,15 @@ def get_num_players():
|
|||
|
||||
def render_leaderboard():
|
||||
rating_lists = get_rating_lists()
|
||||
streak_lists = get_streak_lists()
|
||||
streak_lists = get_stat_lists("maximum_streak")
|
||||
leaders = get_leaders(rating_lists, streak_lists)
|
||||
|
||||
leaderboards = {
|
||||
'Player Rating': rating_lists,
|
||||
'Maximum Streak': streak_lists
|
||||
'Maximum Streak': streak_lists,
|
||||
'Current Streak': get_stat_lists("current_streak", order_type="DESC"),
|
||||
'Average Bottom Deck Risk': get_stat_lists("average_bdr", 'ASC', precision=2, default=float("inf")),
|
||||
'Winrate': get_stat_lists('winrate', order_type='DESC', precision=1, percents=True)
|
||||
}
|
||||
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
|
||||
|
|
Loading…
Reference in a new issue