def testRepoUpdate(self): student = Student(1,"asd",123) self.__repoStudents.add(student) newStudent = Student(1,"abc",123) self.__repoStudents.update(newStudent) students = self.__repoStudents.getAll() self.assertEqual(students[0].getName(),"abc")
def __uiAddStudent(self): print("Adding a student...\nID:") id = int(input()) print("Name:") name = input() print("Group:") group = input() self.__controllerStudents.addStudent(id, name, group) self.__undoAction.addToUndoList("1", Student(id, name, group)) self.__undoAction.addToRedoList("1", Student(id, name, group))
def testUndoRedoStudent(self): self.__controllerStudents.addStudent(1,"alex",123) self.__undoAction.addToUndoList("1",Student(1,"alex",123)) self.__undoAction.addToRedoList("1",Student(1,"alex",123)) self.__undoAction.undoController() students = self.__controllerStudents.getAllStudents() self.assertEqual(students,[]) self.__undoAction.redoController() students = self.__controllerStudents.getAllStudents() self.assertEqual(len(students),1) self.__controllerStudents.removeStudent(1,"alex",123) self.__undoAction.addToUndoList("2",Student(1,"alex",123)) self.__undoAction.addToRedoList("2",Student(1,"alex",123)) self.__undoAction.undoController() students = self.__controllerStudents.getAllStudents() self.assertEqual(len(students),1) pass
def init_(): global conn conn = Connection_("my_new_test.db") conn._create_table() s = Student("aa", "bb", "cc", "gg") # conn.insert_new_student(s._generate_id(),s.get_student_name(),"b","c","d") # TODO: pass student_name object here, To avoid space or wrong name . print(conn.is_user_exists(s.get_student_name()))
def getRandomStudent(self): #ID = random.randint(10000, 99999) ID = random.randint(74180, 74190) group = random.randint(100, 999) name = str( random.choice(self.__randomFirstName) + " " + random.choice(self.__randomSecondName)) return Student(ID, group, name)
def __uiUpdateStudent(self): print("Updating a student...\nID:") id = int(input()) print("Name:") name = input() print("Group:") group = input() oldStudent = self.__controllerStudents.getStudentByID(id) self.__controllerStudents.updateStudentGroup(id, name, group) self.__undoAction.addToUndoList("3", oldStudent) self.__undoAction.addToRedoList("3", Student(id, name, group))
def removeStudent(self, id, name, group): ''' class function for removing a student in - id - student id name - student name group - student group out - raises: repoError in case the element doesn't exist ''' student = Student(id, name, group) self.__repoStudents.remove(student)
def add_student(student_name, class_id): try: student = Student(name=student_name) if class_id: student.class_id = class_id db.session.add(student) db.session.commit() return jsonify(student=student.serialize) except Exception as e: db.session.rollback() raise e
def testSave(self): mike = Student(name='Mike Bloom', password='******', username='******', email='*****@*****.**') mike.save() mike.class_ = '1900' mike.save() mike2 = Student.findUser('mikebloom', 'password') self.assertEqual(mike2.class_, '1900', "Object returned has correct properties")
def we_have_the_following_students(context): students = {} for row in context.table: student_id = row['student_id'] firstname = row['firstname'] lastname = row['lastname'] students[student_id] = Student(student_id, firstname, lastname) context.students = students for value in students.values(): print(str(value)) pass
def addStudent(self, id, name, group): ''' class function for adding a student in - id - student id name - student name group - student group out - raises: repoError in case the element already exists validError in case the input is invalid ''' student = Student(id, name, group) self.__validatorStudents.validateStudent(student) self.__repoStudents.add(student)
def updateStudentGroup(self, id, name, newGroup): ''' class function for updating a student in - id - student id name - student name newGroup - student group to be updated out - raises: repoError in case the element doesn't exist validError in case the input is invalid ''' newStudent = Student(id, name, newGroup) self.__validatorStudents.validateStudent(newStudent) self.__repoStudents.update(newStudent)
def __readStudents(self): ''' Class method to read the students from a file. This method will form a list of objects of type Student and return it. ''' file = open(self.__fileName, "r") content = file.readlines() students = IterableStructure() for line in content: line.strip() line = line.replace('\n', '') line = line.split(';') students.append(Student(int(line[0]), line[1], line[2])) file.close() return students
def add_user(self, username, password, is_student, course): if is_student: if username not in self.students.keys(): if self.users_database.add_student(username, password, course): self.students[username] = Student(username, password, course) return True return False else: if username not in self.valuers.keys(): if self.users_database.add_valuer(username, password): self.valuers[username] = Valuer(username, password) return True return False
def __add_student(): gui.print_title_new_student() name = gui.input_data(strings.input_name) age = gui.input_data(strings.input_age) __show_groups() res = 0 while not res: group_id = raw_input(strings.input_group_id) res = __validate_int(group_id) if res: if not __groups_lab.get_groups().has_key((int(group_id))): print strings.wrong_input res = 0 __students_lab.add_student(Student(name=name, age=age, group_id=group_id))
def test_student_enrollment_quiz_taking_and_grading(quiz1, quiz2): teacher_sam = Teacher(1, "Sam", "Doe") student1 = Student(1, "Joe", "Bar") course = Course("MATH_101", 4) spring_2003_math_101 = course.add_class("SPRING", 2003, teacher_sam) student1.enroll(spring_2003_math_101) spring_2003_math_101.assign_quiz(quiz1) spring_2003_math_101.assign_quiz(quiz2) student1.answer_quiz(spring_2003_math_101, 1, 1, ['A']) student1.answer_quiz(spring_2003_math_101, 1, 2, ['B']) student1.answer_quiz(spring_2003_math_101, 2, 1, ['A']) student1.answer_quiz(spring_2003_math_101, 2, 2, ['A']) student1.grade_quiz(spring_2003_math_101, 1) == 100.0 student1.grade_quiz(spring_2003_math_101, 2) == 50.0 assert student1.accumulate_grade(spring_2003_math_101) == 75.0
def add_student(): user = session['user'] if user['type'] == 'Manager' or 'Mentor' or "Employee": student_url = "student_list" if request.method == "POST": user_id = None login = request.form['login'] email = request.form['email'] name = request.form['name'] surname = request.form['surname'] date_of_birth = None city = None phone = None team_id = None card = None new_student = Student(user_id, name, surname, email, date_of_birth, city, phone, login, team_id, card) new_student.save() return redirect(url_for(student_url)) return render_template('add_student.html', url=student_url, user=user) return redirect(url_for('error.html'))
def save_student(save, id=None): print('asdasdasd') if save == 'add': student = Student(id=id, first_name=request.form['first-name'], last_name=request.form['last-name'], password=request.form['password'], telephone=request.form.get('phone-number', ''), mail=request.form.get('mail', ''), team_id=request.form.get('team', '')) print('ADD') student.add_student() elif save == 'edit' and id: # SQLALCHEMY - need to get element from db and edit it , rather then create new object (won't work , other way) print('IN EDIT') student = Student.get_by_id(id) student.first_name = request.form['first-name'] student.last_name = request.form['last-name'] student.password = request.form['password'] student.telephone = request.form.get('phone-number', '') student.mail = request.form.get('mail', '') student.team_id = request.form.get('team', '') student.add_student()
def setUp(self): self.__test_student = Student(1,"Alin",123) self.__test_assignment = Assignment(2,"lab12","11/11/2034")
def __init__(self): self.students = {} #add to student dictionary s = Student(1, "Carson", "Alexander", "09012005") self.students[s.student_id] = s s = Student(2, "Meredith", "Alonso", "09022002") self.students[s.student_id] = s s = Student(3, "Arturo", "Anand", "09032003") self.students[s.student_id] = s s = Student(4, "Gytis", "Barzdukas", "09012001") self.students[s.student_id] = s s = Student(5, "Peggy", "Justice", "09012001") self.students[s.student_id] = s s = Student(6, "Laura", "Norman", "09012003") self.students[s.student_id] = s s = Student(7, "Nino", "Olivetto", "09012005") self.students[s.student_id] = s self.professors = {} #professor_id first_name last_name hire_date p = Professor(1, "Kim", "Abercrombie", "1995-03-11") self.professors[p.professor_id] = p p = Professor(2, "Fadi", "Fakhouri", "2002-07-06") self.professors[p.professor_id] = p p = Professor(3, "Roger", "Harui", "1998-07-01") self.professors[p.professor_id] = p p = Professor(4, "Candace", "Kapoor", "2001-01-15") self.professors[p.professor_id] = p p = Professor(5, "Roger", "Zheng", "2004-02-12") self.professors[p.professor_id] = p self.courses = {} #add to course dictionary c = Course(1050, "Chemistry", 3, self.professors[1]) self.courses[c.course_id] = c c = Course(4022, "Microeconomics", 3, self.professors[3]) self.courses[c.course_id] = c c = Course(4041, "Macroeconomics", 3, self.professors[3]) self.courses[c.course_id] = c c = Course(1045, "Calculus", 4, self.professors[4]) self.courses[c.course_id] = c c = Course(3141, "Trigonometry", 4, self.professors[4]) self.courses[c.course_id] = c c = Course(2021, "Composition", 3, self.professors[2]) self.courses[c.course_id] = c c = Course(2042, "Literature", 4, self.professors[5]) self.courses[c.course_id] = c self.enrollments = {} #add enrolled students into courses enroll_id = 11050 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[1], self.courses[1050]) self.enrollments[enroll_id] = enrollment enroll_id = 14022 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[1], self.courses[4022]) self.enrollments[enroll_id] = enrollment enroll_id = 14041 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[1], self.courses[4041]) self.enrollments[enroll_id] = enrollment enroll_id = 21045 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[2], self.courses[1045]) self.enrollments[enroll_id] = enrollment enroll_id = 23141 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[2], self.courses[3141]) self.enrollments[enroll_id] = enrollment enroll_id = 22021 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[2], self.courses[4041]) self.enrollments[enroll_id] = enrollment enroll_id = 31050 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[3], self.courses[1050]) self.enrollments[enroll_id] = enrollment enroll_id = 41050 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[4], self.courses[1050]) self.enrollments[enroll_id] = enrollment enroll_id = 44022 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[4], self.courses[4022]) self.enrollments[enroll_id] = enrollment enroll_id = 54041 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[5], self.courses[2021]) self.enrollments[enroll_id] = enrollment enroll_id = 61045 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[6], self.courses[1045]) self.enrollments[enroll_id] = enrollment enroll_id = 73141 #combine student id + chemistry id enrollment = Enrollment(enroll_id, self.students[7], self.courses[3141]) self.enrollments[enroll_id] = enrollment
def register(): # Output message if something goes wrong... msg = '' # Check if "username", "password" and "email" POST requests exist (user submitted form) if request.method == 'POST' and 'category' in request.form and 'registration_id' in request.form and 'user_name' in request.form and 'password' in request.form and 'email' in request.form and 'phone_number' in request.form and 'first_name' in request.form and 'middle_name' in request.form and 'last_name' in request.form: # Create variables for easy access username = request.form['user_name'] password = request.form['password'] email = request.form['email'] category = request.form['category'] registration_id = request.form['registration_id'] middle_name = request.form['middle_name'] first_name = request.form['first_name'] last_name = request.form['last_name'] phone_number = request.form['phone_number'] if category == 'student': student1 = Student(username, password, phone_number, email, first_name, middle_name, last_name, registration_id) # address1 = Address("Distelstraat 6", "Schaerbeek", "Brussels", "Brussels", "Belgium", "1030") # program = Program("Masters in Applied Computer Science", "MACS") student1.address_id = 1 student1.program_id = 1 db.session.add(student1) db.session.commit() if request.method == 'POST' and 'category' in request.form and 'registration_id' in request.form and 'user_name' in request.form and 'password' in request.form and 'email' in request.form and 'phone_number' in request.form and 'first_name' in request.form: # Create variables for easy access print('unicheck!!!!!!') username = request.form['user_name'] password = request.form['password'] email = request.form['email'] category = request.form['category'] if category == 'company': company_code = request.form['registration_id'] else: university_code = request.form['registration_id'] name = request.form['first_name'] phone_number = request.form['phone_number'] if category == 'company': company = Company(username, password, phone_number, email, name, company_code) address1 = Address("Distelstraat 6", "Schaerbeek", "Brussels", "Brussels", "Belgium", "1030") company.address_id = 1 db.session.add(company) db.session.commit() print('commitCHECK!!') elif (category == 'university'): university = University(username, password, phone_number, email, name, university_code) address3 = Address("Uitbreidingstraat 8", "Berchem", "Antwerp", "Antwerp", "Belgium", "2600") program = Program("Masters in Applied Computer Science", "MACS") university.address_id = 3 # university.programs.append(program) db.session.add(university) db.session.commit() print('commitCHECK!!') return 'DONE!'
def recognition(self): locations = [] encodings = [] last_calculation = 0 # Linking to the computer camera vc = cv2.VideoCapture(0, cv2.CAP_DSHOW) self.done.set(value=False) while not self.done.get(): start = time() # Getting the last frame captured by the camera _, frame = vc.read() # Mirroring the frame for a better video back frame = cv2.flip(frame, 1) # Recalculating faces locations & encodings every 2 seconds if time() - last_calculation >= 2: encodings = face_encodings(frame) locations = face_locations(frame) last_calculation = time() for (top, right, bottom, left), face_encoding in zip(locations, encodings): matches = [] for key in self.gui.database: matches += compare_faces([self.gui.database[key][2]], face_encoding) if True in matches: key = list(self.gui.database.keys())[matches.index(True)] student = Student(self.gui, id_=key, first_name=self.gui.database[key][0], last_name=self.gui.database[key][1]) if self.student is None or student != self.student: self.student = student # if not self.got_schedule: # self.got_schedule = self.student.get_schedule() cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0)) cv2.putText(img=frame, text=self.student.get_last_name(), org=(left, top - 10), fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=1, color=(0, 255, 0)) else: cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0)) cv2.putText(img=frame, text="Unknown", org=(left, top - 10), fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=1, color=(0, 255, 0)) frame = cv2.resize(frame, (int(0.72 * self.gui.width), self.gui.height), interpolation=cv2.INTER_AREA) # Somehow the pixels are stored as BGR so we have to arrange them as RGB frame = ImageTk.PhotoImage( image=PIL.Image.fromarray(frame[..., ::-1])) self.itemconfigure(self.video_back_id, image=frame) if (time() - last_calculation) < 1: self.fps = round(1 / (time() - start)) self.itemconfigure(self.fps_id, text=f"FPS: {self.fps}") self.gui.root.update() self.hide()
from model.university import University from model.university_program import university_program # Dont remove db.create_all() address1 = Address("Distelstraat 6", "Schaerbeek", "Brussels", "Brussels", "Belgium", "1030") address2 = Address("Hemeryckxlaan 10", "Kontich", "Antwerp", "Antwerp", "Belgium", "2660") address3 = Address("Uitbreidingstraat 8", "Berchem", "Antwerp", "Antwerp", "Belgium", "2600") address4 = Address("Celestijnenlaan 69", "", "Leuven", "Vlaams-Brabant", "Belgium", "3000") company = Company("uza", "password", "+3212345678", "*****@*****.**", "UZA", "CPY1") company.address = address1 program = Program("Masters in Applied Computer Science", "MACS") student1 = Student("student1", "password1", "+3245678910", "*****@*****.**", "Jeff", "Ronald", "Bezos", "STU1") student1.address = address2 student1.program = program student2 = Student("student2", "password2", "+3244557766", "*****@*****.**", "John", "Bill", "Gates", "STU2") student2.address = address4 student2.program = program student3 = Student("student3", "password3", "+3244557786", "*****@*****.**", "Shawn", "James", "Hill", "STU3") student3.address = address4 student3.program = program university = University("ua_uni1", "password3", "+32889966771", "*****@*****.**", "UA", "UNI1") university.address = address3 university.programs.append(program)
def initializeEntity(self): self.__storeStudents([ Student(1, "alex", "123"), Student(2, "abc", "125"), Student(3, "alin", 127) ])
def registration(self): locations = [] encodings = [] # Creating an instance of Student class to dump the user entries in the database when the face encoding is set student_to_register = Student(self.gui, self.id.get(), self.first_name.get(), self.last_name.get()) temporary_encoding = None student_face_is_detected = False # Linking to the computer camera vc = cv2.VideoCapture(0, cv2.CAP_DSHOW) self.done.set(value=False) self.video_back_frame.place(x=0.15 * self.gui.width, y=0) last_calculation = 0 start = time() self.set_timer = False while not self.done.get(): # Getting the last frame captured by the camera _, frame = vc.read() # Mirroring the frame for a better video back frame = cv2.flip(frame, 1) # Processing where the faces are on the frame if time() - last_calculation >= 0.5: encodings = face_encodings(frame) locations = face_locations(frame) last_calculation = time() student_face_is_detected = False if len(encodings) > 0: if temporary_encoding is None: temporary_encoding = list(encodings[0]) elif temporary_encoding is not None: for (top, right, bottom, left), face_encoding in zip(locations, encodings): matches = compare_faces([temporary_encoding], face_encoding) if matches[0]: student_face_is_detected = True # Drawing a green rectangle around the face of the student cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0)) if time() - start > 3: if not self.set_timer: self.video_back_canvas.itemconfigure( self.timer_text, text="3", font=('helvetica', 70), fill="#00ff00", anchor="center") self.id_after_timer_2 = self.gui.root.after( 1000, lambda: [ self.video_back_canvas. itemconfigure(self.timer_text, text="2", font=('helvetica', 70 ), fill="#00ff00", anchor="center"), self.reset_timer_2() ]) self.id_after_timer_1 = self.gui.root.after( 2500, lambda: [ self.video_back_canvas. itemconfigure(self.timer_text, text="1", font=('helvetica', 70 ), fill="#00ff00", anchor="center"), self.reset_timer_1() ]) self.id_after_timer_0 = self.gui.root.after( 4000, lambda: [ self.video_back_canvas. itemconfigure(self.timer_text, text=" "), self.reset_timer_0(), student_to_register. set_face_encoding( encoding=temporary_encoding), self.gui.root.after( 1000, self.done.set(value=True) ) ]) self.set_timer = True if not student_face_is_detected: self.cancel_timer() elif len(encodings) == 0: if self.set_timer: self.cancel_timer() # Resizing the video back to fit our canvas frame = cv2.resize(frame, (int(0.7 * self.gui.width), self.gui.height), interpolation=cv2.INTER_AREA) # Somehow the pixels are stored as BGR so we have to arrange them as RGB frame = ImageTk.PhotoImage( image=PIL.Image.fromarray(frame[..., ::-1])) self.video_back_canvas.itemconfigure(self.video_back_id, image=frame) self.gui.root.update() student_to_register.dump_info() self.video_back_frame.place_forget() self.hide() self.gui.start_menu.display()
def create_student(self, query_result): if not query_result: return None return Student(*query_result)
def testRepoRemove(self): student = Student(1,"asd",123) self.__repoStudents.add(student) self.__repoStudents.remove(student) students = self.__repoStudents.getAll() self.assertEqual(students,[])
def inputStudent(self): student = input("Give student (ID, group, name): ") student = student.split(None, 2) if len(student) != 3: raise ConsoleError return Student(student[0], student[1], student[2])
DB.start_connection() DB.drop_db() DB.generate_database_schema() session = DB.Session_factory() user1 = User("Mohammad", "Siavashi", "*****@*****.**", "4490347022", "MS95", "2223858", True, [], [], []) session.add(user1) student1 = Student( first_name="Ahmad", last_name="siavash", expire_date=datetime.datetime.now(), advisor="ahmad", national_id="44903232527", student_id="9332045", user_id=session.query(User).filter(User.username == "MS95").first().id, classes=[], exams=[], workbooks=[]) session.add(student1) student2 = Student( first_name="Zahra", last_name="Rahmaniyan", expire_date=datetime.datetime.now(), advisor="Bahareh", national_id="09366194077", student_id="9332010", user_id=session.query(User).filter(User.username == "MS95").first().id,
def testRepoAdd(self): student = Student(1,"alex",99) self.__repoStudents.add(student) students = self.__repoStudents.getAll() self.assertEqual(students[0].getID(),1)