@mschaeffler/node-red-logic 3.6.0 → 3.7.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_hysteresis.js +1 -1
- package/math_mean.js +2 -2
- package/math_reduce.js +2 -1
- package/math_statistics.js +13 -4
- package/package.json +1 -1
- package/tools.js +5 -0
package/math_hysteresis.js
CHANGED
|
@@ -84,7 +84,7 @@ module.exports = function(RED) {
|
|
|
84
84
|
getPayload( function(value)
|
|
85
85
|
{
|
|
86
86
|
msg.value = Number( value );
|
|
87
|
-
let status = { fill:data[msg.topic]?.status??"gray", shape:"dot", text:msg.value
|
|
87
|
+
let status = { fill:data[msg.topic]?.status??"gray", shape:"dot", text:tools.formatNumber( msg.value ) };
|
|
88
88
|
|
|
89
89
|
if( ! isNaN( msg.value ) )
|
|
90
90
|
{
|
package/math_mean.js
CHANGED
|
@@ -93,7 +93,7 @@ module.exports = function(RED) {
|
|
|
93
93
|
msg.count = count;
|
|
94
94
|
last[msg.topic] = {value:value,time:now};
|
|
95
95
|
context.set( "last", last );
|
|
96
|
-
node.status({fill:"green",shape:"dot",text:`${item.length} / ${
|
|
96
|
+
node.status({fill:"green",shape:"dot",text:`${item.length} / ${tools.formatNumber(value)}`});
|
|
97
97
|
send( msg );
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -118,7 +118,7 @@ module.exports = function(RED) {
|
|
|
118
118
|
}
|
|
119
119
|
else
|
|
120
120
|
{
|
|
121
|
-
node.status({fill:"gray",shape:"dot",text:`${item.length} / ${
|
|
121
|
+
node.status({fill:"gray",shape:"dot",text:`${item.length} / ${tools.formatNumber(value)}`});
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
else
|
package/math_reduce.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
module.exports = function(RED) {
|
|
2
|
+
var tools = require('./tools.js');
|
|
2
3
|
|
|
3
4
|
function ReduceNode(config) {
|
|
4
5
|
RED.nodes.createNode(this,config);
|
|
@@ -112,7 +113,7 @@ module.exports = function(RED) {
|
|
|
112
113
|
{
|
|
113
114
|
case "mean": msg.payload /= msg.count; break;
|
|
114
115
|
}
|
|
115
|
-
status.text = msg.payload
|
|
116
|
+
status.text = tools.formatNumber( msg.payload );
|
|
116
117
|
if( node.filter )
|
|
117
118
|
{
|
|
118
119
|
if( msg.payload !== node.last )
|
package/math_statistics.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
module.exports = function(RED) {
|
|
2
|
+
var tools = require('./tools.js');
|
|
2
3
|
|
|
3
4
|
function StatsNode(config) {
|
|
4
5
|
RED.nodes.createNode(this,config);
|
|
@@ -80,10 +81,12 @@ module.exports = function(RED) {
|
|
|
80
81
|
count: item.length,
|
|
81
82
|
min: Number.MAX_SAFE_INTEGER,
|
|
82
83
|
max: Number.MIN_SAFE_INTEGER };
|
|
83
|
-
let
|
|
84
|
+
let sumV = 0;
|
|
85
|
+
let sumT = 0;
|
|
84
86
|
for( const value of item )
|
|
85
87
|
{
|
|
86
|
-
|
|
88
|
+
sumV += value.value;
|
|
89
|
+
sumT += value.time;
|
|
87
90
|
if( value.value < msg.stat.min )
|
|
88
91
|
{
|
|
89
92
|
msg.stat.min = value.value;
|
|
@@ -93,17 +96,23 @@ module.exports = function(RED) {
|
|
|
93
96
|
msg.stat.max = value.value;
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
|
-
msg.stat.average =
|
|
99
|
+
msg.stat.average = sumV / msg.stat.count;
|
|
100
|
+
const avgT = sumT / msg.stat.count;
|
|
97
101
|
let varianz = 0;
|
|
102
|
+
let zaehler = 0;
|
|
103
|
+
let nenner = 0;
|
|
98
104
|
for( const value of item )
|
|
99
105
|
{
|
|
100
106
|
varianz += ( value.value - msg.stat.average ) ** 2;
|
|
107
|
+
zaehler += ( value.value - msg.stat.average ) * ( value.time - avgT );
|
|
108
|
+
nenner += ( value.time - avgT ) ** 2;
|
|
101
109
|
}
|
|
102
110
|
msg.stat.deviation = Math.sqrt( varianz / msg.stat.count );
|
|
103
111
|
msg.stat.variation = msg.stat.deviation / msg.stat.average;
|
|
112
|
+
msg.stat.slope = msg.stat.count > 1 ? zaehler / nenner * 1000 : null;
|
|
104
113
|
if( node.showState )
|
|
105
114
|
{
|
|
106
|
-
node.status({fill:"green",shape:"dot",text:`${msg.stat.count} / ${msg.stat.deviation
|
|
115
|
+
node.status({fill:"green",shape:"dot",text:`${msg.stat.count} / ${tools.formatNumber(msg.stat.deviation)}`});
|
|
107
116
|
}
|
|
108
117
|
send( msg );
|
|
109
118
|
}
|
package/package.json
CHANGED