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

[blockly] Riemann sum persistence extension and js tern definitions #2893

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mherwege
Copy link
Contributor

@mherwege mherwege commented Dec 2, 2024

Depends on openhab/openhab-js#401
Depends on openhab/openhab-core#4461

This will also require a new js scripting library release.

This PR extends the Blockly block getting a statistical value from persistence to be aligned with core and js scripting extensions.
The added statistical function is Riemann sum. This is an approximation of the integral value and can e.g. be used to calculate an approximation for energy consumption (in kWh) when the instantanous power (in W) is persisted.
The existing sum method calculates a naive sum, ignoring the time dimension and is not applicable for this. It could be used only if the persistence interval is constant by using the sum and multiplying with the interval duration.

There are multiple types of Riemann sum calculations depending on which value is used as an approximation in each bucket. The ones implemented in core (and js scripting) are: left, right, trapezoidal and midpoint. If the Riemann sum statistical method block is selected in the block, a parameter for this will also be shown, defaulting to left.

As average, variance and deviation statistical methods are based on Riemann sum calculations (the current average calculation assumes Riemann sums of type left), these methods now also have this extra type input parameter (defaulting to left).

Note that in most cases, the trapezoidal (or midpoint) methods would result in better accuracy. However, for backward compatibility reasons, the default has been kept on left.

Copy link

relativeci bot commented Dec 2, 2024

#2825 Bundle Size — 10.99MiB (+0.02%).

8ee5c9c(current) vs 1c84a5b main#2821(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 1 change
                 Current
#2825
     Baseline
#2821
No change  Initial JS 1.9MiB 1.9MiB
No change  Initial CSS 577.29KiB 577.29KiB
Change  Cache Invalidation 17.98% 17.32%
No change  Chunks 227 227
No change  Assets 250 250
No change  Modules 2952 2952
No change  Duplicate Modules 154 154
No change  Duplicate Code 1.8% 1.8%
No change  Packages 98 98
No change  Duplicate Packages 2 2
Bundle size by type  Change 7 changes Regression 7 regressions
                 Current
#2825
     Baseline
#2821
Regression  JS 9.2MiB (+100%) undefined
Regression  CSS 867.41KiB (+100%) undefined
Regression  Fonts 526.1KiB (+100%) undefined
Regression  Media 295.6KiB (+100%) undefined
Regression  IMG 140.74KiB (+100%) undefined
Regression  HTML 1.38KiB (+100%) undefined
Regression  Other 871B (+100%) undefined

Bundle analysis reportBranch mherwege:riemann_sumProject dashboard


Generated by RelativeCIDocumentationReport issue

@mherwege
Copy link
Contributor Author

@stefan-hoehn FYI, not to be merged yet, as waiting for the core and javascript enhancements.

@mherwege mherwege changed the title [Blockly] Riemann sum persistence extension and js tern definitions [blockly] Riemann sum persistence extension and js tern definitions Dec 16, 2024
@stefan-hoehn
Copy link
Contributor

Can you add what the extension is about. We should avoid overloading blocks with too many things (not saying you do so 😉)

@mherwege
Copy link
Contributor Author

Can you add what the extension is about. We should avoid overloading blocks with too many things (not saying you do so 😉)

I have added some description in the first post. This is about keeping the persistence blocks in line with the (still proposed) core and js scripting extensions.
Agreed it should not be overloaded. But I believe this is an important part of rules, and being able to use all variations of persistence extensions in Blocky feels important to me.

@florian-h05 florian-h05 added enhancement New feature or request main ui Main UI awaiting other PR Depends on another PR labels Dec 22, 2024
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
@stefan-hoehn
Copy link
Contributor

And let's not forget to update the blockly docs after that ;-)

@mherwege
Copy link
Contributor Author

And let's not forget to update the blockly docs after that ;-)

I will try to remember, but first there are 3 PR's to be merged (core, JS, UI) before even considering the doc. I will only docs when these are accepted and I can bring up a system with all these running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting other PR Depends on another PR enhancement New feature or request main ui Main UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants