Beispiel #1
0
class CurriculumUnit(db.Model, _CurriculumUnit):
    __tablename__ = 'curriculum_unit'
    __table_args__ = (db.UniqueConstraint('subject_id', 'stud_group_id'), )

    id = db.Column('curriculum_unit_id',
                   db.INTEGER,
                   primary_key=True,
                   autoincrement=True)
    subject_id = db.Column(db.ForeignKey('subject.subject_id'),
                           nullable=False,
                           index=True)
    stud_group_id = db.Column(db.ForeignKey('stud_group.stud_group_id'),
                              nullable=False,
                              index=True)
    teacher_id = db.Column(db.ForeignKey('teacher.teacher_id'),
                           nullable=False,
                           index=True)
    mark_type = db.Column('mark_type',
                          db.Enum(*MarkTypeDict.keys()),
                          nullable=False)
    hours_att_1 = db.Column('hours_att_1', db.SMALLINT, nullable=False)
    hours_att_2 = db.Column('hours_att_2', db.SMALLINT, nullable=False)
    hours_att_3 = db.Column('hours_att_3', db.SMALLINT, nullable=False)

    subject = db.relationship('Subject')
    teacher = db.relationship('Teacher')
    att_marks = db.relationship('AttMark',
                                lazy=True,
                                backref='curriculum_unit')
Beispiel #2
0
class ScheduleRecord(db.Model):
    __tablename__='chedule_records'
    id = db.Column(db.Integer, primary_key = True)

    doctor_id = db.Column(db.Integer, db.ForeignKey('doctors.id'),nullable=False)
    doctor = db.relationship('Doctor', backref=db.backref('schedules', lazy=True))

    date = db.Column(db.Date,nullable=False)
    status = db.Column(db.String(40), nullable=False)
    unique_status = db.UniqueConstraint('doctor_id','date')
Beispiel #3
0
class Appointment(db.Model):
    __tablename__='appointments'
    id = db.Column(db.Integer, primary_key=True)
    record = db.relationship('Record', uselist=False)

    doctor_id= db.Column(db.Integer, db.ForeignKey('doctors.id'), nullable=False)
    doctor = db.relationship('Doctor')

    date = db.Column(db.Date, nullable=False)
    time = db.Column(db.Time, nullable=False)
    unique_time = db.UniqueConstraint('doctor_id','date','time')
Beispiel #4
0
class StudGroup(db.Model, _ObjectWithSemester, _ObjectWithYear):
    __tablename__ = 'stud_group'
    __table_args__ = (db.UniqueConstraint('stud_group_year',
                                          'stud_group_semester',
                                          'stud_group_num',
                                          'stud_group_subnum'), )

    id = db.Column('stud_group_id',
                   db.INTEGER,
                   primary_key=True,
                   autoincrement=True)
    year = db.Column('stud_group_year', db.SMALLINT, nullable=False)
    semester = db.Column('stud_group_semester', db.SMALLINT, nullable=False)
    num = db.Column('stud_group_num', db.SMALLINT, nullable=False)
    subnum = db.Column('stud_group_subnum',
                       db.SMALLINT,
                       nullable=False,
                       default=0)
    specialty = db.Column('stud_group_specialty',
                          db.String(200),
                          nullable=False)
    specialization = db.Column('stud_group_specialization', db.String(200))

    active = db.Column('stud_group_active',
                       db.BOOLEAN,
                       nullable=False,
                       default=True)

    students = db.relationship('Student', lazy=True, backref='stud_group',\
                               order_by="Student.surname, Student.firstname, Student.middlename")
    curriculum_units = db.relationship('CurriculumUnit',
                                       lazy=True,
                                       backref='stud_group',
                                       order_by="CurriculumUnit.id")

    @property
    def num_print(self):
        if self.num is None or self.subnum is None:
            return None
        return "%d.%d" % (self.num, self.subnum) if self.subnum != 0 else str(
            self.num)
Beispiel #5
0
class AttMark(db.Model):
    __tablename__ = 'att_mark'
    __table_args__ = (db.UniqueConstraint('curriculum_unit_id',
                                          'student_id'), )

    att_mark_id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    curriculum_unit_id = db.Column(
        db.ForeignKey('curriculum_unit.curriculum_unit_id'), nullable=False)
    student_id = db.Column(db.ForeignKey('student.student_id'),
                           nullable=False,
                           index=True)
    att_mark_1 = db.Column(db.SMALLINT)
    att_mark_2 = db.Column(db.SMALLINT)
    att_mark_3 = db.Column(db.SMALLINT)
    att_mark_exam = db.Column(db.SMALLINT)
    att_mark_append_ball = db.Column(db.SMALLINT)
    student = db.relationship('Student')

    @property
    def result_print(self):
        att_marks = (self.att_mark_1, self.att_mark_2, self.att_mark_3)
        if any(m is None for m in att_marks):
            return None

        mark_results = MarkResult[self.curriculum_unit.mark_type]
        min_ball = MarkResult["test_simple"][1]["min"]
        max_ball = mark_results[-1]["max"]

        if self.curriculum_unit.mark_type == "exam" and self.att_mark_exam is None:
            return None

        if any(m < min_ball for m in att_marks):
            return min(att_marks), mark_results[0]

        hours = (self.curriculum_unit.hours_att_1,
                 self.curriculum_unit.hours_att_2,
                 self.curriculum_unit.hours_att_3)
        ball_raw = sum(
            [att_marks[i] * hours[i]
             for i in range(len(att_marks))]) / sum(hours)
        # Округление
        ball = int(ball_raw)
        if ball_raw - ball >= 0.5:
            ball += 1

        if self.curriculum_unit.mark_type == "exam":
            ball += self.att_mark_exam

        if self.curriculum_unit.mark_type in (
                "exam", "test_diff") and self.att_mark_append_ball is not None:
            ball += self.att_mark_append_ball

        if ball > max_ball:
            ball = max_ball

        for mr in mark_results:
            if mr["min"] <= ball <= mr["max"]:
                return ball, mr

    @property
    def fill_data(self):
        r = {
            "att_1": self.att_mark_1 is not None,
            "att_2": False,
            "att_3": False,
            "all": False
        }

        r["att_2"] = r["att_1"] and self.att_mark_2 is not None
        r["all"] = r["att_3"] = r["att_2"] and self.att_mark_3 is not None

        if self.curriculum_unit.mark_type == "exam":
            r["all"] = r["all"] and self.att_mark_exam is not None

        return r