Exemple #1
0
    def load_grade(self, path: str) -> None:
        fp_g: Iterator[Tuple[str]] = file_reader(path,
                                                 4,
                                                 sep='\t',
                                                 header=True)
        student_cwid: int
        course: str
        letter_grade: str
        instructor_cwid: int

        try:
            for student_cwid, course, letter_grade, instructor_cwid in fp_g:
                if student_cwid not in self.students:
                    raise ValueError(
                        f"There's a unknown student with CWID: {student_cwid}")
                if instructor_cwid not in self.instructors:
                    raise ValueError(
                        f"There's a grade from unknown instructor: {instructor_cwid}"
                    )

                self.students[student_cwid].add_courses(course, letter_grade)
                self.instructors[instructor_cwid].add_student(course)
        except FileNotFoundError as err:
            print(err)
        except ValueError as err:
            print(err)
Exemple #2
0
    def load_instructor(self, path: str) -> None:
        fp_i: Iterator[Tuple[str]] = file_reader(path, 3, sep='|', header=True)
        CWID: int
        name: str
        dpt: str

        try:
            for CWID, name, dpt in fp_i:
                if CWID in self.instructors:
                    print('Duplicated instructor.')
                else:
                    self.instructors[CWID] = Instructor(CWID, name, dpt)
        except FileNotFoundError as err:
            print(err)
        except ValueError as err:
            print(err)
Exemple #3
0
    def load_majors(self, path) -> None:
        fp_m: Iterator[Tuple[str]] = file_reader(path,
                                                 3,
                                                 sep='\t',
                                                 header=True)
        dept: str
        flag: str
        course: str

        try:
            for dept, flag, course in fp_m:
                if dept not in self.majors.keys():
                    self.majors[dept] = Major(dept)
                self.majors[dept].add_course(flag, course)
        except ValueError as err:
            print(err)
        except FileNotFoundError as err:
            print(err)
Exemple #4
0
    def load_student(self, path: str) -> None:
        fp_s: Iterator[Tuple[str]] = file_reader(path, 3, sep=';', header=True)
        CWID: int
        name: str
        major_name: str

        try:
            for CWID, name, major_name in fp_s:
                if CWID in self.students:
                    print('Duplicated student.')
                elif major_name not in self.majors:
                    print(f"{CWID}: {name} has a unknown major {major_name}")
                else:
                    major: Major = self.majors[major_name]
                    self.students[CWID] = Student(CWID, name, major, {}, 0)
        except FileNotFoundError as err:
            print(err)
            # sys.exit(1)
        except ValueError as err:
            print(err)