From 3d25f968f7cfa3b790633491f8276933703e27d8 Mon Sep 17 00:00:00 2001 From: LoC Date: Mon, 15 May 2023 09:35:04 +0200 Subject: [PATCH 1/3] Fixed result count sort mechanism Signed-off-by: LoC --- src/routes/admin/evaluate/[type]/+page.svelte | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/routes/admin/evaluate/[type]/+page.svelte b/src/routes/admin/evaluate/[type]/+page.svelte index 95aad98..dc35531 100644 --- a/src/routes/admin/evaluate/[type]/+page.svelte +++ b/src/routes/admin/evaluate/[type]/+page.svelte @@ -85,9 +85,12 @@ } }); - all_nums.sort().reverse(); + all_nums.sort((a, b) => { + return a - b; + }); + + const top = all_nums.reverse().slice(0, result_count); - const top = all_nums.slice(0, result_count); new_question.results = question.results.filter((result) => { return top.includes(result.count); }); From 993befc572001202e22c78dc1cb8ccd8990d15e7 Mon Sep 17 00:00:00 2001 From: M1st3r-G <122550667+M1st3r-G@users.noreply.github.com> Date: Sun, 21 May 2023 12:11:40 +0200 Subject: [PATCH 2/3] Create README.md --- script/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 script/README.md diff --git a/script/README.md b/script/README.md new file mode 100644 index 0000000..c74a7b8 --- /dev/null +++ b/script/README.md @@ -0,0 +1 @@ +Scripts to evaluate the Data (or create QR codes) uses the JSON generated by the Website. Fonts need to be in a seperate directory calles customFonts. From 8747bef8efb5329be2b1bf8cc01085e53830b9cb Mon Sep 17 00:00:00 2001 From: M1st3r-G <122550667+M1st3r-G@users.noreply.github.com> Date: Sun, 21 May 2023 12:12:33 +0200 Subject: [PATCH 3/3] Add files via upload --- script/filterData.py | 55 +++++++++++++++++++++++++++++++++++ script/plotData.py | 68 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 script/filterData.py create mode 100644 script/plotData.py diff --git a/script/filterData.py b/script/filterData.py new file mode 100644 index 0000000..4acc038 --- /dev/null +++ b/script/filterData.py @@ -0,0 +1,55 @@ +import json as js +from typing import List +with open("results_teacher.json", "r", encoding="utf-8") as f: + teacherData: dict = js.load(f) +with open("results_student.json", "r", encoding="utf-8") as f: + studentData: dict = js.load(f) + + +def cleanUp(data: dict, maxTop: int, fileName: str): + if fileName == "": + fileName = f"{data=}fixed".split("=")[0] + saveFile = open(fileName, "a", encoding="utf-8") + + for question in data: + questionString: str = question["question"] + answers: List[dict] = question["answers"] + + totalVotes = 0 + bestList = [] + for answer in answers: + curName = answer["possibility"] + curCount = answer["count"] + for index, item in enumerate(bestList): + if item[1] < curCount: + bestList.insert(index, (curName, curCount)) + break + else: + bestList.append((curName, curCount)) + totalVotes += curCount + + counter = -1 + current = 150 + topList = [] + name = "" + for i in bestList: + if counter == maxTop: + break + + if i[1] == current: + name = name + "+" + i[0] + current = i[1] + elif i[1] < current: + topList.append((name, current, f"{round(current * 100 / totalVotes, 2)}%")) + current = i[1] + name = i[0] + counter += 1 + topList.pop(0) + toPrint = f"{questionString},{totalVotes}" + for idx, itm in enumerate(topList): + toPrint = toPrint + f",{itm[0]};{itm[1]};{itm[2]}" + saveFile.write(toPrint.replace(" ", " ") + "\n") + + +cleanUp(studentData, 3, "student3.txt") +cleanUp(teacherData, 3, "teacher3.txt") diff --git a/script/plotData.py b/script/plotData.py new file mode 100644 index 0000000..fef4511 --- /dev/null +++ b/script/plotData.py @@ -0,0 +1,68 @@ +import matplotlib.pyplot as plt +from matplotlib import font_manager +from seaborn import despine + +# Lädt die Fonts aus dem Ordner +font_dirs = ['customFonts/'] +font_files = font_manager.findSystemFonts(fontpaths=font_dirs) +for font_file in font_files: + font_manager.fontManager.addfont(font_file) + + +def displayPlot(data: str, fontFamily, fontName): + # Farbe + colorV = (184/256, 15/256, 15/256) + # Say, "the default sans-serif font is COMIC SANS" + plt.rcParams[f'font.sans-serif'] = fontName + # Then, "ALWAYS use sans-serif fonts" + plt.rcParams[f'font.family'] = fontFamily + + # Update aller Farben + params = {"ytick.color": "w", + "xtick.color": "w", + "axes.labelcolor": "w", + "axes.edgecolor": "w" + } + plt.rcParams.update(params) + # Daten aus dem String trennen + question, total, *answerData = (data.split(",")) + people = [] + values = [] + for a in answerData: + people.append(a.split(";")[0].replace("+", "\n")) + values.append(int(a.split(";")[1])) + + # plotting the chart horizontally Daher der Flip[::-1] + plt.barh(people[::-1], values[::-1], color=colorV) + + # Setzen der Unterschrift (Stimmen) + plt.xlabel(f'Stimmen (Gesamt: {total})', fontsize=16) + # Setzten des Fragen Titels + plt.title(question, color="w", fontsize=22) + + # Hinzufügen der Genauen Stimmenanzahlen hinter den Bars + for i, v in enumerate(values[::-1]): + plt.text(v + 0.5, i, str(v), color='white', fontsize=14, ha='left', va='center') + # Setzen des x-Achse (Platz für Nummer, inlusion der 0) + plt.xlim((0, round(1.1*values[0]))) + # Entfernt die Zahlenabstände der Achsen + plt.tick_params(axis='y', labelsize=14) + plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) + # Entfernt überall (außer unten?) den Strich + despine(left=True) + + # Speichert ds Bild + plt.savefig(f"diagramm/{question.replace(' ', '_')[:question.index('?')]}.png", transparent=True, bbox_inches="tight", dpi=300) + + # Cleart alle einstellungen eingaben + plt.clf() + plt.cla() + + +# Für alle Zeilen +for line in open("student3.txt", "r", encoding="utf-8").readlines(): + displayPlot(line[:-1], "Aleo", "Regular") + +# Das Problem ist die Spine (bottom) die Nicht die Graphen Länge, sondern nun auch die Y-Label länge umfassen Soll +# Das Problem mit der Überschrift ist das GLeiche, sie soll nicht mehr der Grapghen Beschreiben sondern Auch die Länge der Labels umfassen +# Die Labels sind aber eigentlich nur Zahlen, also nicht lang.