Example #1
0
def create_courses(roster_data, keep_df=None):
    """
    Create Course objects by doing one pass of roster file and using info from fields
    StudentID, coursename, TeacherID. Based on the 'keeplist', determine whether a course in mandatry

    Return data frame with new column that contains list of Course objects
    """

    # Track courses (Course objects) that are created; will eventually be added to main roster dataframe
    course_list = []

    for ix, row in roster_data.iterrows():

        # Info for the course
        sid = row["StudentID"]
        course = row["coursename"]
        teachID = row["TeacherID"]
        subject = row["subject"]

        # Does Course already exist
        exists = False
        for course_obj in course_list:
            course_name = course_obj.course_name
            teach_id = course_obj.teacher_id

            if course == course_name and teachID == teach_id:
                course_obj.add(sid)
                course_list.append(course_obj)
                exists = True
                break

        # Continue if course existed
        if exists:
            continue
        else:

            # Check if there is a keep list and, if so, check if this course shoudl be listed as mandatory
            keep = False
            if isinstance(keep_df, pd.DataFrame):
                if course in keep_df["coursename"].tolist() or subject in keep_df["subject"].tolist():
                    keep = True

            # Create new course
            new_course = Course(course, teachID, subject, keep)
            new_course.add(sid)

            course_list.append(new_course)

    roster_data["Course"] = course_list
    return roster_data
Example #2
0
    def decode_one_course(quarter, course: dict) -> Course:
        '''
        course = { 'coursename': 'xxx', 'formalname':'xxx', '_derived_classes': [dict] }
        '''
        current_course = Course(quarter, course['coursename'],
                                course['formalname'])
        current_primary_class = None

        if CourseDecoder.secondary_class_exists(course['_derived_classes']):
            #print("secondary classes exist")
            for derived_class in course['_derived_classes']:
                if derived_class['Type'].upper() in PRIMARYCLASS_TYPE:
                    try:
                        current_primary_class = DerivedClass(
                            current_course, **derived_class)
                        current_course.add(current_primary_class)
                    except Exception as E:
                        if DEBUGGING: raise E
                        continue
                elif derived_class['Type'].upper() in SECONDARYCLASS_TYPE:
                    try:
                        current_secondary_class = DerivedClass(
                            current_course, **derived_class)
                        current_primary_class.add(current_secondary_class)
                    except Exception as E:
                        if DEBUGGING: raise E
                        continue
                else:
                    raise DecodeCourseError(
                        'Unrecognized Class Type : class with type {} in course {}??'
                        .format(derived_class['Type'], current_course.name()))

        else:
            for derived_class in course['_derived_classes']:
                current_course.add(
                    DerivedClass(current_course, **derived_class))

        return current_course
Example #3
0
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()