grapher/model.py
2025-01-05 01:01:39 +01:00

62 lines
2.8 KiB
Python

from peewee import *
from datetime import datetime
db = SqliteDatabase('test.db')
class BaseModel(Model):
class Meta:
database = db
class Class(BaseModel):
name = CharField()
created_at = DateTimeField(default=datetime.now)
class Student(BaseModel):
prename = CharField()
surname = CharField()
sex = CharField()
class_id = ForeignKeyField(Class, backref='class')
created_at = DateTimeField(default=datetime.now)
class Lecture(BaseModel):
title = CharField()
points = IntegerField()
class_id = ForeignKeyField(Class, backref='class')
created_at = DateTimeField(default=datetime.now)
class Submission(BaseModel):
student_id = ForeignKeyField(Student, backref='student')
lecture_id = ForeignKeyField(Lecture, backref='lecture')
points = FloatField()
created_at = DateTimeField(default=datetime.now)
db.connect()
db.create_tables([Class, Student, Lecture, Submission])
if __name__ == "__main__":
import random
# Generate Test Data
class1 = Class.create(name="WiSe 22/23")
class2 = Class.create(name="WiSe 23/24")
class3 = Class.create(name="WiSe 24/25")
phil = Student.create(prename="Phil", surname="Keier", sex="Male", class_id=class1.id)
calvin = Student.create(prename="Calvin", surname="Brandt", sex="Male", class_id=class2.id)
nova = Student.create(prename="Nova", surname="Eib", sex="Female", class_id=class1.id)
kathi = Student.create(prename="Katharina", surname="Walz", sex="Female", class_id=class3.id)
victoria = Student.create(prename="Victoria", surname="Möller", sex="Female", class_id=class3.id)
lec1 = Lecture.create(title="Tutorial 1", points=30, class_id=class1.id)
lec2 = Lecture.create(title="Tutorial 1", points=30, class_id=class3.id)
lec3 = Lecture.create(title="Tutorial 2", points=20, class_id=class1.id)
lec4 = Lecture.create(title="Tutorial 2", points=20, class_id=class2.id)
lec5 = Lecture.create(title="Extended Applications", points=44, class_id=class1.id)
sub1_phil = Submission.create(student_id=phil.id, lecture_id=lec1.id, points=random.randint(0, lec1.points))
sub2_phil = Submission.create(student_id=phil.id, lecture_id=lec3.id, points=random.randint(0, lec3.points))
sub3_phil = Submission.create(student_id=phil.id, lecture_id=lec5.id, points=random.randint(0, lec5.points))
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))