@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.
@@ -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.toPrecision(4) };
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} / ${value.toPrecision(4)}`});
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} / ${value.toPrecision(4)}`});
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.toPrecision(4);
116
+ status.text = tools.formatNumber( msg.payload );
116
117
  if( node.filter )
117
118
  {
118
119
  if( msg.payload !== node.last )
@@ -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 sum = 0;
84
+ let sumV = 0;
85
+ let sumT = 0;
84
86
  for( const value of item )
85
87
  {
86
- sum += value.value;
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 = sum/msg.stat.count;
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.toPrecision(4)}`});
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "3.6.0",
3
+ "version": "3.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",
package/tools.js CHANGED
@@ -77,3 +77,8 @@ exports.distance = function(a,b)
77
77
  {
78
78
  return a>b ? a-b : b-a;
79
79
  }
80
+
81
+ exports.formatNumber = function(value)
82
+ {
83
+ return value > 5000 ? value.toFixed( 0 ) : value.toPrecision( 4 );
84
+ }