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 SiteEvaluations by timestamp #105

Merged
merged 2 commits into from
Oct 26, 2022
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
17 changes: 16 additions & 1 deletion django/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion django/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ uritemplate = "^4.1.1"
iso3166 = "^2.1.1"
rio-tiler = "^3.1.6"
mercantile = "^1.2.1"
django-filter = "^22.1"

[tool.poetry.dev-dependencies]
black = "~22.6.0"
Expand Down Expand Up @@ -67,7 +68,10 @@ plugins = ["mypy_django_plugin.main", "mypy_drf_plugin.main"]


[[tool.mypy.overrides]]
module = "mercantile"
module = [
"django_filters",
"mercantile"
]
ignore_missing_imports = true


Expand Down
16 changes: 14 additions & 2 deletions django/src/rdwatch/views/site_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import django_filters

from django.contrib.gis.db.models.aggregates import Collect
from django.contrib.postgres.aggregates import JSONBAgg
from django.db.models import Count, Max, Min
Expand All @@ -12,6 +14,14 @@
from rdwatch.serializers import SiteEvaluationListSerializer


class SiteEvaluationsFilter(django_filters.FilterSet):
timestamp = django_filters.DateTimeFromToRangeFilter()

class Meta:
model = SiteEvaluation
fields = ["timestamp"]


class SiteEvaluationsSchema(AutoSchema):
def get_operation_id(self, *args):
return "getSiteEvaluations"
Expand All @@ -28,8 +38,10 @@ def get_responses(self, *args, **kwargs):
@schema(SiteEvaluationsSchema())
def site_evaluations(request: HttpRequest):
queryset = (
SiteEvaluation.objects.order_by("-timestamp")
.annotate(
SiteEvaluationsFilter(
request.GET, queryset=SiteEvaluation.objects.order_by("-timestamp")
)
.qs.annotate(
timemin=Min("observations__timestamp"),
timemax=Max("observations__timestamp"),
)
Expand Down