From f52ff3c3e02f4cf3f7b69bc3cacdb8e5f232d220 Mon Sep 17 00:00:00 2001 From: Peter Dudfield <34686298+peterdudfield@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:42:19 +0100 Subject: [PATCH] Issue/dont save if nan (#72) * drop nans if in generation_mw * pydantic<2.0 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * if capacity is zero, fill nans * only update location if there are results * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- gspconsumer/app.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/gspconsumer/app.py b/gspconsumer/app.py index a712f60..f676bab 100644 --- a/gspconsumer/app.py +++ b/gspconsumer/app.py @@ -194,6 +194,10 @@ def pull_data_and_save( else: logger.debug(f"This is the first lot gsp yield data for GSP {(gsp.gsp_id)}") + # capacity is zero, set nans to 0 + if gsp_yield_df["capacity_mwp"].sum() == 0: + gsp_yield_df["generation_mw"] = 0 + # drop any nan values in generation_mw column gsp_yield_df = gsp_yield_df.dropna(subset=["generation_mw"]) @@ -221,14 +225,15 @@ def pull_data_and_save( gsp_yield_sql.location = gsp # update installed capacity - current_installed_capacity = gsp_yield_sql.location.installed_capacity_mw - new_installed_capacity = gsp_yield_df["installedcapacity_mwp"].iloc[0] - if current_installed_capacity != new_installed_capacity: - logger.debug( - f"Going to update the capacity from " - f"{current_installed_capacity} to {new_installed_capacity}" - ) - gsp_yield_sql.location.installed_capacity_mw = new_installed_capacity + if len(gsp_yield_df) > 0: + current_installed_capacity = gsp_yield_sql.location.installed_capacity_mw + new_installed_capacity = gsp_yield_df["installedcapacity_mwp"].iloc[0] + if current_installed_capacity != new_installed_capacity: + logger.debug( + f"Going to update the capacity from " + f"{current_installed_capacity} to {new_installed_capacity}" + ) + gsp_yield_sql.location.installed_capacity_mw = new_installed_capacity logger.debug(f"Found {len(gsp_yields_sql)} gsp yield for GSPs {gsp.gsp_id}")