diff --git a/india_forecast_app/adjuster.py b/india_forecast_app/adjuster.py index bb18af9..cc7280c 100644 --- a/india_forecast_app/adjuster.py +++ b/india_forecast_app/adjuster.py @@ -108,6 +108,18 @@ def get_me_values( # drop the hour column me_df.drop(columns=["horizon_hour"], inplace=True) + if len(me_df) == 0: + return me_df + + # interpolate horizon_minutes up to 15 minutes blocks, its currently in 60 minute blocks + # currently in 0, 60, 120,... + # change to 0, 15, 30, 45, 60, 75, 90, 105, 120, ... + me_df = me_df.set_index("horizon_minutes") + me_df = me_df.reindex(range(0, max(me_df.index), 15)).interpolate(limit=3) + + # reset indiex + me_df = me_df.reset_index() + return me_df @@ -154,9 +166,6 @@ def adjust_forecast_with_adjuster( me_values, on="horizon_minutes", how="left" ) - # interpolate nans with window limit of 3 - forecast_values_df_adjust["me_kw"].interpolate(limit=3, inplace=True) - # if me_kw is null, set to 0 forecast_values_df_adjust["me_kw"].fillna(0, inplace=True) diff --git a/tests/test_adjuster.py b/tests/test_adjuster.py index 3c84cce..6027b99 100644 --- a/tests/test_adjuster.py +++ b/tests/test_adjuster.py @@ -21,6 +21,10 @@ def test_get_me_values(db_session, sites, generation_db_values, forecasts): me_df = get_me_values(db_session, hour, site_uuid=sites[0].site_uuid, ml_model_name="test") assert len(me_df) != 0 + assert len(me_df) == 96 + assert me_df["me_kw"].sum() != 0 + assert me_df["horizon_minutes"][0] == 0 + assert me_df["horizon_minutes"][1] == 15 def test_get_me_values_no_generation(db_session, sites, forecasts):