implement cfg.puzzle.extra_days

This commit is contained in:
Jörn-Michael Miehe 2023-11-24 01:40:54 +01:00
parent 082f50c66b
commit 090da8c679
6 changed files with 34 additions and 13 deletions

View file

@ -1,6 +1,5 @@
# MUSS # MUSS
- api: Config-Liste von Extra-Türchen (kein Buchstabe, nur manuelles Bild)
# KANN # KANN
@ -21,3 +20,4 @@
- api: admin Login case sensitivity (username "admin" == "AdMiN") - api: admin Login case sensitivity (username "admin" == "AdMiN")
- api: `config.solution` - whitespace="IGNORE"->"REMOVE" umbenennen, +Sonderzeichen - api: `config.solution` - whitespace="IGNORE"->"REMOVE" umbenennen, +Sonderzeichen
- api: Config-Option "Überspringe leere Türchen" (standard ja) - api: Config-Option "Überspringe leere Türchen" (standard ja)
- api: Config-Liste von Extra-Türchen (kein Buchstabe, nur manuelles Bild)

View file

@ -34,9 +34,6 @@ class Site(BaseModel):
class Puzzle(BaseModel): class Puzzle(BaseModel):
# Türchen ohne Buchstabe überspringen
skip_empty: bool = True
# Tag, an dem der Kalender startet # Tag, an dem der Kalender startet
begin_day: int = 1 begin_day: int = 1
@ -46,6 +43,12 @@ class Puzzle(BaseModel):
# Kalender so viele Tage nach der letzten Türöffnung schließen # Kalender so viele Tage nach der letzten Türöffnung schließen
close_after: int = 90 close_after: int = 90
# Tage, für die kein Buchstabe vorgesehen wird
extra_days: set[int] = set()
# Türchen ohne Buchstabe überspringen
skip_empty: bool = True
class Image(BaseModel): class Image(BaseModel):
# Quadrat, Seitenlänge in px # Quadrat, Seitenlänge in px

View file

@ -1,5 +1,4 @@
import re import re
from collections import defaultdict
from dataclasses import dataclass from dataclasses import dataclass
from datetime import date from datetime import date
from io import BytesIO from io import BytesIO
@ -42,6 +41,11 @@ async def get_all_parts(
Lösung auf vorhandene Tage aufteilen Lösung auf vorhandene Tage aufteilen
""" """
# noch keine Buchstaben verteilt
result = {day: "" for day in days}
# extra-Tage ausfiltern
days = [day for day in days if day not in cfg.puzzle.extra_days]
solution_length = len(cfg.solution.clean) solution_length = len(cfg.solution.clean)
num_days = len(days) num_days = len(days)
@ -55,12 +59,9 @@ async def get_all_parts(
*rnd.sample(days, solution_length % num_days), *rnd.sample(days, solution_length % num_days),
] ]
result: defaultdict[int, str] = defaultdict(str)
for day, letter in zip(solution_days, cfg.solution.clean): for day, letter in zip(solution_days, cfg.solution.clean):
result[day] += letter result[day] += letter
result |= {missed_day: "" for missed_day in set(days) - set(result.keys())}
return result return result
@ -74,7 +75,7 @@ async def get_all_event_dates(
""" """
if cfg.puzzle.skip_empty: if cfg.puzzle.skip_empty:
days = [day for day in days if parts[day] != ""] days = [day for day in days if parts[day] != "" or day in cfg.puzzle.extra_days]
return EventDates( return EventDates(
today=date.today(), today=date.today(),

View file

@ -36,12 +36,13 @@ class AdminConfigModel(BaseModel):
clean: str clean: str
class __Puzzle(BaseModel): class __Puzzle(BaseModel):
skip_empty: bool
first: date first: date
next: date | None next: date | None
last: date last: date
end: date end: date
seed: str seed: str
extra_days: list[int]
skip_empty: bool
class __Calendar(BaseModel): class __Calendar(BaseModel):
config_file: str config_file: str
@ -88,12 +89,13 @@ async def get_config_model(
"clean": cfg.solution.clean, "clean": cfg.solution.clean,
}, },
"puzzle": { "puzzle": {
"skip_empty": cfg.puzzle.skip_empty,
"first": event_dates.first, "first": event_dates.first,
"next": event_dates.next, "next": event_dates.next,
"last": event_dates.last, "last": event_dates.last,
"end": event_dates.end, "end": event_dates.end,
"seed": cfg.random_seed, "seed": cfg.random_seed,
"extra_days": sorted(cfg.puzzle.extra_days),
"skip_empty": cfg.puzzle.skip_empty,
}, },
"calendar": { "calendar": {
"config_file": cfg.calendar, "config_file": cfg.calendar,

View file

@ -69,6 +69,19 @@
"{{ admin_config_model.puzzle.seed }}" "{{ admin_config_model.puzzle.seed }}"
</dd> </dd>
<dt>Extra-Tage</dt>
<dd>
<template
v-for="(day, index) in admin_config_model.puzzle.extra_days"
:key="`extra_day-${index}`"
>
<span>
<template v-if="index > 0">, </template>
{{ day }}
</span>
</template>
</dd>
<dt>Leere Türchen</dt> <dt>Leere Türchen</dt>
<dd v-if="admin_config_model.puzzle.skip_empty">Überspringen</dd> <dd v-if="admin_config_model.puzzle.skip_empty">Überspringen</dd>
<dd v-else>Anzeigen</dd> <dd v-else>Anzeigen</dd>
@ -199,12 +212,13 @@ export default class extends Vue {
clean: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", clean: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
}, },
puzzle: { puzzle: {
skip_empty: true,
first: "2023-12-01", first: "2023-12-01",
next: "2023-12-01", next: "2023-12-01",
last: "2023-12-24", last: "2023-12-24",
end: "2024-04-01", end: "2024-04-01",
seed: "", seed: "",
extra_days: [],
skip_empty: true,
}, },
calendar: { calendar: {
config_file: "lorem ipsum", config_file: "lorem ipsum",

View file

@ -7,12 +7,13 @@ export interface AdminConfigModel {
clean: string; clean: string;
}; };
puzzle: { puzzle: {
skip_empty: boolean;
first: string; first: string;
next: string | null; next: string | null;
last: string; last: string;
end: string; end: string;
seed: string; seed: string;
extra_days: number[];
skip_empty: boolean;
}; };
calendar: { calendar: {
config_file: string; config_file: string;