diff --git a/api/advent22_api/core/__init__.py b/api/advent22_api/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/advent22_api/core/depends.py b/api/advent22_api/core/depends.py index 7925258..33a43b8 100644 --- a/api/advent22_api/core/depends.py +++ b/api/advent22_api/core/depends.py @@ -12,16 +12,6 @@ from .sequence_helpers import Random, set_len, shuffle from .webdav import WebDAV -async def shuffle_solution( - cfg: Config = Depends(get_config), -) -> str: - """ - Lösung: Reihenfolge zufällig bestimmen - """ - - return "".join(await shuffle(cfg.puzzle.solution)) - - async def get_days( cal_cfg: CalendarConfig = Depends(get_calendar_config), ) -> list[int]: @@ -32,10 +22,10 @@ async def get_days( return list(set(door.day for door in cal_cfg.doors)) -async def get_solution_parts( +async def get_day_parts( cfg: Config = Depends(get_config), days: list[int] = Depends(get_days), -) -> dict[int, set[str]]: +) -> dict[int, str]: """ Lösung auf vorhandene Tage aufteilen """ @@ -49,10 +39,10 @@ async def get_solution_parts( *rnd.sample(days, solution_length % num_days), ] - result: dict[int, set[str]] = {} + result: dict[int, str] = {} for day, letter in zip(solution_days, cfg.puzzle.solution): - result[day] = result.get(day, set()) - result[day].add(letter) + result[day] = result.get(day, "") + result[day] += letter return result @@ -68,18 +58,18 @@ async def shuffle_images_auto( return await shuffle(ls) -async def get_part( +async def get_part_for_day( day: int, - shuffled_solution: str = Depends(shuffle_solution), + parts: dict[int, str] = Depends(get_day_parts), ) -> str: """ Heute angezeigter Teil der Lösung """ - return shuffled_solution[day] + return parts[day] -async def get_random( +async def get_random_for_day( day: int, ) -> Random: """ @@ -89,12 +79,12 @@ async def get_random( return await Random.get(day) -async def gen_auto_image( +async def gen_auto_image_for_day( day: int, auto_images: list[str] = Depends(shuffle_images_auto), cfg: Config = Depends(get_config), - rnd: Random = Depends(get_random), - part: str = Depends(get_part), + rnd: Random = Depends(get_random_for_day), + part: str = Depends(get_part_for_day), ) -> Image.Image: """ Automatisch generiertes Bild erstellen @@ -120,12 +110,12 @@ async def gen_auto_image( return image.img -async def get_image( +async def get_image_for_day( day: int, auto_images: list[str] = Depends(shuffle_images_auto), cfg: Config = Depends(get_config), - rnd: Random = Depends(get_random), - part: str = Depends(get_part), + rnd: Random = Depends(get_random_for_day), + part: str = Depends(get_part_for_day), ) -> Image.Image: """ Bild für einen Tag abrufen @@ -141,6 +131,6 @@ async def get_image( except RuntimeError: # Erstelle automatisch generiertes Bild - return await gen_auto_image( + return await gen_auto_image_for_day( day=day, auto_images=auto_images, cfg=cfg, rnd=rnd, part=part ) diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index b0be7a9..5a293cf 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -3,22 +3,15 @@ from datetime import date from fastapi import APIRouter, Depends from pydantic import BaseModel +from ..core import depends from ..core.calendar_config import CalendarConfig, get_calendar_config from ..core.config import Config, get_config -from ..core.depends import get_solution_parts, shuffle_solution from ..core.settings import SETTINGS from ._security import require_admin, user_is_admin router = APIRouter(prefix="/admin", tags=["admin"]) -@router.get("/parts") -async def get_parts( - shuffle=Depends(get_solution_parts), -) -> dict[int, set[str]]: - return shuffle - - @router.get("/is_admin") async def is_admin( is_admin: bool = Depends(user_is_admin), @@ -28,8 +21,12 @@ async def is_admin( class ConfigModel(BaseModel): class __Puzzle(BaseModel): + class __Part(BaseModel): + day: int + part: str + solution: str - shuffled: str + day_parts: list[__Part] begin: date end: date closing: date @@ -64,13 +61,16 @@ async def get_config_model( _: None = Depends(require_admin), cfg: Config = Depends(get_config), cal_cfg: CalendarConfig = Depends(get_calendar_config), - shuffled_solution: str = Depends(shuffle_solution), + day_parts: dict[int, str] = Depends(depends.get_day_parts), ) -> ConfigModel: return ConfigModel.model_validate( { "puzzle": { "solution": cfg.puzzle.solution, - "shuffled": shuffled_solution, + "day_parts": [ + {"day": day, "part": part} + for day, part in sorted(day_parts.items()) + ], "begin": date.today(), # TODO "end": date.today(), # TODO "closing": date.today(), # TODO diff --git a/api/advent22_api/routers/days.py b/api/advent22_api/routers/days.py index ece8e87..8507cea 100644 --- a/api/advent22_api/routers/days.py +++ b/api/advent22_api/routers/days.py @@ -4,8 +4,8 @@ from fastapi import APIRouter, Depends, HTTPException, status from fastapi.responses import StreamingResponse from PIL import Image +from ..core import depends from ..core.config import get_config -from ..core.depends import get_image, get_part, shuffle_solution from ..core.image_helpers import api_return_image from ._security import user_can_view_door, user_is_admin, user_visible_doors @@ -17,9 +17,6 @@ async def startup() -> None: cfg = await get_config() print(cfg.puzzle.solution) - shuffled_solution = await shuffle_solution(cfg) - print(shuffled_solution) - @router.get("/date") async def get_date() -> str: @@ -43,7 +40,7 @@ async def get_visible_days( @router.get("/part/{day}") async def get_part_for_day( - part: str = Depends(get_part), + part: str = Depends(depends.get_part_for_day), ) -> str: """ Heutiger Lösungsteil @@ -57,7 +54,7 @@ async def get_part_for_day( response_class=StreamingResponse, ) async def get_image_for_day( - image: Image.Image = Depends(get_image), + image: Image.Image = Depends(depends.get_image_for_day), can_view: bool = Depends(user_can_view_door), is_admin: bool = Depends(user_is_admin), ) -> StreamingResponse: diff --git a/ui/src/components/ConfigView.vue b/ui/src/components/ConfigView.vue index 5cf05bd..b4e5ded 100644 --- a/ui/src/components/ConfigView.vue +++ b/ui/src/components/ConfigView.vue @@ -13,7 +13,18 @@
{{ admin_config_model.puzzle.solution }}
Reihenfolge
-
{{ admin_config_model.puzzle.shuffled }}
+
+ +
Offene Türchen
10
@@ -50,8 +61,10 @@
Türchen
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 - + + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 + + @@ -125,7 +138,7 @@ import BulmaDrawer from "./bulma/Drawer.vue"; interface ConfigModel { puzzle: { solution: string; - shuffled: string; + day_parts: { day: number; part: string }[]; begin: string; end: string; closing: string; @@ -156,7 +169,7 @@ export default class extends Vue { public admin_config_model: ConfigModel = { puzzle: { solution: "ABCDEFGHIJKLMNOPQRSTUVWX", - shuffled: "AGFCINBEWLKQMXDURPOSJVHT", + day_parts: [], begin: "01.12.2023", end: "24.12.2023", closing: "01.04.2024",