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

PB-1169 Search forecast properties #500

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

benschs
Copy link
Contributor

@benschs benschs commented Jan 23, 2025

spec

Add forecast properties to search filter for GET and POST. Refactor
forecast:variable and forecast:perturbed descriptions into schema properties to
be reused.

New spec for Get /search
Screenshot from 2025-01-22 16-15-37

New spec for POST /search
Screenshot from 2025-01-22 16-15-58

In the GET parameters I decided to use underscores(_) instead of colons(:) for the parameter names as colons need to be url encoded. The parameter names are quite long, but I think it's ok to be more descriptive, otherwise we could also shorten forecast to fc (e.g. fc_reference_datetime). In the POST parameters i kept the colon in the names to stay consistent.

Implementation

Add filters for forecast properties to search endpoints.
Can filter for forecast_reference_datetime either by exact value or by a range.
The filter for forecast_perturbed is a boolean, but in the GET parameters python does not accept the values false/true, only capitalized False/True are accepted. Do we have a convention on how to handle this?

I did not add any indexes for the forecast fields. Do you think we should add them already on all fields? I can't really tell how the search will be used and if it makes sense to just add an index as it will make writes slower.

Copy link
Contributor

@asteiner-swisstopo asteiner-swisstopo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me thanks 👍 A few suggestions on the code comments and one suggestion for less code duplication.

Comment on lines +112 to +113
queryset:
A django queryset (https://docs.djangoproject.com/en/3.0/ref/models/querysets/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That refers to self, right? I would not list that here.

Same on line 131.

queryset:
A django queryset (https://docs.djangoproject.com/en/3.0/ref/models/querysets/)
date_time:
A string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an example of how this would typically look like ('2020-10-28T13:05:10Z').

queryset:
A django queryset (https://docs.djangoproject.com/en/3.0/ref/models/querysets/)
start_datetime:
A string with the start datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a note that this can also be ".."

Comment on lines +331 to +342
def filter_by_forecast_horizon(self, duration):
return self.get_queryset().filter_by_forecast_horizon(duration)

def filter_by_forecast_duration(self, duration):
return self.get_queryset().filter_by_forecast_duration(duration)

def filter_by_forecast_variable(self, val):
return self.get_queryset().filter_by_forecast_variable(val)

def filter_by_forecast_perturbed(self, pert):
return self.get_queryset().filter_by_forecast_perturbed(pert)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't all these be replaced by something less redundant?

For example

def filter_by_field(self, field_name, value):
    return self.get_queryset().filter(**{field_name: value})

Comment on lines +591 to +602
cls.items = cls.factory.create_item_samples(
[
'item-forecast-1',
'item-forecast-2',
'item-forecast-3',
'item-forecast-4',
'item-forecast-5'
],
cls.collection,
db_create=True,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating these items individually with create_item_sample such that you can set the name of the samples. Otherwise in the tests you refer to the automatically set names ("item-1", "item-2", ...) instead of the ones on the item ("item-forecast-1", "item-forecast-2", ...).

Add forecast properties to search filter for GET and POST. Refactor
forecast:variable and forecast:perturbed descriptions into schema properties to
be reused.
Add filters for forecast properties to search endpoints.
Can filter for forecast_reference_datetime either by exact value or by a range.
Decided to remove the forecast parameters because the variable name differs to
the post variable names (using underscore instead of colon) and colons need
url encoding.
Decided to remove the forecast filtering options from the GET /search request
due to colons in the parameter names.
Also fixed the POST request body to actually use the parameters that contain a
colon.
@benschs benschs force-pushed the feat-pb-1169-search-forecast branch from 8c248f9 to 3e0d8fc Compare January 23, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants