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

Time-Weighted Averages #46

Closed
Tracked by #107
inselbuch opened this issue Jan 22, 2021 · 5 comments
Closed
Tracked by #107

Time-Weighted Averages #46

inselbuch opened this issue Jan 22, 2021 · 5 comments
Labels
proposed-feature A proposed feature or function to ease a task

Comments

@inselbuch
Copy link

What's the functionality you would like to add

To produce evenly spaced values of arbitrary intervals. Time-weighted averages weight each value within the period by the length of time the value held true. So the initial value in a period must weight the immediately preceding the period as well.

How would the function be used

select twa(value, interval '10 minute')
from table
where time between '0:00' and now();

select twa(value, interval '15 minute')
from table
where time between '0:00' and now();

-Arithmetic averages (sum of samples/number of sample) can give wildly misleading results (e.g., a single, ephemeral, spike can alter the meaning dramatically)

  • When using values from multiple measurements it is handy to have them aligned in time
  • The arithmetic average of Time-weighted averages is valid because the samples are equidistant
  • Time-weighted averages can be used statistically (whereas arithmetic averages cannot)
    -Arithmetic averages of generated, evenly spaced values (buckets) over large periods, is memory-intensive
    -True time-weighted algorithm is accurate to the precision of the time stamp, not the granularity of the selected bucket size.

What scale is this useful at?

All scales when you are seeking the truth.

@inselbuch inselbuch added the proposed-feature A proposed feature or function to ease a task label Jan 22, 2021
@JLockerman
Copy link
Contributor

Thank you for opening this issue @inselbuch!

Let me see if I understand the functionality: if you have a dataset like

 time | value
------+-------
00:00 |   1
00:05 |   2
00:07 |   3
00:10 |   1
00:20 |   4

Assuming we store all only those times at which value the time-weighted average over 10 minutes would be

(0.5 * 1) + (0.2 * 2) + (0.3 * 3) = 1.8

for the interval [00:00, 00:10) and

(1 * 1) = 1.8

for the interval [00:10, 00:20). Is that correct?

@inselbuch
Copy link
Author

inselbuch commented Jan 22, 2021 via email

@inselbuch
Copy link
Author

@JLockerman JLockerman added this to Backlog in Sprint Planning Jan 26, 2021
@JLockerman JLockerman moved this from Backlog to To do in Sprint Planning Jan 26, 2021
@JLockerman JLockerman moved this from To do to Backlog in Sprint Planning Jan 26, 2021
@JLockerman JLockerman moved this from TBD to Now in Priority Planning Jan 28, 2021
@JLockerman
Copy link
Contributor

Am experimental version of this is available in 0.1.0, and should also be available on Forge soon.

@JLockerman JLockerman moved this from Now to Done in Priority Planning Mar 26, 2021
@Loquacity Loquacity self-assigned this Jun 8, 2021
@JLockerman JLockerman added this to Stabalizing in Feature Progress Jun 21, 2021
@JLockerman JLockerman moved this from Stabilizing to Done in Feature Progress Jul 15, 2021
@JLockerman
Copy link
Contributor

This was released in 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposed-feature A proposed feature or function to ease a task
Projects
Development

No branches or pull requests

3 participants