@mschaeffler/node-red-logic 0.9.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/math_statistics.html +6 -1
- package/math_statistics.js +39 -19
- package/package.json +1 -1
package/math_statistics.html
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
minData:{value:"1", required:true, validate:function(v){
|
|
12
12
|
return v!=='' && !isNaN(v) && Number(v)>0;}
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
filter:{value:false}
|
|
14
15
|
},
|
|
15
16
|
inputs:1,
|
|
16
17
|
outputs:1,
|
|
@@ -51,6 +52,10 @@
|
|
|
51
52
|
<label for="node-input-minData"><i class="fa fa-check-square-o "></i> min. Data</label>
|
|
52
53
|
<input type="text" id="node-input-minData">
|
|
53
54
|
</div>
|
|
55
|
+
<div class="form-row">
|
|
56
|
+
<label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
|
|
57
|
+
<input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
58
|
+
</div>
|
|
54
59
|
</script>
|
|
55
60
|
|
|
56
61
|
<script type="text/html" data-help-name="statistics">
|
package/math_statistics.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports = function(RED) {
|
|
|
8
8
|
this.property = config.property || "payload";
|
|
9
9
|
this.deltaTime= Number( config.deltaTime )*1000;
|
|
10
10
|
this.minData = Number( config.minData );
|
|
11
|
+
this.filter = Boolean( config.filter );
|
|
11
12
|
|
|
12
13
|
node.on('input', function(msg,send,done) {
|
|
13
14
|
if( msg.invalid )
|
|
@@ -38,33 +39,52 @@ module.exports = function(RED) {
|
|
|
38
39
|
|
|
39
40
|
if( item.length >= this.minData )
|
|
40
41
|
{
|
|
41
|
-
|
|
42
|
-
count: item.length,
|
|
43
|
-
min: Number.MAX_SAFE_INTEGER,
|
|
44
|
-
max: Number.MIN_SAFE_INTEGER };
|
|
45
|
-
let sum = 0;
|
|
46
|
-
for( const value of item )
|
|
42
|
+
function checkFilter()
|
|
47
43
|
{
|
|
48
|
-
|
|
49
|
-
if(
|
|
44
|
+
let last = context.get( "last" ) ?? {};
|
|
45
|
+
if( payload !== last[msg.topic] )
|
|
50
46
|
{
|
|
51
|
-
msg.
|
|
47
|
+
last[msg.topic] = payload;
|
|
48
|
+
context.set( "last", last );
|
|
49
|
+
return true;
|
|
52
50
|
}
|
|
53
|
-
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if( !node.filter || checkFilter() )
|
|
55
|
+
{
|
|
56
|
+
msg.stat = {
|
|
57
|
+
count: item.length,
|
|
58
|
+
min: Number.MAX_SAFE_INTEGER,
|
|
59
|
+
max: Number.MIN_SAFE_INTEGER };
|
|
60
|
+
let sum = 0;
|
|
61
|
+
for( const value of item )
|
|
62
|
+
{
|
|
63
|
+
sum += value.value;
|
|
64
|
+
if( value.value < msg.stat.min )
|
|
65
|
+
{
|
|
66
|
+
msg.stat.min = value.value;
|
|
67
|
+
}
|
|
68
|
+
if( value.value > msg.stat.max )
|
|
69
|
+
{
|
|
70
|
+
msg.stat.max = value.value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
msg.stat.average = sum/msg.stat.count;
|
|
74
|
+
let varianz = 0;
|
|
75
|
+
for( const value of item )
|
|
54
76
|
{
|
|
55
|
-
msg.stat.
|
|
77
|
+
varianz += ( value.value - msg.stat.average ) ** 2;
|
|
56
78
|
}
|
|
79
|
+
msg.stat.deviation = Math.sqrt( varianz / msg.stat.count );
|
|
80
|
+
msg.stat.variation = msg.stat.deviation / msg.stat.average;
|
|
81
|
+
node.status({fill:"green",shape:"dot",text:`${msg.stat.count} / ${msg.stat.deviation.toPrecision(4)}`});
|
|
82
|
+
send( msg );
|
|
57
83
|
}
|
|
58
|
-
|
|
59
|
-
let varianz = 0;
|
|
60
|
-
for( const value of item )
|
|
84
|
+
else
|
|
61
85
|
{
|
|
62
|
-
|
|
86
|
+
node.status({fill:"gray",shape:"dot",text:item.length});
|
|
63
87
|
}
|
|
64
|
-
msg.stat.deviation = Math.sqrt( varianz / msg.stat.count );
|
|
65
|
-
msg.stat.variation = msg.stat.deviation / msg.stat.average;
|
|
66
|
-
node.status({fill:"green",shape:"dot",text:msg.stat.count});
|
|
67
|
-
send( msg );
|
|
68
88
|
}
|
|
69
89
|
else
|
|
70
90
|
{
|
package/package.json
CHANGED