-
-
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
Add MEDIAN group function #4344
Conversation
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/feature-request-median/157728/12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM. Thanks!
...b.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java
Outdated
Show resolved
Hide resolved
...s/org.openhab.core/src/main/java/org/openhab/core/library/types/ArithmeticGroupFunction.java
Outdated
Show resolved
Hide resolved
@jimtng Great you took this one. I am wondering if it makes sense to use a more performant algorithm using heaps? See https://www.baeldung.com/java-stream-integers-median-using-heap. I expect it will for the other case with persistence when looking at a longer period with many data points. Here the impact could be important because this recalculation (and sorting) will be done for every state change of an item in the group. |
And here is a text on another, at first side even better, algorithm: https://rcoh.me/posts/linear-time-median-finding/ |
@mherwege great idea! I'm going to do some tests comparing the two/three implementations. I'm also wondering about keeping an in-memory sorted list and update it whenever the members changed. That would involve a sorting operation at the beginning, and only deletion + insertion of (changed|added|removed) item(s), which should probably be even faster than any quickselect / heap median algorithm. However, the way it's currently done, we got given a list of items with no knowledge of the groupitem (only the baseitem). So to do that, a lot of things would need to be changed. |
@jimtng I am not sure the extra complexity of handling item state changes + item addition + item removal in a group are worth it for this use case. Using an algorithm that scales linearly (or at least most of the time) with number of items I suspect does. |
That’s what the heap approach could optimise. |
Note: waiting for #4345 to be merged, and refactor to use the |
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
2941f20
to
cfd87ca
Compare
Thanks, updated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks y'all guys for implementing. |
Resolve #4341