-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this 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.
app/stac_api/managers.py
Outdated
queryset: | ||
A django queryset (https://docs.djangoproject.com/en/3.0/ref/models/querysets/) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the "queryset" comment
app/stac_api/managers.py
Outdated
queryset: | ||
A django queryset (https://docs.djangoproject.com/en/3.0/ref/models/querysets/) | ||
date_time: | ||
A string |
There was a problem hiding this comment.
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').
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more info for date_time
app/stac_api/managers.py
Outdated
queryset: | ||
A django queryset (https://docs.djangoproject.com/en/3.0/ref/models/querysets/) | ||
start_datetime: | ||
A string with the start datetime |
There was a problem hiding this comment.
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 ".."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added information about open start and open end in the comment
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) | ||
|
There was a problem hiding this comment.
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})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a deeper look at this, but am not sure it makes sense to just change this. I prefer to keep it consistent with the existing field filters. Maybe in the future we could refactor all of the search filters.
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, | ||
) |
There was a problem hiding this comment.
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", ...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use the create_item_sample
and check against the item forecast names
8c248f9
to
3e0d8fc
Compare
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.
Fix code comments. Refactor create sample data names.
3e0d8fc
to
d2492aa
Compare
Add index for the item forecast properties as they can be used as filters in the item search.
Move models file into folder /models and rename file to general.py. Fix all imports that referenced the models file.
Move collection related models into separate file. Move item related models into separate file. Fix import statements across all files.
spec
Add forecast properties to search filter for POST. Refactor
forecast:variable
andforecast:perturbed
descriptions into schema properties tobe reused.
New spec for POST /search
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.Decided to only support filtering of forecast properties in the POST /search request.
Implementation
Add filters for forecast properties to search endpoint.
Can filter for
forecast:reference_datetime
either by exact value or by a range.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.Decided to add indexes on all forecast fields.
Refactor
Linter fails as the
models.py
file is larger than 1000 lines. The last to commit move the model into a new directory and split it into multiple files.