Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Aug 31, 2023
1 parent 84e7003 commit 0f35259
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
convert_forecasts_to_many_datetime_many_generation,
convert_location_sql_to_many_datetime_many_generation,
)
from utils import floor_30_minutes_dt, get_start_datetime, filter_forecast_values
from utils import floor_30_minutes_dt, filter_forecast_values, get_start_datetime

logger = structlog.stdlib.get_logger()

Expand Down
9 changes: 8 additions & 1 deletion src/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def convert_location_sql_to_many_datetime_many_generation(


def convert_forecasts_to_many_datetime_many_generation(
forecasts: List[ForecastSQL], historic: bool = True
forecasts: List[ForecastSQL],
historic: bool = True,
start_datetime_utc: Optional[datetime] = None,
end_datetime_utc: Optional[datetime] = None,
) -> List[OneDatetimeManyForecastValues]:
"""Change forecasts to list of OneDatetimeManyForecastValues
Expand All @@ -134,6 +137,10 @@ def convert_forecasts_to_many_datetime_many_generation(

for forecast_value in forecast_values:
datetime_utc = forecast_value.target_time
if start_datetime_utc is not None and datetime_utc < start_datetime_utc:
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)

# if the datetime object is not in the dictionary, add it
Expand Down
9 changes: 8 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np
import structlog
from nowcasting_datamodel.models import ForecastValue, ForecastSQL
from nowcasting_datamodel.models import ForecastSQL, ForecastValue
from pydantic import Field
from pytz import timezone

Expand Down Expand Up @@ -67,6 +67,13 @@ def floor_6_hours_dt(dt: datetime):


def format_datetime(datetime_str: str = None):
"""
Format datetime string to datetime object
If None return None, if not timezone, add UTC
:param datetime_str:
:return:
"""
if datetime_str is None:
return None

Expand Down

0 comments on commit 0f35259

Please sign in to comment.