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

Implement Last Observation Carried Forward #7

Open
schlunsen opened this issue Dec 30, 2020 · 6 comments
Open

Implement Last Observation Carried Forward #7

schlunsen opened this issue Dec 30, 2020 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@schlunsen
Copy link
Collaborator

https://docs.timescale.com/latest/using-timescaledb/reading-data#locf

Should probably be integrated with time_bucket_gapfill

    metrics.timescale.time_bucket_gapfill('time', '1 day', ranges[0], ranges[1], datapoints=240, locf=True)
@schlunsen schlunsen added the help wanted Extra attention is needed label Dec 30, 2020
@schlunsen
Copy link
Collaborator Author

schlunsen commented Dec 31, 2020

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

@DoGab
Copy link

DoGab commented Apr 30, 2021

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?

@schlunsen
Copy link
Collaborator Author

schlunsen commented Apr 30, 2021

from django.db.models import Func

@schlunsen
Copy link
Collaborator Author

@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 :)

@DoGab
Copy link

DoGab commented May 3, 2021

@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!

@jacobsayer
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants