def add_calculated_rul(df):
    """Calculates Remaining Useful Life (RUL) and adds it to dataset, which is returned.
    
    Parameters
    -----------
	df : pd.DataFrame
        Dataframe containing time-series data.
        
    Returns
	pd.DataFrame
        dataset, inclusive of calculated RUL values.
    """

    # RUL is negative and trends to zero (end of life point)
    df["RUL"] = (
        df.groupby("id")
        .apply(lambda x: x["cycle"].max() - x["cycle"])
        .reset_index()["cycle"]
    )

    return df