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

Merged
merged 8 commits into from
Jan 27, 2025
Merged

Conversation

benschs
Copy link
Contributor

@benschs benschs commented Jan 23, 2025

spec

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

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.
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.

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.

Copy link
Contributor Author

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

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').

Copy link
Contributor Author

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

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 ".."

Copy link
Contributor Author

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

Comment on lines +331 to +338
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})

Copy link
Contributor Author

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.

Comment on lines 591 to 606
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", ...).

Copy link
Contributor Author

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

@benschs benschs force-pushed the feat-pb-1169-search-forecast branch from 8c248f9 to 3e0d8fc Compare January 23, 2025 14:54
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.
@benschs benschs force-pushed the feat-pb-1169-search-forecast branch from 3e0d8fc to d2492aa Compare January 27, 2025 07:58
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.
@benschs benschs merged commit 1e2d766 into develop Jan 27, 2025
5 checks passed
@benschs benschs deleted the feat-pb-1169-search-forecast branch January 27, 2025 15:48
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