minor doc + refactoring
This commit is contained in:
parent
97d4d1e136
commit
a4a0893e7d
2 changed files with 16 additions and 19 deletions
|
@ -15,13 +15,17 @@ class Server(BaseModel):
|
||||||
# Dateiname Schriftart
|
# Dateiname Schriftart
|
||||||
font: str
|
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
|
# TODO penner
|
||||||
month: int = 12
|
month: int = 12
|
||||||
|
|
||||||
# Alle Türen bleiben noch so viele Monate offen
|
# Alle Türen bleiben noch so viele Tage offen
|
||||||
# TODO penner
|
# TODO penner
|
||||||
keep_open: int = 3
|
keep_open: int = 90
|
||||||
|
|
||||||
|
|
||||||
class Puzzle(BaseModel):
|
class Puzzle(BaseModel):
|
||||||
|
@ -48,7 +52,7 @@ class Config(BaseModel):
|
||||||
puzzle: Puzzle
|
puzzle: Puzzle
|
||||||
|
|
||||||
|
|
||||||
async def get_config() -> "Config":
|
async def get_config() -> Config:
|
||||||
"""
|
"""
|
||||||
Globale Konfiguration lesen
|
Globale Konfiguration lesen
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -34,7 +34,11 @@ async def get_all_parts(
|
||||||
|
|
||||||
rnd = await Random.get()
|
rnd = await Random.get()
|
||||||
solution_days = [
|
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)),
|
*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),
|
*rnd.sample(days, solution_length % num_days),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -46,17 +50,6 @@ async def get_all_parts(
|
||||||
return result
|
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(
|
async def get_all_auto_image_names(
|
||||||
days: list[int] = Depends(get_all_days),
|
days: list[int] = Depends(get_all_days),
|
||||||
images: list[str] = Depends(list_images_auto),
|
images: list[str] = Depends(list_images_auto),
|
||||||
|
@ -88,7 +81,7 @@ async def gen_day_auto_image(
|
||||||
day: int,
|
day: int,
|
||||||
cfg: Config = Depends(get_config),
|
cfg: Config = Depends(get_config),
|
||||||
auto_image_names: list[str] = Depends(get_all_auto_image_names),
|
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:
|
) -> Image.Image:
|
||||||
"""
|
"""
|
||||||
Automatisch generiertes Bild erstellen
|
Automatisch generiertes Bild erstellen
|
||||||
|
@ -106,7 +99,7 @@ async def gen_day_auto_image(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Buchstaben verstecken
|
# Buchstaben verstecken
|
||||||
for letter in day_part:
|
for letter in day_parts[day]:
|
||||||
await image.hide_text(
|
await image.hide_text(
|
||||||
xy=cast(_XY, tuple(rnd.choices(range(30, 470), k=2))),
|
xy=cast(_XY, tuple(rnd.choices(range(30, 470), k=2))),
|
||||||
text=letter,
|
text=letter,
|
||||||
|
@ -120,7 +113,7 @@ async def get_day_image(
|
||||||
day: int,
|
day: int,
|
||||||
cfg: Config = Depends(get_config),
|
cfg: Config = Depends(get_config),
|
||||||
auto_image_names: list[str] = Depends(get_all_auto_image_names),
|
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:
|
) -> Image.Image:
|
||||||
"""
|
"""
|
||||||
Bild für einen Tag abrufen
|
Bild für einen Tag abrufen
|
||||||
|
@ -137,5 +130,5 @@ async def get_day_image(
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
# Erstelle automatisch generiertes Bild
|
# Erstelle automatisch generiertes Bild
|
||||||
return await gen_day_auto_image(
|
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
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue