Пример #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"))
Пример #2
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)
Пример #3
0
    def __readFromFile(self):

        self.data = {}
        with open(self.__file, "r") as fp:
            for line in fp:
                args = line.split("|")
                x = Student(int(args[0]), args[1])
                self.data[x.getID()] = x
 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)
Пример #5
0
 def mod_student(self, dto):
     """
     Call validate on dto(), convert dto to Student, call validate() on it replace it in the repo.
     dto should contain "id,name". Missing fields are initialised with None.
     Validate and repo exceptions are raised.
     """
     dto.validate(["id", "name"])
     student = Student(*dto.split())
     Student.validate(student)
     self._student_repository.mod_entity(student)
Пример #6
0
 def add_student(self, dto):
     """
     Call validate on dto(), convert dto to Student, call validate() on it and add it to the repo.
     dto should contain "name". Missing fields are initialised with None.
     Validate and repo exceptions are raised.
     """
     dto.validate(["name"])
     student = Student(None, *dto.split())
     student.validate()
     self._student_repository.add_entity(student)
Пример #7
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)
Пример #8
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"))
Пример #9
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)
Пример #10
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)
Пример #11
0
    def readAStudent(self):
        while True:
            try:
                id = input("ID: ")
                name = input("Name: ")
                attendaces = input("Attendaces: ")
                grade = input("Grade: ")
                stud = Student(id, name, int(attendaces), int(grade))
                assert stud.isValid()
                break
            except:
                print("Invalid Input, try again!")

        return stud
Пример #12
0
 def test_failed_students(self):
     student3 = Student(3, "Maria")
     self.students.save(student3)
     self.grade_controller.add(self.student2.get_id(),
                               self.course1.get_id(), 4)
     self.grade_controller.add(self.student2.get_id(),
                               self.course2.get_id(), 5)
     self.grade_controller.add(student3.get_id(), self.course1.get_id(), 4)
     self.grade_controller.add(student3.get_id(), self.course2.get_id(), 7)
     self.assertEqual(self.grade_controller.failed_students()[0][0],
                      "Vancea")
     self.assertEqual(self.grade_controller.failed_students()[1][0], "I")
     self.assertEqual(self.grade_controller.failed_students()[0][1], 2)
     self.assertEqual(self.grade_controller.failed_students()[1][1], 1)
Пример #13
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
    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)
Пример #15
0
    def __readStudentFromFile(self, line):
        """
        Citeste un student dintr-un fisier si returneaza obiectul
        :param line: linia de pe care se citeste studentul - string
        :return student: obiectul corespunzator studentului
        """
        #structura unei linii din fisier: IDStudent,Prenume,Nume
        attr = line.split(",")
        student = Student(attr[0], attr[1], attr[2])

        optionals = self.__getStudentOptionals(attr[0])
        if len(optionals) !=0:
            for opt in optionals:
                student.addDiscipline(opt)

        return student
Пример #16
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)
Пример #17
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"))
Пример #18
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]
Пример #19
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))
Пример #20
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]
Пример #21
0
 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 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
Пример #23
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)
Пример #24
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)
Пример #25
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 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)
Пример #27
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)
Пример #28
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
Пример #29
0
 def test_best_students(self):
     student3 = Student(3, "Maria")
     self.students.save(student3)
     self.grade_controller.add(self.student2.get_id(),
                               self.course1.get_id(), 10)
     self.grade_controller.add(self.student2.get_id(),
                               self.course2.get_id(), 5)
     self.grade_controller.add(student3.get_id(), self.course1.get_id(), 7)
     self.grade_controller.add(student3.get_id(), self.course2.get_id(), 7)
     self.assertEqual(len(self.grade_controller.search_highest_grades()), 1)
     self.assertEqual(
         self.grade_controller.search_highest_grades()[0][0].get_id(), 2)
     self.assertEqual(
         self.grade_controller.search_highest_grades()[0][0].get_name(),
         "Alex")
     self.assertEqual(self.grade_controller.search_highest_grades()[0][1],
                      7.5)
Пример #30
0
 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
Пример #31
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')
Пример #32
0
 def _test_student(self):
     '''
     Tests if creating a student works
     '''
     student = [Student(" john", 1), Student(" a ", "1"), Student(1, "1.5"), Student(True, True)]
     
     assert Student.getName(student[0]) == " john"
     assert Student.getID(student[0]) == 1
     
     assert Student.getName(student[1]) == " a "
     assert Student.getID(student[1]) == 1
     
     assert Student.getName(student[2]) == ""
     assert Student.getID(student[2]) == -1
     
     assert Student.getName(student[3]) == ""
     assert Student.getID(student[3]) == 1