def readStudent(): f = pickle.load(open("students.pickle", "r")) for line in f: info = line.split() student = Student((int)(info[0]), info[1], info[2]) student.setGPA((float)(info[3])) AllStudents.append(student)
def readStudent(): f = open("students.txt", "r") for line in f.readlines(): info = line.split() student = Student((int)(info[0]), info[1], info[2]) student.setGPA((float)(info[3])) AllStudents.append(student)
def test__add_student__validInput__addsStudent(self): self.__student_repository.add(self.addValidInput) students = self.__student_repository.get_all_items() self.assertEqual(students, [ Student(1, "Test Student", 917), Student(2, "Student Test", 916), Student(3, "Le Student", 916) ])
def test_add_student(serv=Service()): serv.students = [] serv.add_student(Student(1, "test", 911)) assert len(serv.students) == 1 try: serv.add_student(Student(1, "test2", 912)) assert False except ValueError: assert True
def filterStudentList__Group125__ListWithoutTheStudentsOfGroup125(): history = [] some_student = Student(17, "ef", 128) removed_student1 = Student(1725, "abcdef", 125) removed_student2 = Student(333, "aaaaa", 125) list_of_students = [removed_student1, some_student, removed_student2] expected_result = [some_student] Services.filter_student_list(list_of_students, 125, history) Tests.__assert_lists_of_students(list_of_students, expected_result)
def test_filter_student(serv=Service()): serv.students = [ Student(1, "t1", 911), Student(2, "t2", 912), Student(3, "t3", 914) ] serv.filter_students(911) assert len(serv.students) == 2 serv.filter_students(913) assert len(serv.students) == 2
def loadAllStudents(self): try: self.db.connect() cursor = self.db.cursor() cursor.execute('Select * from Students') table = cursor.fetchall() # iterate through every data in the table students for row in table: student = Student() student.lastName = row[1] student.firstName = row[2] student.registrationNr = row[3] student.className = row[4] self.studentList.append(student) # we also have to add the grades in the list cursor.execute('select students.registrationNr, subjects.subjectName, grades.grade ' 'from grades ' 'join students on grades.student_id = students.id ' 'join subjects on grades.subject_id= subjects.id;') table=cursor.fetchall() for row in table: # value[0]= registration nr, value[1]= subject name , value[2]=grade for student in self.studentList: # if we find a student that has the registration nr to that student we add the grade if row[0] == student.registrationNr: student.addGrades(row[1], row[2]) # we close the environment except MySQLdb.Error as err: print ('Something went wrong:{}'.format(err))
def generate_entries(): EntryList = [] IDs = [i for i in range(1, 10000)] random.shuffle(IDs) for i in range(10): EntryList.append(Student(IDs[i], names.get_full_name(), random.randint(1, 1000))) return EntryList
def readCourse(): f = pickle.load(open("courses.pickle", "r")) for line in f: info = line.split() print(info) course = Student((int)(info[0]), info[1], info[2]) AllCourses.append(course)
def readCourse(lock): with lock: f = open("courses.txt", "r") for line in f.readlines(): info = line.split() course = Student((int)(info[0]), info[1], info[2]) AllCourses.append(course)
def generate_entries(list_of_students, number_of_entries): """ Generates random entries and adds them in the list of students that has been given as a parameter. Input: - list_of_students - A list with instances of the Student class - number_of_entries - An integer which represents the number of entries that will be generated. """ last_names = [ "Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor" ] first_names = [ "Oliver", "George", "Harry", "Noah", "Jack", "Charlie", "Leo", "Jacob", "Freddie", "Alfie", "Olivia", "Amelia", "Isla", "Ava", "Emily", "Sophia", "Grace", "Mia", "Poppy", "Ella" ] for entry in range(0, number_of_entries): first_name_generated = first_names[randint(0, len(first_names) - 1)] last_name_generated = last_names[randint(0, len(last_names) - 1)] generated_student = Student( randint(1, 100000), first_name_generated + " " + last_name_generated, randint(1, 5)) list_of_students.append(generated_student)
def readFromFile(self): classBook = open('classBook.txt') if os.path.getsize('classBook.txt') > 0: for line in classBook: # we separate the data by ':' , the first element will represent the student information # the rest is subjects and marks studentInfo = re.split(':', line) firsName, lastName, registrationNr, grade = studentInfo[ 0].split(',') registrationNr = int(registrationNr) grade = int(grade) student = Student(firsName, lastName, registrationNr, grade) if len(studentInfo) > 1: for index in range(1, len(studentInfo) - 1): subject, mark = studentInfo[index].split() student.addGrade(subject, mark) self.studentList.append(student)
def add_student_info(c1ass): print("Enter student info:") id = int(input("ID: ")) name = str(input("Name:")) dob = str(input("Date of birth:")) student = Student(id, name, dob) c1ass.append(student) print("This student is added")
def addStudents(): n = (int)(input("How many student(s) you want to add? ")) for i in range(n): id = (int)(input("Student's Id? ")) name = (str)(input("Student's name? ")) dob = (str)(input("Student's Date of Birth? ")) student = Student(id, name, dob) AllStudents.append(student)
def remove_student(self, studentID, dummy1, dummy2): student = Student(studentID, None, None) removed_student = self.__student_repository.search(student) self.__student_repository.remove(student) grades = self.__grade_repository.get_all_grades_student(studentID) for grade in grades: self.__grade_repository.remove(grade) return removed_student.get_id(), removed_student.get_name( ), removed_student.get_group()
def load_from_file (self): f = open(self.__fisier, "r+") self.repo.lista_studenti=[] for linie in f: linie = linie.split(",") if linie!=[]: student = Student(int(linie [0]), linie [1], int(linie [2])) self.repo.adaugare_student(student) f.close()
def cauta_student(self, studentid): """ Metoda pentru validarea unui student in vederea cautarii sale in repo :param studentid: int :return: True, daca studentul se afla deja in repo, False, in caz contrar """ student = Student(studentid, "asf", 21) self.valid_student.validare_student(student) return self.repo_student.cauta_student(student)
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 update_student(self, studentID, update, dummy): searched_student = Student(studentID, None, None) student = self.__student_repository.search(searched_student) group = student.get_group() old_name = student.get_name() self.remove_student(studentID, None, None) self.__student_validator.validate_student(student) self.add_student(studentID, update, group) return old_name
def sterge_student(self, studentid): """ Metoda pentru validarea unui student in vederea stergerii sale in repo :param studentid: int :return: """ student = Student(studentid, "asf", 21) self.valid_student.validare_student(student) self.repo_student.sterge_student(student)
def createStudent(self, studentInfo): lastName, firstName, registrationNr, className = studentInfo.split(',') registrationNr = int(registrationNr) className = int(className) # create the object student student = Student(lastName, firstName, registrationNr, className) if self.repository.addToList(student) == 0: # if the student was already in the DB we return False return False
def setUp(self): self.__student_repository = Repository() self.__student_repository.add(Student(1, "Test Student", 917)) self.__student_repository.add(Student(2, "Student Test", 916)) self.addValidInput = Student(3, "Le Student", 916) self.addInvalidInput = Student(1, "Le Student", "da") self.removeValidInput = Student(1, None, None) self.removeInvalidInput = Student(5, None, None) self.updateValidInput = Student(1, None, None) self.updateInvalidInput = Student(5, None, None) self.updateParameter = "New Student"
def student_info(s_count): s_list = [] for i in range(s_count): print("Student : ", i + 1) id = input("\tStudent ID : ") name = input("\tStudent Name : ") DoB = input("\tStudent Date of Birth (DD/MM/YYYY) : ") s_list.append(S.Student(id, name, DoB)) s_list = sorted(s_list, key=lambda x: x.id) return s_list
def addStudent(): NumStu =[] count= int(input("Number of students")) for i in range(0,count): Name= input ("Student name:") BD = input ("Birthday:") ID = int (input("Student ID :")) s = Student(name, BD, ID) NumStu.append(s) return NumStu
def modificare_student(self, studentid, nume, grupa): """ Metoda pentru validarea unui student in vederea modificarii sale in repo :param studentid: int :param nume: string :param grupa: int :return: """ student = Student(studentid, nume, grupa) self.valid_student.validare_student(student) self.repo_student.modificare_student(student)
def adauga_student(self, studentid, nume, grup): """ Metoda pentru validarea unui student in vederea adaugarii sale in repo :param studentid: int :param nume: string :param grup: int :return: """ student = Student(studentid, nume, grup) self.valid_student.validare_student(student) self.repo_student.adaugare_student(student)
def __init__(self, file_name): """ Repository for students using persistent storage powered by json text files. :param file_name: string representing the location of the students.json """ StudentRepo.__init__(self) self.file_name = file_name file = open(self.file_name, "r") for obj in json.load(file): self.add_student(Student(obj["sid"], obj["name"])) file.close()
def inputstudent(): sc.addstr("Enter StudentID:") sc.refresh() id = sc.getstr().decode() sc.addstr("Enter StudentName:") sc.refresh() name = sc.getstr().decode() sc.addstr("Enter date of brith:") sc.refresh() dob = sc.getstr().decode() Student(id, name, dob) if len(Students) == 0: f = open("students.txt", "w") else: f = open("students.txt", "a") f.write(id + "\n" + name + "\n" + dob + "\n") f.close() Student(id, name, dob)
def add_student_info(c1ass): print("Enter student info:") id = int(input("ID: ")) name = str(input("Name:")) dob = str(input("Date of birth:")) student = Student(id, name, dob) c1ass.append(student) print("This student is added") open = open("student.tex", "a") open.write(f"{id} {name} {dob} \n") open.close()