src/canvas-extractor/edfi_canvas_extractor/mapping/section_associations.py
def map_to_udm_section_associations(enrollments_df: DataFrame) -> DataFrame:
    """
    Maps a DataFrame containing Canvas enrollments into the Ed-Fi LMS Unified Data
    Model (UDM) format.

    Parameters
    ----------
    enrollments_df: DataFrame
        Pandas DataFrame containing all Canvas enrollments

    Returns
    -------
    DataFrame
        A LMSSectionAssociations-formatted DataFrame

    DataFrame columns are:
        SourceSystemIdentifier: A unique number or alphanumeric code assigned to a the section-association by
            the source system
        SourceSystem: The system code or name providing the user data
        EnrollmentStatus: Possible values are Active, Expired, Invite pending, Request Pending, Archived
        LMSUserSourceSystemIdentifier: A unique number or alphanumeric code assigned to a user by the source
            system
        LMSSectionSourceSystemIdentifier: A unique number or alphanumeric code assigned to a section by the
            source system
        CreateDate: Date/time at which the record was first retrieved
        LastModifiedDate: Date/time when the record was modified, or when first retrieved
        SourceCreateDate: Date this record was created in the LMS
        SourceLastModifiedDate: Date this record was last updated in the LMS
    """

    if enrollments_df.empty:
        return enrollments_df

    assert "id" in enrollments_df.columns
    assert "enrollment_state" in enrollments_df.columns
    assert "user_id" in enrollments_df.columns
    assert "course_section_id" in enrollments_df.columns
    assert "created_at" in enrollments_df.columns
    assert "updated_at" in enrollments_df.columns

    enrollments_df = enrollments_df[
        [
            "id",
            "enrollment_state",
            "user_id",
            "course_section_id",
            "created_at",
            "updated_at",
            "CreateDate",
            "LastModifiedDate",
        ]
    ].copy()

    enrollments_df.rename(
        columns={
            "id": "SourceSystemIdentifier",
            "enrollment_state": "EnrollmentStatus",
            "user_id": "LMSUserSourceSystemIdentifier",
            "course_section_id": "LMSSectionSourceSystemIdentifier",
            "created_at": "SourceCreateDate",
            "updated_at": "SourceLastModifiedDate",
        },
        inplace=True,
    )

    enrollments_df["SourceCreateDate"] = enrollments_df["SourceCreateDate"].apply(
        _get_date_formated
    )

    enrollments_df["SourceLastModifiedDate"] = enrollments_df[
        "SourceLastModifiedDate"
    ].apply(_get_date_formated)

    enrollments_df["EnrollmentStatus"] = enrollments_df["EnrollmentStatus"].apply(
        _get_enrollment_status
    )

    enrollments_df["SourceSystem"] = SOURCE_SYSTEM

    return enrollments_df

    Maps a DataFrame containing Canvas enrollments into the Ed-Fi LMS Unified Data
    Model (UDM) format.

    Parameters
    ----------
    enrollments_df: DataFrame
        Pandas DataFrame containing all Canvas enrollments

    Returns
    -------
    DataFrame
        A LMSSectionAssociations-formatted DataFrame

    DataFrame columns are:
        SourceSystemIdentifier: A unique number or alphanumeric code assigned to a the section-association by
            the source system
        SourceSystem: The system code or name providing the user data
        EnrollmentStatus: Possible values are Active, Expired, Invite pending, Request Pending, Archived
        LMSUserSourceSystemIdentifier: A unique number or alphanumeric code assigned to a user by the source
            system
        LMSSectionSourceSystemIdentifier: A unique number or alphanumeric code assigned to a section by the
            source system
        CreateDate: Date/time at which the record was first retrieved
        LastModifiedDate: Date/time when the record was modified, or when first retrieved
        SourceCreateDate: Date this record was created in the LMS
        SourceLastModifiedDate: Date this record was last updated in the LMS
    
Maps a DataFrame containing Canvas enrollments into the Ed-Fi LMS Unified Data
Model (UDM) format.

Parameters

DataFrame
Pandas DataFrame containing all Canvas enrollments

Returns




Maps a DataFrame containing Canvas enrollments into the Ed - Fi LMS Unified Data Model ( UDM ) format . Parameters DataFrame Pandas DataFrame containing all Canvas enrollments Returns
def map_to_udm_section_associations(enrollments_df: DataFrame) -> DataFrame:
    if enrollments_df.empty:
        return enrollments_df
    assert "id" in enrollments_df.columns
    assert "enrollment_state" in enrollments_df.columns
    assert "user_id" in enrollments_df.columns
    assert "course_section_id" in enrollments_df.columns
    assert "created_at" in enrollments_df.columns
    assert "updated_at" in enrollments_df.columns
    enrollments_df = enrollments_df[
        [
            "id",
            "enrollment_state",
            "user_id",
            "course_section_id",
            "created_at",
            "updated_at",
            "CreateDate",
            "LastModifiedDate",
        ]
    ].copy()
    enrollments_df.rename(
        columns={
            "id": "SourceSystemIdentifier",
            "enrollment_state": "EnrollmentStatus",
            "user_id": "LMSUserSourceSystemIdentifier",
            "course_section_id": "LMSSectionSourceSystemIdentifier",
            "created_at": "SourceCreateDate",
            "updated_at": "SourceLastModifiedDate",
        },
        inplace=True,
    )
    enrollments_df["SourceCreateDate"] = enrollments_df["SourceCreateDate"].apply(
        _get_date_formated
    )
    enrollments_df["SourceLastModifiedDate"] = enrollments_df[
        "SourceLastModifiedDate"
    ].apply(_get_date_formated)
    enrollments_df["EnrollmentStatus"] = enrollments_df["EnrollmentStatus"].apply(
        _get_enrollment_status
    )
    enrollments_df["SourceSystem"] = SOURCE_SYSTEM
    return enrollments_df
def map_to_udm_section_associations ( enrollments_df : DataFrame ) -> DataFrame : if enrollments_df . empty : return enrollments_df assert "id" in enrollments_df . columns assert "enrollment_state" in enrollments_df . columns assert "user_id" in enrollments_df . columns assert "course_section_id" in enrollments_df . columns assert "created_at" in enrollments_df . columns assert "updated_at" in enrollments_df . columns enrollments_df = enrollments_df [ [ "id" , "enrollment_state" , "user_id" , "course_section_id" , "created_at" , "updated_at" , "CreateDate" , "LastModifiedDate" , ] ] . copy ( ) enrollments_df . rename ( columns = { "id" : "SourceSystemIdentifier" , "enrollment_state" : "EnrollmentStatus" , "user_id" : "LMSUserSourceSystemIdentifier" , "course_section_id" : "LMSSectionSourceSystemIdentifier" , "created_at" : "SourceCreateDate" , "updated_at" : "SourceLastModifiedDate" , } , inplace = True , ) enrollments_df [ "SourceCreateDate" ] = enrollments_df [ "SourceCreateDate" ] . apply ( _get_date_formated ) enrollments_df [ "SourceLastModifiedDate" ] = enrollments_df [ "SourceLastModifiedDate" ] . apply ( _get_date_formated ) enrollments_df [ "EnrollmentStatus" ] = enrollments_df [ "EnrollmentStatus" ] . apply ( _get_enrollment_status ) enrollments_df [ "SourceSystem" ] = SOURCE_SYSTEM return enrollments_df
Maps a DataFrame containing Canvas enrollments into the Ed-Fi LMS Unified Data
Model (UDM) format.
Maps a DataFrame containing Canvas enrollments into the Ed - Fi LMS Unified Data Model ( UDM ) format .
"""
    Maps a DataFrame containing Canvas enrollments into the Ed-Fi LMS Unified Data
    Model (UDM) format.

    Parameters
    ----------
    enrollments_df: DataFrame
        Pandas DataFrame containing all Canvas enrollments

    Returns
    -------
    DataFrame
        A LMSSectionAssociations-formatted DataFrame

    DataFrame columns are:
        SourceSystemIdentifier: A unique number or alphanumeric code assigned to a the section-association by
            the source system
        SourceSystem: The system code or name providing the user data
        EnrollmentStatus: Possible values are Active, Expired, Invite pending, Request Pending, Archived
        LMSUserSourceSystemIdentifier: A unique number or alphanumeric code assigned to a user by the source
            system
        LMSSectionSourceSystemIdentifier: A unique number or alphanumeric code assigned to a section by the
            source system
        CreateDate: Date/time at which the record was first retrieved
        LastModifiedDate: Date/time when the record was modified, or when first retrieved
        SourceCreateDate: Date this record was created in the LMS
        SourceLastModifiedDate: Date this record was last updated in the LMS
    """
enrollments_df
DataFrame