Skip to content

Commit

Permalink
add adjuster for gsp_id=0
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Mar 13, 2024
1 parent d34d218 commit 16d2a06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/gsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ def get_all_available_forecasts(
f"The option is {historic=} for user {user}"
)

# adjust gsp_id 0
if 0 in gsp_ids:
idx = [i for i, forecasts in enumerate(forecasts.forecasts) if forecasts.location.gsp_id == 0]
if len(idx) > 0:
logger.info(f"Adjusting forecast values for gsp id 0, {adjust_limit}")
forecasts.forecasts[idx[0]] = forecasts.forecasts[idx[0]].adjust(limit=adjust_limit)
else:
logger.warning(f"Could not find gsp id 0 in the forecasts")

return forecasts


Expand Down
22 changes: 21 additions & 1 deletion src/pydantic_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" pydantic models for API"""
import logging
import os
from datetime import datetime
from typing import Dict, List, Optional

Expand All @@ -10,6 +11,9 @@
logger = logging.getLogger(__name__)


adjust_limit = float(os.getenv("ADJUST_MW_LIMIT", 0.0))


class GSPYield(EnhancedBaseModel):
"""GSP Yield data"""

Expand Down Expand Up @@ -146,7 +150,23 @@ def convert_forecasts_to_many_datetime_many_generation(
continue
if end_datetime_utc is not None and datetime_utc > end_datetime_utc:
continue
forecast_mw = round(forecast_value.expected_power_generation_megawatts, 2)

forecast_mw = forecast_value.expected_power_generation_megawatts

# adjust the value if gsp id 0, this is the national
if gsp_id == '0':
adjust_mw = forecast_value.adjust_mw
if adjust_mw > adjust_limit:
adjust_mw = adjust_limit
elif adjust_mw < -adjust_limit:
adjust_mw = -adjust_limit

forecast_mw = forecast_mw - adjust_mw

if forecast_mw < 0:
forecast_mw = 0.0

forecast_mw = round(forecast_mw, 2)

# if the datetime object is not in the dictionary, add it
if datetime_utc not in many_forecast_values_by_datetime:
Expand Down

0 comments on commit 16d2a06

Please sign in to comment.