Skip to content

Commit

Permalink
Merge pull request #13 from openclimatefix/issue/reduce-error
Browse files Browse the repository at this point in the history
change error to warning
  • Loading branch information
peterdudfield authored Jul 4, 2024
2 parents 931c8e8 + 311135b commit e20d38a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
23 changes: 11 additions & 12 deletions ruvnl_consumer_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ def fetch_data(data_url: str) -> pd.DataFrame:

start_utc = dt.datetime.fromtimestamp(int(record["SourceTimeSec"]), tz=dt.UTC)
power_kw = record["Average2"] * 1000 # source is in MW, convert to kW
if v=="wind":
if(start_utc<dt.datetime.now(dt.timezone.utc)-dt.timedelta(hours=1)):
start_ist = start_utc. astimezone(pytz.timezone('Asia/Calcutta'))
start_ist=str(start_ist)
now = dt.datetime.now(pytz.timezone('Asia/Calcutta'))
now = str(now)
timestamp_after_raise = f"Timestamp Now: {now} Timestamp data: {start_ist}"
timestamp_fstring = f"{timestamp_after_raise}"
raise Exception("Start time is at least 1 hour old. " + timestamp_fstring)
if v == "wind":
if start_utc < dt.datetime.now(dt.timezone.utc) - dt.timedelta(hours=1):
start_ist = start_utc.astimezone(pytz.timezone("Asia/Calcutta"))
start_ist = str(start_ist)
now = dt.datetime.now(pytz.timezone("Asia/Calcutta"))
now = str(now)
timestamp_after_raise = f"Timestamp Now: {now} Timestamp data: {start_ist}"
timestamp_fstring = f"{timestamp_after_raise}"
log.warning("Start time is at least 1 hour old. " + timestamp_fstring)

data.append({"asset_type": v, "start_utc": start_utc, "power_kw": power_kw})
log.info(
f"Found generation data for asset type: {v}, " f"{power_kw} kW at {start_utc} UTC"
Expand Down Expand Up @@ -155,7 +155,6 @@ def save_generation_data(
log.info(f"Generation data: {asset_type}:\n{asset_data.to_string()}")



@click.command()
@click.option(
"--write-to-db",
Expand All @@ -175,7 +174,7 @@ def app(write_to_db: bool, log_level: str) -> None:
"""
logging.basicConfig(stream=sys.stdout, level=getattr(logging, log_level.upper()))

log.info(f'Running data consumer app (version: {__version__})')
log.info(f"Running data consumer app (version: {__version__})")

url = os.getenv("DB_URL", "sqlite:///test.db")
data_url = os.getenv("DATA_URL", DEFAULT_DATA_URL)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def test_old_fetch_data(self, requests_mock):
text=load_mock_response("tests/mock/responses/ruvnl-valid-response.json")
)

with pytest.raises(Exception): # noqa
fetch_data(DEFAULT_DATA_URL)
# we now just get a warning
fetch_data(DEFAULT_DATA_URL)

def test_catch_bad_response_json(self, requests_mock):
"""Test for catching invalid response JSON"""
Expand Down

0 comments on commit e20d38a

Please sign in to comment.