@mschaeffler/node-red-logic 1.4.0 → 1.4.2

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/counter.js CHANGED
@@ -10,7 +10,7 @@ module.exports = function(RED) {
10
10
  if( msg.invalid )
11
11
  {
12
12
  done();
13
- return null;
13
+ return;
14
14
  }
15
15
  msg.count = context.get( "count" ) ?? 0;
16
16
  if( msg.reset || msg.topic==="init" )
package/logic_and.js CHANGED
@@ -16,12 +16,12 @@ module.exports = function(RED) {
16
16
  if( msg.invalid )
17
17
  {
18
18
  done();
19
- return null;
20
19
  }
21
- if( msg.reset || msg.topic==="init" )
20
+ else if( msg.reset || msg.topic==="init" )
22
21
  {
23
22
  context.set( "data", {} );
24
23
  node.status( "" );
24
+ done();
25
25
  }
26
26
  else
27
27
  {
@@ -73,9 +73,8 @@ module.exports = function(RED) {
73
73
  node.status( "waiting for data" );
74
74
  }
75
75
  }
76
+ done();
76
77
  }
77
-
78
- done();
79
78
  });
80
79
  }
81
80
 
package/logic_bool.js CHANGED
@@ -14,7 +14,7 @@ module.exports = function(RED) {
14
14
  if( msg.invalid )
15
15
  {
16
16
  done();
17
- return null;
17
+ return;
18
18
  }
19
19
  msg.payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
20
20
  let status = { text:msg.payload ?? "error" };
package/logic_not.js CHANGED
@@ -14,7 +14,7 @@ module.exports = function(RED) {
14
14
  if( msg.invalid )
15
15
  {
16
16
  done();
17
- return null;
17
+ return;
18
18
  }
19
19
  msg.payload = ! tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
20
20
  let status = { text:msg.payload ?? "error" };
package/logic_or.js CHANGED
@@ -16,12 +16,12 @@ module.exports = function(RED) {
16
16
  if( msg.invalid )
17
17
  {
18
18
  done();
19
- return null;
20
19
  }
21
- if( msg.reset || msg.topic==="init" )
20
+ else if( msg.reset || msg.topic==="init" )
22
21
  {
23
22
  context.set( "data", {} );
24
23
  node.status( "" );
24
+ done();
25
25
  }
26
26
  else
27
27
  {
@@ -73,9 +73,8 @@ module.exports = function(RED) {
73
73
  node.status( "waiting for data" );
74
74
  }
75
75
  }
76
+ done();
76
77
  }
77
-
78
- done();
79
78
  });
80
79
  }
81
80
 
package/math_falling.js CHANGED
@@ -24,9 +24,8 @@ module.exports = function(RED) {
24
24
  if( msg.invalid )
25
25
  {
26
26
  done();
27
- return null;
28
27
  }
29
- if( msg.reset || msg.topic==="init" )
28
+ else if( msg.reset || msg.topic==="init" )
30
29
  {
31
30
  context.set( "data", {} );
32
31
  node.status( "" );
@@ -26,9 +26,8 @@ module.exports = function(RED) {
26
26
  if( msg.invalid )
27
27
  {
28
28
  done();
29
- return null;
30
29
  }
31
- if( msg.reset || msg.topic==="init" )
30
+ else if( msg.reset || msg.topic==="init" )
32
31
  {
33
32
  context.set( "data", {} );
34
33
  node.status( "" );
package/math_mean.html CHANGED
@@ -5,6 +5,7 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload", required:true},
8
+ propertyType:{value:"msg"},
8
9
  deltaTime:{value:"60", required:true, validate:function(v){
9
10
  return v!=='' && !isNaN(v) && Number(v)>0;}
10
11
  },
@@ -28,8 +29,8 @@
28
29
  oneditprepare: function() {
29
30
  $("#node-input-property").typedInput({
30
31
  type:"msg",
31
- types:["msg"],
32
- typeField: "#node-input-property-type"
32
+ types:["msg","jsonata"],
33
+ typeField: "#node-input-propertyType"
33
34
  });
34
35
  }
35
36
  });
@@ -43,7 +44,7 @@
43
44
  <div class="form-row">
44
45
  <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
45
46
  <input type="text" id="node-input-property">
46
- <input type="hidden" id="node-input-property-type">
47
+ <input type="hidden" id="node-input-propertyType">
47
48
  </div>
48
49
  <div class="form-row">
49
50
  <label for="node-input-minMean"><i class="fa fa-hourglass-o"></i> Zeitspanne</label>
package/math_mean.js CHANGED
@@ -5,81 +5,116 @@ module.exports = function(RED) {
5
5
  //this.config = config;
6
6
  var node = this;
7
7
  var context = this.context();
8
- this.property = config.property || "payload";
9
- this.deltaTime= Number( config.deltaTime )*1000;
10
- this.minData = Number( config.minData );
11
- this.filter = Number( config.filter ?? 0 )*1000;
12
- this.zeroIsZero = config.zeroIsZero ?? false;
8
+ this.property = config.property || "payload";
9
+ this.propertyType = config.propertyType ?? "msg";
10
+ this.deltaTime = Number( config.deltaTime )*1000;
11
+ this.minData = Number( config.minData );
12
+ this.filter = Number( config.filter ?? 0 )*1000;
13
+ this.zeroIsZero = config.zeroIsZero ?? false;
14
+ if( this.propertyType === "jsonata" )
15
+ {
16
+ try {
17
+ this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
18
+ }
19
+ catch (e) {
20
+ node.error(RED._("debug.invalid-exp", {error: this.property}));
21
+ return;
22
+ }
23
+ }
13
24
 
14
25
  node.on('input', function(msg,send,done) {
15
26
  if( msg.invalid )
16
27
  {
17
28
  done();
18
- return null;
19
29
  }
20
- if( msg.reset || msg.topic==="init" )
30
+ else if( msg.reset || msg.topic==="init" )
21
31
  {
22
32
  context.set( "data", {} );
23
33
  context.set( "last", {} );
24
34
  node.status( "" );
35
+ done();
25
36
  }
26
37
  else
27
38
  {
28
- const now = Date.now();
29
- const payload = Number( RED.util.getMessageProperty( msg, node.property ) );
30
- if( ! isNaN( payload ) )
39
+ const now = Date.now();
40
+ function getPayload(callback)
31
41
  {
32
- let last = context.get( "last" ) ?? {};
33
- let data = context.get( "data" ) ?? {};
34
- let item = data[msg.topic] ?? [];
35
- item.push( { time:now, value:payload } );
36
- while( item[0].time < now - this.deltaTime )
37
- {
38
- item.shift();
39
- }
40
- data[msg.topic] = item;
41
- context.set( "data", data );
42
-
43
- function sendValue(value)
42
+ if( node.propertyPrepared )
44
43
  {
45
- msg.payload = value;
46
- last[msg.topic] = now;
47
- context.set( "last", last );
48
- node.status({fill:"green",shape:"dot",text:`${item.length} / ${msg.payload.toPrecision(4)}`});
49
- send( msg );
44
+ RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
45
+ {
46
+ if( err )
47
+ {
48
+ done( RED._("debug.invalid-exp", {error: editExpression}) );
49
+ }
50
+ else
51
+ {
52
+ callback( value );
53
+ }
54
+ } );
50
55
  }
51
-
52
- if( this.zeroIsZero && payload === 0 )
56
+ else
53
57
  {
54
- sendValue( 0 );
58
+ callback( RED.util.getMessageProperty( msg, node.property ) );
55
59
  }
56
- else if( item.length >= this.minData )
60
+ }
61
+ getPayload( function(value)
62
+ {
63
+ const payload = Number( value );
64
+ if( ! isNaN( payload ) )
57
65
  {
58
- let sum = 0;
59
- for( const value of item )
66
+ let last = context.get( "last" ) ?? {};
67
+ let data = context.get( "data" ) ?? {};
68
+ let item = data[msg.topic] ?? [];
69
+ item.push( { time:now, value:payload } );
70
+ while( item[0].time < now - this.deltaTime )
71
+ {
72
+ item.shift();
73
+ }
74
+ data[msg.topic] = item;
75
+ context.set( "data", data );
76
+
77
+ function sendValue(value)
78
+ {
79
+ msg.payload = value;
80
+ last[msg.topic] = now;
81
+ context.set( "last", last );
82
+ node.status({fill:"green",shape:"dot",text:`${item.length} / ${msg.payload.toPrecision(4)}`});
83
+ send( msg );
84
+ }
85
+
86
+ if( this.zeroIsZero && payload === 0 )
60
87
  {
61
- sum += value.value;
88
+ sendValue( 0 );
62
89
  }
63
- if( (last[msg.topic]??0)+this.filter < now )
90
+ else if( item.length >= this.minData )
64
91
  {
65
- sendValue( sum/item.length );
92
+ let sum = 0;
93
+ for( const value of item )
94
+ {
95
+ sum += value.value;
96
+ }
97
+ if( (last[msg.topic]??0)+this.filter < now )
98
+ {
99
+ sendValue( sum/item.length );
100
+ }
101
+ else
102
+ {
103
+ node.status({fill:"gray",shape:"dot",text:`${item.length} / ${msg.payload.toPrecision(4)}`});
104
+ }
66
105
  }
67
106
  else
68
107
  {
69
- node.status({fill:"gray",shape:"dot",text:`${item.length} / ${msg.payload.toPrecision(4)}`});
108
+ node.status({fill:"gray",shape:"dot",text:"to less data"});
70
109
  }
71
110
  }
72
111
  else
73
112
  {
74
- node.status({fill:"gray",shape:"dot",text:"to less data"});
113
+ node.status({fill:"red",shape:"dot",text:"payload is NaN"});
75
114
  }
76
- }
77
- else
78
- {
79
- node.status({fill:"red",shape:"dot",text:"payload is NaN"});
80
- }
115
+ done();
116
+ } );
81
117
  }
82
- done();
83
118
  });
84
119
  }
85
120
 
package/math_minus.html CHANGED
@@ -5,6 +5,7 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload",required:true},
8
+ propertyType:{value:"msg"},
8
9
  showState:{value:false},
9
10
  filter:{value:false}
10
11
  },
@@ -23,8 +24,8 @@
23
24
  oneditprepare: function() {
24
25
  $("#node-input-property").typedInput({
25
26
  type:"msg",
26
- types:["msg"],
27
- typeField: "#node-input-property-type"
27
+ types:["msg","jsonata"],
28
+ typeField: "#node-input-propertyType"
28
29
  })
29
30
  }
30
31
  });
@@ -38,7 +39,7 @@
38
39
  <div class="form-row">
39
40
  <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
40
41
  <input type="text" id="node-input-property">
41
- <input type="hidden" id="node-input-property-type">
42
+ <input type="hidden" id="node-input-propertyType">
42
43
  </div>
43
44
  <div class="form-row">
44
45
  <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
package/math_minus.js CHANGED
@@ -4,49 +4,84 @@ module.exports = function(RED) {
4
4
  RED.nodes.createNode(this,config);
5
5
  //this.config = config;
6
6
  var node = this;
7
- this.property = config.property ?? "payload";
8
- this.showState = config.showState;
9
- this.filter = Boolean( config.filter );
10
- this.last = null;
7
+ this.property = config.property ?? "payload";
8
+ this.propertyType = config.propertyType ?? "msg";
9
+ this.showState = config.showState;
10
+ this.filter = Boolean( config.filter );
11
+ this.last = null;
12
+ if( this.propertyType === "jsonata" )
13
+ {
14
+ try {
15
+ this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
16
+ }
17
+ catch (e) {
18
+ node.error(RED._("debug.invalid-exp", {error: this.property}));
19
+ return;
20
+ }
21
+ }
11
22
 
12
23
  node.on('input', function(msg,send,done) {
13
24
  if( msg.invalid )
14
25
  {
15
26
  done();
16
- return null;
27
+ return;
17
28
  }
18
- msg.payload = - Number( RED.util.getMessageProperty( msg, node.property ) );
19
- let status = { text:msg.payload };
20
- if( ! isNaN( msg.payload ) )
29
+ function getPayload(callback)
21
30
  {
22
- if( node.filter )
31
+ if( node.propertyPrepared )
23
32
  {
24
- status.shape = "dot";
25
- if( msg.payload !== node.last )
33
+ RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
26
34
  {
27
- node.last = msg.payload;
28
- status.fill = "green";
29
- send( msg );
35
+ if( err )
36
+ {
37
+ done( RED._("debug.invalid-exp", {error: editExpression}) );
38
+ }
39
+ else
40
+ {
41
+ callback( value );
42
+ }
43
+ } );
44
+ }
45
+ else
46
+ {
47
+ callback( RED.util.getMessageProperty( msg, node.property ) );
48
+ }
49
+ }
50
+ getPayload( function(value)
51
+ {
52
+ msg.payload = Number( value );
53
+ let status = { text:msg.payload };
54
+ if( ! isNaN( msg.payload ) )
55
+ {
56
+ if( node.filter )
57
+ {
58
+ status.shape = "dot";
59
+ if( msg.payload !== node.last )
60
+ {
61
+ node.last = msg.payload;
62
+ status.fill = "green";
63
+ send( msg );
64
+ }
65
+ else
66
+ {
67
+ status.fill = "gray";
68
+ }
30
69
  }
31
70
  else
32
71
  {
33
- status.fill = "gray";
72
+ send( msg );
34
73
  }
35
74
  }
36
75
  else
37
76
  {
38
- send( msg );
77
+ status.text = "not a Number";
39
78
  }
40
- }
41
- else
42
- {
43
- status.text = "not a Number";
44
- }
45
- if( node.showState )
46
- {
47
- node.status( status );
48
- }
49
- done();
79
+ if( node.showState )
80
+ {
81
+ node.status( status );
82
+ }
83
+ done();
84
+ } );
50
85
  });
51
86
  }
52
87
 
package/math_number.html CHANGED
@@ -5,6 +5,7 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload",required:true},
8
+ propertyType:{value:"msg"},
8
9
  showState:{value:false},
9
10
  filter:{value:false}
10
11
  },
@@ -23,8 +24,8 @@
23
24
  oneditprepare: function() {
24
25
  $("#node-input-property").typedInput({
25
26
  type:"msg",
26
- types:["msg"],
27
- typeField: "#node-input-property-type"
27
+ types:["msg","jsonata"],
28
+ typeField: "#node-input-propertyType"
28
29
  })
29
30
  }
30
31
  });
@@ -38,7 +39,7 @@
38
39
  <div class="form-row">
39
40
  <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
40
41
  <input type="text" id="node-input-property">
41
- <input type="hidden" id="node-input-property-type">
42
+ <input type="hidden" id="node-input-propertyType">
42
43
  </div>
43
44
  <div class="form-row">
44
45
  <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
package/math_number.js CHANGED
@@ -4,49 +4,84 @@ module.exports = function(RED) {
4
4
  RED.nodes.createNode(this,config);
5
5
  //this.config = config;
6
6
  var node = this;
7
- this.property = config.property ?? "payload";
8
- this.showState = config.showState;
9
- this.filter = Boolean( config.filter );
10
- this.last = null;
7
+ this.property = config.property ?? "payload";
8
+ this.propertyType = config.propertyType ?? "msg";
9
+ this.showState = config.showState;
10
+ this.filter = Boolean( config.filter );
11
+ this.last = null;
12
+ if( this.propertyType === "jsonata" )
13
+ {
14
+ try {
15
+ this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
16
+ }
17
+ catch (e) {
18
+ node.error(RED._("debug.invalid-exp", {error: this.property}));
19
+ return;
20
+ }
21
+ }
11
22
 
12
23
  node.on('input', function(msg,send,done) {
13
24
  if( msg.invalid )
14
25
  {
15
26
  done();
16
- return null;
27
+ return;
17
28
  }
18
- msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
19
- let status = { text:msg.payload };
20
- if( ! isNaN( msg.payload ) )
29
+ function getPayload(callback)
21
30
  {
22
- if( node.filter )
31
+ if( node.propertyPrepared )
23
32
  {
24
- status.shape = "dot";
25
- if( msg.payload !== node.last )
33
+ RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
26
34
  {
27
- node.last = msg.payload;
28
- status.fill = "green";
29
- send( msg );
35
+ if( err )
36
+ {
37
+ done( RED._("debug.invalid-exp", {error: editExpression}) );
38
+ }
39
+ else
40
+ {
41
+ callback( value );
42
+ }
43
+ } );
44
+ }
45
+ else
46
+ {
47
+ callback( RED.util.getMessageProperty( msg, node.property ) );
48
+ }
49
+ }
50
+ getPayload( function(value)
51
+ {
52
+ msg.payload = Number( value );
53
+ let status = { text:msg.payload };
54
+ if( ! isNaN( msg.payload ) )
55
+ {
56
+ if( node.filter )
57
+ {
58
+ status.shape = "dot";
59
+ if( msg.payload !== node.last )
60
+ {
61
+ node.last = msg.payload;
62
+ status.fill = "green";
63
+ send( msg );
64
+ }
65
+ else
66
+ {
67
+ status.fill = "gray";
68
+ }
30
69
  }
31
70
  else
32
71
  {
33
- status.fill = "gray";
72
+ send( msg );
34
73
  }
35
74
  }
36
75
  else
37
76
  {
38
- send( msg );
77
+ status.text = "not a Number";
39
78
  }
40
- }
41
- else
42
- {
43
- status.text = "not a Number";
44
- }
45
- if( node.showState )
46
- {
47
- node.status( status );
48
- }
49
- done();
79
+ if( node.showState )
80
+ {
81
+ node.status( status );
82
+ }
83
+ done();
84
+ } );
50
85
  });
51
86
  }
52
87
 
package/math_raising.js CHANGED
@@ -24,9 +24,8 @@ module.exports = function(RED) {
24
24
  if( msg.invalid )
25
25
  {
26
26
  done();
27
- return null;
28
27
  }
29
- if( msg.reset || msg.topic==="init" )
28
+ else if( msg.reset || msg.topic==="init" )
30
29
  {
31
30
  context.set( "data", {} );
32
31
  node.status( "" );
package/math_reduce.js CHANGED
@@ -18,12 +18,12 @@ module.exports = function(RED) {
18
18
  if( msg.invalid )
19
19
  {
20
20
  done();
21
- return null;
22
21
  }
23
- if( msg.reset || msg.topic==="init" )
22
+ else if( msg.reset || msg.topic==="init" )
24
23
  {
25
24
  context.set( "data", {} );
26
25
  node.status( "" );
26
+ done();
27
27
  }
28
28
  else
29
29
  {
@@ -108,8 +108,8 @@ module.exports = function(RED) {
108
108
  status.text = "payload is NaN";
109
109
  }
110
110
  node.status( status );
111
+ done();
111
112
  }
112
- done();
113
113
  });
114
114
  }
115
115
 
@@ -5,6 +5,7 @@
5
5
  defaults: {
6
6
  name:{value:""},
7
7
  property:{value:"payload", required:true},
8
+ propertyType:{value:"msg"},
8
9
  deltaTime:{value:"60", required:true, validate:function(v){
9
10
  return v!=='' && !isNaN(v) && Number(v)>0;}
10
11
  },
@@ -26,8 +27,8 @@
26
27
  oneditprepare: function() {
27
28
  $("#node-input-property").typedInput({
28
29
  type:"msg",
29
- types:["msg"],
30
- typeField: "#node-input-property-type"
30
+ types:["msg","jsonata"],
31
+ typeField: "#node-input-propertyType"
31
32
  });
32
33
  }
33
34
  });
@@ -41,7 +42,7 @@
41
42
  <div class="form-row">
42
43
  <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
43
44
  <input type="text" id="node-input-property">
44
- <input type="hidden" id="node-input-property-type">
45
+ <input type="hidden" id="node-input-propertyType">
45
46
  </div>
46
47
  <div class="form-row">
47
48
  <label for="node-input-minMean"><i class="fa fa-hourglass-o"></i> Zeitspanne</label>
@@ -5,78 +5,113 @@ module.exports = function(RED) {
5
5
  //this.config = config;
6
6
  var node = this;
7
7
  var context = this.context();
8
- this.property = config.property || "payload";
9
- this.deltaTime= Number( config.deltaTime )*1000;
10
- this.minData = Number( config.minData );
8
+ this.property = config.property || "payload";
9
+ this.propertyType = config.propertyType ?? "msg";
10
+ this.deltaTime = Number( config.deltaTime )*1000;
11
+ this.minData = Number( config.minData );
12
+ if( this.propertyType === "jsonata" )
13
+ {
14
+ try {
15
+ this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
16
+ }
17
+ catch (e) {
18
+ node.error(RED._("debug.invalid-exp", {error: this.property}));
19
+ return;
20
+ }
21
+ }
11
22
 
12
23
  node.on('input', function(msg,send,done) {
13
24
  if( msg.invalid )
14
25
  {
15
26
  done();
16
- return null;
17
27
  }
18
- if( msg.reset || msg.topic==="init" )
28
+ else if( msg.reset || msg.topic==="init" )
19
29
  {
20
30
  context.set( "data", {} );
21
31
  node.status( "" );
32
+ done();
22
33
  }
23
34
  else
24
35
  {
25
- const now = Date.now();
26
- const payload = Number( RED.util.getMessageProperty( msg, node.property ) );
27
- if( ! isNaN( payload ) )
36
+ const now = Date.now();
37
+ function getPayload(callback)
28
38
  {
29
- let data = context.get( "data" ) ?? {};
30
- let item = data[msg.topic] ?? [];
31
- item.push( { time:now, value:payload } );
32
- while( item[0].time < now - this.deltaTime )
39
+ if( node.propertyPrepared )
33
40
  {
34
- item.shift();
41
+ RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
42
+ {
43
+ if( err )
44
+ {
45
+ done( RED._("debug.invalid-exp", {error: editExpression}) );
46
+ }
47
+ else
48
+ {
49
+ callback( value );
50
+ }
51
+ } );
35
52
  }
36
- data[msg.topic] = item;
37
- context.set( "data", data );
38
-
39
- if( item.length >= this.minData )
53
+ else
40
54
  {
41
- msg.stat = {
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 )
55
+ callback( RED.util.getMessageProperty( msg, node.property ) );
56
+ }
57
+ }
58
+ getPayload( function(value)
59
+ {
60
+ const payload = Number( value );
61
+ if( ! isNaN( payload ) )
62
+ {
63
+ let data = context.get( "data" ) ?? {};
64
+ let item = data[msg.topic] ?? [];
65
+ item.push( { time:now, value:payload } );
66
+ while( item[0].time < now - this.deltaTime )
67
+ {
68
+ item.shift();
69
+ }
70
+ data[msg.topic] = item;
71
+ context.set( "data", data );
72
+
73
+ if( item.length >= this.minData )
47
74
  {
48
- sum += value.value;
49
- if( value.value < msg.stat.min )
75
+ msg.stat = {
76
+ count: item.length,
77
+ min: Number.MAX_SAFE_INTEGER,
78
+ max: Number.MIN_SAFE_INTEGER };
79
+ let sum = 0;
80
+ for( const value of item )
50
81
  {
51
- msg.stat.min = value.value;
82
+ sum += value.value;
83
+ if( value.value < msg.stat.min )
84
+ {
85
+ msg.stat.min = value.value;
86
+ }
87
+ if( value.value > msg.stat.max )
88
+ {
89
+ msg.stat.max = value.value;
90
+ }
52
91
  }
53
- if( value.value > msg.stat.max )
92
+ msg.stat.average = sum/msg.stat.count;
93
+ let varianz = 0;
94
+ for( const value of item )
54
95
  {
55
- msg.stat.max = value.value;
96
+ varianz += ( value.value - msg.stat.average ) ** 2;
56
97
  }
98
+ msg.stat.deviation = Math.sqrt( varianz / msg.stat.count );
99
+ msg.stat.variation = msg.stat.deviation / msg.stat.average;
100
+ node.status({fill:"green",shape:"dot",text:`${msg.stat.count} / ${msg.stat.deviation.toPrecision(4)}`});
101
+ send( msg );
57
102
  }
58
- msg.stat.average = sum/msg.stat.count;
59
- let varianz = 0;
60
- for( const value of item )
103
+ else
61
104
  {
62
- varianz += ( value.value - msg.stat.average ) ** 2;
105
+ node.status({fill:"gray",shape:"dot",text:"to less data"});
63
106
  }
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} / ${msg.stat.deviation.toPrecision(4)}`});
67
- send( msg );
68
107
  }
69
108
  else
70
109
  {
71
- node.status({fill:"gray",shape:"dot",text:"to less data"});
110
+ node.status({fill:"red",shape:"dot",text:"payload is NaN"});
72
111
  }
73
- }
74
- else
75
- {
76
- node.status({fill:"red",shape:"dot",text:"payload is NaN"});
77
- }
112
+ done();
113
+ } );
78
114
  }
79
- done();
80
115
  });
81
116
  }
82
117
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "nodes for simple operations.",
5
5
  "license": "LGPL-2.1",
6
6
  "homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",