def test_read_lab_time_correctness_nolab():
    """Test if read_lab_time() returns the right content if the course has no lab."""
    file_obj = check_file_open('tests/test_lab.json')
    each_course = file_obj['Test Data']['CourseData']['ACCT'][2]
    temp_course = course.Course()
    temp_course = read_lab_time(each_course, temp_course)
    assert len(temp_course.lab) == 0
def test_read_lab_time_correctness_lab():
    """Test if read_lab_time() returns the right content if the course has a lab."""
    file_obj = check_file_open('tests/test_lab.json')
    each_courses = file_obj['Test Data']['CourseData']['ACCT']
    for i in range(len(each_courses)):
        each_course = each_courses[i]
        temp_course = course.Course()
        temp_course = read_lab_time(each_course, temp_course)
        assert temp_course == target_output.labs[i]
Пример #3
0
def read_course_proto(json_object, course_list, department_name, enrollment_dict):
    """Convert course json object to lists of objects, using Protocol Buffer generated class

    With the raw json file of the quarter,
    and the department name, this function reads data from json file and initializes Course objects
    using the data from json file. The initialized Course objects will be put into the course_list
    argument and the list of all course titles under this department name will be returned

    Args:
      json_object: the list which generated by reading the json file

      course_list: the list of courses, mutates during runtime to
                          be filled with course objects
      department_name: the department name, used to access the json file
                      and to record what courses are in this department
      enrollment_dict: Key: course number(crn)'crn'
                      Value: A dictionary including enrollment information such as active enrollment number(act),
                      remaining open seat number(rem), waitlist remaining(WL Rem), and fetch time(fetch_time).
    Raises:
        KeyError: If the attributes provided are not in the json key list
    Returns:
        The list containing the name of all courses in this department

    """
    each_department = department.Department()
    each_department.deptName = department_name
    for each_course in json_object['CourseData'][department_name]:
        temp_course = course.Course()
        temp_course.UID = each_course['CRN']
        temp_course.crn = each_course['CRN']
        temp_course.course_num = each_course['Crse']
        temp_course.section_num = each_course['Sec']
        temp_course.campus = each_course['Cmp']
        temp_course.num_credit = float(each_course['Cred'])
        temp_course.course_title = each_course['Title']
        temp_course.startTime = each_course['Time'][:8]
        temp_course.endTime = each_course['Time'][9:]
        temp_course.cap = int(each_course['Act']) + int(each_course['Rem'])
        temp_course.instructor_name = each_course['Instructor']
        temp_course.startDate = each_course['Date (MM/DD)'][:5]
        temp_course.endDate = each_course['Date (MM/DD)'][6:]
        temp_course.location = each_course['Location']
        temp_course.days = 'ONLINE' if ('ONLINE' in temp_course.location) else each_course['Days']
        temp_course.attribute = each_course['Attribute']
        temp_course = read_lab_time(each_course, temp_course)
        course_list.append(temp_course)
        enrollment_dict[temp_course.crn] = {'crn': temp_course.crn, 'fetch_time_datetime': json_object['FetchTime'],
            'fetch_time': datetime.fromtimestamp(json_object['FetchTime']).strftime("%m/%d/%Y, %H:%M:%S"),
            ACTIVE: int(each_course[ACTIVE]), REMAIN: int(each_course[REMAIN]), WAITLIST_REMAIN: int(each_course[WAITLIST_REMAIN])}
        if temp_course not in each_department.courses:
            each_department.courses.append(temp_course)
    return each_department
Пример #4
0
def read_course_proto(json_object, course_list, department_name):
    """Convert course json object to lists of objects, using Protocol Buffer generated class

    With the raw json file of the quarter,
    and the department name, this function reads data from json file and initializes Course objects
    using the data from json file. The initialized Course objects will be put into the course_list
    argument and the list of all course titles under this department name will be returned

    Args:
      json_object: the list which generated by reading the json file

      course_list: the list of courses, mutates during runtime to
                          be filled with course objects
      department_name: the department name, used to access the json file
                      and to record what courses are in this department
    Raises:
        KeyError: If the attributes provided are not in the json key list
    Returns:
        The list containing the name of all courses in this department

    """
    each_department = department.Department()
    each_department.deptName = department_name
    for each_course in json_object['CourseData'][department_name]:
        temp_course = course.Course()
        temp_course.UID = each_course['CRN']
        temp_course.crn = each_course['CRN']
        temp_course.course_num = each_course['Crse']
        temp_course.section_num = each_course['Sec']
        temp_course.campus = each_course['Cmp']
        temp_course.num_credit = float(each_course['Cred'])
        temp_course.course_title = each_course['Title']
        temp_course.startTime = each_course['Time'][:8]
        temp_course.endTime = each_course['Time'][9:]
        temp_course.instructor_name = each_course['Instructor']
        temp_course.startDate = each_course['Date (MM/DD)'][:5]
        temp_course.endDate = each_course['Date (MM/DD)'][6:]
        temp_course.location = each_course['Location']
        temp_course.days = 'ONLINE' if (
            'ONLINE' in temp_course.location) else each_course['Days']
        temp_course.attribute = each_course['Attribute']
        temp_course = read_lab_time(each_course, temp_course)
        course_list.append(temp_course)
        if temp_course not in each_department.courses:
            each_department.courses.append(temp_course)
    return each_department
Пример #5
0
import sys
sys.path.append('./src')
import course_pb2 as course
import department_pb2 as department

courseList = []
departmentList = []
labs = []

course_32072 = course.Course()
course_32072.UID = '32072'
course_32072.crn = '32072'
course_32072.course_num = 'D001A'
course_32072.section_num = '12'
course_32072.campus = 'DA'
course_32072.num_credit = 5.000
course_32072.course_title = 'FINAN ACCOUNTNG I'
course_32072.days = 'TR'
course_32072.startTime = '11:00 am'
course_32072.endTime = '01:15 pm'
course_32072.cap = 45
course_32072.instructor_name = 'Mary,Amelia,Breen'
course_32072.startDate = '01/08'
course_32072.endDate = '03/30'
course_32072.location = 'DA L84'
course_32072.attribute = ''

course_35071 = course.Course()
course_35071.UID = '35071'
course_35071.crn = '35071'
course_35071.course_num = 'D074'