diff --git a/src/render_site.py b/src/render_site.py index 21d943e..d5ce969 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -9,6 +9,7 @@ import psycopg2.extras import stats import constants +import config import utils import ratings from dataclasses import dataclass @@ -101,6 +102,48 @@ class GameRow: variant_rating_after: float +@dataclass +class Player: + user_id: int + player_name: str + user_accounts: List[str] + + +@dataclass +class PlayerStats: + current_streak: int + max_streak: int + games_played: int + games_won: int + total_bdr: int + total_crits_lost: int + total_moves: int + + @property + def winrate(self): + if self.games_played == 0: + return 0 + return round(100 * float(self.games_won) / self.games_played, 1) + + @property + def average_bdr(self): + if self.games_played == 0: + return 0 + return round(float(self.total_bdr) / self.games_played, 3) + + @property + def average_crits_lost(self): + if self.games_played == 0: + return 0 + return round(float(self.total_crits_lost) / self.games_played, 3) + + @property + def average_moves(self): + if self.games_played == 0: + return 0 + return round(float(self.total_moves) / self.games_played, 3) + + def get_games(): cur = conn_manager.get_connection().cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute( @@ -352,6 +395,10 @@ def build_variant_stats_by_variant(variant_rows: List[VariantRow]): return variant_stats, variant_stats_per_player, variant_names +def build_unique_variants(variant_rows: List[VariantRow]): + return [row for row in variant_rows if row.num_players == config.config_manager.get_config().min_player_count] + + def render_leaderboard(): rating_lists = get_rating_lists() streak_lists = get_streak_list() @@ -374,7 +421,8 @@ def render_leaderboard(): total_games_played=get_total_games(), total_players=get_num_players(), latest_run=datetime.datetime.now().isoformat(), - variants=variant_rows + variants_with_player_nums=variant_rows, + unique_variants=build_unique_variants(variant_rows) # variants=variants, ) diff --git a/templates/main.html b/templates/main.html index c10865d..6fcb72f 100644 --- a/templates/main.html +++ b/templates/main.html @@ -18,8 +18,17 @@