src/google-classroom-extractor/edfi_google_classroom_extractor/mapping/user_section_associations.py
def _students_or_teachers_to_user_section_associations_df(
    students_or_teachers_df: DataFrame,
) -> DataFrame:
    """
    Convert a Student or Teacher API DataFrame to a UserSectionAssociation DataFrame

    Parameters
    ----------
    students_or_teachers_df: DataFrame
        is a Students or Teachers API DataFrame

    Returns
    -------
    DataFrame
        a UserSectionAssociation DataFrame based on the given Students or Teachers API DataFrame

    Notes
    -----
    UserSectionAssociation DataFrame columns are:
        EnrollmentStatus: The status of the user section association. E.g., Active,
            Inactive, Withdrawn
        LMSSectionSourceSystemIdentifier: A unique numeric identifier assigned to the section
        SourceSystem: The system code or name providing the user data
        SourceSystemIdentifier: A unique number or alphanumeric code
            assigned to a user by the source system
        LMSUserSourceSystemIdentifier: A unique numeric identifier assigned to the user
        SourceCreateDate: Date this record was created in the LMS
        SourceLastModifiedDate: Date this record was last updated in the LMS
        CreateDate: Date this record was created in the extractor
        LastModifiedDate: Date this record was last updated in the extractor
    """
    assert "userId" in students_or_teachers_df.columns
    assert "courseId" in students_or_teachers_df.columns

    user_section_associations_df: DataFrame = students_or_teachers_df[
        [
            "userId",
            "courseId",
            "CreateDate",
            "LastModifiedDate",
        ]
    ]

    user_section_associations_df = user_section_associations_df.rename(
        columns={
            "userId": "LMSUserSourceSystemIdentifier",
            "courseId": "LMSSectionSourceSystemIdentifier",
        }
    )

    user_section_associations_df[
        "SourceSystemIdentifier"
    ] = user_section_associations_df[["LMSUserSourceSystemIdentifier", "LMSSectionSourceSystemIdentifier"]].agg(
        "-".join, axis=1
    )

    user_section_associations_df["SourceSystem"] = SOURCE_SYSTEM
    user_section_associations_df["EnrollmentStatus"] = ENROLLMENT_STATUS_ACTIVE
    user_section_associations_df["SourceCreateDate"] = ""  # No create date available from API
    user_section_associations_df[
        "SourceLastModifiedDate"
    ] = ""  # No modified date available from API
    return user_section_associations_df

    Convert a Student or Teacher API DataFrame to a UserSectionAssociation DataFrame

    Parameters
    ----------
    students_or_teachers_df: DataFrame
        is a Students or Teachers API DataFrame

    Returns
    -------
    DataFrame
        a UserSectionAssociation DataFrame based on the given Students or Teachers API DataFrame

    Notes
    -----
    UserSectionAssociation DataFrame columns are:
        EnrollmentStatus: The status of the user section association. E.g., Active,
            Inactive, Withdrawn
        LMSSectionSourceSystemIdentifier: A unique numeric identifier assigned to the section
        SourceSystem: The system code or name providing the user data
        SourceSystemIdentifier: A unique number or alphanumeric code
            assigned to a user by the source system
        LMSUserSourceSystemIdentifier: A unique numeric identifier assigned to the user
        SourceCreateDate: Date this record was created in the LMS
        SourceLastModifiedDate: Date this record was last updated in the LMS
        CreateDate: Date this record was created in the extractor
        LastModifiedDate: Date this record was last updated in the extractor
    
Convert a Student or Teacher API DataFrame to a UserSectionAssociation DataFrame
Parameters

DataFrame
is a Students or Teachers API DataFrame

Returns



Notes

UserSectionAssociation DataFrame columns are:
EnrollmentStatus: The status of the user section association.
Convert a Student or Teacher API DataFrame to a UserSectionAssociation DataFrame Parameters DataFrame is a Students or Teachers API DataFrame Returns Notes UserSectionAssociation DataFrame columns are : EnrollmentStatus : The status of the user section association .
def _students_or_teachers_to_user_section_associations_df(
    students_or_teachers_df: DataFrame,
) -> DataFrame:
    assert "userId" in students_or_teachers_df.columns
    assert "courseId" in students_or_teachers_df.columns
    user_section_associations_df: DataFrame = students_or_teachers_df[
        [
            "userId",
            "courseId",
            "CreateDate",
            "LastModifiedDate",
        ]
    ]
    user_section_associations_df = user_section_associations_df.rename(
        columns={
            "userId": "LMSUserSourceSystemIdentifier",
            "courseId": "LMSSectionSourceSystemIdentifier",
        }
    )
    user_section_associations_df[
        "SourceSystemIdentifier"
    ] = user_section_associations_df[["LMSUserSourceSystemIdentifier", "LMSSectionSourceSystemIdentifier"]].agg(
        "-".join, axis=1
    )
    user_section_associations_df["SourceSystem"] = SOURCE_SYSTEM
    user_section_associations_df["EnrollmentStatus"] = ENROLLMENT_STATUS_ACTIVE
    user_section_associations_df["SourceCreateDate"] = ""  
    user_section_associations_df[
        "SourceLastModifiedDate"
    ] = ""  
    return user_section_associations_df
def _students_or_teachers_to_user_section_associations_df ( students_or_teachers_df : DataFrame , ) -> DataFrame : assert "userId" in students_or_teachers_df . columns assert "courseId" in students_or_teachers_df . columns user_section_associations_df : DataFrame = students_or_teachers_df [ [ "userId" , "courseId" , "CreateDate" , "LastModifiedDate" , ] ] user_section_associations_df = user_section_associations_df . rename ( columns = { "userId" : "LMSUserSourceSystemIdentifier" , "courseId" : "LMSSectionSourceSystemIdentifier" , } ) user_section_associations_df [ "SourceSystemIdentifier" ] = user_section_associations_df [ [ "LMSUserSourceSystemIdentifier" , "LMSSectionSourceSystemIdentifier" ] ] . agg ( "-" . join , axis = 1 ) user_section_associations_df [ "SourceSystem" ] = SOURCE_SYSTEM user_section_associations_df [ "EnrollmentStatus" ] = ENROLLMENT_STATUS_ACTIVE user_section_associations_df [ "SourceCreateDate" ] = "" user_section_associations_df [ "SourceLastModifiedDate" ] = "" return user_section_associations_df
Convert a Student or Teacher API DataFrame to a UserSectionAssociation DataFrame
Parameters
Convert a Student or Teacher API DataFrame to a UserSectionAssociation DataFrame Parameters
"""
    Convert a Student or Teacher API DataFrame to a UserSectionAssociation DataFrame

    Parameters
    ----------
    students_or_teachers_df: DataFrame
        is a Students or Teachers API DataFrame

    Returns
    -------
    DataFrame
        a UserSectionAssociation DataFrame based on the given Students or Teachers API DataFrame

    Notes
    -----
    UserSectionAssociation DataFrame columns are:
        EnrollmentStatus: The status of the user section association. E.g., Active,
            Inactive, Withdrawn
        LMSSectionSourceSystemIdentifier: A unique numeric identifier assigned to the section
        SourceSystem: The system code or name providing the user data
        SourceSystemIdentifier: A unique number or alphanumeric code
            assigned to a user by the source system
        LMSUserSourceSystemIdentifier: A unique numeric identifier assigned to the user
        SourceCreateDate: Date this record was created in the LMS
        SourceLastModifiedDate: Date this record was last updated in the LMS
        CreateDate: Date this record was created in the extractor
        LastModifiedDate: Date this record was last updated in the extractor
    """ # No create date available from API # No modified date available from API
students_or_teachers_df
DataFrame