def setUp(self): self.undo = UndoController() self.stCtr = StudentController(Repository(), StudentValidator(), self.undo) self.asCtr = AssignmnetController(Repository(), AssignmentValidator(), self.undo) self.grade = Grade(1, 1, 5.0) self._grCtr = GradeController(Repository(), GradeValidator(), self.stCtr, self.asCtr, self.undo)
def __init__(self): self._undo = UndoController() self._stud = StudentController(Repository(), StudentValidator(), self._undo) self._assign = AssignmnetController(Repository(), AssignmentValidator(), self._undo) self._grade = GradeController(Repository(), GradeValidator(), self._stud, self._assign, self._undo) self._stat = Statistics(self._grade)
def setUp(self): self._undo = UndoController() self._stCtr = StudentController(Repository(), StudentValidator(), self._undo) self._asCtr = AssignmnetController(Repository(), AssignmentValidator(), self._undo) self._grCtr = GradeController(Repository(), GradeValidator(), self._stCtr, self._asCtr, self._undo) self._stat = Statistics(self._grCtr) populateAsCtrSTATIC(self._asCtr) populateStCtrSTATIC(self._stCtr)
stRepo = BinRepository("data\\" + sets.repoSt, Student) asRepo = BinRepository("data\\" + sets.repoAs, Assignment) grRepo = BinRepository("data\\" + sets.repoGr, Grade) elif sets.repo == "json_file": stRepo = JsonRepository("data\\" + sets.repoSt, Student) asRepo = JsonRepository("data\\" + sets.repoAs, Assignment) grRepo = JsonRepository("data\\" + sets.repoGr, Grade) elif sets.repo == "mongoDB": stRepo = MongoRepository(Student) asRepo = MongoRepository(Assignment) grRepo = MongoRepository(Grade) else: raise ValueError("Repo must be from memory/text_file/binary_file/json_file/mongoDB") stCtr = StudentController(stRepo, StudentValidator(), undoCtr) asCtr = AssignmnetController(asRepo, AssignmentValidator(), undoCtr) grCtr = GradeController(grRepo, GradeValidator(), stCtr, asCtr, undoCtr) stat = Statistics(grCtr) if sets.ui == "cli": menu = CliMenu(undoCtr, stCtr, asCtr, grCtr, stat) menu.mainMenu() elif sets.ui == "gui": import sys app = QtWidgets.QApplication(sys.argv) StudentsManagement = QtWidgets.QMainWindow() ui = Ui_StudentsManagement(undoCtr, stCtr, asCtr, grCtr, stat) ui.setupUi(StudentsManagement) StudentsManagement.show() sys.exit(app.exec_()) else:
class UnitTestGradeController(unittest.TestCase): ''' ''' def setUp(self): self.undo = UndoController() self.stCtr = StudentController(Repository(), StudentValidator(), self.undo) self.asCtr = AssignmnetController(Repository(), AssignmentValidator(), self.undo) self.grade = Grade(1, 1, 5.0) self._grCtr = GradeController(Repository(), GradeValidator(), self.stCtr, self.asCtr, self.undo) def tearDown(self): unittest.TestCase.tearDown(self) def testAdd(self): self.assertEqual(len(self._grCtr.getAll()), 0) self._grCtr.add(self.grade) self.assertEqual(len(self._grCtr.getAll()), 1) print(self._grCtr.getAll()) self._grCtr.add(Grade(3, 2, 2.2)) self.assertEqual(len(self._grCtr.getAll()), 2) self.undo.undo() self.undo.undo() self.assertEqual(len(self._grCtr.getAll()), 0) self.assertRaises(ControllerException, self.undo.undo) self.assertRaises(TypeError, self._grCtr.add, 1) def testRemoveGr(self): self._grCtr.add(self.grade) self._grCtr.add(Grade(3, 2, 2.2)) self.assertEqual(len(self._grCtr.getAll()), 2) self._grCtr.remove(1, 1) self.assertEqual(len(self._grCtr.getAll()), 1) self.assertEqual(self._grCtr.getAll()[0], Grade(3, 2, 2.2)) self.assertRaises(ValueError, self._grCtr.remove, 1, 1) 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)) def testRmvAsGr(self): self._grCtr.assignment.add(Assignment(1, "ASC", "8/10/2018")) self.asCtr.add(Assignment(2, "FP", "10/10/2018")) self.assertEqual(len(self.asCtr.getAll()), 2) self._grCtr.add(Grade(1, 1, 2.0)) self._grCtr.add(Grade(1, 2, 7.0)) self._grCtr.add(Grade(2, 1, 5.0)) self._grCtr.add(Grade(2, 2, 3.0)) self.undo.undo() self.undo.undo() self._grCtr.add(Grade(2, 1, 8.0)) self._grCtr.add(Grade(2, 2, 9.0)) self.assertEqual(len(self._grCtr.getAll()), 4) self._grCtr.removeAssign(2) self.assertEqual(len(self.asCtr.getAll()), 1) self.assertEqual(len(self._grCtr.getAll()), 2) self.undo.undo() self.assertEqual(len(self.asCtr.getAll()), 2) self.assertEqual(len(self._grCtr.getAll()), 4) self.undo.redo() self.assertEqual(self._grCtr.getAll()[1], Grade(1, 2, 7.0)) self.assertFalse(self._grCtr.removeAssign(2)) def testUpdate(self): self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) self._grCtr.update(Grade(1, 1, 3.25)) self.assertEqual(self._grCtr.getAll()[1], Grade(1, 1, 3.25)) self.assertRaises(TypeError, self._grCtr.update, 1) def testFindByID(self): self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) x = self._grCtr.findByID(1, 1) self.assertEqual(x, Grade(1, 1, 2.0)) x = self._grCtr.findByID(3, 1) self.assertEqual(x, -1) x = self._grCtr.filterGradesBy(1, 1) self.assertEqual(x[0], Grade(1, 1, 2.0)) x = self._grCtr.filterGradesBy(3, 1) self.assertEqual(x, []) def testGiveAssign(self): self.stCtr.add(Student(1, "John", "913")) self.stCtr.add(Student(2, "Mary", "913")) self.stCtr.add(Student(3, "Oliver", "914")) self.stCtr.add(Student(4, "Greg", "913")) self.stCtr.add(Student(5, "Silvia", "914")) self.assertEqual(len(self.stCtr.getAll()), 5) self.asCtr.add(Assignment(1, "ASC", "08/12/2018")) self.asCtr.add(Assignment(2, "FP", "29/11/2018")) self.assertEqual(len(self.asCtr.getAll()), 2) self._grCtr.giveAssigToGroup(2, "913") self.assertEqual(len(self._grCtr.getAll()), 3) self._grCtr.giveAssigToGroup(1, "914") self.assertEqual(len(self._grCtr.getAll()), 5) self.undo.undo() self.undo.undo() self._grCtr.setAssigStud(2, 3) self.assertEqual(len(self._grCtr.getAll()), 1) self.assertEqual(self._grCtr.getAll()[0], Grade(2, 3, 0.0)) self.assertRaises(ValueError, self._grCtr.giveAssigToGroup, 5, "dsadas2") self.assertFalse(self._grCtr.setAssigStud(2, 3)) def testSetGrade(self): self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) self.assertTrue(self._grCtr.setGrade(1, 2, 9.0)) self.assertEqual(self._grCtr.getAll()[0], Grade(2, 1, 9.0)) self.undo.undo() self.assertRaises(ControllerException, self._grCtr.setGrade, 1, 1, 2.3) self.assertRaises(ValueError, self._grCtr.setGrade, 3, 1, 2.3) def testFilter(self): self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) self._grCtr.add(Grade(2, 2, 3.0)) self._grCtr.add(Grade(4, 2, 0.0)) self._grCtr.add(Grade(5, 1, 5.0)) x = self._grCtr.filterGradesBy(1, 1) self.assertEqual(x[0], Grade(1, 1, 2.0)) x = self._grCtr.filterGradesBy(3, 1) self.assertEqual(x, []) x = self._grCtr.filterGradesBy(2) self.assertEqual(len(x), 2) x = self._grCtr.filterGradesBy(1) self.assertEqual(len(x), 3) x = self._grCtr.filterGradesBy(None, 3) self.assertEqual(len(x), 0) x = self._grCtr.filterGradesBy(None, 2) self.assertEqual(len(x), 2) x = self._grCtr.filterGradesBy() self.assertEqual(len(x), 5) def testUngradeStud(self): self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) self._grCtr.add(Grade(2, 3, 3.0)) self._grCtr.add(Grade(4, 2, 0.0)) self._grCtr.add(Grade(3, 2, 0.0)) x = self._grCtr.getStudUngrade(1) self.assertEqual(len(x), 1) x = self._grCtr.getStudUngrade(2) self.assertEqual(len(x), 2) x = self._grCtr.getStudUngrade(3) self.assertEqual(len(x), 0) self.assertIsInstance(str(self._grCtr), str) def testException(self): x = ControllerException("TEst") self.assertTrue(x.messages) self.assertTrue(str(x))
class Menu: def __init__(self): self._undo = UndoController() self._stud = StudentController(Repository(), StudentValidator(), self._undo) self._assign = AssignmnetController(Repository(), AssignmentValidator(), self._undo) self._grade = GradeController(Repository(), GradeValidator(), self._stud, self._assign, self._undo) self._stat = Statistics(self._grade) @staticmethod def printMenu(): men = "\nAvailable commands:\n" men += "\t 1 - Add student\n" men += "\t 2 - Remove student\n" men += "\t 3 - Update student infos\n" men += "\t 4 - List students\n" men += "\t 5 - Add assignment\n" men += "\t 6 - Remove assignment\n" men += "\t 7 - Update assignment infos\n" men += "\t 8 - List assignments\n" men += "\t 9 - Add assignment to student/group\n" men += "\t10 - List grades\n" men += "\t11 - Set grade\n" men += "\t12 - All students who received a given assignment, ordered alphabetically or by average grade for that assignment\n" men += "\t13 - All students who are late in handing in at least one assignment. These are all the students who have an ungraded assignment for which the deadline has passed\n" men += "\t14 - Students with the best school situation, sorted in descending order of the average grade received for all assignments\n" men += "\t15 - All assignments for which there is at least one grade, sorted in descending order of the average grade received by all students who received that assignment\n" men += "\t16 - Undo\n" men += "\t17 - Redo\n" men += "\t18 - Help\n" men += "\t 0 - Exit\n" print(men) def mainMenu(self): Menu.printMenu() populateStCtrDYN(self._stud, 100) populateAsCtrDYN(self._assign, 100) populateGrCtrDYN(self._grade, 100) #populateStCtrSTATIC(self._stud) #populateAsCtrSTATIC(self._assign) #populateGrCtrSTATIC(self._grade) while True: try: cmd = input("Enter command: ").strip() if cmd == '0': print( "Thank you for using grading system! Have a great day! :)" ) return 0 elif cmd == '1': self.uiAddStud() elif cmd == '2': self.uiRmvStud() elif cmd == '3': self.uiUpdateStud() elif cmd == '4': self.uiListStud() elif cmd == '5': self.uiAddAssig() elif cmd == '6': self.uiRmvAssig() elif cmd == '7': self.uiUpdateAssig() elif cmd == '8': self.uiListAssig() elif cmd == '9': self.uiAddAssigToStGr() elif cmd == '10': self.uiListGrades() elif cmd == '11': self.uiGradeStud() elif cmd == '12': self.uiStat1() elif cmd == '13': self.uiStat2() elif cmd == '14': self.uiStat3() elif cmd == '15': self.uiStat4() elif cmd == '16': self._undo.undo() elif cmd == '17': self._undo.redo() elif cmd == '18': Menu.printMenu() else: print("Invalid CMD!") except Exception as er: print("Error: " + str(er)) def uiAddStud(self): sID = (input("Student ID: ")) if sID.isnumeric(): sID = int(sID) else: raise TypeError("ID must be an int!") sName = input("Student name: ") sGroup = input("Student group: ") stu = Student(sID, sName, sGroup) self._stud.add(stu) return True def uiRmvStud(self): sID = input("ID of student you want to delete: ") if sID.isnumeric(): sID = int(sID) else: raise TypeError("ID must be an int!") self._grade.removeStud(sID) 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!") def uiListStud(self): print(self._stud) def uiAddAssig(self): aID = input("Assignment ID: ") if aID.isnumeric(): aID = int(aID) else: raise TypeError("ID must be an int!") aDesc = input("Assignment description: ") aDeadline = input("Assignment deadline: ") assig = Assignment(aID, aDesc, aDeadline) self._assign.add(assig) return True def uiRmvAssig(self): aID = input("ID of assignment you want to delete: ") if aID.isnumeric(): aID = int(aID) else: raise TypeError("ID must be an int!") self._grade.removeAssign(aID) def uiUpdateAssig(self): cmd = input( "To update an assignment specific info type 1\nor 2 for complete infos:" ).strip() assign = Assignment(-1, -1, -1) if cmd == '1': info = input( "To modify: Description type 1, Deadline type 2: ").strip() if info == '1': assign.id = int(input("Assignments ID you want to update: ")) newDesc = input("Enter new description: ") assign.description = newDesc assign.deadline = self._assign.findByID(assign.id).deadline AssignmentValidator().validate(assign) self._assign.update(assign) return True elif info == '2': assign.id = int(input("Assignments ID you want to update: ")) newDeadline = input("Enter new deadline: ") assign.deadline = newDeadline assign.description = self._assign.findByID( assign.id).description AssignmentValidator().validate(assign) self._assign.update(assign) return True else: print("Invalid command!") elif cmd == '2': assign.id = int(input("Assignment ID you are looking to update: ")) assign.description = input("Enter new description: ") assign.deadline = input("Enter new deadline: ") AssignmentValidator().validate(assign) self._assign.update(assign) return True else: print("Invalid command!") def uiListAssig(self): print(self._assign) def uiListGrades(self): print(self._grade) def uiAddAssigToStGr(self): cmd = input( "Type 1 for setting an assignment to a student or 2 to set it to a group: " ).strip() if (cmd == '1'): aID = input("Assignment ID: ") sID = input("Student ID: ") if aID.isnumeric() and sID.isnumeric(): aID = int(aID) sID = int(sID) else: raise TypeError("ID must be an int!") self._grade.setAssigStud(aID, sID) elif (cmd == '2'): gr = input("Group: ") aID = input("Assignment ID: ") if aID.isnumeric(): aID = int(aID) else: raise TypeError("ID must be an int!") self._grade.giveAssigToGroup(aID, gr) else: print("Invalid command!") def uiGradeStud(self): sID = input("Write the id of student you want to grade: ") if not sID.isnumeric(): raise Exception("Student id must be a positive int") sID = int(sID) if type(self._stud.findByID(sID)) != Student: raise ValueError("No student with such an id!") x = self._grade.getStudUngrade(sID) if len(x) == 0: raise Exception("No assignments to grade!") assigIDs = [] for i in x: assigIDs.append(i.assignID) print("\t" + str(i)) aID = input("Write the assignment id from the above list: ") if not aID.isnumeric(): raise Exception("Assignment id must be a positive int") aID = int(aID) if aID not in assigIDs: raise ValueError("Assignment id must be from the above list!") grade = float(input("Write the grade:")) x = self._grade.setGrade(sID, aID, grade) print(x) def uiStat1(self): aID = input("Write the assignment id for the statistic: ") if not aID.isnumeric(): raise Exception("Assignment id must be a positive int") aID = int(aID) x = self._stat.getStudGivenAssig(aID) if len(x) > 0: print( "All students who received a given assignment, ordered alphabetically or by average grade for that assignment" ) for i in x: print(str(i)) else: print("No student satisffies this condition!") def uiStat2(self): x = self._stat.getLateStuds() if len(x) > 0: print( "All students who are late in handing in at least one assignment.\nThese are all the students who have an ungraded assignment for which the deadline has passed" ) for i in x: print(str(i)) else: print("No student satisffies this condition!") def uiStat3(self): x = self._stat.getStudBestGrSchool() if len(x) > 0: print( "Students with the best school situation, sorted in descending order of the average grade received for all assignments" ) for i in x: print(i) else: print("No student satisffies this condition!") def uiStat4(self): x = self._stat.getAssigByGrade() if len(x) > 0: print( "All assignments for which there is at least one grade, sorted in descending order of the average grade received by all students who received that assignment" ) for i in x: print(i) else: print("No assignmnet satisffies this condition!")