From a4a0893e7de1118104af782b0256ca58433f66b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 14 Sep 2023 23:38:35 +0000 Subject: [PATCH] minor doc + refactoring --- api/advent22_api/core/config.py | 12 ++++++++---- api/advent22_api/core/depends.py | 23 ++++++++--------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/api/advent22_api/core/config.py b/api/advent22_api/core/config.py index 97ccbf8..128225c 100644 --- a/api/advent22_api/core/config.py +++ b/api/advent22_api/core/config.py @@ -15,13 +15,17 @@ class Server(BaseModel): # Dateiname Schriftart font: str - # Monat, während dem der Kalender läuft + # Tag, an dem der Kalender startet + # TODO penner + first_day: int = 1 + + # Monat, in dem der Kalender startet # TODO penner month: int = 12 - # Alle Türen bleiben noch so viele Monate offen + # Alle Türen bleiben noch so viele Tage offen # TODO penner - keep_open: int = 3 + keep_open: int = 90 class Puzzle(BaseModel): @@ -48,7 +52,7 @@ class Config(BaseModel): puzzle: Puzzle -async def get_config() -> "Config": +async def get_config() -> Config: """ Globale Konfiguration lesen """ diff --git a/api/advent22_api/core/depends.py b/api/advent22_api/core/depends.py index a164e59..29bfbc5 100644 --- a/api/advent22_api/core/depends.py +++ b/api/advent22_api/core/depends.py @@ -34,7 +34,11 @@ async def get_all_parts( rnd = await Random.get() solution_days = [ + # wie oft passen die Tage "ganz" in die Länge der Lösung? + # zB 26 Buchstaben // 10 Tage == 2 mal => 2 Zeichen pro Tag *rnd.shuffled(days * (solution_length // num_days)), + # wie viele Buchstaben bleiben übrig? + # zB 26 % 10 == 6 Buchstaben => an 6 Tagen ein Zeichen mehr *rnd.sample(days, solution_length % num_days), ] @@ -46,17 +50,6 @@ async def get_all_parts( return result -async def get_day_part( - day: int, - parts: dict[int, str] = Depends(get_all_parts), -) -> str: - """ - Heute angezeigter Teil der Lösung - """ - - return parts[day] - - async def get_all_auto_image_names( days: list[int] = Depends(get_all_days), images: list[str] = Depends(list_images_auto), @@ -88,7 +81,7 @@ async def gen_day_auto_image( day: int, cfg: Config = Depends(get_config), auto_image_names: list[str] = Depends(get_all_auto_image_names), - day_part: str = Depends(get_day_part), + day_parts: dict[int, str] = Depends(get_all_parts), ) -> Image.Image: """ Automatisch generiertes Bild erstellen @@ -106,7 +99,7 @@ async def gen_day_auto_image( ) # Buchstaben verstecken - for letter in day_part: + for letter in day_parts[day]: await image.hide_text( xy=cast(_XY, tuple(rnd.choices(range(30, 470), k=2))), text=letter, @@ -120,7 +113,7 @@ async def get_day_image( day: int, cfg: Config = Depends(get_config), auto_image_names: list[str] = Depends(get_all_auto_image_names), - day_part: str = Depends(get_day_part), + day_parts: dict[int, str] = Depends(get_all_parts), ) -> Image.Image: """ Bild für einen Tag abrufen @@ -137,5 +130,5 @@ async def get_day_image( except RuntimeError: # Erstelle automatisch generiertes Bild return await gen_day_auto_image( - day=day, cfg=cfg, auto_image_names=auto_image_names, day_part=day_part + day=day, cfg=cfg, auto_image_names=auto_image_names, day_parts=day_parts )