def delete_student_from_course(self): """ deleting student from course, that invokes Student's method unenroll_me_from_course """ # always ensure that the operating teacher is exists in db if not self.is_teacher_exists(): print("Teacher with email - {} does not exist") return course_name = self.get_students_of_course() student_email = input("Please, type the email of student to delete from course >") s = Student(student_email) # 2 check whether student is enrolled to course if not s.is_enrolled(course_name): print("The student with email - {} does not enrolled to course - {}".format(student_email, course_name)) return c = course.Course(course_name) # deleting from courses json file c.unenroll_student(s.get_email()) # deleting student details about course from users json file db_st = Student.get_db().read_db() for st_i in range(len(db_st["students"])): if db_st["students"][st_i]["email"] == s.get_email(): # removing course name from student's enrolled courses list db_st["students"][st_i]["enrolled_courses"].remove(course_name) # mechanism to erasing marks of unenrolled course from users db if len(db_st["students"][st_i]["marks"]) > 0: for m_s in range(len(db_st["students"][st_i]["marks"])): if db_st["students"][st_i]["marks"][m_s]["course_name"] == course_name: db_st["students"][st_i]["marks"].remove(db_st["students"][st_i]["marks"][m_s]) break Student.get_db().write_db(db_st) print("Student with email - {} is deleted from course - {}".format(student_email, course_name))
def process_new_rectangle(path, caldata, r): print "New rectangle!" # identify cid cid = None for c in caldata.courses.itervalues(): if c['name'] == r['cname']: cid = c['id'] if cid is None: raise Exception("Unknown course") c = course.Course(cid, r['cname']) # load relevant details file det = load_or_new_details(path, cid) # build element el = element.Element(r['organiser'], r['what'], r['where'], FullPattern(r['when']), False, r['type'], c) # add to groups for term in range(0, 3): e = copy.deepcopy(el) if e.restrictToTerm(term): g = det.getGroup(r['type'], term) g.group.append(e) # save details det_fn = os.path.join(path, "details_%s.json" % cid) j = det.to_json() # outside open to allow exceptions c = open(det_fn, "wb") json.dump(j, c) c.close() return cid
def delete_teacher(): """ erases the records of Teacher from json file """ email = input("Please, enter email of teacher to delete >") t = Teacher(email) if not t.is_teacher_exists(): print("Teacher with email - {} is does not exists".format(email)) return # before deletion of teacher, there should be saved the courses that before leaded by the teacher teachers_courses = [] db_t = t.get_db().read_db() for t_i in range(len(db_t["teachers"])): if db_t["teachers"][t_i]["email"] == t.get_email(): teachers_courses = db_t["teachers"][t_i]["leading_courses"] del db_t["teachers"][t_i] break t.get_db().write_db(db_t) # using the list of courses that leaded by deleted teacher, by default, # that courses' teacher's value would be reassigned to admins email # this will give opportunity for admin to update those courses after # some time for crs_name in teachers_courses: c = course.Course(crs_name) crs_to_upd = c.get_course() crs_to_upd.set_new_teacher("root@admin") crs_to_upd.extend_limited_places() crs_to_upd.update_course() print("Teacher with email - {} is deleted".format(email)) return
def enroll_me_to_course(self): """ used to enroll student to course by themselves invokes Course's enroll student method """ courses = course.Course.get_courses() if len(courses) == 0: print("No courses added. Please, check later") return # printing all free courses for student course.Course.print_all_free_courses() course_name = input("Please, type course name to enroll >") crs = course.Course(course_name) crs.enroll_student(self.get_email()) users = self.get_db().read_db() for st_i in range(len(users["students"])): if users["students"][st_i]["email"] == self.get_email(): if course_name in users["students"][st_i]["enrolled_courses"]: print("You have already enrolled to course {}".format(course_name)) return users["students"][st_i]["enrolled_courses"].append(course_name) break self.get_db().write_db(users) print("You have joined to the course - {}".format(course_name))
def test_window(self): students = [course.Student(i, "Shit" + str(i)) for i in range(5)] questions = [survey.NumericQuestion(i, "FUCKNQ" + str(i), 2, 8) for i in range(5)] s = survey.Survey(questions) answers = [1, 0, 0, 3, 4, 1, 0, 1, 1, 1, 2, 1, 2, 2, 2, 3, 2, 1, 0, 1, 3, 0, 0, 3, 2] i = 0 for q in questions: for stu in students: stu.set_answer(q, survey.Answer(2 + answers[i])) i += 1 c = course.Course("Asshole101") c.enroll_students(students) grouping1 = grouper.WindowGrouper(1).make_grouping(c, s) assert len(grouping1) == 5 assert grouping_to_list_of_list(grouping1) == [[0], [1], [2], [3], [4]] grouping2 = grouper.WindowGrouper(2).make_grouping(c, s) assert len(grouping2) == 3 assert grouping_to_list_of_list(grouping2) == [[0], [1, 2], [3, 4]] grouping3 = grouper.WindowGrouper(3).make_grouping(c, s) assert len(grouping3) == 2 assert grouping_to_list_of_list(grouping3) == [[0, 1, 2], [3, 4]] grouping5 = grouper.WindowGrouper(5).make_grouping(c, s) assert len(grouping5) == 1 assert grouping_to_list_of_list(grouping5) == [[0, 1, 2, 3, 4]]
def get_students_of_course(self): """ prints the list of students of specific course """ # always ensure that the operating teacher is exists in db if not self.is_teacher_exists(): print("Teacher with email - {} does not exist".format(self.get_email())) return # checking whether teacher has courses to lead if self.get_lead_courses() is None: print("You do not have any courses to lead") return # if yes, print self.print_my_courses() course_name = input("Please, type the course name >") c = course.Course(course_name) # 1 check whether teacher leads course if not c.is_teacher_leads(self.get_email()): print("You do not lead the course - {}".format(course_name)) return students = c.get_course().get_list_of_students() if students is None: print("Course is not enrolled by any student") return print("{} students: ".format(course_name)) for s in students: print(s) return course_name
def test_course_class_course_get_students() -> None: s1 = course.Student(1, 'Misha') s2 = course.Student(2, 'Jenni') courses = course.Course('CSC148') courses.enroll_students([s1, s2]) assert courses.get_students() == (s1, s2) assert not courses.get_students() == (s2, s1)
def unenroll_me_from_course(self): """ used to unenroll student from course by students invokes unenroll_student method """ if not self.is_student_exist(): print("Student with email - {} does not exist".format(self.get_email())) return my_courses = self.get_my_courses() for c in my_courses: print(c) course_name = input("Please, type the name of course from you want to unenroll >") c = course.Course(course_name) c.unenroll_student(self.get_email()) target_st = self.get_db().read_db() for st_i in range(len(target_st["students"])): if target_st["students"][st_i]["email"] == self.get_email(): target_st["students"][st_i]["enrolled_courses"].remove(course_name) # mechanism to erasing marks of unenrolled course from users db if len(target_st["students"][st_i]["marks"]) > 0: for m_s in range(len(target_st["students"][st_i]["marks"])): if list(target_st["students"][st_i]["marks"][m_s].keys())[0] == course_name: target_st["students"][st_i]["marks"].remove(target_st["students"][st_i]["marks"][m_s]) break self.get_db().write_db(target_st) print("You've unenrolled from the course - {}".format(course_name))
def test_make_grouping_greedy(self): new_course = course.Course('CSC148') q1 = survey.CheckboxQuestion(1, 'Hobbies?', ['Movie', 'Sing', 'Dance', 'Game']) new_survey = survey.Survey([q1]) students = [course.Student(1, 'Zoro'), course.Student(2, 'Aaron'), course.Student(3, 'Gertrude'), course.Student(4, 'Yvette'), course.Student(6, 'Steph'), course.Student(7, 'Draymond'), course.Student(8, 'Andrew')] new_course.enroll_students(students) new_grouper = grouper.GreedyGrouper(2) new_grouping = new_grouper.make_grouping(new_course, new_survey) groups = new_grouping.get_groups() temp_list = [] for i in range(0, len(groups)): people = groups[i].get_members() temp_list.extend(people) if i == (len(groups) - 1): assert len(groups[i]) <= 2 else: assert len(groups[i]) == 2 course_students = new_course.get_students() for student in course_students: assert student in temp_list assert len(temp_list) == 7
def create_course(self): # find the course number course_number_raw = self.dom.xpath( '//*[@id="main"]/table[1]/tbody[2]/tr/td[4]/text()') # strip whitespace course_number = course_number_raw[0].strip() # find the course title course_title_raw = self.dom.xpath( '//*[@id="main"]/table[1]/tbody[2]/tr/td[6]/text()') # strip whitespace course_title = course_title_raw[0].strip() # find the course description description_raw = self.dom.xpath('//*[@id="main"]/text()') longest_index = 0 for i in range(len(description_raw)): if len(description_raw[i].strip()) > longest_index: longest_index = i # assuming course description is the longest value in the list description = description_raw[longest_index].strip() # separate prerequisites from description above if "(Prerequisites:" in description: description, prerequisites = description.split("(Prerequisites:") description = description.replace('\n', '') prerequisites = prerequisites[2:-2] else: prerequisites = "Error" # Find the credit hours credit_hours_raw = self.dom.xpath( '//*[@id="main"]/table[1]/tbody[2]/tr/td[10]/text()') # Strip white space credit_hours = credit_hours_raw[0].strip() # find the course level course_level_raw = self.dom.xpath( '//*[@id="main"]//text()[contains(.,"Undergraduate") or contains(.,"Graduate")]' ) # strip white space course_level = course_level_raw[0].strip() # find the mnTC goals mntc_goals_raw = self.dom.xpath( '//*[@id="main"]//text()[contains(.,"Goal")]') # strip whitespace and store as array mntc_goals = [] for goal in mntc_goals_raw: if goal.strip().startswith("Goal"): mntc_goals.append(goal.strip()) # Create Course self.currentCourse = course.Course(course_number, course_title, description, credit_hours, course_level, mntc_goals, prerequisites) if self.currentCourse.number in self.currentDepartment.courses: self.currentCourse = self.currentDepartment.courses[course_number] else: self.currentDepartment.courses[course_number] = self.currentCourse
def load_course(data: Dict[str, Any]) -> course.Course: """Return a course created using the information in <data>""" course_name = data['name'] course_ = course.Course(course_name) students = [course.Student(s_data['id'], s_data['name']) for s_data in data['students']] course_.enroll_students(students) return course_
def test__has_student() -> None: course1 = course.Course("CSC148") ted = course.Student(1, "Ted") fred = course.Student(2, "Fred") students = [ted, fred] course1.enroll_students(students) assert course1._Course__has_student(ted) assert not course1._Course__has_student(course.Student(3, "Bob"))
def getClasses(self): rawClassList = self.soupDoc.findAll('div', attrs={"class": "AssignmentClass"}) classList = [] for i in rawClassList: classList.append( course.Course(BeautifulSoup(str(i), "html.parser"))) return classList
def test_course_get_students(self) -> None: c = course.Course("mental health") students = [ course.Student(1, "ay"), course.Student(3, "bee"), course.Student(2, "sea") ] c.enroll_students(students) assert c.get_students()[1].name == 'sea'
def test_course_class_course_all_answered() -> None: s1 = course.Student(1, 'Misha') courses = course.Course('CSC148') courses.enroll_students([s1]) question = survey.YesNoQuestion(1, 'Do you like food?') answer = survey.Answer(True) s1.set_answer(question, answer) surveys = survey.Survey([question]) assert courses.all_answered(surveys)
def test_course_simple(self): c = course.Course("SHIT101") assert c.name == 'SHIT101' # Note that we cannot test all_answered at this point # since Survey is not yet implemented at step 3 # everything should be empty at this point assert c.students == [] assert c.get_students() == ()
def test_enroll_students(self): new_course = course.Course('CSC148') students = [course.Student(1, 'Zoro'), course.Student(2, 'Aaron'), course.Student(3, 'Gertrude'), course.Student(4, 'Yvette'), course.Student(4, 'George'), course.Student(6, 'Steph'), course.Student(7, 'Draymond'), course.Student(8, 'Andrew')] new_course.enroll_students(students) assert len(new_course.students) == 0 new_course = course.Course('CSC165') students = [course.Student(1, 'Zoro'), course.Student(2, 'Aaron'), course.Student(3, 'Gertrude')] new_course.enroll_students(students) new_course.enroll_students(students) assert len(new_course.students) == 3
def update_calendar(det_str, cal): c = course.Course(det_str['id'], det_str['name']) cal.refresh_course(c) if 'staticurls' in det_str: # static calendar cal.make_course_static(c, det_str['staticurls']) else: # generate new rectangles zoo = rectangle.RectangleZoo.zoo_from_details( c, details.Details.from_json(det_str)) cal.replace_course_rectangles(c, zoo)
def test_enroll_students(self, students) -> None: stu_list = students course1 = course.Course('csc1') course1.enroll_students(students) s1 = students[0] s2 = students[1] s3 = students[2] s4 = students[3] s5 = students[4] assert course1.students == [s1, s2, s3, s4, s5] assert course1.students == stu_list
def test_generatePossibleSchedules(self): """ schedule.generatePossibleSchedules should return correct values. """ class_2_1 = coursedataparser.toClass( "", ("21000", "LEC", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) class_2_2 = coursedataparser.toClass( "", ("22000", "LEC", "1", "0", "STAFF", "MWF 4:00- 5:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) course2 = course.Course("", [class_2_1, class_2_2]) class_3_1 = coursedataparser.toClass( "", ("31000", "LEC", "1", "0", "STAFF", "TuTh 7:00- 8:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) class_3_2 = coursedataparser.toClass( "", ("32000", "LEC", "1", "0", "STAFF", "MW 7:00- 8:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) course3 = course.Course("", [class_3_1, class_3_2]) class_4_1 = coursedataparser.toClass( "", ("41000", "LEC", "1", "0", "STAFF", "TuTh 10:00- 11:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) course4 = course.Course("", [class_4_1]) class_5_1 = coursedataparser.toClass( "", ("51000", "LEC", "1", "0", "STAFF", "TuTh 10:00- 10:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) course5 = course.Course("", [class_5_1]) scheds_1 = schedule.generatePossibleSchedules([course2], {}) scheds_2 = schedule.generatePossibleSchedules([course2, course4], {}) scheds_3 = schedule.generatePossibleSchedules([course2, course3], {}) scheds_4 = schedule.generatePossibleSchedules([course4, course5], {}) self.assertEqual([s.classes for s in scheds_1], [(class_2_1, ), (class_2_2, )]) self.assertEqual([s.classes for s in scheds_2], [(class_2_1, class_4_1), (class_2_2, class_4_1)]) self.assertEqual([s.classes for s in scheds_3], [(class_2_1, class_3_1), (class_2_1, class_3_2), (class_2_2, class_3_1), (class_2_2, class_3_2)]) self.assertEqual([s.classes for s in scheds_4], [])
def _convertConnectedSplitClassesToCourseData(splitClasses: 'list of list of course.Class', courseName: str) -> ('list of course.Course', 'dict of (courseNum:list of course.Class)'): """ For connected course data split classes, returns sub-course objects and dict of connected class data. Assumes only two sub-courses for connected courses. """ course1Classes = [] course2Classes = [] connectedClassDict = {} for i in range(0, len(splitClasses), 2): currCourse1Class = splitClasses[i][0] course1Classes.append(currCourse1Class) key = currCourse1Class.code connectedClassDict[key] = [] for currCourse2Class in splitClasses[i + 1]: course2Classes.append(currCourse2Class) connectedClassDict[key].append(currCourse2Class) course1 = course.Course(courseName, course1Classes) course2 = course.Course(courseName, course2Classes) return [course1, course2], connectedClassDict
def setUpClass(cls): # called one time, at beginning print('setUpClass()') cls.school = school.School().get() name_1 = 'Yangyi Li' name_2 = 'Jerry' name_3 = 'Grass' gender_a = 'male' gender_b = 'male' gender_c = 'female' cls.student1 = student.Student(name_1, gender_a, 'yli43') cls.student2 = student.Student(name_2, gender_b, 'j777') cls.student3 = student.Student(name_3, gender_c, 'g690') cls.cs201 = course.Course("cs201", "Jason Hibbeler") cls.cs205 = course.Course("cs205", "Jason Hibbeler") cls.cs011 = course.Course("cs011", "teacher") cls.school.add_course(cls.cs201) cls.school.add_course(cls.cs205) cls.school.add_student(cls.student1) cls.school.add_student(cls.student2) cls.school.add_student(cls.student3)
def test_get_students(self): new_course = course.Course('CSC148') students = [course.Student(1, 'Zoro'), course.Student(2, 'Aaron'), course.Student(3, 'Gertrude'), course.Student(4, 'Yvette'), course.Student(6, 'Steph'), course.Student(7, 'Draymond'), course.Student(8, 'Andrew')] new_course.enroll_students(students) assert len(new_course.get_students()) == 7 assert isinstance(new_course.get_students(), tuple)
def test_all_answered(self, answers, questions): new_course = course.Course('CSC148') students = [course.Student(1, 'Zoro'), course.Student(2, 'Aaron'), course.Student(3, 'Gertrude'), course.Student(4, 'Yvette'), course.Student(6, 'Steph'), course.Student(7, 'Draymond'), course.Student(8, 'Andrew')] s = survey.Survey(questions) new_course.enroll_students(students) assert new_course.all_answered(s) == False
def test_course_complex(self): c = course.Course("SHIT101") c.enroll_students([]) # enroll empty list, got empty assert c.students == [] assert c.get_students() == () # add one student c.enroll_students([course.Student(0, "FUCK0")]) assert len(c.students) == 1 assert [(x.id, x.name) for x in c.students] == [(0, 'FUCK0')] assert len(c.get_students()) == 1 assert isinstance(c.get_students(), tuple) assert [(x.id, x.name) for x in c.get_students()] == [(0, 'FUCK0')] # add same student again should not change anything c.enroll_students([course.Student(0, "FUCK0")]) assert len(c.students) == 1 assert [(x.id, x.name) for x in c.students] == [(0, 'FUCK0')] assert len(c.get_students()) == 1 assert isinstance(c.get_students(), tuple) assert [(x.id, x.name) for x in c.get_students()] == [(0, 'FUCK0')] # add student with empty name should not change anything c.enroll_students([course.Student(888, "")]) assert len(c.students) == 1 assert [(x.id, x.name) for x in c.students] == [(0, 'FUCK0')] assert len(c.get_students()) == 1 assert isinstance(c.get_students(), tuple) assert [(x.id, x.name) for x in c.get_students()] == [(0, 'FUCK0')] # add some more c.enroll_students([course.Student(2, "FUCK2"), course.Student(1, "FUCK1"), course.Student(99, "FUCK99")]) assert len(c.students) == 4 assert len(c.get_students()) == 4 assert isinstance(c.get_students(), tuple) assert [(x.id, x.name) for x in c.get_students()] == [(0, 'FUCK0'), (1, 'FUCK1'), (2, 'FUCK2'), (99, 'FUCK99')] # add some more, but contains invalid student, should change nothing c.enroll_students([course.Student(2, "FUCK2"), course.Student(0, "FUCK0"), course.Student(88, "FUCK88"), course.Student(99, "FUCK99")]) assert len(c.students) == 4 assert len(c.get_students()) == 4 assert isinstance(c.get_students(), tuple) assert [(x.id, x.name) for x in c.get_students()] == [(0, 'FUCK0'), (1, 'FUCK1'), (2, 'FUCK2'), (99, 'FUCK99')]
def test_course_enroll(self) -> None: c = course.Course("underwater basket weaving") assert c.name == 'underwater basket weaving' assert c.students == [] students = [ course.Student(1, "ay"), course.Student(3, "bee"), course.Student(2, "sea") ] c.enroll_students(students) assert len(c.students) == len(students) for s in students: assert s in c.students
def from_json(data): out = RectangleZoo() for cdata in data: tmpl = cdata[0] if isinstance(cdata, list) else cdata dt = daytime.DayTimeRange(tmpl['day'], tmpl['starttime'], tmpl['endtime']) c = course.Course(tmpl['cid'], tmpl['cname']) # XXX is this correct behaviour? rid = tmpl['rid'].split(':')[1] merge = rid[0] == 'Y' if 'rid' in tmpl else True key = RectangleZoo._calc_key(tmpl['type'], tmpl['what'], dt, c, merge) out.clusters[key] = RectangleCluster.from_json(key, cdata) return out
def test_grouper_class_grouping_get_groups_() -> None: c1 = course.Course('CSC148') s1 = course.Student(1, 'Ali') s2 = course.Student(2, 'Kat') s3 = course.Student(3, 'Dorsa') s4 = course.Student(4, 'Sophia') s5 = course.Student(5, 'Momo') s6 = course.Student(6, 'Joseph') c1.enroll_students([s1, s2, s3, s4, s5, s6]) a1 = grouper.AlphaGrouper(2) q1 = survey.MultipleChoiceQuestion(1, 'What is your choice?', ['A', 'B', 'C']) sur1 = survey.Survey([q1]) a1.make_grouping(c1, sur1) assert len(a1.make_grouping(c1, sur1).get_groups()) == 3
def add_student_to_course(self): """ invoked by teacher writes to 2 json files records of student's email """ # always ensure that the operating teacher is exists in db if not self.is_teacher_exists(): print("Teacher with email - {} does not exist") return # checking whether teacher has courses to lead if self.get_lead_courses() is None: print("You do not have any courses to lead") return # if yes, print self.print_my_courses() course_name = input("Please, type the course name >") c = course.Course(course_name) # 1 check whether teacher leads course if not c.is_teacher_leads(self.get_email()): print("You do not lead the course - {}".format(course_name)) return print("Here is the list of all students") # provide the list of students to enroll them to course Student.print_all_students() student_email = input("Please, type student email to enroll him/her to course - {} >".format(course_name)) s = Student(student_email) if not s.is_student_exist(): print("Student with email - {} does not exists".format(student_email)) return # if student does not enrolled to course, then enroll him/her if not s.is_enrolled(course_name): c.enroll_student(student_email) users = Student.get_db().read_db() for st_i in range(len(users["students"])): if users["students"][st_i]["email"] == student_email: if course_name in users["students"][st_i]["enrolled_courses"]: print("Student - {} enrolled to course {}".format(student_email, course_name)) return users["students"][st_i]["enrolled_courses"].append(course_name) break Student.get_db().write_db(users) print("Student - {} have joined to the course - {}".format(student_email, course_name)) else: print("Student with email - {} is already enrolled to course".format(course_name))
def readCourseFileToCourseData(courseFile: pathlib.Path) -> ([course.Course], 'dict of (courseNum:list of course.Class) OR None'): """ Reads course data from argument file. If course is connected, returns sub-courses and dict of connected class data. If course is not connected, returns sub-courses and None. Assumes only two sub-courses for connected courses. """ print("courseFileType is: ") courseName = courseFile.stem tuples = readCourseFileToTuples(courseFile) splitClasses = _convertToClassesByType(courseName, tuples) if _isConnected(splitClasses): return _convertConnectedSplitClassesToCourseData(splitClasses, courseName) else: subCourses = [course.Course(courseName, subCourseClasses) for subCourseClasses in splitClasses] return subCourses, None