Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add national history #304

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def get_latest_forecast_values_for_a_specific_gsp_from_database(
:return: list of latest forecat values
"""

start_datetime = get_start_datetime(start_datetime=start_datetime_utc)
start_datetime = get_start_datetime(start_datetime=start_datetime_utc, days=365)

if (forecast_horizon_minutes is None) and (creation_utc_limit is None):
forecast_values = get_forecast_values_latest(
Expand All @@ -218,14 +218,25 @@ def get_latest_forecast_values_for_a_specific_gsp_from_database(
)

else:
if creation_utc_limit is not None and creation_utc_limit < datetime.now(
tz=timezone.utc
) - timedelta(days=7):
model = ForecastValueSQL
elif start_datetime_utc is not None and start_datetime_utc < datetime.now(
tz=timezone.utc
) - timedelta(days=7):
model = ForecastValueSQL
else:
model = ForecastValueSevenDaysSQL

forecast_values = get_forecast_values(
session=session,
gsp_id=gsp_id,
start_datetime=start_datetime,
end_datetime=end_datetime_utc,
forecast_horizon_minutes=forecast_horizon_minutes,
model_name="blend",
model=ForecastValueSevenDaysSQL,
model=model,
only_return_latest=True,
created_utc_limit=creation_utc_limit,
)
Expand Down
1 change: 1 addition & 0 deletions src/gsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def get_forecasts_for_a_specific_gsp(

start_datetime_utc = format_datetime(start_datetime_utc)
end_datetime_utc = format_datetime(end_datetime_utc)
creation_limit_utc = format_datetime(creation_limit_utc)

if gsp_id > GSP_TOTAL:
return Response(None, status.HTTP_204_NO_CONTENT)
Expand Down
7 changes: 5 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def format_datetime(datetime_str: str = None):


def get_start_datetime(
n_history_days: Optional[Union[str, int]] = None, start_datetime: Optional[datetime] = None
n_history_days: Optional[Union[str, int]] = None,
start_datetime: Optional[datetime] = None,
days: Optional[int] = 3,
) -> datetime:
"""
Get the start datetime for the query
Expand All @@ -88,12 +90,13 @@ def get_start_datetime(
:param start_datetime: optional start datetime for the query.
If not set, after now, or set to over three days ago
defaults to N_HISTORY_DAYS env var, which defaults to yesterday.
:param days: number of days limit the data by
:return: start datetime
"""

now = datetime.now(tz=utc)

if start_datetime is None or now - start_datetime > timedelta(days=3):
if start_datetime is None or now - start_datetime > timedelta(days=days):
if n_history_days is None:
n_history_days = os.getenv("N_HISTORY_DAYS", "yesterday")

Expand Down
Loading