Beispiel #1
0
 def test_mod_entity(self):
     self.repo.add_entity(Student(None, "old"))
     self.repo.mod_entity(Student("1", "new"))
     entity, = self.repo.get_entity(Entity(None))
     self.assertEqual(entity["NAME"], "new")
     with self.assertRaises(LookupError):
         self.repo.mod_entity(Student("2", "error"))
 def setUp(self):
     students = StudentRepository()
     self.student1 = Student(1, "Maria")
     self.student2 = Student(2, "Alex")
     self.student3 = Student(3, "Maria")
     students.save(self.student1)
     students.save(self.student2)
     self.student_controller = StudentController(students)
Beispiel #3
0
 def setUp(self):
     self.students = StudentRepository()
     self.student1 = Student(1, "Alex")
     self.students.save(self.student1)
     self.student2 = Student(2, "Filip")
     self.student3 = Student(3, "Paul")
     self.student4 = Student(1, "Luca")
     self.students.save(self.student2)
Beispiel #4
0
 def test_update(self):
     self.repo.add(self.student1)
     self.repo.add(self.student2)
     self.repo.add(self.student4)
     new_student = Student(12, "Radu Stefan", 918)
     self.repo.update(new_student)
     self.assertEqual(self.repo._data,
                      [self.student1, new_student, self.student4])
     new_student2 = Student(13, "Ion Cristian Mihai", 999)
     self.repo.update(new_student2)
Beispiel #5
0
def populateStCtrSTATIC(studCtrl):
    studCtrl.add(Student(1, "Ion", "10"))
    studCtrl.add(Student(2, "Ioan", "15"))
    studCtrl.add(Student(3, "Ioana", "10"))
    studCtrl.add(Student(4, "John", "10"))
    studCtrl.add(Student(5, "Greg", "12"))
    studCtrl.add(Student(6, "Mircea", "10"))
    studCtrl.add(Student(7, "Ana", "10"))
    studCtrl.add(Student(8, "Maria", "20"))
    studCtrl.add(Student(9, "Crez", "12"))
    studCtrl.add(Student(10, "Hary", "10"))
Beispiel #6
0
 def testRests(self):
     self.sCtr.add(deepcopy(self.s))
     self.s.id = 2
     self.s.name = "Mary"
     self.sCtr.add(deepcopy(self.s))
     self.sCtr.add(Student(3, "Zaci", "912"))
     x = self.sCtr.sortByGroup(self.sCtr.getAll())
     self.assertEqual(x[0], Student(3, "Zaci", "912"))
     x = self.sCtr.sortByName(self.sCtr.getAll())
     self.assertEqual(x[0], Student(1, "John", "913"))
     self.assertIsInstance(str(self.sCtr), str)
Beispiel #7
0
 def setUp(self):
     self.grades = GradeRepository()
     self.course1 = Course(1, "Asc", "Vancea")
     self.student1 = Student(1, "Vlad")
     self.student2 = Student(2, "Ion")
     self.course2 = Course(2, "Fp", "I")
     self.grade1 = Grade(self.student1, self.course1, 10)
     self.grade2 = Grade(self.student1, self.course2, 4)
     self.grade3 = Grade(self.student2, self.course1, 7)
     self.grade4 = Grade(self.student1, self.course1, 8)
     self.grades.save(self.grade1)
     self.grades.save(self.grade2)
    def test_add(self):
        student1 = Student(1, "Jerry", 913)
        student2 = Student(2, "Bob", 918)
        student3 = Student(3, "Daniel", 914)

        collection = Collection()
        collection.add(student1)
        collection.add(student2)
        collection.add(student3)

        self.assertEqual(len(collection), 3)

        self.assertEqual(collection[0], student1)
        self.assertEqual(collection[1], student2)
        self.assertEqual(collection[2], student3)
Beispiel #9
0
    def testRepo(self):
        repo = Repository()
        assert repo.add(Student('1', 'Mihai Ionut', 10, 10)) == False
        assert repo.add(Student('2', 'Mihai Ionut', 10, 10)) == False
        assert repo.add(Student('3', 'Mihai Ionut', 10, 10)) == False

        repo.addBonus(Student('1', 'Mihai', 13, 9), 1)
        repo.addBonus(Student('2', 'Ionut', 5, 8), 1)
        for i in repo.getAll():
            if i.getID() == 1:
                assert i.getGrade() == 10
            if i.getID() == 2:
                assert i.getGrade() == 9

        assert len(repo.getAll()) == 10
Beispiel #10
0
 def test_del_entity(self):
     self.repo.add_entity(Student(None, None))
     self.repo.del_entity(Entity("1"))
     entities = self.repo.get_entity(Entity(None))
     self.assertEqual(len(entities), 0)
     with self.assertRaises(LookupError):
         self.repo.del_entity(Entity("1"))
Beispiel #11
0
    def __init__(self):
        # Put csv in dataframe object
        dfStudents = pd.read_csv("files/studentenenvakken.csv",
                                 encoding="ISO-8859-1")
        dfCourses = pd.read_csv("files/courses.csv")

        students = []
        for index, row in dfStudents.iterrows():
            newStudent = Student(row[2])
            students.append(newStudent)

        self.courses = []
        for index, row in dfCourses.iterrows():
            newCourse = Course(row[0], students, row[3])
            self.courses.append(newCourse)

        # Set rooms with sizes
        room1 = Room(1, 41)
        room2 = Room(2, 22)
        room3 = Room(3, 20)
        room4 = Room(4, 56)
        room5 = Room(5, 48)
        room6 = Room(6, 117)
        room7 = Room(7, 60)
        self.rooms = [room1, room2, room3, room4, room5, room6, room7]

        # Set timeblocks
        timeblock1 = TimeBlock(1, 9)
        timeblock2 = TimeBlock(2, 11)
        timeblock3 = TimeBlock(3, 13)
        timeblock4 = TimeBlock(4, 15)
        self.timeblocks = [timeblock1, timeblock2, timeblock3, timeblock4]
Beispiel #12
0
 def get_top_students(self):
     """
     Get all marks, compute total average for every student which has marks by subject average and
         return the first 20% students(or 1 if 20% < 1) with highest averages as ordered dicts.
     """
     marks = self._mark_repository.get_entity(Mark(None, None, None, None))
     students = self._student_repository.get_entity(Student(None, None))
     compact_marks = defaultdict(lambda: defaultdict(list))
     for mark in marks:
         compact_marks[mark["STUD ID"]][mark["SUBJ ID"]].append(mark["MARK"])
     result = []
     for student in students:
         if student["ID"] in compact_marks:
             student_averages = []
             for subject in compact_marks[student["ID"]]:
                 subject_marks = compact_marks[student["ID"]][subject]
                 subject_average = sum([int(mark) for mark in subject_marks]) / len(subject_marks)
                 student_averages.append(subject_average)
             student_average = sum(student_averages) / len(student_averages)
             student["AVERAGE"] = format(student_average, ".2f")
             result.append(student)
     # result = sorted(result, key=lambda item: float(item["AVERAGE"]), reverse=True)
     result = sorted_custom(result, "shell", key=lambda item: float(item["AVERAGE"]), reverse=True)
     top_students_limit = 20 * len(students) // 100 or 1
     return result[:top_students_limit]
Beispiel #13
0
    def test_addstudentrepo(self):
        stud = str(Student('123', 'Mark Park', '912'))

        self.list_s_repo.add_student_to_list(stud)
        self.assertEqual(len(self.list_s_repo.student_list), 1)

        stud = Student('124', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        stud = Student('125', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        stud = Student('126', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        stud = Student('127', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)

        self.assertEqual(len(self.list_s_repo.student_list), 5)
 def get_students_marks_by_subject(self, dto, sort_method, sort_reverse):
     """
     Call validate() on dto, convert dto to Mark and
         return all students which have marks at this subject as ordered dicts.
     dto should contain "subj_id". Missing fields are initialised with None.
     sort_method is "avg" or "name", where "avg" sorts by marks average and "name" sorts by student name.
     sort_reverse instructs to sort in ascending order if False or in descending order if True.
     """
     dto.validate(["subj_id"])
     mark = Mark(None, None, *dto.split(), None)
     marks = self._mark_repository.get_entity(mark)
     students = self._student_repository.get_entity(Student(None, None))
     compact_marks = defaultdict(list)
     for mark in marks:
         compact_marks[mark["STUD ID"]].append(mark["MARK"])
     result = []
     for student in students:
         if student["ID"] in compact_marks:
             student_marks = compact_marks[student["ID"]]
             student_average = sum([int(mark) for mark in student_marks]) / len(student_marks)
             student["MARKS"] = ", ".join(student_marks)
             student["AVERAGE"] = format(student_average, ".2f")
             result.append(student)
     sort_methods = {
         "avg": lambda item: float(item["AVERAGE"]),
         "name": lambda item: item["NAME"]
     }
     result = sorted(result, key=sort_methods[sort_method], reverse=sort_reverse)
     return result
Beispiel #15
0
 def uiUpdateStud(self):
     cmd = input("To update a student specific info type 1\n or 0 for complete infos:").strip()
     s = Student(-1, -1, -1)
     if cmd == '1':
         info = input("To modify: Name type 1, Group type 2: ").strip()
         if info == '1':
             s.id = int(input("Students ID you want to update: "))
             s.name = input("Enter new name: ")
             s.group = self._stud.findByID(s.id).group
             StudentValidator().validate(s)
             self._stud.update(s)
             return True
         elif info == '2':
             s.id = int(input("Students ID you want to update: "))
             s.group = input("Enter new grop: ")
             s.name = self._stud.findByID(s.id).name
             StudentValidator().validate(s)
             self._stud.update(s)
             return True
         else:
             print("Invalid command!")
     elif cmd == '0':
         s.id = int(input("Students ID you want to update: "))
         s.name = input("Enter new name: ")
         s.group = input("Enter new grop: ")
         StudentValidator().validate(s)
         self._stud.update(s)
         return True
     else:
         print("Invalid command!")
Beispiel #16
0
 def generate_students(self, amount):
     for value in range(amount):
         name = Generator.get_random_object(
             self.__first_names) + ' ' + Generator.get_random_object(
                 self.__last_names)
         group = Generator.get_random_number(900, 920)
         self.__student_repository.add(Student(None, name, group))
 def setUp(self):
     self.student = Student(1, "Vlad")
     self.course = Course(10, "Asc", "Vancea")
     self.grade = Grade(self.student, self.course, 10)
     self.invalid_grade = Grade(self.student, self.course, 30)
     self.invalid_grade2 = Grade(self.student, self.course, -30)
     self.validator_g = GradeValidator()
 def test_add(self):
     self.assertEqual(len(self.__student_repository), 0)
     self.__student_repository.add(self.__student)
     self.assertEqual(len(self.__student_repository), 1)
     student2 = Student(None, "Test2", 712)
     self.__student_repository.add(student2)
     self.assertEqual(len(self.__student_repository), 2)
     self.assertEqual(self.__student_repository.get_all()[1], student2)
Beispiel #19
0
 def get_student_by_name(self, dto):
     """
     Call validate on dto(), convert dto to Student and return a list of matching students as ordered dicts.
     dto should contain "name". Missing fields are initialised with None.
     """
     dto.validate(["name"])
     student = Student(None, *dto.split())
     return self._student_repository.get_entity(student)
Beispiel #20
0
def getStud(nb):
    ids = getListOfIDs(nb)
    names = getListOfNames(nb)
    groups = getGroups(nb)
    lista = []
    for i in range(nb):
        lista.append(Student(ids[i], names[i], groups[i]))
    return lista
Beispiel #21
0
 def setUp(self):
     self.students = StudentRepository()
     courses = CourseRepository()
     grades = GradeRepository()
     self.course1 = Course(1, "Asc", "Vancea")
     self.student1 = Student(1, "Vlad")
     self.student2 = Student(2, "Alex")
     courses.save(self.course1)
     self.students.save(self.student1)
     self.students.save(self.student2)
     self.course2 = Course(2, "Fp", "I")
     courses.save(self.course2)
     self.grade1 = Grade(self.student1, self.course1, 10)
     self.grade2 = Grade(self.student1, self.course2, 4)
     grades.save(self.grade1)
     grades.save(self.grade2)
     self.grade_controller = GradeController(courses, self.students, grades)
Beispiel #22
0
 def testGetByGr(self):
     self.sCtr.add(deepcopy(self.s))
     self.s.id = 2
     self.s.name = "Mary"
     self.sCtr.add(deepcopy(self.s))
     self.sCtr.add(Student(3, "Daci", "912"))
     lg = self.sCtr.getStudByGroup("913")
     self.assertEqual(len(lg), 2)
Beispiel #23
0
 def testUpdate(self):
     self.sCtr.add(deepcopy(self.s))
     self.s.id = 2
     self.s.name = "Mary"
     self.sCtr.add(deepcopy(self.s))
     self.sCtr.update(Student(2, "Jane", '321'))
     self.assertEqual(self.sCtr.getAll()[1].name, "Jane")
     self.assertRaises(TypeError, self.sCtr.update, 3)
 def create(self, id, name):
     '''
     create -> Student
     Creates and returns a Student that has the given id and name
     :param id: int >= 0
     :param name: string
     '''
     student = Student(id, name)
     return student
Beispiel #25
0
    def add_student(self, id, name, group):
        """
        we add a student with the given id, name, group
        :param id: the given id
        :param name: the given name
        :param group: the given group
        """
        self.validator.validate(self, Student(id, name, group))
        student = Student(id, name, group)

        undo_function = FunctionCall(
            self.student_list_service.remove_student_from_list, student)
        redo_function = FunctionCall(
            self.student_list_service.add_student_to_list, student)
        operation = OperationCall(undo_function, redo_function)
        self._undo_service.record(operation)

        self.student_list_service.add_student_to_list(student)
Beispiel #26
0
 def del_student(self, dto):
     """
     Call validate on dto(), convert dto to Student and delete it from the repo.
     dto should contain "id". Missing fields are initialised with None.
     Repo exceptions are raised.
     """
     dto.validate(["id"])
     student = Student(*dto.split(), None)
     self._student_repository.del_entity(student)
Beispiel #27
0
    def test_removestudentrepo(self):

        self.assertEqual(len(self.list_s_repo.student_list), 0)

        stud = Student('124', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        self.list_s_repo.remove_student_from_list(stud)
        stud = Student('125', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        self.list_s_repo.remove_student_from_list(stud)
        stud = Student('126', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        self.list_s_repo.remove_student_from_list(stud)
        stud = Student('127', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        self.list_s_repo.remove_student_from_list(stud)

        self.assertEqual(len(self.list_s_repo.student_list), 0)
Beispiel #28
0
    def test_updatestudentrepo(self):
        stud = Student('124', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        stud = Student('125', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        stud = Student('126', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)
        stud = Student('127', 'Mark Park', '912')
        self.list_s_repo.add_student_to_list(stud)


        self.list_s_repo.update_student_in_list(0, '913')
        self.assertEqual(self.list_s_repo[0].student_group, '913')
        try:
            self.list_s_repo.update_student_in_list(0,'912')
            self.assertTrue('OK')
        except studentRepoException:
            self.assertFalse('Not good')
 def testRmvStGr(self):
     self._grCtr.student.add(Student(1, "John", "913"))
     self.stCtr.add(Student(2, "Mary", "913"))
     self.assertEqual(len(self.stCtr.getAll()), 2)
     self._grCtr.add(Grade(3, 1, 2.0))
     self._grCtr.add(Grade(4, 1, 7.0))
     self._grCtr.add(Grade(2, 1, 5.0))
     self._grCtr.add(Grade(2, 2, 3.0))
     self.assertEqual(len(self._grCtr.getAll()), 4)
     self._grCtr.removeStud(1)
     self.assertEqual(len(self.stCtr.getAll()), 1)
     self.assertEqual(len(self._grCtr.getAll()), 1)
     self.undo.undo()
     self.assertEqual(len(self.stCtr.getAll()), 2)
     self.assertEqual(len(self._grCtr.getAll()), 4)
     self.undo.redo()
     self.assertEqual(self.stCtr.getAll()[0], Student(2, "Mary", "913"))
     self.assertEqual(self._grCtr.getAll()[0], Grade(2, 2, 3.0))
     self.assertFalse(self._grCtr.removeStud(1))
Beispiel #30
0
 def generate_random_student(self):
     for i in range(0, 10):
         id = self.generate_random_id()
         surname = ['Dan', 'Pop', 'Marcus', 'George', 'Farcau', 'Molnar', 'Vancea', 'Pintea', 'Nistor']  # 9 terms
         names = ['Sergiu', 'George', 'Raul', 'Catalin', 'Marian', 'Raluca', 'Andrei', 'Mircea', 'Alex',                       'Victor']  # 10
         groups = ['911', '912', '913', '914', '915', '916', '917']  # 7 terms
         rand_names = surname[random.randint(0,8)] + " " + names[random.randint(0,9)]
         rand_groups = groups[random.randint(0,6)]
         student = Student(id, rand_names, rand_groups)
         self.llist_s.student_list_service.add_student_to_list(student)