@mschaeffler/node-red-logic 0.6.1 → 0.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/logic_bool.html CHANGED
@@ -60,8 +60,8 @@
60
60
  <tr> <td></td> <td>true</td> <td>true</td> </tr>
61
61
  <tr> <td></td> <td>0</td> <td>false</td> </tr>
62
62
  <tr> <td></td> <td>1</td> <td>true</td> </tr>
63
- <tr> <td></td> <td>on</td> <td>false</td> </tr>
64
- <tr> <td></td> <td>off</td> <td>true</td> </tr>
63
+ <tr> <td></td> <td>off</td> <td>false</td> </tr>
64
+ <tr> <td></td> <td>on</td> <td>true</td> </tr>
65
65
  </table>
66
66
 
67
67
  <h3>Input</h3>
package/math_reduce.html CHANGED
@@ -45,19 +45,6 @@
45
45
  types:["msg"],
46
46
  typeField: "#node-input-property-type"
47
47
  });
48
- /*
49
- $("#node-input-algo").typedInput({
50
- types:[{
51
- value:"algo",
52
- options: [
53
- { value: "add", label: "Addition"},
54
- { value: "mean", label: "Mean Value"},
55
- { value: "prod", label: "Product"},
56
- { value: "min", label: "Minimum" },
57
- { value: "max", label: "Maximum" }
58
- ]
59
- }]
60
- })*/
61
48
  }
62
49
  });
63
50
  </script>
@@ -0,0 +1,103 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('statistics',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload", required:true},
8
+ deltaTime:{value:"60", required:true, validate:function(v){
9
+ return v!=='' && !isNaN(v) && Number(v)>0;}
10
+ },
11
+ minData:{value:"1", required:true, validate:function(v){
12
+ return v!=='' && !isNaN(v) && Number(v)>0;}
13
+ }
14
+ },
15
+ inputs:1,
16
+ outputs:1,
17
+ icon:"font-awesome/fa-arrows-alt",
18
+ label: function() {
19
+ return this.name||"statistics";
20
+ },
21
+ labelStyle: function() {
22
+ return this.name?"node_label_italic":"";
23
+ },
24
+ inputLabels: 'input',
25
+ outputLabels: 'output',
26
+ oneditprepare: function() {
27
+ $("#node-input-property").typedInput({
28
+ type:"msg",
29
+ types:["msg"],
30
+ typeField: "#node-input-property-type"
31
+ });
32
+ }
33
+ });
34
+ </script>
35
+
36
+ <script type="text/html" data-template-name="statistics">
37
+ <div class="form-row">
38
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
39
+ <input type="text" id="node-input-name" placeholder="Name">
40
+ </div>
41
+ <div class="form-row">
42
+ <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
43
+ <input type="text" id="node-input-property">
44
+ <input type="hidden" id="node-input-property-type">
45
+ </div>
46
+ <div class="form-row">
47
+ <label for="node-input-minMean"><i class="fa fa-hourglass-o"></i> Zeitspanne</label>
48
+ <input type="text" id="node-input-deltaTime">
49
+ </div>
50
+ <div class="form-row">
51
+ <label for="node-input-minData"><i class="fa fa-check-square-o "></i> min. Data</label>
52
+ <input type="text" id="node-input-minData">
53
+ </div>
54
+ </script>
55
+
56
+ <script type="text/html" data-help-name="statistics">
57
+
58
+ <p>Calculate statistical values of one or more data streams.</p>
59
+ <p>Each stream can be debounced by arithmatic mean.</p>
60
+ <p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
61
+
62
+ <h3>Input</h3>
63
+
64
+ <p>The different inputs are differentiated by topics.</p>
65
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
66
+
67
+ <dl class="message-properties">
68
+ <dt>topic <span class="property-type">string</span></dt>
69
+ <dd> name of the input channel.</dd>
70
+ <dt>payload <span class="property-type">number</span></dt>
71
+ <dd> input value for <code>topic</code>.</dd>
72
+ </dl>
73
+
74
+ <h3>Output</h3>
75
+
76
+ <dl class="message-properties">
77
+ <dt>payload <span class="property-type">number</span></dt>
78
+ <dd> result of combining of all input topics.</dd>
79
+ <dt>stats.count <span class="property-type">number</span></dt>
80
+ <dd> number of data elements.</dd>
81
+ <dt>stats.min <span class="property-type">number</span></dt>
82
+ <dd> minimal value.</dd>
83
+ <dt>stats.max <span class="property-type">number</span></dt>
84
+ <dd> maximal value.</dd>
85
+ <dt>stats.average <span class="property-type">number</span></dt>
86
+ <dd> average value.</dd>
87
+ <dt>stats.deviation <span class="property-type">number</span></dt>
88
+ <dd> standard deviation.</dd>
89
+ <dt>stats.variation <span class="property-type">number</span></dt>
90
+ <dd> coefficient of variation.</dd>
91
+ </dl>
92
+
93
+ <h3>Parameter</h3>
94
+
95
+ <dl class="message-properties">
96
+ <dt>Property <span class="property-type">string</span></dt>
97
+ <dd> defines the message property to be used as payload.</dd>
98
+ <dt>delta time <span class="property-type">number</span></dt>
99
+ <dd> time frame to collect the data for the analysis.</dd>
100
+ <dt>min. Data <span class="property-type">number</span></dt>
101
+ <dd> min. amount of data points to generate an output.</dd>
102
+ </dl>
103
+ </script>
@@ -0,0 +1,83 @@
1
+ module.exports = function(RED) {
2
+
3
+ function StatsNode(config) {
4
+ RED.nodes.createNode(this,config);
5
+ //this.config = config;
6
+ var node = this;
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
+
12
+ node.on('input', function(msg,send,done) {
13
+ if( msg.invalid )
14
+ {
15
+ return null;
16
+ }
17
+ if( msg.reset || msg.topic==="init" )
18
+ {
19
+ context.set( "data", {} );
20
+ node.status( "" );
21
+ }
22
+ else
23
+ {
24
+ const now = Date.now();
25
+ const payload = Number( RED.util.getMessageProperty( msg, node.property ) );
26
+ if( ! isNaN( payload ) )
27
+ {
28
+ let data = context.get( "data" ) ?? {};
29
+ let item = data[msg.topic] ?? [];
30
+ item.push( { time:now, value:payload } );
31
+ while( item[0].time < now - this.deltaTime )
32
+ {
33
+ item.shift();
34
+ }
35
+ data[msg.topic] = item;
36
+ context.set( "data", data );
37
+
38
+ if( item.length >= this.minData )
39
+ {
40
+ msg.stat = {
41
+ count: item.length,
42
+ min: Number.MAX_SAFE_INTEGER,
43
+ max: Number.MIN_SAFE_INTEGER };
44
+ let sum = 0;
45
+ for( const value of item )
46
+ {
47
+ sum += value.value;
48
+ if( value.value < msg.stat.min )
49
+ {
50
+ msg.stat.min = value.value;
51
+ }
52
+ if( value.value > msg.stat.max )
53
+ {
54
+ msg.stat.max = value.value;
55
+ }
56
+ }
57
+ msg.stat.average = sum/msg.stat.count;
58
+ let varianz = 0;
59
+ for( const value of item )
60
+ {
61
+ varianz += ( value.value - msg.stat.average ) ** 2;
62
+ }
63
+ msg.stat.deviation = Math.sqrt( varianz / msg.stat.count );
64
+ msg.stat.variation = msg.stat.deviation / msg.stat.average;
65
+ node.status({fill:"green",shape:"dot",text:msg.stat.count});
66
+ send( msg );
67
+ }
68
+ else
69
+ {
70
+ node.status({fill:"gray",shape:"dot",text:"to less data"});
71
+ }
72
+ }
73
+ else
74
+ {
75
+ node.status({fill:"red",shape:"dot",text:"payload is NaN"});
76
+ }
77
+ }
78
+ done();
79
+ });
80
+ }
81
+
82
+ RED.nodes.registerType("statistics",StatsNode);
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "0.6.1",
3
+ "version": "0.7.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",
@@ -25,7 +25,8 @@
25
25
  "reduce":"math_reduce.js",
26
26
  "fallingEdge":"math_falling.js",
27
27
  "raisingEdge":"math_raising.js",
28
- "hysteresisEdge":"math_hysteresis.js"
28
+ "hysteresisEdge":"math_hysteresis.js",
29
+ "statistics":"math_statistics.js"
29
30
  }
30
31
  },
31
32
  "author": {