src/schoology-extractor/edfi_schoology_extractor/mapping/attendance.py
def map_to_udm(
    attendance: List[Dict[str, Any]],
    section_associations: pd.DataFrame,
    sync_callback: Optional[Callable[[pd.DataFrame], None]] = None,
) -> pd.DataFrame:
    """
    Maps a DataFrame containing Schoology attendance events into the Ed-Fi LMS
    Unified Data Model (UDM) format.

    Parameters
    ----------
    attendance: list
        List containing the API response from Schoology
    section_associations: DataFrame
        DataFrame containing UDM-mapped section associations
    sync_callback: Callable
        Function for injecting additional synchronization logic

    Returns
    -------
    DataFrame
        A new DataFrame in the UDM attendance events format

    Notes
    -----
    Most mappers accept a DataFrame as input - but attendance conversion to
        DataFrame is complex, therefore it is handled directly in this
        function instead of upstream.

    DataFrame columns are:
        SourceSystemIdentifier: A unique number or alphanumeric code
            assigned to a user by the source system
        SourceSystem: The system code or name providing the user data
        Date: Attendance date, formatted as YYYY-mm-dd
        AttendanceStatus: one of (present, absent, late, excused)
        LMSUserSourceSystemIdentifier: source system identifier for the user
        LMSUserLMSSectionAssociationSourceSystemIdentifier: source system
            identifier for the section association
        CreateDate: datetime at which the record was first retrieved
        LastModifiedDate: datetime 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 len(attendance) == 0:
        return pd.DataFrame()

    df = _flatten_into_dataframe(attendance)

    df["SourceSystem"] = constants.SOURCE_SYSTEM
    df["SourceSystemIdentifier"] = df.apply(
        lambda row: f"{row['enrollment_id']}#{row['EventDate']}", axis=1
    )

    df["AttendanceStatus"] = df["AttendanceStatus"].apply(_get_status)

    sa = section_associations[
        [
            "SourceSystemIdentifier",
            "LMSUserSourceSystemIdentifier",
            "LMSSectionSourceSystemIdentifier",
        ]
    ].copy()
    # This data type conversion was required because Schoology is returning
    # enrollment Id as an integer in the Attendance endpoint, but as a string
    # with the Enrollment endpoint.
    sa = sa.astype({"SourceSystemIdentifier": "int64"})

    df = df.merge(
        sa,
        how="inner",
        left_on="enrollment_id",
        right_on="SourceSystemIdentifier",
        suffixes=("", "_r"),
    )

    df = df[
        [
            "SourceSystem",
            "SourceSystemIdentifier",
            "AttendanceStatus",
            "EventDate",
            "LMSUserSourceSystemIdentifier",
            "LMSSectionSourceSystemIdentifier",
        ]
    ]

    df["SourceCreateDate"] = ""
    df["SourceLastModifiedDate"] = ""

    if sync_callback is not None:
        df = sync_callback(df)

    return df

    Maps a DataFrame containing Schoology attendance events into the Ed-Fi LMS
    Unified Data Model (UDM) format.

    Parameters
    ----------
    attendance: list
        List containing the API response from Schoology
    section_associations: DataFrame
        DataFrame containing UDM-mapped section associations
    sync_callback: Callable
        Function for injecting additional synchronization logic

    Returns
    -------
    DataFrame
        A new DataFrame in the UDM attendance events format

    Notes
    -----
    Most mappers accept a DataFrame as input - but attendance conversion to
        DataFrame is complex, therefore it is handled directly in this
        function instead of upstream.

    DataFrame columns are:
        SourceSystemIdentifier: A unique number or alphanumeric code
            assigned to a user by the source system
        SourceSystem: The system code or name providing the user data
        Date: Attendance date, formatted as YYYY-mm-dd
        AttendanceStatus: one of (present, absent, late, excused)
        LMSUserSourceSystemIdentifier: source system identifier for the user
        LMSUserLMSSectionAssociationSourceSystemIdentifier: source system
            identifier for the section association
        CreateDate: datetime at which the record was first retrieved
        LastModifiedDate: datetime 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 Schoology attendance events into the Ed-Fi LMS
Unified Data Model (UDM) format.

Parameters

list
List containing the API response from Schoology
section_associations: DataFrame
DataFrame containing UDM-mapped section associations
sync_callback: Callable
Function for injecting additional synchronization logic

Returns

DataFrame
A new DataFrame in the UDM attendance events format

Notes

Most mappers accept a DataFrame as input - but attendance conversion to
DataFrame is complex, therefore it is handled directly in this
function instead of upstream.


Maps a DataFrame containing Schoology attendance events into the Ed - Fi LMS Unified Data Model ( UDM ) format . Parameters list List containing the API response from Schoology section_associations : DataFrame DataFrame containing UDM - mapped section associations sync_callback : Callable Function for injecting additional synchronization logic Returns DataFrame A new DataFrame in the UDM attendance events format Notes Most mappers accept a DataFrame as input - but attendance conversion to DataFrame is complex therefore it is handled directly in this function instead of upstream .
def map_to_udm(
    attendance: List[Dict[str, Any]],
    section_associations: pd.DataFrame,
    sync_callback: Optional[Callable[[pd.DataFrame], None]] = None,
) -> pd.DataFrame:
    if len(attendance) == 0:
        return pd.DataFrame()
    df = _flatten_into_dataframe(attendance)
    df["SourceSystem"] = constants.SOURCE_SYSTEM
    df["SourceSystemIdentifier"] = df.apply(
        lambda row: f"{row['enrollment_id']}#{row['EventDate']}", axis=1
    )
    df["AttendanceStatus"] = df["AttendanceStatus"].apply(_get_status)
    sa = section_associations[
        [
            "SourceSystemIdentifier",
            "LMSUserSourceSystemIdentifier",
            "LMSSectionSourceSystemIdentifier",
        ]
    ].copy()
    sa = sa.astype({"SourceSystemIdentifier": "int64"})
    df = df.merge(
        sa,
        how="inner",
        left_on="enrollment_id",
        right_on="SourceSystemIdentifier",
        suffixes=("", "_r"),
    )
    df = df[
        [
            "SourceSystem",
            "SourceSystemIdentifier",
            "AttendanceStatus",
            "EventDate",
            "LMSUserSourceSystemIdentifier",
            "LMSSectionSourceSystemIdentifier",
        ]
    ]
    df["SourceCreateDate"] = ""
    df["SourceLastModifiedDate"] = ""
    if sync_callback is not None:
        df = sync_callback(df)
    return df
def map_to_udm ( attendance : List [ Dict [ str , Any ] ] , section_associations : pd . DataFrame , sync_callback : Optional [ Callable [ [ pd . DataFrame ] , None ] ] = None , ) -> pd . DataFrame : if len ( attendance ) == 0 : return pd . DataFrame ( ) df = _flatten_into_dataframe ( attendance ) df [ "SourceSystem" ] = constants . SOURCE_SYSTEM df [ "SourceSystemIdentifier" ] = df . apply ( lambda row : f"{row['enrollment_id']}#{row['EventDate']}" , axis = 1 ) df [ "AttendanceStatus" ] = df [ "AttendanceStatus" ] . apply ( _get_status ) sa = section_associations [ [ "SourceSystemIdentifier" , "LMSUserSourceSystemIdentifier" , "LMSSectionSourceSystemIdentifier" , ] ] . copy ( ) sa = sa . astype ( { "SourceSystemIdentifier" : "int64" } ) df = df . merge ( sa , how = "inner" , left_on = "enrollment_id" , right_on = "SourceSystemIdentifier" , suffixes = ( "" , "_r" ) , ) df = df [ [ "SourceSystem" , "SourceSystemIdentifier" , "AttendanceStatus" , "EventDate" , "LMSUserSourceSystemIdentifier" , "LMSSectionSourceSystemIdentifier" , ] ] df [ "SourceCreateDate" ] = "" df [ "SourceLastModifiedDate" ] = "" if sync_callback is not None : df = sync_callback ( df ) return df
Maps a DataFrame containing Schoology attendance events into the Ed-Fi LMS
Unified Data Model (UDM) format.
Maps a DataFrame containing Schoology attendance events into the Ed - Fi LMS Unified Data Model ( UDM ) format .
"""
    Maps a DataFrame containing Schoology attendance events into the Ed-Fi LMS
    Unified Data Model (UDM) format.

    Parameters
    ----------
    attendance: list
        List containing the API response from Schoology
    section_associations: DataFrame
        DataFrame containing UDM-mapped section associations
    sync_callback: Callable
        Function for injecting additional synchronization logic

    Returns
    -------
    DataFrame
        A new DataFrame in the UDM attendance events format

    Notes
    -----
    Most mappers accept a DataFrame as input - but attendance conversion to
        DataFrame is complex, therefore it is handled directly in this
        function instead of upstream.

    DataFrame columns are:
        SourceSystemIdentifier: A unique number or alphanumeric code
            assigned to a user by the source system
        SourceSystem: The system code or name providing the user data
        Date: Attendance date, formatted as YYYY-mm-dd
        AttendanceStatus: one of (present, absent, late, excused)
        LMSUserSourceSystemIdentifier: source system identifier for the user
        LMSUserLMSSectionAssociationSourceSystemIdentifier: source system
            identifier for the section association
        CreateDate: datetime at which the record was first retrieved
        LastModifiedDate: datetime 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
    """ # This data type conversion was required because Schoology is returning # enrollment Id as an integer in the Attendance endpoint, but as a string # with the Enrollment endpoint.
attendance
List[Dict[str, Any]]
section_associations
pd.DataFrame
sync_callback
Optional[Callable[[pd.DataFrame], None]]