Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions script/README.md
Original file line number Diff line number Diff line change
@@ -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.
55 changes: 55 additions & 0 deletions script/filterData.py
Original file line number Diff line number Diff line change
@@ -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")
68 changes: 68 additions & 0 deletions script/plotData.py
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 5 additions & 2 deletions src/routes/admin/evaluate/[type]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down