@mschaeffler/node-red-logic 0.8.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/logic_not.html ADDED
@@ -0,0 +1,97 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('not',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ showState:{value:false},
9
+ filter:{value:false}
10
+ },
11
+ inputs:1,
12
+ outputs:1,
13
+ icon: "font-awesome/fa-exclamation",
14
+ label: function() {
15
+ return this.name||"not";
16
+ },
17
+ labelStyle: function() {
18
+ return this.name?"node_label_italic":"";
19
+ },
20
+ paletteLabel: "not",
21
+ inputLabels: 'input',
22
+ outputLabels: 'boolean',
23
+ oneditprepare: function() {
24
+ $("#node-input-property").typedInput({
25
+ type:"msg",
26
+ types:["msg"],
27
+ typeField: "#node-input-property-type"
28
+ })
29
+ }
30
+ });
31
+ </script>
32
+
33
+ <script type="text/html" data-template-name="not">
34
+ <div class="form-row">
35
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
36
+ <input type="text" id="node-input-name" placeholder="Name">
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
40
+ <input type="text" id="node-input-property">
41
+ <input type="hidden" id="node-input-property-type">
42
+ </div>
43
+ <div class="form-row">
44
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
45
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
46
+ </div>
47
+ <div class="form-row">
48
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
49
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
50
+ </div>
51
+ </script>
52
+
53
+ <script type="text/html" data-help-name="not">
54
+
55
+ <p>Inverts the boolean value.</p>
56
+ <p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
57
+
58
+ <table>
59
+ <tr> <th>type</th> <th>input</th> <th>output</th> </tr>
60
+ <tr> <td>boolean</td> <td>false</td> <td>false</td> </tr>
61
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
62
+ <tr> <td>number</td> <td>0</td> <td>false</td> </tr>
63
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
64
+ <tr> <td>string</td> <td>false</td> <td>false</td> </tr>
65
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
66
+ <tr> <td></td> <td>0</td> <td>false</td> </tr>
67
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
68
+ <tr> <td></td> <td>off</td> <td>false</td> </tr>
69
+ <tr> <td></td> <td>on</td> <td>true</td> </tr>
70
+ </table>
71
+
72
+ <h3>Input</h3>
73
+
74
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
75
+
76
+ <dl class="message-properties">
77
+ <dt>payload <span class="property-type"></span></dt>
78
+ <dd> input value.</dd>
79
+ </dl>
80
+
81
+ <h3>Output</h3>
82
+
83
+ <dl class="message-properties">
84
+ <dt>payload <span class="property-type">boolean</span></dt>
85
+ <dd> bool value of payload.</dd>
86
+ </dl>
87
+
88
+ <h3>Parameter</h3>
89
+
90
+ <dl class="message-properties">
91
+ <dt>Property <span class="property-type">string</span></dt>
92
+ <dd> defines the message property to be used as payload.</dd>
93
+ <dt>Status <span class="property-type">boolean</span></dt>
94
+ <dd> shows the actual value as a node status.</dd>
95
+ </dl>
96
+
97
+ </script>
package/logic_not.js ADDED
@@ -0,0 +1,51 @@
1
+ module.exports = function(RED) {
2
+ var tools = require('./tools.js');
3
+
4
+ function NotNode(config) {
5
+ RED.nodes.createNode(this,config);
6
+ //this.config = config;
7
+ var node = this;
8
+ this.property = config.property || "payload";
9
+ this.showState = config.showState;
10
+ this.filter = Boolean( config.filter );
11
+ this.last = null;
12
+
13
+ node.on('input', function(msg,send,done) {
14
+ if( msg.invalid )
15
+ {
16
+ done();
17
+ return null;
18
+ }
19
+ msg.payload = ! tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
20
+ let status = { text:msg.payload ?? "error" };
21
+ if( msg.payload !== null )
22
+ {
23
+ if( node.filter )
24
+ {
25
+ status.shape = "dot";
26
+ if( msg.payload !== node.last )
27
+ {
28
+ node.last = msg.payload;
29
+ status.fill = "green";
30
+ send( msg );
31
+ }
32
+ else
33
+ {
34
+ status.fill = "gray";
35
+ }
36
+ }
37
+ else
38
+ {
39
+ send( msg );
40
+ }
41
+ }
42
+ if( node.showState )
43
+ {
44
+ node.status( status );
45
+ }
46
+ done();
47
+ });
48
+ }
49
+
50
+ RED.nodes.registerType("not",NotNode);
51
+ }
@@ -0,0 +1,83 @@
1
+ #<script type="text/javascript">
2
+ RED.nodes.registerType('negate',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ showState:{value:false},
9
+ filter:{value:false}
10
+ },
11
+ inputs:1,
12
+ outputs:1,
13
+ icon: "font-awesome/fa-minus",
14
+ label: function() {
15
+ return this.name||"minus";
16
+ },
17
+ labelStyle: function() {
18
+ return this.name?"node_label_italic":"";
19
+ },
20
+ paletteLabel: "minus",
21
+ inputLabels: 'input',
22
+ outputLabels: 'number',
23
+ oneditprepare: function() {
24
+ $("#node-input-property").typedInput({
25
+ type:"msg",
26
+ types:["msg"],
27
+ typeField: "#node-input-property-type"
28
+ })
29
+ }
30
+ });
31
+ </script>
32
+
33
+ <script type="text/html" data-template-name="negate">
34
+ <div class="form-row">
35
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
36
+ <input type="text" id="node-input-name" placeholder="Name">
37
+ </div>
38
+ <div class="form-row">
39
+ <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
40
+ <input type="text" id="node-input-property">
41
+ <input type="hidden" id="node-input-property-type">
42
+ </div>
43
+ <div class="form-row">
44
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
45
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
46
+ </div>
47
+ <div class="form-row">
48
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
49
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
50
+ </div>
51
+ </script>
52
+
53
+ <script type="text/html" data-help-name="negate">
54
+
55
+ <p>negates the payload.</p>
56
+ <p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
57
+
58
+ <h3>Input</h3>
59
+
60
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
61
+
62
+ <dl class="message-properties">
63
+ <dt>payload <span class="property-type"></span></dt>
64
+ <dd> input value.</dd>
65
+ </dl>
66
+
67
+ <h3>Output</h3>
68
+
69
+ <dl class="message-properties">
70
+ <dt>payload <span class="property-type">number</span></dt>
71
+ <dd> number value of payload.</dd>
72
+ </dl>
73
+
74
+ <h3>Parameter</h3>
75
+
76
+ <dl class="message-properties">
77
+ <dt>Property <span class="property-type">string</span></dt>
78
+ <dd> defines the message property to be used as payload.</dd>
79
+ <dt>Status <span class="property-type">boolean</span></dt>
80
+ <dd> shows the actual value as a node status.</dd>
81
+ </dl>
82
+
83
+ </script>
package/math_minus.js ADDED
@@ -0,0 +1,54 @@
1
+ module.exports = function(RED) {
2
+
3
+ function MinusNode(config) {
4
+ RED.nodes.createNode(this,config);
5
+ //this.config = config;
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;
11
+
12
+ node.on('input', function(msg,send,done) {
13
+ if( msg.invalid )
14
+ {
15
+ done();
16
+ return null;
17
+ }
18
+ msg.payload = - Number( RED.util.getMessageProperty( msg, node.property ) );
19
+ let status = { text:msg.payload };
20
+ if( ! isNaN( msg.payload ) )
21
+ {
22
+ if( node.filter )
23
+ {
24
+ status.shape = "dot";
25
+ if( msg.payload !== node.last )
26
+ {
27
+ node.last = msg.payload;
28
+ status.fill = "green";
29
+ send( msg );
30
+ }
31
+ else
32
+ {
33
+ status.fill = "gray";
34
+ }
35
+ }
36
+ else
37
+ {
38
+ send( msg );
39
+ }
40
+ }
41
+ else
42
+ {
43
+ status.text = "not a Number";
44
+ }
45
+ if( node.showState )
46
+ {
47
+ node.status( status );
48
+ }
49
+ done();
50
+ });
51
+ }
52
+
53
+ RED.nodes.registerType("negate",MinusNode);
54
+ }
@@ -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">
@@ -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.8.0",
3
+ "version": "1.0.0",
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",
@@ -19,9 +19,11 @@
19
19
  "nodes": {
20
20
  "counter":"counter.js",
21
21
  "tobool":"logic_bool.js",
22
+ "not":"logic_not.js",
22
23
  "or":"logic_or.js",
23
24
  "and":"logic_and.js",
24
25
  "tonumber":"math_number.js",
26
+ "negate":"math_minus.js",
25
27
  "reduce":"math_reduce.js",
26
28
  "fallingEdge":"math_falling.js",
27
29
  "raisingEdge":"math_raising.js",