示例#1
0
    def scan_student_info(self):
        """scans students.txt and populate it to a dictionary"""

        path = "students.txt"
        for i in file_reader(path, 3, ';', True, 0):
            self.student_dict[i[0]] = [i[1], i[2], 0, 0, [], [], []]

        path = "grades.txt"
        for i in file_reader(path, 4, '|', True):
            self.student_dict[i[0]][2] += self.grade_dict[i[2]]
            self.student_dict[i[0]][3] += 1
            self.student_dict[i[0]][4].append(i[1])

            # populate course_dict
            try:
                self.course_dict[i[1]][0].append(i[0])

            except Exception as e:
                self.course_dict[i[1]] = [[], '', '', '']
                self.course_dict[i[1]][0].append(i[0])
            self.course_dict[i[1]][1] = i[3]
        for i in self.student_dict.values():
            i[5] = diff(self.major_dict[i[1]][0], i[4])
            if common(self.major_dict[i[1]][1], i[4]):
                i[6] = self.major_dict[i[1]][1]
        print('Student Scanned')
示例#2
0
 def scan_majors(self):
     """scans majors.txt and populate it to a dictionary"""
     path = "majors.txt"
     for i in file_reader(path, 3, '\t', True, 2):
         self.major_dict[i[0]] = [[], []]
     for i in file_reader(path, 3, '\t', True):
         if i[1] == 'R':
             self.major_dict[i[0]][0].append(i[2])
         elif i[1] == 'E':
             self.major_dict[i[0]][1].append(i[2])
         else:
             raise ValueError("Course Flag Error")
     print("Majors Scanned")
 def test_file_reader_should_read(self):
     """test bahavior when file opened successfully"""
     path = "/Users/yikanwang/Documents/Fall2020/SSW 810/homework/test_file"
     false_header: Iterator[list[str]] = file_reader(path, 3, ' ')
     self.assertEqual(next(false_header), ['xander', 'score', '3'])
     self.assertEqual(next(false_header), ['julie', 'score', '4'])
     self.assertEqual(next(false_header), ['adam', 'score', '7'])
     self.assertNotEqual(next(false_header), ['noname', 'score', '7'])
示例#4
0
    def scan_instructors(self):
        """scans instructors.txt and populate it to dictionary"""

        path = "instructors.txt"
        for i in file_reader(path, 3, '|', True):
            self.instructor_dict[i[0]] = [i[1]]
            self.instructor_dict[i[0]].append(i[2])

        keys = self.course_dict.keys()
        for key in keys:
            ins_Id = self.course_dict[key][1]
            self.course_dict[key][2] = self.instructor_dict[ins_Id][0]
            self.course_dict[key][3] = self.instructor_dict[ins_Id][1]

        print('Instructor Scanned')
 def test_file_reader_should_throw_if_file_found(self):
     """test bahavior when file not opened successfully"""
     directory = 'nosuchfile.txt'
     with self.assertRaises(StopIteration):
         next(file_reader(directory, 3, ' '))