From 55148c48ab63c66bdc67f26c0d6d42ad15d39f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Mon, 4 Dec 2023 23:49:42 +0100 Subject: [PATCH] move leader cards to summary page --- css/leaderboards.css | 5 ++++- src/render_site.py | 17 +++++++++++++---- src/utils.py | 7 +++++++ templates/content.html | 23 +++++++++++++---------- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/css/leaderboards.css b/css/leaderboards.css index 35f8cfa..9ea81a5 100644 --- a/css/leaderboards.css +++ b/css/leaderboards.css @@ -1,11 +1,14 @@ .player-name { - font-size: 1.25rem; + font-size: 1.5rem; font-weight: bold; } .alt-name { font-size: 0.75rem; color: #777; } +.leaderboard-category { + font-size: 1.25rem; +} .score { font-size: 1.5rem; font-weight: bold; diff --git a/src/render_site.py b/src/render_site.py index 41977da..332c10c 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -1,6 +1,9 @@ +import shutil from pathlib import Path from typing import Dict, List +import subprocess + import jinja2 import datetime import psycopg2.extras @@ -28,6 +31,7 @@ class PlayerStreakEntry(PlayerEntry): @dataclass class Leader: title: str + category: str entry: PlayerEntry @@ -112,14 +116,14 @@ def get_leaders(rating_lists: Dict, streak_lists: Dict) -> Dict[int, Dict[str, L if len(rating_list) != 0: leader = rating_list[0] leaders[rating_type] = { - 'Player Rating': Leader('Highest Rating', leader) + 'Player Rating': Leader('Highest Rating', utils.describe_rating_type(rating_type), leader) } for rating_type, streak_list in streak_lists.items(): if len(streak_list) != 0: leader = streak_list[0] if rating_type not in leaders.keys(): leaders[rating_type] = {} - leaders[rating_type]['Top Streak'] = Leader('Longest Win Streak', leader) + leaders[rating_type]['Top Streak'] = Leader('Longest Win Streak', utils.describe_rating_type(rating_type), leader) return leaders @@ -254,7 +258,9 @@ def render_leaderboard(): # variants=variants, ) - output_file = Path(constants.WEBSITE_OUTPUT_DIRECTORY) / 'index.html' + out_dir = Path(constants.WEBSITE_OUTPUT_DIRECTORY) + + output_file = out_dir / 'index.html' output_file.parent.mkdir(exist_ok=True, parents=True) with open(output_file, 'w') as f: f.write(rendered_html) @@ -269,11 +275,14 @@ def render_leaderboard(): variant_name=variant_names[variant_id] ) - output_file = Path(constants.WEBSITE_OUTPUT_DIRECTORY) / 'variant' / str(variant_id) / 'index.html' + output_file = out_dir / 'variant' / str(variant_id) / 'index.html' output_file.parent.mkdir(exist_ok=True, parents=True) with open(output_file, 'w') as f: f.write(rendered_var) + # Copy CSS to output directory + shutil.copytree('css', 'build/css', dirs_exist_ok=True) + render_leaderboard() diff --git a/src/utils.py b/src/utils.py index 825407e..4e5ea6c 100644 --- a/src/utils.py +++ b/src/utils.py @@ -75,3 +75,10 @@ def get_rating_type(clue_starved: bool): return 1 else: return 0 + + +def describe_rating_type(rating_type: int): + if rating_type == 0: + return "Standard" + elif rating_type == 1: + return "Clue Starved" \ No newline at end of file diff --git a/templates/content.html b/templates/content.html index 195b884..98e3971 100644 --- a/templates/content.html +++ b/templates/content.html @@ -2,20 +2,23 @@ {% block content %}
- -
+
+ {% for rating_type, leaders in leaders.items() %} - {% for category, data in leaders.items() %} -
-
-
{{ data.title }}
-

{{ data.entry.player_name }}

-

{{ data.entry.user_accounts }}

-

{{ data.entry.score }}

+
+ {% for category, data in leaders.items() %} +
+
+
{{ data.title }}
+

({{data.category}})

+

{{ data.entry.player_name }}

+

{{ data.entry.user_accounts }}

+

{{ data.entry.score }}

+
+ {% endfor %}
{% endfor %} - {% endfor %}