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

#2597 Bundle Size — 10.9MiB (+0.02%).

bf47ebf(current) vs bd9c6f0 main#2593(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 1 change
                 Current
#2597
     Baseline
#2593
No change  Initial JS 1.9MiB 1.9MiB
No change  Initial CSS 577.39KiB 577.39KiB
Change  Cache Invalidation 18.09% 18.15%
No change  Chunks 226 226
No change  Assets 249 249
No change  Modules 2947 2947
No change  Duplicate Modules 154 154
No change  Duplicate Code 1.8% 1.8%
No change  Packages 96 96
No change  Duplicate Packages 2 2
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#2597
     Baseline
#2593
Regression  JS 9.11MiB (+0.02%) 9.11MiB
No change  CSS 866.47KiB 866.47KiB
No change  Fonts 526.1KiB 526.1KiB
No change  Media 295.6KiB 295.6KiB
No change  IMG 140.74KiB 140.74KiB
No change  HTML 1.38KiB 1.38KiB
No change  Other 871B 871B

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]>
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