def instructors_DB(self): """ Structure: CWID, Name, Department reading in the instructors.txt file line by line, updating the basic info for one instructor """ for person_info in file_reader(self.instructors_path, 3, sep='|', header=True): self.instructors[person_info[0]] = Instructor(person_info)
def test_file_reader(self) -> None: """ This function is used to test file_reader function """ path = "G:/Stevens/Courses/Sem4/Assignment/SSW810_Python/Assignment8/input/student_majors.txt" file = file_reader(path, 3, '|', header=True) self.assertTrue(next(file) == ('123', 'Jin He', 'Computer Science')) self.assertTrue( next(file) == ('234', 'Nanda Koka', 'Software Engineering')) self.assertTrue( next(file) == ('345', 'Benji Cai', 'Software Engineering'))
def majors_DB(self): """ Structure: Department, Flag, Course Method: If major is already in the dict, then ignore, just update info. As each time declare an instance, the required and electives would be an emplty set, this would avoid clean the set by mistake. """ for major, flag, course in file_reader(self.majors_path, 3, sep='\t', header=True): if major not in self.majors: self.majors[major] = Major(major) self.majors[major].update_major(flag, course)
def students_DB(self): """ Structure: CWID, Name, Major reading in the students.txt file line by line, updating the basic info for one student also for each instance of students, passing in major info """ for person_info in file_reader(self.students_path, 3, sep=';', header=True): CWID, name, major = person_info if major not in self.majors: raise ValueError( 'Error! Missing major {} information.'.format(major)) if CWID not in self.students: self.students[CWID] = Student(person_info, self.majors[major])
def grades_DB(self): """ Structure: CWID_student, Course, Grade, CWID_instructor """ for CWID_stu, course, grade, CWID_ins in file_reader(self.grades_path, 4, sep='|', header=True): if CWID_stu not in self.students.keys( ): # course info in grades.txt but no corresponding student is found raise ValueError( 'Student CWID {} is not in the student system.'.format( CWID_stu)) # course info in grades.txt but no corresponding instructor is found if CWID_ins not in self.instructors.keys(): raise ValueError( 'Instructor CWID {} is not in the instructor system.'. format(CWID_stu)) # add a course and grade to the student containers self.students[CWID_stu].add_course(course, grade) # add a course and increment the number of students by 1 to the instructor containers self.instructors[CWID_ins].add_course(course)