@mschaeffler/node-red-logic 0.9.0 → 1.0.1

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/logic_and.html CHANGED
@@ -92,6 +92,8 @@
92
92
  <dd> defines the message property to be used as payload.</dd>
93
93
  <dt>min. Data <span class="property-type">number</span></dt>
94
94
  <dd> min. amount of topics to generate an output.</dd>
95
+ <dt>Filter <span class="property-type">boolean</span></dt>
96
+ <dd> block sending of unchanged <code>property</code>.</dd>
95
97
  </dl>
96
98
 
97
99
  </script>
package/logic_bool.html CHANGED
@@ -92,6 +92,8 @@
92
92
  <dd> defines the message property to be used as payload.</dd>
93
93
  <dt>Status <span class="property-type">boolean</span></dt>
94
94
  <dd> shows the actual value as a node status.</dd>
95
+ <dt>Filter <span class="property-type">boolean</span></dt>
96
+ <dd> block sending of unchanged <code>property</code>.</dd>
95
97
  </dl>
96
98
 
97
99
  </script>
package/logic_not.html CHANGED
@@ -92,6 +92,8 @@
92
92
  <dd> defines the message property to be used as payload.</dd>
93
93
  <dt>Status <span class="property-type">boolean</span></dt>
94
94
  <dd> shows the actual value as a node status.</dd>
95
+ <dt>Filter <span class="property-type">boolean</span></dt>
96
+ <dd> block sending of unchanged <code>property</code>.</dd>
95
97
  </dl>
96
98
 
97
99
  </script>
package/logic_or.html CHANGED
@@ -92,6 +92,8 @@
92
92
  <dd> defines the message property to be used as payload.</dd>
93
93
  <dt>min. Data <span class="property-type">number</span></dt>
94
94
  <dd> min. amount of topics to generate an output.</dd>
95
+ <dt>Filter <span class="property-type">boolean</span></dt>
96
+ <dd> block sending of unchanged <code>property</code>.</dd>
95
97
  </dl>
96
98
 
97
99
  </script>
package/math_minus.html CHANGED
@@ -78,6 +78,8 @@
78
78
  <dd> defines the message property to be used as payload.</dd>
79
79
  <dt>Status <span class="property-type">boolean</span></dt>
80
80
  <dd> shows the actual value as a node status.</dd>
81
+ <dt>Filter <span class="property-type">boolean</span></dt>
82
+ <dd> block sending of unchanged <code>property</code>.</dd>
81
83
  </dl>
82
84
 
83
85
  </script>
package/math_number.html CHANGED
@@ -78,6 +78,8 @@
78
78
  <dd> defines the message property to be used as payload.</dd>
79
79
  <dt>Status <span class="property-type">boolean</span></dt>
80
80
  <dd> shows the actual value as a node status.</dd>
81
+ <dt>Filter <span class="property-type">boolean</span></dt>
82
+ <dd> block sending of unchanged <code>property</code>.</dd>
81
83
  </dl>
82
84
 
83
85
  </script>
package/math_reduce.html CHANGED
@@ -136,6 +136,8 @@
136
136
  <dd> min. amount of topics to generate an output.</dd>
137
137
  <dt>Algorithm <span class="property-type">string</span></dt>
138
138
  <dd> algorithm to combine the values.</dd>
139
+ <dt>Filter <span class="property-type">boolean</span></dt>
140
+ <dd> block sending of unchanged <code>property</code>.</dd>
139
141
  </dl>
140
142
 
141
143
  <h3>Algorithms</h3>
@@ -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">
@@ -95,9 +100,11 @@
95
100
  <dl class="message-properties">
96
101
  <dt>Property <span class="property-type">string</span></dt>
97
102
  <dd> defines the message property to be used as payload.</dd>
98
- <dt>delta time <span class="property-type">number</span></dt>
103
+ <dt>Delta time <span class="property-type">number</span></dt>
99
104
  <dd> time frame to collect the data for the analysis.</dd>
100
105
  <dt>min. Data <span class="property-type">number</span></dt>
101
106
  <dd> min. amount of data points to generate an output.</dd>
107
+ <dt>Filter <span class="property-type">boolean</span></dt>
108
+ <dd> block sending of unchanged <code>property</code>.</dd>
102
109
  </dl>
103
110
  </script>
@@ -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
- 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 )
42
+ function checkFilter()
47
43
  {
48
- sum += value.value;
49
- if( value.value < msg.stat.min )
44
+ let last = context.get( "last" ) ?? {};
45
+ if( payload !== last[msg.topic] )
50
46
  {
51
- msg.stat.min = value.value;
47
+ last[msg.topic] = payload;
48
+ context.set( "last", last );
49
+ return true;
52
50
  }
53
- if( value.value > msg.stat.max )
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.max = value.value;
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
- msg.stat.average = sum/msg.stat.count;
59
- let varianz = 0;
60
- for( const value of item )
84
+ else
61
85
  {
62
- varianz += ( value.value - msg.stat.average ) ** 2;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "0.9.0",
3
+ "version": "1.0.1",
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",