-
Notifications
You must be signed in to change notification settings - Fork 50
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
Last datapoint is ignored in the calculation of average(time_weight('locf', TIME, value)) #732
Comments
Unfortunately the |
Hmm, trying out the example I gave you it looks like the interpolation will still consider the data to end at the last point if there isn't a next aggregate. Unfortunately this makes a workaround even uglier, you have to replace the
This isn't really an reasonable approach here, so I'll work with the team and see if we can't get something much more useful into our next release. Perhaps you can help inform what that looks like, which of the following approaches seems more reasonable to you?
or
|
Hey @WireBaron, I'm the one that opened the above-mentioned Stackoverflow question. My specific use case would be the calculation of time_weighted averages in the timespan of a couple months with daily timebuckets. Therefore with your proposed solution it would be kind of hard to realize that behavior because you would have to somehow dynamically determine the bounds for each day. For my use case the best solution would be if extrapolated_average would just take the timebucket into account and calculate the time_weight depending on the whole interval. |
@Timsgmlr - sorry for opening this issue; I just wanted to help - unfortunately I can't change the reporter - but next time I'll only suggest to open an issue here instead of creating a new issue. |
Hey, don't worry about it, I'm glad you directly opened the issue. I just wanted to make clear why I'm answering, when technically the question was directed to you. |
I worked with this a bit with the rest of the team, and it doesn't look like either the There are a couple of improvements we do want to make to @Timsgmlr - if you're using WITH time_weights AS (
SELECT
time_bucket('1d', ts) as bucket,
time_weight('locf', ts, val) as agg
FROM data
GROUP BY 1
)
SELECT
AVG(
interpolated_average(agg, bucket, '1d',
LAG(agg) OVER (ORDER BY bucket),
LEAD(agg) OVER (ORDER BY bucket))
)
FROM time_weights That being said, it's likely better to rollup the aggregates before calling WITH time_weights AS (
SELECT
time_bucket('1d', ts) as bucket,
time_weight('locf', ts, val) as agg
FROM data
GROUP BY 1
)
SELECT
average(rollup(agg))
FROM time_weights |
Relevant system information:
Describe the bug]
reported in https://stackoverflow.com/questions/75680213/time-weighted-average-in-timescaledb-using-last-observation-carried-forward
incorrect average is computed from
time_weight
; seems like the last datapoint is not counted inTo Reproduce
Expected behavior
I guess for
k=1
andk=2
the same resultset would be expected; but instead theaverage
is equal to thek=0
caseActual behavior
The text was updated successfully, but these errors were encountered: