Skip to content

Commit

Permalink
add option of limiting days back in
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Oct 3, 2023
1 parent 5821433 commit ecd71fc
Show file tree
Hide file tree
Showing 2 changed files with 6 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 @@ -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 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:
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

0 comments on commit ecd71fc

Please sign in to comment.