def __update_student(self): key = int(raw_input("Input Student->ID:")) surname = raw_input("Input Student->new SURNAME:") name = raw_input("Input Student->new Name:") date_str = raw_input("Input Student->new BIRTHDAY ('24-05-2010'):") birthday = datetime.strptime(date_str, "%d-%m-%Y").date() group_id = int(raw_input("Input Student->new GROUP_ID:")) student = Student(surname, name, birthday, group_id) StudentController().update(key, student)
def __create_student(self): surname = raw_input("Input Student->SURNAME:") name = raw_input("Input Student->Name:") date_str = raw_input("Input Student->BIRTHDAY ('24-05-2010'):") birthday = datetime.strptime(date_str, "%d-%m-%Y").date() group_id = int(raw_input("Input Student->GROUP_ID:")) student = Student(surname, name, birthday, group_id) StudentController().create(student) print student.id
def __init__(self, settings): self._settings = settings print("repo_type is: " + settings["repo_type"]) if settings["repo_type"] == "memory": self.studentRepo = Repository() self.disciplineRepo = Repository() self.gradeRepo = Repository() elif settings["repo_type"] == "text": self.studentRepo = TextRepository("student", settings["student"]) self.disciplineRepo = TextRepository("discipline", settings["discipline"]) self.gradeRepo = TextRepository("grade", settings["grade"]) self.writeToBinaryFile("students.pickle", self.studentRepo) self.writeToBinaryFile("disciplines.pickle", self.disciplineRepo) self.writeToBinaryFile("grades.pickle", self.gradeRepo) elif settings["repo_type"] == "pickle": self.studentRepo = PickleRepository(settings["student"]) self.disciplineRepo = PickleRepository(settings["discipline"]) self.gradeRepo = PickleRepository(settings["grade"]) self.undoController = UndoController() self.studentValidator = StudentValidator() self.studentController = StudentController(self.studentValidator, self.studentRepo, self.undoController) self.disciplineValidator = DisciplineValidator() self.disciplineController = DisciplineController( self.disciplineValidator, self.disciplineRepo, self.undoController) self.gradeValidator = GradeValidator() self.gradeController = GradeController(self.gradeValidator, self.gradeRepo, self.disciplineRepo, self.studentRepo, self.undoController) self.statusController = StudentStatusController( self.studentRepo, self.disciplineRepo, self.gradeRepo)
def setUp(self): self.undoController = UndoController() self.studentRepo = Repository() self.studentValidator = StudentValidator() self.studentController = StudentController(self.studentValidator, self.studentRepo, self.undoController) self.disciplineRepo = Repository() self.disciplineValidator = DisciplineValidator() self.disciplineController = DisciplineController( self.disciplineValidator, self.disciplineRepo, self.undoController) self.gradeRepo = Repository() self.gradeValidator = GradeValidator() self.gradeController = GradeController(self.gradeValidator, self.gradeRepo, self.disciplineRepo, self.studentRepo, self.undoController)
def main(self): StudRepo = StudentFileRepo("student.txt") StudContr = StudentController(StudRepo, StudentValidator) print(StudRepo) labrep = LabRepo("laboratory.txt", StudRepo) LabContr = LabController(labrep, StudRepo) print(labrep) cons = UI(StudContr, LabContr) cons.start()
def load_data_to_db(): group = Group("Python") GroupController().create(group) group = Group("Java") GroupController().create(group) group = Group("C++") GroupController().create(group) group = Group("C#") GroupController().create(group) group = Group("JavaScript") GroupController().create(group) # -------------------------------- student = Student("Pavelchak", "Andrii", to_date("09-05-1976"), 1) StudentController().create(student) student = Student("Yatsuk", "Yuri", to_date("26-04-1983"), 1) StudentController().create(student) student = Student("Veres", "Zenovii", to_date("19-08-1984"), 2) StudentController().create(student) student = Student("Ivaniuk", "Oleh", to_date("02-09-1983"), 5) StudentController().create(student) student = Student("Lopachak", "Oleh", to_date("09-05-1976"), 3) StudentController().create(student) student = Student("Garaniuk", "Ihor", to_date("09-05-1953"), 2) StudentController().create(student) student = Student("Mokrenko", "Petro", to_date("09-12-1939"), 4) StudentController().create(student) student = Student("Kovela", "Ivan", to_date("09-05-1948"), 4) StudentController().create(student)
class UI: def __init__(self, settings): self._settings = settings print("repo_type is: " + settings["repo_type"]) if settings["repo_type"] == "memory": self.studentRepo = Repository() self.disciplineRepo = Repository() self.gradeRepo = Repository() elif settings["repo_type"] == "text": self.studentRepo = TextRepository("student", settings["student"]) self.disciplineRepo = TextRepository("discipline", settings["discipline"]) self.gradeRepo = TextRepository("grade", settings["grade"]) self.writeToBinaryFile("students.pickle", self.studentRepo) self.writeToBinaryFile("disciplines.pickle", self.disciplineRepo) self.writeToBinaryFile("grades.pickle", self.gradeRepo) elif settings["repo_type"] == "pickle": self.studentRepo = PickleRepository(settings["student"]) self.disciplineRepo = PickleRepository(settings["discipline"]) self.gradeRepo = PickleRepository(settings["grade"]) self.undoController = UndoController() self.studentValidator = StudentValidator() self.studentController = StudentController(self.studentValidator, self.studentRepo, self.undoController) self.disciplineValidator = DisciplineValidator() self.disciplineController = DisciplineController( self.disciplineValidator, self.disciplineRepo, self.undoController) self.gradeValidator = GradeValidator() self.gradeController = GradeController(self.gradeValidator, self.gradeRepo, self.disciplineRepo, self.studentRepo, self.undoController) self.statusController = StudentStatusController( self.studentRepo, self.disciplineRepo, self.gradeRepo) def writeToBinaryFile(self, _filename, obj): f = open(_filename, "wb") pickle.dump(obj, f) f.close() def showmenu(self): print("Commands: ") print("1. add") print("2. remove") print("3. update") print("4. list") print("5. grade") print("6. search") print("7. statistics") print("8. undo") print("9. redo") print("99. halp") print("0. exit") def main_loop(self): self.showmenu() while True: self.studentRepo.save_file() self.disciplineRepo.save_file() self.gradeRepo.save_file() try: n = int(input(">>")) except ValueError: print("[ERROR] Invalid Command") continue if n == 0: break elif n == 1: print("-- add --") try: m = int(input("1. Student - 2. Discipline >>")) except ValueError: print("[ERROR] Invalid entry!") continue if m == 1: try: _id = int(input("Enter Student_ID: ")) except ValueError: print("[ERROR] ID must be a number") continue _name = input("Enter Student_Name: ") try: self.studentController.create(_id, _name) except StudentException as e: print(e) elif m == 2: try: _id = int(input("Enter Discipline_ID: ")) except ValueError: print("[ERROR] ID must be a number") continue _name = input("Enter Discipline_Name: ") try: self.disciplineController.create(_id, _name) except DisciplineException as e: print(e) else: print("[ERROR] Invalid Command") elif n == 2: print("-- remove --") try: m = int(input("1. Student - 2. Discipline >>")) except ValueError: print("[ERROR] Invalid entry!") continue except AttributeError: print("[ERROR] Couldn't find student") if m == 1: try: _id = int(input("Enter Student_ID: ")) except ValueError: print("[ERROR] ID must be a number") continue try: co = CascadedOperation() co.add(self.studentController.remove(_id)) listt = self.gradeController.remove_by_student(_id) for i in listt: co.add(i) self.undoController.add_operation(co) except GradeException as e: print(e) elif m == 2: try: _id = int(input("Enter Discipline_ID: ")) except ValueError: print("[ERROR] ID must be a number") continue try: co = CascadedOperation() co.add(self.disciplineController.remove(_id)) listt = self.gradeController.remove_by_discipline(_id) for i in listt: co.add(i) self.undoController.add_operation(co) except GradeException as e: print(e) else: print("[ERROR] Invalid Command") elif n == 3: print("-- update --") try: m = int(input("1. Student - 2. Discipline >>")) except ValueError: print("[ERROR] Invalid entry!") continue if m == 1: try: _id = int(input("Enter Student_ID: ")) except ValueError: print("[ERROR] ID must be a number") continue name = input("Enter New Name: ") try: self.studentController.update(_id, name) except StudentException as e: print(e) elif m == 2: try: _id = int(input("Enter Discipline_ID: ")) except ValueError: print("[ERROR] ID must be a number") continue name = input("Enter New Name: ") try: self.disciplineController.update(_id, name) except DisciplineException as e: print(e) elif n == 4: print("-- list --") try: m = int( input("1. Student - 2. Discipline - 3. Grades >>")) except ValueError: print("[ERROR] Invalid entry!") continue if m == 1: print(self.studentRepo) elif m == 2: print(self.disciplineRepo) elif m == 3: print(self.gradeRepo) elif n == 5: print("-- grade --") try: disc = int(input("Discipline ID: ")) stud = int(input("Student ID: ")) grade = int(input("Grade: ")) except ValueError: print("[ERROR] Invalid input!") continue self.gradeController.create(disc, stud, grade) elif n == 6: print("-- search --") try: m = int(input("1. By ID - 2. By Name >>")) except ValueError: print("[ERROR] Invalid entry!") continue if m == 1: try: _id = int(input("Enter ID: ")) except ValueError: print("[ERROR] ID must be a number") continue print("____________________Students____________________") print(self.studentController.find(_id)) print() print("___________________Disciplines__________________") print(self.disciplineController.find(_id)) elif m == 2: string = input("Enter a string to search by: ") print("____________________Students____________________") print(self.studentController.search(string)) print() print("___________________Disciplines__________________") print(self.disciplineController.search(string)) elif n == 7: msg = "Students enrolled to each discipline sorted by name:" print( msg.rjust(70 + len(msg) // 2, '>').ljust(150 - len("msg") // 2, '<')) d = self.gradeController.all_disciplines() for i in d.keys(): print('_' * 20 + self.disciplineController.find(i).name + '_' * 20) for j in d[i]: print(j) listt = self.statusController.get_failing_students() print('\n') msg = "Students failing at a discipline" print( msg.rjust(70 + len(msg) // 2, '>').ljust(150 - len("msg") // 2, '<')) for i in listt: student = i[0] fails = i[1:] print(str(student) + " FAILING AT:") for j in fails: print(j) print() print('\n') msg = "Students with the best school situation sorted by aggregated average grade" print( msg.rjust(70 + len(msg) // 2, '>').ljust(150 - len("msg") // 2, '<')) listt = self.statusController.get_best_students() for i in listt: print(str(i[0]) + ' ------- Grade: ' + str(i[1])) print('\n') listt = self.statusController.get_discipline_statistics() msg = "Disciplines sorted by the average of the grades of all students at that discipline" print( msg.rjust(70 + len(msg) // 2, '>').ljust(150 - len("msg") // 2, '<')) for i in listt: print(str(i[0]) + ' -------- Average: ' + str(i[1])) elif n == 8: try: self.undoController.undo() except Exception: pass elif n == 9: try: self.undoController.redo() except Exception: pass elif n == 99: self.showmenu() else: print("Invalid command!")
def initStudents(): strepo.store(Student("1", "Ma Rupe", "916")) strepo.store(Student("2", "Tema Asta", "913")) strepo.store(Student("3", "Foarte Tare", "910")) strepo.store(Student("4", "Ioana", "915")) def initAssignments(): assrepo.store(Assignment("7", "descriere 1", "5.6")) assrepo.store(Assignment("8", "descriere nr 2", "12.10")) assrepo.store(Assignment("9", "descriere 4", "13.12")) assrepo.store(Assignment("10", "Spelling", "14.12")) def initGrades(): grdrepo.store( Grade("5", Assignment("10", "Spelling", "14.12"), Student("4", "Ioana", "915"), "6")) initStudents() initAssignments() initGrades() undoctrl = UndoController(opList) stctrl = StudentController(strepo, stvalidator) assctrl = AssignmentController(assrepo, assvalidator) grdctrl = GradeController(grdrepo, assrepo, strepo) ctrl = Controller(stctrl, assctrl, grdctrl, undoctrl) ui = UI(ctrl, undoctrl) ui.start()
return settings settings = readSettings() studRepo = None assRepo = None grdRepo = None if 'CSV' == settings['repository']: studRepo = StudCSVFileRepository(settings['students']) assRepo = AssCSVFileRepository(settings['assignments']) grdRepo = GradeCSVFileRepository(settings['assignments'], settings['students']) if 'binary' == settings['repository']: studRepo = PickleFileRepository(settings['students']) assRepo = PickleFileRepository(settings['assignments']) grdRepo = PickleFileRepository(settings['grades']) assValidator = AssignmentValidator() studValidator = StudentValidator() opList = [] undoCtrl = UndoController(opList) studCtrl = StudentController(studRepo, studValidator) assCtrl = AssignmentController(assRepo, assValidator) grdCtrl = GradeController(grdRepo, assRepo, studRepo) statCtrl = StatisticsController(grdRepo) ctrl = Controller(studCtrl, assCtrl, grdCtrl, statCtrl, undoCtrl) ui = UI(ctrl, undoCtrl) ui.start()
class Test(unittest.TestCase): def setUp(self): self.undoController = UndoController() self.studentRepo = Repository() self.studentValidator = StudentValidator() self.studentController = StudentController(self.studentValidator, self.studentRepo, self.undoController) self.disciplineRepo = Repository() self.disciplineValidator = DisciplineValidator() self.disciplineController = DisciplineController( self.disciplineValidator, self.disciplineRepo, self.undoController) self.gradeRepo = Repository() self.gradeValidator = GradeValidator() self.gradeController = GradeController(self.gradeValidator, self.gradeRepo, self.disciplineRepo, self.studentRepo, self.undoController) def test_student(self): stud = Student(1, "Ancau") self.assertTrue(stud.id == 1 and stud.name == "Ancau") self.assertTrue(len(self.studentRepo) == 0) anca = self.studentController.create(1, "Ancau Adrian") popa = self.studentController.create(2, "Popa Cristian") self.assertRaises(StudentException, self.studentController.create, 2, "Niganinga") self.assertTrue(self.studentController.find(1) == anca) self.assertTrue(self.studentRepo.find(2) == popa) self.assertEqual(len(self.studentRepo), 2) cascade_remove(self.studentController, self.gradeController, self.undoController, 2) self.assertTrue(len(self.studentRepo), 1) self.undoController.undo() self.assertTrue(len(self.studentRepo), 2) self.undoController.redo() self.assertTrue(len(self.studentRepo), 1) def test_discipline(self): math = self.disciplineController.create(1, "Math") engl = self.disciplineController.create(2, "English") self.assertEqual(len(self.disciplineRepo), 2) self.assertEqual(self.disciplineRepo.find(1), math) self.assertEqual(self.disciplineController.find(2), engl) self.disciplineController.update(2, 'History') self.assertEqual(self.disciplineController.find(2), Discipline(2, 'History')) def test_grade(self): first = self.gradeController.create(1, 1, 10) second = self.gradeController.create(2, 1, 7) self.assertRaises(GradeException, self.gradeController.create, 1, 1, 12) self.gradeController.remove_single_grade(1, 1, 10) self.assertNotIn(first, self.gradeController.all_students(1)) def undo_test(self): self.disciplineController.create(3, "Undo test") self.undoController.undo() self.assertNotIn(Discipline(3, "Undo test"), self.disciplineRepo.get_all()) self.undoController.redo() self.assertIn(Discipline(3, "Undo test"), self.disciplineRepo.get_all())
def __select_student(self): print "TABLE Student:" students = StudentController().find_all() for student in students: print student
def __patch_student(self): key = int(raw_input("Input Student->ID:")) field_name = raw_input("Input Student->field name:") value = raw_input("Input Student->new VALUE:") StudentController().patch(key, field_name, value)
def __find_by_id_student(self): key = int(raw_input("Input Student->ID:")) student = StudentController().find_by_id(key) print student
def __delete_student(self): key = int(raw_input("Input Student->ID:")) StudentController().delete(key)