-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix calculation of average for values with not equally spaced samples #102
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days. Please check if the issue is still relevant in the most current version of the adapter and tell us. Also check that all relevant details, logs and reproduction steps are included and update them if needed. Thank you for your contributions. |
The problem is still open and relevant. The reproduction steps did not change. I am wondering if nobody else is interested in this, as this is a rather fundamental problem that makes the plugin produce wrong results for all but equidistantly sampled values. Or do people just not recognize that the results are wrong? |
I also have problems with non equaly distributed values for the delta option. Unless for the 15min range, all values are wrong. Is there any progress expectable? Otherwise i have to progeam it with blockly by my own. I would prefer to use statistics |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days. Please check if the issue is still relevant in the most current version of the adapter and tell us. Also check that all relevant details, logs and reproduction steps are included and update them if needed. Thank you for your contributions. |
In the following, I assume that the term "average" is meant to be the same as the mean of a measure.
Describe the bug
Calculation of average does not work right for values with not equally spaced samples.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Compute the correct result (see below).
Versions:
Background
The reason for this problem is the way how averages are computed, which does not cover the general case of not equally spaced samples (it only works with equally spaced samples).
In general, the mean
m
of an analog signalx
in the time intervalT
is defined asm = 1/T * integral_T x(t) dt
. For sampled (i.e. discrete time) measures, this translates intom = 1/T * sum x_i * delta t_i
withdelta t_i = t_i+1 - t_i
. In other words, eachx_i
must be weighted by the period of time for which it has been active.Currently, the average is calculated as follows:
m = 1/N * sum x_i
withN
being the number of samples. This gives the correct result if samples are equally spaced (i.e.delta t_i
is some constant independent ofi
), but not in the general case.Example
I monitor the outside temperature at my home with a resolution of 1 K. A sample is recorded whenever the temperature changes, or if there has been no change for a long time (e.g., 1 hour). Now let's say I record the following temperature profile: 1°C at 0:00, 2°C at 0:05, 3°C at 0:10, 4°C at 0:15, 5°C at 0:20, 5°C at 1:20 (i.e., no change between 0:20 and 1:20). The correct mean would be
m = 1/80min * (1°C * 5min + 2°C * 5min + 3°C * 5min + 4°C * 5min + 5°C * 60min) = 4,375°C
. But currently, the computed result would bem = 1/6 * (1 + 2 + 3 + 4 + 5 + 5) = 3,33°C
, which is far from the correct result (note that the temperature has been < 4°C for less than 15 minutes and >= 4°C for 65 minutes).The way of computing the result should be fixed to work for the general case. Unfortunately I have no knowledge about internal iobroker structures or even Javascript to be able to provide a fix, but I think fixing this issue is a low-hanging fruit (clear improvement, should not cause much effort).
The text was updated successfully, but these errors were encountered: