Skip to content

fill

ies_pi_predict.api.fill

task_fill

task_fill(
    building_url: str,
    auth_token: str,
    input_channels: list[str],
    output_channel: str,
    prediction_channel: str,
    predict_start: datetime,
    predict_end: datetime,
    output_folder: str,
) -> dict[str, any]

task_predict is the task that calls the ies_pi_predict.predict function. It processes the resulting dataframe by saving it in a csv file. It needs to be in the global namespace to be able to be correctly picked by the Worker.

Parameters:

Name Type Description Default
predict_start, predict_end

same as ies_pi_predict.fill_gaps

required
output_folder str

The folder where to save the csv

required

Returns:

Name Type Description
dict dict[str, any]

{ "output_filename": str, "algorhythm": str, "score": float, "rmse": float,

dict[str, any]

}

Source code in src/ies_pi_predict/api/fill.py
def task_fill(building_url: str, auth_token: str,
    input_channels: list[str], output_channel: str, prediction_channel: str,
    predict_start: datetime, predict_end: datetime, 
    output_folder: str) -> dict[str, any]:
    """
    task_predict is the task that calls the `ies_pi_predict.predict` function.
    It processes the resulting dataframe by saving it in a csv file.
    It needs to be in the global namespace to be able to be correctly picked
    by the Worker.

    Args:
        building_url, auth_token, 
        input_channels, output_channel, prediction_channel,
        predict_start, predict_end: same as `ies_pi_predict.fill_gaps`
        output_folder (str): The folder where to save the csv

    Returns:
        dict: {
            "output_filename": str,
            "algorhythm": str,
            "score": float,
            "rmse": float,
        }
    """    
    try:
        df, algorhythm, score, rmse = fill_gaps(
            building_url, auth_token, 
            input_channels, output_channel, prediction_channel,
            predict_start, predict_end
        )
    except Exception as e:
        # Other exceptions could be difficult to serialize for the task runner
        raise Exception(str(e))

    timestamp = datetime.now().strftime(datetime_format)
    id = uuid4()
    filename = f"{timestamp}-{id}.csv"
    filepath = Path(output_folder, filename)
    df.to_csv(filepath)

    return {
        "output_filename": filename,
        "algorhythm": str(algorhythm),
        "score": score,
        "rmse": rmse,
    }