Skip to content

Commit

Permalink
Issue/dont save if nan (#72)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
peterdudfield and pre-commit-ci[bot] authored Sep 5, 2023
1 parent 8b12e84 commit f52ff3c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions gspconsumer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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}")

Expand Down

0 comments on commit f52ff3c

Please sign in to comment.