player pages: add rating, fix bug on rating type
This commit is contained in:
parent
271430e901
commit
dd13cd4ae9
1 changed files with 45 additions and 25 deletions
|
@ -12,7 +12,6 @@ import stats
|
|||
import constants
|
||||
import config
|
||||
import utils
|
||||
import ratings
|
||||
from dataclasses import dataclass
|
||||
|
||||
from database import conn_manager
|
||||
|
@ -122,6 +121,7 @@ class Player:
|
|||
class PlayerStats(GeneralStats):
|
||||
current_streak: int = 0
|
||||
max_streak: int = 0
|
||||
rating: int = 0
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -353,31 +353,51 @@ def get_variant_rows() -> List[VariantRow]:
|
|||
]
|
||||
|
||||
|
||||
def get_player_stats() -> Dict[int, Dict[int, PlayerStats]]:
|
||||
def get_player_stats() -> Dict[str, Dict[int, PlayerStats]]:
|
||||
cur = conn_manager.get_new_cursor()
|
||||
cur.execute(
|
||||
"SELECT "
|
||||
" user_id,"
|
||||
" player_name,"
|
||||
" variant_type,"
|
||||
" games_played,"
|
||||
" games_won,"
|
||||
" total_bdr,"
|
||||
" total_crits_lots,"
|
||||
" total_game_moves,"
|
||||
" current_streak,"
|
||||
" maximum_streak "
|
||||
"FROM user_statistics "
|
||||
"INNER JOIN users "
|
||||
" ON user_statistics.user_id = users.id "
|
||||
"ORDER BY user_id, variant_type"
|
||||
)
|
||||
ret = {}
|
||||
for (user_id, player_name, variant_type, games_played, games_won, total_bdr, total_crits_lost, total_game_moves, current_streak, maximum_streak) in cur.fetchall():
|
||||
if player_name not in ret.keys():
|
||||
ret[player_name] = {}
|
||||
ret[player_name][variant_type] = PlayerStats(games_played, games_won, total_bdr, total_crits_lost, total_game_moves, current_streak, maximum_streak)
|
||||
|
||||
rating_types = [utils.get_rating_type(x) for x in [False, True]]
|
||||
for rating_type in rating_types:
|
||||
cur.execute(
|
||||
"SELECT "
|
||||
" users.id,"
|
||||
" player_name,"
|
||||
" games_played,"
|
||||
" games_won,"
|
||||
" total_bdr,"
|
||||
" total_crits_lots,"
|
||||
" total_game_moves,"
|
||||
" current_streak,"
|
||||
" maximum_streak,"
|
||||
" user_accounts,"
|
||||
" current_rating "
|
||||
"FROM user_statistics "
|
||||
"INNER JOIN users "
|
||||
" ON user_statistics.user_id = users.id AND user_statistics.variant_type = %s "
|
||||
"INNER JOIN ("
|
||||
" SELECT DISTINCT ON (user_accounts.user_id)"
|
||||
" user_accounts.user_id,"
|
||||
" array_agg(user_accounts.username ORDER BY user_accounts.username) AS user_accounts,"
|
||||
" COALESCE(value_after, rating) AS current_rating"
|
||||
" FROM users "
|
||||
" LEFT OUTER JOIN user_ratings "
|
||||
" ON user_ratings.user_id = users.id AND user_ratings.type = %s "
|
||||
" LEFT OUTER JOIN user_accounts "
|
||||
" ON users.id = user_accounts.user_id "
|
||||
" INNER JOIN user_base_ratings "
|
||||
" ON users.id = user_base_ratings.user_id AND user_base_ratings.type = %s"
|
||||
" GROUP BY (user_accounts.user_id, player_name, value_after, league_id, rating) "
|
||||
" ORDER BY user_accounts.user_id, league_id DESC"
|
||||
" ) AS ratings "
|
||||
" ON ratings.user_id = users.id "
|
||||
"ORDER BY users.id, variant_type",
|
||||
(rating_type, rating_type, rating_type)
|
||||
)
|
||||
for (user_id, player_name, games_played, games_won, total_bdr, total_crits_lost, total_game_moves, current_streak, maximum_streak, user_accounts, current_rating) in cur.fetchall():
|
||||
if player_name not in ret.keys():
|
||||
ret[player_name] = {}
|
||||
row = PlayerRow(user_id, player_name, user_accounts, PlayerStats(games_played, games_won, total_bdr, total_crits_lost, total_game_moves, current_streak, maximum_streak, round(current_rating, 1)))
|
||||
ret[player_name][rating_type] = row
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -483,7 +503,7 @@ def render_leaderboard():
|
|||
player_stat=player_stat
|
||||
)
|
||||
|
||||
output_file = out_dir / 'player' / str(player_name) / 'index.html'
|
||||
output_file = out_dir / 'player' / urllib.parse.quote_plus(player_name) / 'index.html'
|
||||
output_file.parent.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
with open(output_file, 'w') as f:
|
||||
|
|
Loading…
Reference in a new issue