From 0cc4ed243d11a1c5c1360cf97875f0230ba0da3b Mon Sep 17 00:00:00 2001 From: DerGrumpf Date: Sun, 5 Jan 2025 14:21:34 +0100 Subject: [PATCH] Added: Grapher and DB Dump --- model.py | 43 ++++++++++++++++++++++++++-- student_graph.py | 73 ++++++++++++++++++++++++++++++++++++++++-------- view.py | 2 +- 3 files changed, 104 insertions(+), 14 deletions(-) diff --git a/model.py b/model.py index b843d4d..4040768 100644 --- a/model.py +++ b/model.py @@ -34,7 +34,7 @@ db.connect() db.create_tables([Class, Student, Lecture, Submission]) if __name__ == "__main__": - import random + '''import random # Generate Test Data class1 = Class.create(name="WiSe 22/23") class2 = Class.create(name="WiSe 23/24") @@ -58,4 +58,43 @@ if __name__ == "__main__": sub1_nova = Submission.create(student_id=nova.id, lecture_id=lec1.id, points=random.randint(0, lec1.points)) sub2_nova = Submission.create(student_id=nova.id, lecture_id=lec3.id, points=random.randint(0, lec3.points)) sub1_kathi = Submission.create(student_id=kathi.id, lecture_id=lec3.id, points=random.randint(0, lec3.points)) - sub1_vici = Submission.create(student_id=victoria.id, lecture_id=lec2.id, points=random.randint(0, lec2.points)) + sub1_vici = Submission.create(student_id=victoria.id, lecture_id=lec2.id, points=random.randint(0, lec2.points))''' + + classes = Class.select() + d = {c.name: { + "DB ID": c.id, + "Date": c.created_at.isoformat(), + "Students": [ + { + "DB ID": s.id, + "Date": s.created_at.isoformat(), + "First Name": s.prename, + "Last Name": s.surname, + "Sex": s.sex, + "Submissions": [ + { + "DB ID": sub.id, + "Date": sub.created_at.isoformat(), + "Points": sub.points, + "Lecture ID": sub.lecture_id.id + } + for sub in Submission.select().where(Submission.student_id == s.id) + ] + } + for s in Student.select().where(Student.class_id == c.id) + ], + "Lectures": [ + { + "DB ID": l.id, + "Date": l.created_at.isoformat(), + "Title": l.title, + "Points": l.points + } + for l in Lecture.select().where(Lecture.class_id == c.id) + ], + } + for c in classes + } + + import json + print(json.dumps(d)) diff --git a/student_graph.py b/student_graph.py index 04b29d3..3c59689 100644 --- a/student_graph.py +++ b/student_graph.py @@ -2,26 +2,77 @@ import imgui import numpy as np import random +from datatypes import * + from model import * class StudentGraph: def __init__(self): super().__init__() - def __call__(self): - # Setup Data - submissions = Submission.select().where(Submission.student_id == 1) - data = np.array([submission.points/Lecture.get_by_id(submission.lecture_id).points*100 for submission in submissions], dtype=np.float32) + self.classes = None + self.students = None + self.select_class = 0 + self.select_student = 0 + + def __call__(self): + + self.classes = Class.select() + self.students = Student.select().where(Student.class_id == self.classes[self.select_class].id) if self.classes else None + + # Setup Data + submissions = Submission.select().where(Submission.student_id == self.students[self.select_student].id) if self.students else None + data = np.array([submission.points/Lecture.get_by_id(submission.lecture_id).points*100 for submission in submissions], dtype=np.float32) if submissions else None + with imgui.begin("Student Graph", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE): w, h = imgui.get_content_region_available() + + if not isinstance(data, np.ndarray): + imgui.text("No Submission available for this Student") + else: + imgui.plot_histogram( + "##Data", data, overlay_text="Performance per Lecture (in %)", + scale_min=0.0, scale_max=100, + graph_size=(w, h*0.69) + ) + + with imgui.begin_child("Select Class", w/3, h*0.3, border=True): + if not self.classes: + imgui.text("No Class could be queried") + else: + for n, c in enumerate(self.classes, start = 1): + display = f"{n}. {c.name}" + opened, _ = imgui.selectable(display, self.select_class == n-1) + if opened: + self.select_class = n-1 + self.select_student = 0 + + imgui.same_line() - imgui.plot_histogram( - "##Data", data, overlay_text="Performance per Lecture (in %)", - scale_min=0.0, scale_max=100, - graph_size=(w, h*0.9) - ) + with imgui.begin_child("Select Student", w/3, h*0.3, border=True): + if not self.students: + imgui.text("No Student in this class") + else: + for n, s in enumerate(self.students, start = 1): + display = f"{n}. {s.prename} {s.surname}" + opened, _ = imgui.selectable(display, self.select_student == n-1) + if opened: + self.select_student = n-1 - imgui.button("Text") - + imgui.same_line() + + with imgui.begin_child("Student Info", w/3, h*0.3, border=True): + if not submissions: + imgui.text("No Submissions for this Student") + else: + for n, s in enumerate(submissions): + lecture = Lecture.get_by_id(s.lecture_id) + points = s.points + if points.is_integer(): + points = int(points) + + display = f"{n}. {lecture.title} {points}/{lecture.points}" + COLOR = COLOR_TEXT_PASSED if points > lecture.points*0.3 else COLOR_TEXT_FAILED + imgui.text_colored(display, *COLOR) diff --git a/view.py b/view.py index 24ca2f2..499c6a5 100644 --- a/view.py +++ b/view.py @@ -31,7 +31,7 @@ class GrapherLayout: self.student_graph = StudentGraph() def __call__(self): - set_layout((0.7, 0.4), (0.1, 0.1)) + set_layout((1, 0.4), (0, 0.02)) self.student_graph() class EditorLayout: