예제 #1
0
class AvailableSubjects(db.Model, SavableModel):
    __tablename__ = 'availableSubjects'

    id = db.Column(db.Integer, primary_key=True)
    sys_year = db.Column(db.Integer)
    semester = db.Column(db.Enum(SemesterEnum))
    subject_id = db.Column(db.Integer)
    # subject_id = db.Column(db.Integer, db.ForeignKey('subject.id'))
    department_id = db.Column(db.Integer)

    # department_id = db.Column(db.Integer, db.ForeignKey('department.id'))

    def __init__(self, sys_year: int, semester: SemesterEnum, subject: Subject,
                 department: Department):
        self.sys_year = sys_year
        self.semester = semester
        self.subject_id = subject.id
        self.department_id = department.id

    @property
    def subject(self):
        return Subject.query.filter_by(id=self.subject_id).first()

    @staticmethod
    def available_subjects_for_year_sem(year: int, sem: SemesterEnum,
                                        dept: Department):
        subj = AvailableSubjects.query.filter_by(sys_year=year,
                                                 semester=sem,
                                                 department_id=dept.id).all()
        return [x.subject.code for x in subj]
예제 #2
0
class FacultyAccounts(db.Model, SavableModel):
    __tablename__ = 'facultyAccounts'

    id = db.Column(db.Integer, primary_key=True)
    department_id = db.Column(db.Integer)
    # department_id = db.Column(db.Integer, db.ForeignKey('department.id'))
    account_name = db.Column(db.String(256), unique=True)
    account_password = db.Column(db.String(256))
    account_type = db.Column(db.Enum(AccountType))

    def __init__(self, account_name: str, account_password: str,
                 department: Department, account_type: AccountType):
        self.account_name = account_name
        self.account_password = account_password
        self.department_id = department.id
        self.account_type = account_type

    @property
    def department(self) -> str:
        d: Department = Department.query.filter_by(
            id=self.department_id).first()
        return d.name
예제 #3
0
class Subject(db.Model, SavableModel):
    __tablename__ = 'subject'

    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.String(60))
    title = db.Column(db.String(256))
    pre_req = db.Column(db.String(256))
    year = db.Column(db.Enum(YearEnum))
    semester = db.Column(db.Enum(SemesterEnum))
    units = db.Column(db.Integer)

    def __init__(self, code: str, title: str, pre_req: list, year: YearEnum,
                 semester: SemesterEnum, units: int):
        self.units = units
        self.code = code
        self.title = title
        if len(pre_req) > 0:
            self.pre_req = self._pre_req_separator.join(pre_req)
        else:
            self.pre_req = ''
        self.year = year
        self.semester = semester

    @property
    def _pre_req_separator(self):
        return ','

    @property
    def pre_requisite_codes(self) -> [str]:
        r = []
        if len(self.pre_req) > 0:
            r = self.pre_req.split(self._pre_req_separator)
        return r

    @staticmethod
    def check_subject(code: str,
                      title: str,
                      pre_req: list,
                      year: YearEnum,
                      semester: SemesterEnum,
                      units: int,
                      create_if_not_exist=False):
        sep = ','
        pre_req = sep.join(pre_req) if len(pre_req) > 0 else ''
        s: Subject = Subject.query.filter_by(code=code,
                                             title=title,
                                             pre_req=pre_req,
                                             year=year,
                                             semester=semester,
                                             units=units).first()
        if s is None and create_if_not_exist:
            pre_req = pre_req.split(sep) if len(pre_req) > 0 else []
            s = Subject(code=code,
                        title=title,
                        pre_req=pre_req,
                        year=year,
                        semester=semester,
                        units=units)
            s.save()
        return s

    def open_subject(self, sem: SemesterEnum, year: int, dept: Department):
        try:
            if not self.is_open_this_year_sem(sem, year, dept):
                a = AvailableSubjects(year, sem, self, dept)
                a.save()
        except Exception as e:
            print(e)
            return False
        return True

    def is_open_this_year_sem(self, sem: SemesterEnum, year: int,
                              dept: Department):
        a = AvailableSubjects.query.filter_by(sys_year=year,
                                              semester=sem,
                                              subject_id=self.id,
                                              department_id=dept.id).first()
        return a is not None

    @property
    def to_json(self):
        return {
            'subject_id': self.id,
            'subject_code': self.code,
            'title': self.title,
            'pre_req': self.pre_requisite_codes,
            'units': self.units,
            'semester': self.semester.name,
            'year': self.year.name
        }
예제 #4
0
class NewSemData(db.Model, SavableModel):
    __tablename__ = 'newSemData'

    id = db.Column(db.Integer, primary_key=True)
    sys_year = db.Column(db.String(256))
    semester = db.Column(db.Enum(SemesterEnum))
    is_current_semester = db.Column(db.Boolean)

    def __init__(self, sys_year: str, semester: SemesterEnum):
        if not NewSemData.new_sem_is_unique(sys_year.strip(), semester):
            raise Exception('duplicate Data Detected')
        l = NewSemData.latest_id()
        self.id = 0 if l is None else l.id + 1
        self.sys_year = sys_year.strip()
        self.semester = semester
        self.use_as_current()

    def use_as_current(self):
        o = NewSemData.query.filter_by().all()
        for x in o:
            if x.id == self.id:
                x.is_current_semester = True
                continue
            x.is_current_semester = False
        db.session.commit()

    @staticmethod
    def get_current_semester():
        l = NewSemData.query.filter_by(is_current_semester=True).first()
        if l is None:
            l = NewSemData.latest_id()
        return l

    @staticmethod
    def latest_id():
        ls = NewSemData.query.order_by(NewSemData.id.desc()).first()
        return ls

    @staticmethod
    def new_sem_is_unique(sys_year: str, sem: SemesterEnum):
        rv = NewSemData.query.filter_by(sys_year=sys_year,
                                        semester=sem).first()
        print('rv', rv)
        return rv is None

    def to_json(self):
        s = AvailableSubjectEnhance.query.filter_by(new_sem_id=self.id).all()
        s_l = []
        if s is not None:
            s_l = [{'id': q.id, 'code': q.subject_code} for q in s]
        rv = {
            'year': self.sys_year,
            'semester': self.semester.name,
            'subjects': s_l
        }
        return rv

    def to_json_lite(self):
        rv = {
            'id': self.id,
            'year': self.sys_year,
            'semester': self.semester.value,
            'activated': self.is_current_semester
        }
        return rv

    def delete_sem_data(self):
        s = AvailableSubjectEnhance.query.filter_by(new_sem_id=self.id).all()
        for x in s:
            x.delete_avail_sub()
        NewSemData.query.filter_by(id=self.id).delete()
        db.session.commit()
예제 #5
0
class StudentData(db.Model, SavableModel):
    __tablename__ = 'studentData'

    student_id = db.Column(db.Integer, primary_key=True)
    full_name = db.Column(db.String(256))
    course_id = db.Column(db.Integer)
    # course_id = db.Column(db.Integer, db.ForeignKey('course.id'))
    year = db.Column(db.Enum(YearEnum))

    def __init__(self, student_id: int, full_name: str, course: Course,
                 year: YearEnum):
        self.student_id = student_id
        self.full_name = full_name.lower()
        self.course_id = course.id
        self.year = year

    @property
    def student_full_name(self):
        return self.full_name.lower()

    @student_full_name.setter
    def student_full_name(self, val: str):
        self.full_name = val.lower()

    @property
    def course(self):
        return Course.query.filter_by(id=self.course_id).first()

    @property
    def curriculum(self):
        prefix = '20'
        return nearest_curriculum(str(self.student_id), self.course_id, prefix)

    @property
    def student_subjects(self) -> [any]:
        if self.curriculum is None:
            return []
        return self.curriculum.subject_list_to_json

    @property
    def grades(self):
        return StudentGrades.query.filter_by(student_id=self.student_id).all()

    @property
    def passed_subjects(self):
        p = []
        for x in self.grades:
            z: StudentGrades = x
            if grade_is_passed(float(z.grade)):
                p.append(str(z.subject_code))
        return p

    def grades_2_list(self):
        return [{
            'code': g.subject_code,
            'grade': g.grade
        } for g in self.grades]

    def to_json(self):
        return {
            'id': self.student_id,
            'name': self.full_name,
            'year': self.year.name,
            'course': self.course.title,
            'course_curriculum': self.curriculum.to_json,
            'grades': self.grades_2_list()
        }

    @staticmethod
    def search_student(sid):
        return StudentData.query.filter_by(student_id=int(sid)).first()