From 379b90ea3df14ab96fb800e994b7f73cceafe27d Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 6 Oct 2023 18:20:52 +0200 Subject: [PATCH 1/6] =?UTF-8?q?refactor=20code=20and=20add=20stats=20for?= =?UTF-8?q?=20ewiges=20Fr=C3=BChst=C3=BCck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 0 parse.py | 32 +++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) mode change 100644 => 100755 main.py diff --git a/main.py b/main.py old mode 100644 new mode 100755 diff --git a/parse.py b/parse.py index 01483a1..039220b 100644 --- a/parse.py +++ b/parse.py @@ -3,6 +3,16 @@ from pathlib import Path 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[ Dict[int, str], Dict[int, int], @@ -54,29 +64,29 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di '|-\n') for item_id, item_name in items.items(): 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' '{|class="wikitable sortable"\n' '! Größe/Eigenschaft !! Wert !! Anzahl\n' '|-\n') - for size_id in size_ids: + for size_id in SIZE_IDS: for size, count in quest_answers[size_id].items(): ret += f"|| {questions[size_id]}: || {size[1]} || {count}\n|-\n" - ret += "|}\n" - - athene_id = 305 # ID of the question how the logo image is to be named - human_id = 147 # ticket for a human - mascot_id = 148 # ticket for a mascot + ret += "|}\n\n" + + ret += '== Wünsche an das ewige Frühstück ==\n' + for wish in quest_answers[BREAKFASTWISHES_ID]: + ret += f"*
{wish[1]}
\n" + ret += "\n" + 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' '{|class="wikitable sortable"\n' '! Variante !! Stimmen\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 += "|}\n" From 897d03c5edada33e62831aec0162945fe9ddf4b5 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 6 Oct 2023 18:31:00 +0200 Subject: [PATCH 2/6] stats for Rahmenprogramm --- parse.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/parse.py b/parse.py index 039220b..f7af422 100644 --- a/parse.py +++ b/parse.py @@ -4,13 +4,16 @@ 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) +SIZE_IDS = (312, 313, 314, 316, 319, 320, 321, 322, 323, 324) # 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 +# Rahmenprogramm +RAHMERST_ID = 308 +RAHMZWEIT_ID = 317 def parse(filename: Union[str, Path]) -> Tuple[ @@ -75,6 +78,22 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di ret += f"|| {questions[size_id]}: || {size[1]} || {count}\n|-\n" ret += "|}\n\n" + ret += ('== Rahmenprogramm ==\n' + '=== Erstwahlen ===' + '{|class="wikitable sortable"\n' + '! Programmpunkt !! gewählt\n' + '|-\n') + for program, count in quest_answers[RAHMERST_ID].items(): + ret += f"|| {program[1]} || {count}\n|-\n" + ret += ('|}\n' + '=== Zweitwahlen ===\n' + '{|class="wikitable sortable"\n' + '! Programmpunkt !! gewählt\n' + '|-\n') + for program, count in quest_answers[RAHMZWEIT_ID].items(): + ret += f"|| {program[1]} || {count}\n|-\n" + ret += "|}\n\n" + ret += '== Wünsche an das ewige Frühstück ==\n' for wish in quest_answers[BREAKFASTWISHES_ID]: ret += f"*
{wish[1]}
\n" From 1b021758f2523008ba66253f5522dc2614c4cde3 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 6 Oct 2023 18:34:57 +0200 Subject: [PATCH 3/6] stats about food preference --- parse.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/parse.py b/parse.py index f7af422..634174c 100644 --- a/parse.py +++ b/parse.py @@ -14,6 +14,8 @@ MASCOT_ID = 148 # ticket for a mascot # Rahmenprogramm RAHMERST_ID = 308 RAHMZWEIT_ID = 317 +# Yummy! +ESSEN_ID = 302 def parse(filename: Union[str, Path]) -> Tuple[ @@ -94,6 +96,16 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di ret += f"|| {program[1]} || {count}\n|-\n" ret += "|}\n\n" + ret += ('== Essen ==\n' + '{|class="wikitable sortable"\n' + '! Präferenz !! gewählt\n' + '|-\n') + for pref, count in quest_answers[ESSEN_ID].items(): + ret += f"|| {pref[1]} || {count}\n|-\n" + ret += ("|}\n" + "Unverträglichkeiten/Allergien konnten auch angegeben werden, Antworten beim Pretix-Team erfragen." + "\n\n") + ret += '== Wünsche an das ewige Frühstück ==\n' for wish in quest_answers[BREAKFASTWISHES_ID]: ret += f"*
{wish[1]}
\n" From d5c7c669d68ba764d09bdf3caf94b9dd97bb9f25 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 6 Oct 2023 18:44:03 +0200 Subject: [PATCH 4/6] yes/no question stats --- parse.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/parse.py b/parse.py index 634174c..ae75677 100644 --- a/parse.py +++ b/parse.py @@ -16,6 +16,14 @@ RAHMERST_ID = 308 RAHMZWEIT_ID = 317 # Yummy! ESSEN_ID = 302 +# diverse checkboxes +BOOLEAN_IDS = ( + 304, # Deutschlandticket + 307, # Erstkomatikerin + 310, # Workshop-Themen + 301, # Mörderspiel + 311, # nur Rufname auf Badge +) def parse(filename: Union[str, Path]) -> Tuple[ @@ -52,7 +60,6 @@ def parse(filename: Union[str, Path]) -> Tuple[ quest_answers[quest_id][answer_key] = ( quest_answers[quest_id].get(answer_key, 0) + 1 ) - return items, count_items, questions, quest_answers @@ -81,7 +88,7 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di ret += "|}\n\n" ret += ('== Rahmenprogramm ==\n' - '=== Erstwahlen ===' + '=== Erstwahlen ===\n' '{|class="wikitable sortable"\n' '! Programmpunkt !! gewählt\n' '|-\n') @@ -111,6 +118,17 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di ret += f"*
{wish[1]}
\n" ret += "\n" + ret += ('== Ja/Nein-Abfragen ==\n' + '{|class="wikitable sortable"\n' + '! Frage !! Antwort !! Anzahl\n' + '|-\n') + for field in BOOLEAN_IDS: + for answer, count in quest_answers[field].items(): + if answer[1] in ("False", ""): + continue + ret += f"|| {questions[field]}: || {answer[1]} || {count}\n|-\n" + ret += "|}\n\n" + def prefix(id_): return "Mensch sagt:" if id_ == HUMAN_ID else "Maskottchen sagt:" if id_ == MASCOT_ID else "" ret += ('== Wie heißt das Ding? ==\n' From 34ccc6183539134e92de05201ee407ef9118a012 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 6 Oct 2023 18:48:50 +0200 Subject: [PATCH 5/6] show beautiful titles for some questions --- parse.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/parse.py b/parse.py index ae75677..831adb6 100644 --- a/parse.py +++ b/parse.py @@ -1,5 +1,6 @@ import json from pathlib import Path +from pprint import pprint from typing import Dict, Tuple, Union # I have just python3.8 here :( @@ -30,17 +31,19 @@ def parse(filename: Union[str, Path]) -> Tuple[ Dict[int, str], Dict[int, int], Dict[int, str], - Dict[int, Dict[Tuple[int, str], int]] + Dict[int, Dict[Tuple[int, str], int]], + Dict[int, str] ]: """Parse a JSON export from pretix. :param filename: filename of the JSON export to parse. - :returns: Four mappings: + :returns: Five mappings: * item_id to item name * item_id to order count of this item * question_id to question identifier * question_id to stats for this question, which identifies an answer by its item_id and actual answer. The stats map this identifier to number of occurrences + * question_id to question text (the actual question shown to the user) """ with open(filename, 'r', encoding='utf8') as f: data = json.load(f)['event'] @@ -48,6 +51,7 @@ def parse(filename: Union[str, Path]) -> Tuple[ items = {i['id']: i['name'] for i in data['items']} count_items = {id_: 0 for id_ in items} questions = {q['id']: q['identifier'] for q in data['questions']} + quest_titles = {q['id']: q['question'] for q in data['questions']} quest_answers = {id_: {} for id_ in questions} for order in data['orders']: @@ -60,11 +64,11 @@ def parse(filename: Union[str, Path]) -> Tuple[ quest_answers[quest_id][answer_key] = ( quest_answers[quest_id].get(answer_key, 0) + 1 ) - return items, count_items, questions, quest_answers + return items, count_items, questions, quest_answers, quest_titles def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Dict[int, str], - quest_answers: Dict[int, Dict[Tuple[int, str], int]]) -> str: + quest_answers: Dict[int, Dict[Tuple[int, str], int]], quest_titles: Dict[int, str]) -> str: """Generate stats for the Wiki page. Input parameters are output of the parse() function. @@ -126,7 +130,7 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di for answer, count in quest_answers[field].items(): if answer[1] in ("False", ""): continue - ret += f"|| {questions[field]}: || {answer[1]} || {count}\n|-\n" + ret += f"|| {quest_titles[field]}: || {answer[1]} || {count}\n|-\n" ret += "|}\n\n" def prefix(id_): From f3dedeb7e8d4b4f925234b74222a79613e187251 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 6 Oct 2023 18:56:32 +0200 Subject: [PATCH 6/6] athenanas: show custom names --- parse.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/parse.py b/parse.py index 831adb6..db2f072 100644 --- a/parse.py +++ b/parse.py @@ -10,6 +10,7 @@ SIZE_IDS = (312, 313, 314, 316, 319, 320, 321, 322, 323, 324) BREAKFASTWISHES_ID = 309 # Wie heißt die Athenanas? ATHENE_ID = 305 # ID of the question of how the logo image is to be named +ATHENE_CUSTOM_ID = 306 # custom naming of the Athenanas HUMAN_ID = 147 # ticket for a human MASCOT_ID = 148 # ticket for a mascot # Rahmenprogramm @@ -122,7 +123,7 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di ret += f"*
{wish[1]}
\n" ret += "\n" - ret += ('== Ja/Nein-Abfragen ==\n' + ret += ('== Checkbox-Abfragen ==\n' '{|class="wikitable sortable"\n' '! Frage !! Antwort !! Anzahl\n' '|-\n') @@ -140,7 +141,14 @@ def wiki_stats(items: Dict[int, str], count_items: Dict[int, int], questions: Di '! Variante !! Stimmen\n' '|-\n') for variant, count in quest_answers[ATHENE_ID].items(): - ret += f"|| {prefix(variant[0])} {variant[1]} || {count}\n|-\n" + if "Sonstiges" not in variant[1]: + ret += f"|| {prefix(variant[0])} {variant[1]} || {count}\n|-\n" + else: + ret += f"|| {prefix(variant[0])} {variant[1]} || " + for custom in quest_answers[ATHENE_CUSTOM_ID]: + ret += f"{custom[1]}
\n" + ret = ret[:-6] + ret += f"\n|-\n" ret += "|}\n" return ret