From 2cd20465c97fe2e04025fb89fcf6f13fe712fb02 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Mon, 25 Sep 2023 11:47:24 +0200 Subject: [PATCH] fix resource agragation otion last value query --- orchestra/contrib/resources/aggregations.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/orchestra/contrib/resources/aggregations.py b/orchestra/contrib/resources/aggregations.py index f43e7ffd..0806b410 100644 --- a/orchestra/contrib/resources/aggregations.py +++ b/orchestra/contrib/resources/aggregations.py @@ -32,7 +32,12 @@ class Last(Aggregation): verbose_name = _("Last value") def filter(self, dataset, date=None): - dataset = dataset.order_by('object_id', '-id').distinct('monitor') + + # dataset = dataset.order_by('object_id', '-id').distinct('monitor') + now = timezone.now() + epoch = now - datetime.timedelta(minutes=2) + dataset = dataset.filter( created_at__range=(epoch, now )) + if date is not None: dataset = dataset.filter(created_at__lte=date) return dataset