def main(): #testing out the course class ACIT2515 = Course("ACIT2515", "12345", "Computing", "CIT") ACIT2515.add("A01048668") ACIT2515.add("A00000001") ACIT2515.add("A00000002") ACIT2515.remove("A01048668") if (ACIT2515.check("A01048668") == False): print("I should be enrolled in ACIT 2515") ACIT2515.details() ACIT2520 = Course("ACIT2520", "54321", "Computing", "CIT") ACIT2520.add("A01048668") ACIT2520.add("A00000001") ACIT2520.add("A00000002") ACIT2520.add("A00000003") ACIT2520.add("A00000004") ACIT2520.remove("A00000001") ACIT2520.remove("A00000002") ACIT2520.remove("A00000003") ACIT2520.add("A01048668") ACIT2520.details() MATH1350 = Course("MATH1350", "11111", "Mathematics", "CIT") MATH1350.details()
def test_init_with_prereq(self): prereq1 = Course('CSC108') prereq2 = Course('CSC165') course = Course('CSC148', [prereq1, prereq2]) self.assertEqual('CSC148', course.name) self.assertFalse(course.taken) self.assertEqual(course.prereqs, [prereq1, prereq2])
def main(): """ Testing of the course class""" """ Creating an instance of the Course class for ACIT2515 """ print('<--- ACIT 2515 --->') acit2515 = Course('ACIT 2515', 713456, 'BCIT School of Computing', 'CIT') acit2515.add_student('A01054709') acit2515.add_student('A01054938') acit2515.add_student('A00492893') acit2515.remove_student('A01054709') if acit2515.check_enrollment('A01054709') is False: print('I should be enrolled in ACIT2515!') print(acit2515.course_details()) """ Creating an instance of the Course class for ACIT 1515 """ print('<--- ACIT 1515 --->') acit1515 = Course('ACIT 1515', 340923, 'BCIT School of Computing', 'CIT') acit1515.add_student('A01054709') acit1515.add_student('A01054708') acit1515.add_student('A01054707') acit1515.add_student('A01054706') acit1515.add_student('A01054705') acit1515.remove_student('A01054707') acit1515.remove_student('A01054706') acit1515.remove_student('A01054705') acit1515.add_student('A01054709') print(acit1515.course_details()) """ Creating an instance of the Course class for ACIT 1420 """ print('<--- ACIT 1420 --->') acit1420 = Course('ACIT 1420', 348209, 'BCIT School of Computing', 'CIT') print(acit1420.course_details())
def test_get_num_courses_in_program(self): """ 060A - Valid Get Number of Courses in Program """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A01000056") test_course_2 = Course("COMP1409", "123444", "CSD") test_course_2.add_student("A01000056") test_course_3 = Course("COMP1510", "123555", "CSD") test_course_3.add_student("A01000045") test_course_4 = Course("COMP2530", "123667", "CSD") test_course_4.add_student("A01000034") test_school = School("Computing and Academic Studies") test_school.add_course(test_course_1) test_school.add_course(test_course_2) test_school.add_course(test_course_3) test_school.add_course(test_course_4) self.assertEqual(test_school.get_num_courses_in_program("CIT"), 1, "Must be only 1 CIT course") self.assertEqual(test_school.get_num_courses_in_program("CSD"), 3, "Must be 3 CSD courses") self.assertEqual(test_school.get_num_courses_in_program("SSD"), 0, "Must be no SSD courses")
def init_lists(c_list, s_list, a_list): """ This function adds elements to course_list, student_list and admin_list. It makes testing and grading easier. It has three parameters: c_list is the list of Course objects; s_list is the list of Student objects; a_list is the list of Admin objects. This function has no return value. """ course1 = Course("CSC121", 2) course1.add_student("1004") course1.add_student("1003") c_list.append(course1) course2 = Course("CSC122", 2) course2.add_student("1001") c_list.append(course2) course3 = Course("CSC221", 1) course3.add_student("1002") c_list.append(course3) student1 = Student("1001", "111") s_list.append(student1) student2 = Student("1002", "222") s_list.append(student2) student3 = Student("1003", "333") s_list.append(student3) student4 = Student("1004", "444") s_list.append(student4) admin1 = Admin("7001", "777") a_list.append(admin1) admin2 = Admin("8001", "888") a_list.append(admin2)
def main(): # Create and Allocate Course Object Instances in Memory: course1 = Course("Data Structures") course2 = Course("SQL Programming") # Add Students to course1 Object Instance: course1.addStudent("Peter Jones") course1.addStudent("Brian Smith") course1.addStudent("Annie Kennedy") # Add Students to course2 Object Instance: course2.addStudent("Tom Jones") course2.addStudent("Lee Smith") course2.addStudent("Mary Jane") # Display course1 Object Instance List and Length of List: print("Number of students in course 1:", course1.getNumberOfStudents()) for student in course1.getStudents(): print(student, end=", ") print('\n') # Remove Student from course2 Object Instance: if "Tom Jones" in course2.getStudents(): course2.dropStudent("Tom Jones") # Display course2 Object Instance List and Length of List: print("Number of students in course 2:", course2.getNumberOfStudents()) for student in course2.getStudents(): print(student, end=", ") print('\n')
def login(self): username = input("What is your name? ") if username.lower() not in SystemInfo.users_info: print("You are not part of the system. Contact the admin.") sys.exit(0) else: if SystemInfo.users_info[username]["role"] == "student": course = input("What course is this for? ").upper() if course not in SystemInfo.users_info[username]["course"]: print("You are not enrolled in this course.") sys.exit(0) else: join_this_course = Course(course, SystemInfo.course_info[course]) student = User(username, join_this_course) student.startCollab(join_this_course) elif SystemInfo.users_info[username]["role"] == "professor": course = input("What course are you here for? ").upper() if course not in SystemInfo.users_info[username]["course"]: print("You are not teaching this course.") sys.exit(0) else: join_this_course = Course(course, SystemInfo.course_info[course]) professor = Professor(username, join_this_course) professor.uploadLectureOutline() professor.startCollab(join_this_course) elif SystemInfo.users_info[username]["role"] == "admin": admin = Administrator(username) admin.maintainSystem()
def set_courses(self) -> None: for section in self._meeting_sections: # print(section) # Debugging only temp_lst = [] if "T" not in section["code"][0] and "P" not in section["code"][0]: for time in section['times']: temp_lst.append((self._filter.get_start_time() <= time['start'] <= self._filter.get_end_time()) \ and (self._filter.get_start_time() <= time['end'] <= self._filter.get_end_time()) \ and time['day'] not in self._filter.get_days_excluded() \ and not (self._filter.get_lunch_time_start() <= time[ 'start'] <= self._filter.get_lunch_time_end()) and not (self._filter.get_lunch_time_start() <= time[ 'end'] <= self._filter.get_lunch_time_end())) if all(temp_lst): self._lectures_list.append( Course(self._id, self._code, self._name, self._description, self._division, self._department, self._prerequisites, self._exclusions, self._level, self._campus, self._term, self._breadths, section)) else: for time in section['times']: temp_lst.append((self._filter.get_start_time() <= time['start'] <= self._filter.get_end_time()) \ and (self._filter.get_start_time() <= time['end'] <= self._filter.get_end_time()) \ and time['day'] not in self._filter.get_days_excluded() \ and not (self._filter.get_lunch_time_start() <= time[ 'start'] < self._filter.get_lunch_time_end()) and not ( self._filter.get_lunch_time_start() < time['end'] < self._filter.get_lunch_time_end())) if all(temp_lst): self._tutorials_practicals_list.append( Course(self._id, self._code, self._name, self._description, self._division, self._department, self._prerequisites, self._exclusions, self._level, self._campus, self._term, self._breadths, section))
def parse_course_data(filename): """ (str) -> Course Read in prerequisite data from the file called filename, create the Course data structures for the data, and then return the root (top-most) course. See assignment handout for details. """ courses = {} with open(filename, 'r') as source: for line in source: classes = line.split() if classes[0] not in courses: courses[classes[0]] = Course(classes[0]) if classes[1] not in courses: courses[classes[1]] = Course(classes[1]) if courses[classes[0]] not in courses[classes[1]].prereqs: courses[classes[1]].add_prereq(courses[classes[0]]) top = None for cour in courses: boo = True for compare in courses: if courses[cour] in courses[compare].prereqs: boo = False if boo: return courses[cour]
def init_lists(c_list, s_list, a_list): course1 = Course("CSC227", 2) course1.add_student("1003") course1.add_student("1004") c_list.append(course1) course2 = Course("CTI115", 2) course2.add_student("1001") c_list.append(course2) course3 = Course("DBA130", 1) course3.add_student("1002") c_list.append(course3) student1 = Student("1001", "111") s_list.append(student1) student2 = Student("1002", "222") s_list.append(student2) student3 = Student("1003", "333") s_list.append(student3) student4 = Student("1004", "444") s_list.append(student4) admin1 = Admin("8001", "888") a_list.append(admin1) admin2 = Admin("9001", "999") a_list.append(admin2)
def test_get_courses_by_crn(self): # Timeslot can be empty for this c1 = Course("CSCI2121", None) c2 = Course("CSCI2121", None) c3 = Course("CSCI2121", None) c4 = Course("CSCI2122", None) self.assertEquals(3, len(Course.get_all_by_crn("CSCI2121")))
def test_iterate_list(self): cl = CourseList() cl.insert(Course(1000)) for _ in range(20): cl.insert(Course(1200)) totalCourses = 0 for _ in cl: totalCourses += 1 self.assertEqual(totalCourses, 21)
def test_get_all(self): with patch('fileSystemCourseDaoImpl.open', mock_open(read_data=self.mocked_course_data), create=True) as m: expected_courses = [Course(), Course()] actual_courses = self.courseDao.get_all() self.assertEqual(expected_courses, actual_courses)
def test_remove_all(): cl = CourseList() cl.insert(Course(1000, "", 0.0, 0.0)) for _ in range(20): cl.insert(Course(1200, "", 0.0, 0.0)) cl.insert(Course(1800, "", 0.0, 0.0)) assert cl.size() == 22 cl.remove_all(1200) assert cl.size() == 2
def test_iterate_list(): cl = CourseList() cl.insert(Course(1000, "", 0.0, 0.0)) for _ in range(20): cl.insert(Course(1200, "", 0.0, 0.0)) totalCourses = 0 for _ in cl: totalCourses += 1 assert totalCourses == 21
def test_remove_all(self): cl = CourseList() cl.insert(Course(1000)) for _ in range(20): cl.insert(Course(1200)) cl.insert(Course(1800)) self.assertEqual(cl.size(), 22) cl.remove_all(1200) self.assertEqual(cl.size(), 2)
def test_takeable_many_prereqs_satisfied(self): self.c1 = Course('CSC108') self.c2 = Course('CSC148', [self.c1]) self.c3 = Course('CSC165', [self.c1]) self.c4 = Course('CSC207', [self.c1, self.c2, self.c3]) self.c1.taken = True self.assertTrue(self.c2.is_takeable()) self.assertTrue(self.c3.is_takeable()) self.c2.taken = True self.c3.taken = True self.assertTrue(self.c4.is_takeable())
def main (): filePath = "data.txt" # path of file to access. file = open(filePath) # opens file. lines = len(file.readlines()) # accesses number of lines in data file. file = open(filePath) # reopens data file. number = 0 # temporary variable for class number. name = " " # temporary variable for class name. credit = 0 # temporary variable for credit hours. grade = 0.0 # temporary variable for grades. schedule = CourseList(None) # empty CourseList object. for x in range(lines - 1): # for loop parsing each line of data file. firstLine = file.readline() comma = firstLine.index(',') number = firstLine[0:comma] # accesses class number. firstLine = firstLine[comma + 1:len(firstLine)] comma = firstLine.index(',') name = firstLine[0:comma] # accesses class name. firstLine = firstLine[comma + 1:len(firstLine)] comma = firstLine.index(',') credit = firstLine[0:comma] # accesses credit hours. firstLine = firstLine[comma + 1:len(firstLine)] grade = firstLine # accesses grade. schedule.insert(Course(int(number), name, float(credit), float(grade), None)) # inserts a Course object into the CourseList object using parsed data. firstLine = file.readline() # repeats parsing process for last line of the data file. comma = firstLine.index(',') number = firstLine[0:comma] firstLine = firstLine[comma + 1:len(firstLine)] comma = firstLine.index(',') name = firstLine[0:comma] firstLine = firstLine[comma + 1:len(firstLine)] comma = firstLine.index(',') credit = firstLine[0:comma] firstLine = firstLine[comma + 1:len(firstLine)] grade = firstLine schedule.insert(Course(int(number), name, int(credit), float(grade), None)) # inserts last Course object. print("Current List: (", schedule.size(), ")") # prints out current CourseList object size. print("\n") print(schedule) # prints current CourseList with inserted courses. print("\n\n\n") print("Cumulative GPA: ", schedule.calculate_gpa()) # prints out cumulative GPA.
class GradingQuestion(QuestionTemplate): """ Ex: "How is the grading for cmpe 273" Ex: "What is the grading for cmpe 273" """ grading = Group(Lemma("grading"), "grading") regex = Lemmas("How be") + Question(Pos("DT")) + grading + Pos("IN") + Course() + Question(Pos(".")) | \ Lemmas("what be") + Question(Pos("DT")) + Lemma("grading") + Pos("IN") + Course() + Question(Pos(".")) def interpret(self, match): answer = "%s has %s ." grading = IsClassRelated() + match.course + HasFields('grading'.decode('utf-8')) \ + HasAnswer(answer.decode('utf-8')) return grading
class InstructorQuestion(QuestionTemplate): """ Ex: "Who is the instructor of cmpe 273?" "Who teaches cmpe 273?" "By whom is cmpe 273 taught?" """ regex = Lemmas("who be") + Question(Pos("DT")) + Lemma("instructor") + Pos("IN") + Course() + Question(Pos(".")) | \ Lemma("who") + Lemma("teach") + Course() + Question(Pos("."))| \ Pos("IN") + Lemmas("whom be") + Course() + Lemma("taught") + Question(Pos(".")) def interpret(self, match): answer = "The instructor for %s is %s" instructor = IsInstructorInfoRelated() + match.course + HasFields( 'name'.decode('utf-8')) + HasAnswer(answer.decode('utf-8')) return instructor
def test_get_non_existent_course(self): """ 050C - Invalid Get Course Non-Existent """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_course_2 = Course("COMP1510", "456321", "CST") test_course_2.add_student("A010000056") test_course_2.add_student("A010450012") test_school = School("Computing and Academic Studies") test_school.add_course(test_course_1) test_school.add_course(test_course_2) self.assertIsNone(test_school.get_course("ACIT1234"), "No course should exists for ACIT1234")
def parse_csv(csv_file): crn = [] for row in csv_file: # If meridian is not 'AM' or 'PM' set to 'AM' m = row['meridian'] if m != 'AM' and m != 'PM': m = 'AM' # Read in start and end time try: st = check_time(row['start_time']) et = check_time(row['end_time']) except Exception as e: print row raise e # Give start time correct meridian st, et = decide_am_pm(st, et, m) # Create a timeslot ts = parse_time(row['days'], st, et) # Create course # Initialize with no prereqs (need database with prereqs) try: c = Course(row['crn?'], ts, None, **row) except Exception as e: print row raise e crn.append(c) return crn
def readAndCreateSet(): f = open('course-list.txt', 'r') set = LinkedSet() for line in f: course = None if line != '\n': # Split into two halves splitted = line.split('\'') # splitted[1] has course name which spaces # and cannot be parsed normally. name = splitted[1] splitAgain = splitted[0].split(' ') term = splitAgain[0] section = splitAgain[1] available = splitAgain[2] capacity = splitAgain[3] subject = splitAgain[4] course_number = splitAgain[5] course = Course(term, subject, course_number, section, name, available, capacity) set.add(course) #print(set) return set f.close()
def prompt_course() -> Course: ''' prompts user to enter info of a course returns: Course object with the info inputter by user ''' name = "" cred = 0 grade = .0 _type = 'mandatory' name = input("名(串):") print("学分(整):") cred = utils.promptint() while True: grade = input("绩点(字母):").upper() if utils.isgrade(grade): break while True: inp = input("类(必选:0,限选:1,任选:2):") if inp == '0' or inp == 'mandatory' or inp == '必修': _type = '必修' elif inp == '1' or inp == 'limited' or inp == '限选': _type = '限选' elif inp == '2' or inp == 'free' or inp == '任选': _type = '任选' else: continue # 重新请求输入 break return Course(name=name, credit=cred, grade=grade, _type=_type)
def main(): course_code = input("Enter course code: ") quota = int(input("Enter course quota: ")) course1 = Course(course_code, quota) user_input = 5 while user_input != 0: user_input = int( input("Enter 1 for add student, 2 for drop student," "3 for course info, 0 for exit: ")) if user_input == 1: course1.add_student() print("Enrollment: ", course1.getEnrollment()) print() elif user_input == 2: course1.drop_student() print("Enrollment: ", course1.getEnrollment()) print() elif user_input == 3: print("Course code: ", course1.getCourse_code()) print("Quota: ", course1.getQuota()) print("Enrollment: ", course1.getEnrollment()) print() elif user_input == 4: new_quota = int(input("Enter new quota: ")) course1.setQuota(new_quota)
def create_Courses(starting_time, ending_time, time_slot_index, number_of_class_to_be_created): for i in range(number_of_class_to_be_created): # starting_time = 8.75*60 # ending_time = 10.75*60 # # institution_is_availiable = {1:False,2:False,3:False} array_of_institution_index = na.array((1, 2, 3)) #UNCOMMENT rand.shuffle(array_of_institution_index) for i in array_of_institution_index: done = False selected_institution_number = i classroom_list = INSTITUTION_INT_MAP[i].classrooms classroom_index = na.array(range(len(classroom_list))) #UC rand.shuffle(classroom_index) for j in classroom_index: if classroom_list[j].open[time_slot_index - 1] == True: INSTITUTION_INT_MAP[i].classrooms[j].open[time_slot_index - 1] = False selected_classroom_number = j classroom = classroom_list[selected_classroom_number] course = Course(starting_time, ending_time, selected_institution_number, classroom) all_courses[time_slot_index].append(course) done = True break if done: break
def test_course_exists_not_existent_course(self): """ 030C - Valid Course Does Not Exist """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_course_2 = Course("COMP1510", "456321", "CST") test_course_2.add_student("A010000056") test_course_2.add_student("A010450012") test_school = School("Computing and Academic Studies") test_school.add_course(test_course_1) test_school.add_course(test_course_2) self.assertFalse(test_school.course_exists("ACIT1234"), "Course ACIT1234 must NOT exist") self.assertFalse(test_school.course_exists("COMP4321"), "Course4321 must NOT exist")
def test_course_exists(self): """ 030A - Valid Course Exists """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_course_2 = Course("COMP1510", "456321", "CST") test_course_2.add_student("A010000056") test_course_2.add_student("A010450012") test_school = School("Computing and Academic Studies") test_school.add_course(test_course_1) test_school.add_course(test_course_2) self.assertTrue(test_school.course_exists("ACIT2515"), "Course ACIT2515 must exist") self.assertTrue(test_school.course_exists("COMP1510"), "Course COMP1510 must exist")
def test_remove_recursion(self): cl = CourseList() for i in range(1000, 1010): cl.insert(Course(i, "Test", 1.0, 1.0)) RecursionCounter.recursion_count = 0 cl.remove(1005) self.assertGreater(RecursionCounter.recursion_count, 4)
def test_sorted_recursion(self): cl = CourseList() for i in range(1000, 1010): cl.insert(Course(i, "Test", 1.0, 1.0)) RecursionCounter.recursion_count = 0 cl.is_sorted() self.assertGreater(RecursionCounter.recursion_count, 9)