Skip to content

Commit

Permalink
Merge pull request #108 from openclimatefix/fix-batch-system-process
Browse files Browse the repository at this point in the history
Fix batch system process
  • Loading branch information
peterdudfield authored Mar 21, 2022
2 parents 471c69a + 425885d commit 4ef336b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 10 additions & 4 deletions pvoutput/prcoess.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
""" Function to process data """
import logging
from io import StringIO

import numpy as np
import pandas as pd

logger = logging.getLogger(__name__)


def process_system_status(pv_system_status_text, date) -> pd.DataFrame:
"""
Expand All @@ -17,17 +20,20 @@ def process_system_status(pv_system_status_text, date) -> pd.DataFrame:
Returns: dataframe of data
"""

# get system id
system_id = int(pv_system_status_text.split(";")[0])
pv_system_status_text = ";".join(pv_system_status_text.split(";")[1:])

# See https://pvoutput.org/help/data_services.html#data-services-get-system-status
columns = [
"cumulative_energy_gen_Wh",
"instantaneous_power_gen_W",
"temperature_C",
"voltage",
]
if pv_system_status_text == "no status found":
logger.debug("Text was empty so return empty dataframe")
return pd.DataFrame(columns=columns + ["system_id", "datetime"])

# get system id
system_id = int(pv_system_status_text.split(";")[0])
pv_system_status_text = ";".join(pv_system_status_text.split(";")[1:])

try:
one_pv_system_status = pd.read_csv(
Expand Down
2 changes: 1 addition & 1 deletion pvoutput/pvoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def get_system_status(

except NoStatusFound:
_LOG.info(f"system_id {all_pv_system_id}: No status found for date %s", date)
pv_system_status_text = ""
pv_system_status_text = "no status found"

# each pv system is on a new line
pv_systems_status_text = pv_system_status_text.split("\n")
Expand Down
8 changes: 8 additions & 0 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def test_process_system_status_2():
assert (one_status["system_id"] == 1234).all()


def test_process_system_status_none():

one_status = process_system_status(
pv_system_status_text="no status found", date=date(2022, 1, 1)
)
assert len(one_status) == 0


def test_process_system_status_less_columns_two_data_points():
# this has all missing data values
pv_system_status_text = "1234;07:45,21,255;" "07:45,22,256"
Expand Down

0 comments on commit 4ef336b

Please sign in to comment.