Beispiel #1
0
 def statistics_disciplines(self):
     partial_grades = self.__gradeRepository.get_all()
     grades = []
     for grade in partial_grades:
         student = self.__studentRepository.search(
             Student(grade.get_student().get_stud_id(), ""))
         discipline = self.__disciplineRepository.search(
             Discipline(grade.get_discipline().get_dis_id(), ""))
         grades.append(Grade(student, discipline, grade.get_value()))
     disciplines = {}
     for grade in grades:
         if not grade.get_discipline().get_dis_id() in disciplines:
             disciplines[grade.get_discipline().get_dis_id()] = []
         disciplines[grade.get_discipline().get_dis_id()].append(
             grade.get_value())
     results = []
     for item in disciplines.items():
         dis_id = item[0]
         dis_name = self.__disciplineRepository.search(
             Discipline(dis_id, "")).get_dis_name()
         average = sum(item[1]) / len(item[1])
         dis_dto = DisciplineDTO(dis_name, average)
         results.append(dis_dto)
     results.sort(key=lambda x: x.get_average(), reverse=True)
     return results[:]
Beispiel #2
0
 def update_discipline_name(self, dis_id, new_dis_name):
     old_discipline = self.__disciplineRepository.search(
         Discipline(dis_id, ""))
     new_discipline = Discipline(dis_id, new_dis_name)
     self.__disciplineValidator.validate_discipline(new_discipline)
     self.__disciplineRepository.update(old_discipline, new_discipline)
     action = UndoRedoActionTwoObjects(self.__disciplineRepository,
                                       self.__disciplineRepository.update,
                                       new_discipline, old_discipline)
     self.__undoStack.push(action)
     self.__redoStack.clear()
Beispiel #3
0
 def testDiscipline(self):
     repod = disciplineRepository()
     repod.add(Discipline(1, "Info"))
     self.assertEqual(str(repod.getPos(0)), str(Discipline(1, "Info")))
     repod.add(Discipline(2, "Mate"))
     self.assertEqual(str(repod.getPos(1)), str(Discipline(2, "Mate")))
     repod.remove(Discipline(2, "Mate"))
     self.assertEqual(str(repod.getPos(0)), str(Discipline(1, "Info")))
     repod.update(Discipline(1, "Info"), Discipline(1, "FP"))
     self.assertEqual(str(repod.getPos(0)), str(Discipline(1, "FP")))
Beispiel #4
0
 def statistics_students_failing(self):
     partial_grades = self.__gradeRepository.get_all()
     grades = []
     for grade in partial_grades:
         student = self.__studentRepository.search(
             Student(grade.get_student().get_stud_id(), ""))
         discipline = self.__disciplineRepository.search(
             Discipline(grade.get_discipline().get_dis_id(), ""))
         grades.append(Grade(student, discipline, grade.get_value()))
     students = {}
     for grade in grades:
         if not grade.get_student().get_stud_id() in students:
             students[grade.get_student().get_stud_id()] = []
         students[grade.get_student().get_stud_id()].append(
             grade.get_value())
     failing = []
     for item in students.items():
         stud_id = item[0]
         stud_name = self.__studentRepository.search(Student(
             stud_id, "")).get_stud_name()
         average = sum(item[1]) / len(item[1])
         if average < 5.0:
             fail_stud_dto = StudentDTO(stud_name, average)
             failing.append(fail_stud_dto)
     failing.sort(key=lambda x: x.get_average(), reverse=False)
     return failing[:]
Beispiel #5
0
 def statistics_students_best(self):
     partial_grades = self.__gradeRepository.get_all()
     grades = []
     for grade in partial_grades:
         student = self.__studentRepository.search(
             Student(grade.get_student().get_stud_id(), ""))
         discipline = self.__disciplineRepository.search(
             Discipline(grade.get_discipline().get_dis_id(), ""))
         grades.append(Grade(student, discipline, grade.get_value()))
     students = {}
     for grade in grades:
         if not grade.get_student().get_stud_id() in students:
             students[grade.get_student().get_stud_id()] = []
         students[grade.get_student().get_stud_id()].append(
             grade.get_value())
     best = []
     for item in students.items():
         stud_id = item[0]
         stud_name = self.__studentRepository.search(Student(
             stud_id, "")).get_stud_name()
         average = sum(item[1]) / len(item[1])
         best_stud = StudentDTO(stud_name, average)
         best.append(best_stud)
     best.sort(key=lambda x: x.get_average(), reverse=True)
     return best[:3]
 def readDiscipline():
     '''
     reads a disciplineType object from the keyboard
     '''
     uid = int(input("discipline id: "))
     name = input("discipline name: ")
     return Discipline(uid, name)
Beispiel #7
0
 def add_discipline(self, dis_id, dis_name):
     discipline = Discipline(dis_id, dis_name)
     self.__disciplineValidator.validate_discipline(discipline)
     self.__disciplineRepository.add(discipline)
     action = UndoRedoAction(self.__disciplineRepository,
                             self.__disciplineRepository.remove,
                             self.__disciplineRepository.add, discipline)
     self.__undoStack.push(action)
     self.__redoStack.clear()
Beispiel #8
0
 def add_discipline(self, discipline_id, discipline_name):
     '''
     Adds a discipline entity to the given discipline repository
     :param discipline_id:
     :param discipline_name:
     :return: None
     '''
     discipline = Discipline(discipline_id, discipline_name)
     self.__discipline_repository.add(discipline)
Beispiel #9
0
 def get_grades(self):
     grades = self.__gradeRepository.get_all()
     rez = []
     for grade in grades:
         student = self.__studentRepository.search(
             Student(grade.get_student().get_stud_id(), ""))
         discipline = self.__disciplineRepository.search(
             Discipline(grade.get_discipline().get_dis_id(), ""))
         rez.append(Grade(student, discipline, grade.get_value()))
     return rez
Beispiel #10
0
 def add_grade(self, stud_id, dis_id, grad_value):
     student = self.__studentRepository.search(Student(stud_id, ""))
     discipline = self.__disciplineRepository.search(Discipline(dis_id, ""))
     grade = Grade(student, discipline, grad_value)
     self.__gradeValidator.validate_grade(grade)
     self.__gradeRepository.add(grade)
     action = UndoRedoAction(self.__gradeRepository,
                             self.__gradeRepository.remove,
                             self.__gradeRepository.add, grade)
     self.__undoStack.push(action)
     self.__redoStack.clear()
Beispiel #11
0
    def update(self, discipline_id, discipline_name):
        '''
        Updates the discipline that has a given id to have the given name
        :param discipline_id:
        :param discipline_name:
        :return:None
        '''
        discipline = Discipline(discipline_id, discipline_name)
        self.__discipline_repository.update(discipline_id, discipline)
        

        
Beispiel #12
0
    def updateDiscipline(self, disciplineID, name):
        """
        Update a discipline from the repository
        :param args: the discipline arguments
        :return: None.
        """
        discipline = Discipline(disciplineID, name)
        self.__discipline_repository.update(discipline)

        redo = FunctionCall(self.updateDiscipline, disciplineID, name)
        undo = FunctionCall(self.updateDiscipline, disciplineID)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
Beispiel #13
0
 def testGrade(self):
     repog = gradeRepository()
     repog.add(Grade(1, 1, 9))
     self.assertEqual(str(repog.getPos(0)), str(Grade(1, 1, 9)))
     repog.add(Grade(1, 1, 8))
     self.assertEqual(str(repog.getPos(1)), str(Grade(1, 1, 8)))
     repog.add(Grade(2, 2, 9))
     self.assertEqual(str(repog.getPos(2)), str(Grade(2, 2, 9)))
     repog.removeGradeStudent(Student(2, "Razvan"))
     self.assertEqual(str(repog.getPos(1)), str(Grade(1, 1, 8)))
     repog.add(Grade(2, 2, 9))
     self.assertEqual(str(repog.getPos(2)), str(Grade(2, 2, 9)))
     repog.removeGradeDiscipline(Discipline(1, "Fizica"))
     self.assertEqual(str(repog.getPos(0)), str(Grade(2, 2, 9)))
Beispiel #14
0
    def addDiscipline(self, disciplineID, name):
        """
        Add a discipline to the repository
        :param args: the discipline arguments
        :return: None.
        """

        discipline = Discipline(disciplineID, name)
        self.__discipline_repository.save(discipline)

        redo = FunctionCall(self.addDiscipline, disciplineID, name)
        undo = FunctionCall(self.removeDiscipline, disciplineID)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
Beispiel #15
0
 def remove_discipline_and_grades_by_id(self, dis_id):
     action = ComplexUndoRedoAction()
     discipline = self.__disciplineRepository.search(Discipline(dis_id, ""))
     grades = self.__gradeRepository.get_all()
     for grade in grades:
         if grade.get_discipline() == discipline:
             self.__gradeRepository.remove(grade)
             grade_action = UndoRedoAction(self.__gradeRepository,
                                           self.__gradeRepository.add,
                                           self.__gradeRepository.remove,
                                           grade)
             action.add_action(grade_action)
     self.__disciplineRepository.remove(discipline)
     discipline_action = UndoRedoAction(self.__disciplineRepository,
                                        self.__disciplineRepository.add,
                                        self.__disciplineRepository.remove,
                                        discipline)
     action.add_action(discipline_action)
     self.__undoStack.push(action)
     self.__redoStack.clear()
Beispiel #16
0
 def search_discipline_id(self, dis_id):
     discipline = self.__disciplineRepository.search(Discipline(dis_id, ""))
     return discipline
Beispiel #17
0
 def test_validate(self):
     d1 = Discipline('a', "Mate")
     self.assertRaises(DisciplineValidatorException,
                       DisciplineValidator.validate, d1)
 repod = disciplineRepository()
 repog = gradeRepository()
 undoCtrl = UndoController()
 #initialize repository
 repos.add(Student(1, "Vasile"))
 repos.add(Student(2, "Razvan"))
 repos.add(Student(3, "Victor"))
 repos.add(Student(4, "Ion"))
 repos.add(Student(5, "George"))
 repos.add(Student(6, "Andrei"))
 repos.add(Student(7, "Alex"))
 repos.add(Student(8, "Vlad Andrei"))
 repos.add(Student(9, "Adrian"))
 repos.add(Student(10, "Razvan"))
 repos.add(Student(11, "Razvan Andrei"))
 repod.add(Discipline(1, "Fizica"))
 repod.add(Discipline(2, "Matematica"))
 repod.add(Discipline(3, "Romana"))
 repod.add(Discipline(4, "Informatica"))
 repod.add(Discipline(5, "Chimie"))
 repod.add(Discipline(6, "Engleza"))
 repod.add(Discipline(7, "Franceza"))
 repod.add(Discipline(8, "Matematica aplicata"))
 repog.add(Grade(2, 2, 9))
 repog.add(Grade(2, 2, 8))
 repog.add(Grade(1, 2, 9))
 repog.add(Grade(1, 1, 10))
 repog.add(Grade(3, 4, 9))
 repog.add(Grade(4, 4, 10))
 repog.add(Grade(3, 4, 3))
 repog.add(Grade(4, 4, 2))