add dropdown menu for easier variant navigation

This commit is contained in:
Maximilian Keßler 2023-12-08 22:12:46 +01:00
parent 5553124d59
commit 0e0bb06780
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 62 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import psycopg2.extras
import stats import stats
import constants import constants
import config
import utils import utils
import ratings import ratings
from dataclasses import dataclass from dataclasses import dataclass
@ -101,6 +102,48 @@ class GameRow:
variant_rating_after: float 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(): def get_games():
cur = conn_manager.get_connection().cursor(cursor_factory=psycopg2.extras.DictCursor) cur = conn_manager.get_connection().cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute( 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 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(): def render_leaderboard():
rating_lists = get_rating_lists() rating_lists = get_rating_lists()
streak_lists = get_streak_list() streak_lists = get_streak_list()
@ -374,7 +421,8 @@ def render_leaderboard():
total_games_played=get_total_games(), total_games_played=get_total_games(),
total_players=get_num_players(), total_players=get_num_players(),
latest_run=datetime.datetime.now().isoformat(), latest_run=datetime.datetime.now().isoformat(),
variants=variant_rows variants_with_player_nums=variant_rows,
unique_variants=build_unique_variants(variant_rows)
# variants=variants, # variants=variants,
) )

View file

@ -18,8 +18,17 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" id="leaderboards-1-tab" data-toggle="tab" href="#leaderboards-1">Clue Starved</a> <a class="nav-link" id="leaderboards-1-tab" data-toggle="tab" href="#leaderboards-1">Clue Starved</a>
</li> </li>
<li class="nav-item"> <li class="nav-item dropdown">
<a class="nav-link" id="variant-tab" data-toggle="tab" href="#variants">Variants</a> <a class="nav-link dropdown-toggle" href="#" id="variants-dropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Variants
</a>
<div class="dropdown-menu" aria-labelledby="variants-dropdown">
<a class="dropdown-item" id="variant-tab" data-toggle="tab" href="#variants">Overview</a>
<div class="dropdown-divider"></div>
{% for variant in unique_variants %}
<a class="dropdown-item" href="/variant/{{variant.variant_id}}">{{variant.name}}</a>
{% endfor %}
</div>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" id="info-tab" data-toggle="tab" href="#info">Info</a> <a class="nav-link" id="info-tab" data-toggle="tab" href="#info">Info</a>
@ -107,7 +116,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for variant in variants %} {% for variant in variants_with_player_nums %}
<tr> <tr>
<td class="text-center"><strong><a href="variant/{{variant.variant_id}}">{{ variant.name }}</a></strong></td> <td class="text-center"><strong><a href="variant/{{variant.variant_id}}">{{ variant.name }}</a></strong></td>
<td class="text-center">{{ variant.num_players }}</td> <td class="text-center">{{ variant.num_players }}</td>

View file

@ -19,7 +19,7 @@
</li> </li>
{% endfor %} {% endfor %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" id="Back" href="/">Back</a> <a class="nav-link" id="Back" href="/">Back to Main Site</a>
</li> </li>
</ul> </ul>
</div> </div>