Open schlunsen opened 3 years ago
Currently something like this will do the trick
Metric.
timescale.filter(device=device).filter(time__range=range).values('temperature')
.time_bucket_gapfill('time', '1 day', range[0], range[1], datapoints=1).annotate(Avg('temperature'))
.annotate(locf=Func(F('temperature'), function="locf")).order_by('time')
This didn't work for me. I tried to run this in a Django shell on Python 3.8.6 and get the following error:
Metrics.timescale.filter(time__range=ranges).time_bucket_gapfill('time', '1 hour', ranges[0], ranges[1], datapoints=30).annotate(Avg('loss')).annotate(locf=Func(F('loss'), function="locf"))
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'Func' is not defined
Any idea?
from django.db.models import Func
@DoGab As I remember the query above isn't quite there yet, but it's a long time ago since I've played with it.
Really looking forward to hear if you can use it or how to do it :)
@schlunsen Thank you for the Hint. I didn't find the correct library to include.
It worked great! I have not tested it with data that are gapped but for now the query already works!
https://docs.timescale.com/latest/using-timescaledb/reading-data#locf
Should probably be integrated with time_bucket_gapfill