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

filter more in the pass #269

Merged
merged 3 commits into from
Mar 13, 2024
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
6 changes: 5 additions & 1 deletion nowcasting_datamodel/read/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,11 @@ def get_forecast_values(
query = query.filter(model.target_time >= start_datetime)

# also filter on creation time, to speed up things
created_utc_filter = start_datetime - timedelta(days=1)
if created_utc_limit is None:
created_utc_filter = start_datetime - timedelta(days=1)
else:
created_utc_filter = min([created_utc_limit, start_datetime]) - timedelta(days=1)

query = query.filter(model.created_utc >= created_utc_filter)
query = query.filter(ForecastSQL.created_utc >= created_utc_filter)

Expand Down
22 changes: 22 additions & 0 deletions tests/read/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,28 @@ def test_get_forecast_values_gsp_id_latest(db_session):
assert forecast_values_read[0].target_time == forecast_2.forecast_values[96].target_time


@freeze_time("2024-01-01")
def test_get_forecast_values_start_and_creation(db_session):
forecast_1 = make_fake_forecast(
gsp_id=1, session=db_session, t0_datetime_utc=datetime(2024, 1, 2, tzinfo=timezone.utc)
)
forecast_2 = make_fake_forecast(
gsp_id=1, session=db_session, t0_datetime_utc=datetime(2024, 1, 3, tzinfo=timezone.utc)
)
db_session.add_all([forecast_1, forecast_2])

forecast_values_read = get_forecast_values(
session=db_session,
gsp_id=1,
start_datetime=datetime(2024, 1, 2, 1, tzinfo=timezone.utc),
created_utc_limit=datetime(2024, 1, 1, tzinfo=timezone.utc),
)

_ = ForecastValue.from_orm(forecast_values_read[0])

assert len(forecast_values_read) == 76 # only getting forecast ahead


def test_get_all_gsp_ids_latest_forecast(db_session):
f1 = make_fake_forecasts(gsp_ids=[0, 1], session=db_session)
db_session.add_all(f1)
Expand Down
Loading