-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
Persistence Extensions: Riemann Sums #4461
Open
mherwege
wants to merge
9
commits into
openhab:main
Choose a base branch
from
mherwege:riemann_sum
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+1,345
−65
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mherwege
force-pushed
the
riemann_sum
branch
2 times, most recently
from
November 22, 2024 10:33
cbf98c2
to
5c76129
Compare
Tests run fine locally. I am trying to figure out why they do not work in the PR. |
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
mherwege
force-pushed
the
riemann_sum
branch
from
November 22, 2024 17:07
8516df7
to
39a0bbe
Compare
I put in some extra test logging to try to analyze where the difference is between my succeeding local tests and the failing online tests. |
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
All test are passing now and extra logging has been removed. This is ready for review. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4439
At the moment, it is not possible to easily calculate the integral value of the curve represented by persisted values. This is useful for calculating e.g. total energy consumed (in kWh) from instantaneous power meter readings (in W).
The current
sum
persistence actions calculate a sum without considering the time dimension, and therefore are only useful when we have a guaranteed constant interval between persisted values for this.The
average
actions do use a time weighting in their calculation. Multiplying the average with the total duration considered would give an approximation. However, theaverage
calculations assume a constant value over the bucket and take the value at the start of the bucket. Using this average to calculate an integration would also mean an extra calculation (already divided in the action code and multiplied again in the rule).An alternative approach to get an integral value is by setting up an integrated item and a rule that adds value * duration since previous change/upate, triggered on base item change. This works and is flexible in its calculation (value can be approximated based on previous and new item state). It suffers from things like unexpected shutdowns, where the base item and its aggretation may run out of sync.
This PR proposes to create a group of new actions,
riemannSum
, that will calculate the RiemannSum as an approximation for the integral value. Analoguous to the other actions, there are variants taking (or not)startDate
,endDate
andserviceId
as input.There is one extra key parameter, the Riemann type, representing the type of approximation used. Valid values are:
RiemannType.left
: takes the persisted value at the start of the bucket to represent the value for the whole bucket. This is most useful when there is apersistOnChange
strategy and the values represent a step function. An example would be dynamic electricity rates, as they will effectively be constant inside the bucket.RiemannType.right
: takes the persisted value at the end of the bucket.RiemannType.trapezoidal
: takes the average of the persisted value at the start end the end of the bucket, effectively making a linear interpolation to fit the curve. This type is most useful when the real values change continuously. It can be used for any persistence strategy and any interval.RiemannType.midpoint
: uses 3 persisted values and uses the middle of the values as an approximation for the value halfway in the interval between the middle of point 1 and 2 and the middle of point 2 and 3. This is the best approximation when the real values change continuously, the persistence intervals are short and the bucket sizes between persisted values are relatively constant.The existing
average
,variance
anddeviation
actions have been enhanced to use the results of the Riemann sum calculations. They now have variants with an extra parameter where this type can be selected.For backward compatibility and consistency between defaults of the different actions, the action versions for
riemannSum
,average
,variance
anddeviation
without a Riemann type parameter all useRiemannType.left
as a default.Tests have been enhanced end confirmed the existing actions with the existing parameters still behave as before.
If this PR is accepted the scripting libraries should be enhanced to cover these new actions and the new parameters in the existing actions.
For testing, a compiled jar can be downloaded from here.