refactor code and add stats for ewiges Frühstück

This commit is contained in:
Johannes 2023-10-06 18:20:52 +02:00
parent 1b39c3085e
commit 379b90ea3d
2 changed files with 21 additions and 11 deletions

0
main.py Normal file → Executable file
View file

View file

@ -3,6 +3,16 @@ from pathlib import Path
from typing import Dict, Tuple, Union # I have just python3.8 here :( from typing import Dict, Tuple, Union # I have just python3.8 here :(
# ids of the questions which represent a size of a merch product
SIZE_IDS = (312, 313, 314, 316, 319, 320, 321, 322, 323)
# ID of wishlist for ewiges Frühstück
BREAKFASTWISHES_ID = 309
# Wie heißt die Athenanas?
ATHENE_ID = 305 # ID of the question of how the logo image is to be named
HUMAN_ID = 147 # ticket for a human
MASCOT_ID = 148 # ticket for a mascot
def parse(filename: Union[str, Path]) -> Tuple[ def parse(filename: Union[str, Path]) -> Tuple[
Dict[int, str], Dict[int, str],
Dict[int, int], Dict[int, int],
@ -54,29 +64,29 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di
'|-\n') '|-\n')
for item_id, item_name in items.items(): for item_id, item_name in items.items():
ret += f"|| {item_name} || {count_items.get(item_id)}\n|-\n" ret += f"|| {item_name} || {count_items.get(item_id)}\n|-\n"
ret += "|}\n" ret += "|}\n\n"
# ids of the questions which represent a size of a merch product
size_ids = (312, 313, 314, 316, 319, 320, 321, 322, 323)
ret += ('== Merch-Größenverteilung ==\n' ret += ('== Merch-Größenverteilung ==\n'
'{|class="wikitable sortable"\n' '{|class="wikitable sortable"\n'
'! Größe/Eigenschaft !! Wert !! Anzahl\n' '! Größe/Eigenschaft !! Wert !! Anzahl\n'
'|-\n') '|-\n')
for size_id in size_ids: for size_id in SIZE_IDS:
for size, count in quest_answers[size_id].items(): for size, count in quest_answers[size_id].items():
ret += f"|| {questions[size_id]}: || {size[1]} || {count}\n|-\n" ret += f"|| {questions[size_id]}: || {size[1]} || {count}\n|-\n"
ret += "|}\n" ret += "|}\n\n"
athene_id = 305 # ID of the question how the logo image is to be named ret += '== Wünsche an das ewige Frühstück ==\n'
human_id = 147 # ticket for a human for wish in quest_answers[BREAKFASTWISHES_ID]:
mascot_id = 148 # ticket for a mascot ret += f"* <pre>{wish[1]}</pre>\n"
ret += "\n"
def prefix(id_): def prefix(id_):
return "Mensch sagt:" if id_ == human_id else "Maskottchen sagt:" if id_ == mascot_id else "" return "Mensch sagt:" if id_ == HUMAN_ID else "Maskottchen sagt:" if id_ == MASCOT_ID else ""
ret += ('== Wie heißt das Ding? ==\n' ret += ('== Wie heißt das Ding? ==\n'
'{|class="wikitable sortable"\n' '{|class="wikitable sortable"\n'
'! Variante !! Stimmen\n' '! Variante !! Stimmen\n'
'|-\n') '|-\n')
for variant, count in quest_answers[athene_id].items(): for variant, count in quest_answers[ATHENE_ID].items():
ret += f"|| {prefix(variant[0])} {variant[1]} || {count}\n|-\n" ret += f"|| {prefix(variant[0])} {variant[1]} || {count}\n|-\n"
ret += "|}\n" ret += "|}\n"