node-red-contrib-prib-functions 0.20.4 → 0.22.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/matrix/matrix.js CHANGED
@@ -1,8 +1,54 @@
1
1
  const logger = new (require("node-red-contrib-logger"))("Matrix");
2
2
  logger.sendInfo("Copyright 2022 Jaroslav Peter Prib");
3
3
 
4
+ const typedArrays= {Array:Array,Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,
5
+ Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,
6
+ Float64Array:Float64Array,BigInt64Array:BigInt64Array,BigUint64Array:BigUint64Array}
7
+
8
+ Object.keys(typedArrays).map(t=>typedArrays[t]).forEach(object=>{
9
+ if(object.prototype.setAll==null)
10
+ Object.defineProperty(object.prototype, "setAll", {
11
+ value(call,size=this.length) {
12
+ let i=size
13
+ while(i) this[--i]=call();
14
+ return this;
15
+ },
16
+ writable: true,
17
+ configurable: true
18
+ })
19
+ if(object.prototype.setOne==null)
20
+ Object.defineProperty(object.prototype, "setOne", {
21
+ value(call,size=this.length) {
22
+ let i=size
23
+ while(i) this[--i]=1;
24
+ return this;
25
+ },
26
+ writable: true,
27
+ configurable: true
28
+ })
29
+ if(object.prototype.setZero==null)
30
+ Object.defineProperty(object.prototype, "setZero", {
31
+ value(call,size=this.length) {
32
+ let i=size
33
+ while(i) this[--i]=0;
34
+ return this;
35
+ },
36
+ writable: true,
37
+ configurable: true
38
+ })
39
+ if(object.prototype.setRandom==null)
40
+ Object.defineProperty(object.prototype, "setRandom", {
41
+ value(size=this.length) {
42
+ return this.setAll(Math.random,size)
43
+ },
44
+ writable: true,
45
+ configurable: true
46
+ })
47
+ })
48
+
4
49
  const zeroFloat32Value=1e-6;
5
- function Matrix(rows,columns,fill) {
50
+ function Matrix(rows,columns,fill,dataType="Float32Array") {
51
+ this.dataType=dataType
6
52
  if(rows instanceof Array) {
7
53
  this.rows=rows.length;
8
54
  if(this.rows==0) throw Error("expected rows")
@@ -15,11 +61,19 @@ function Matrix(rows,columns,fill) {
15
61
  }
16
62
  if(rows instanceof Object) {
17
63
  Object.assign(this,rows);
64
+ this.dataType??="Float32Array"
18
65
  } else {
19
66
  this.rows=rows;
20
67
  this.columns=columns;
21
68
  }
69
+ if(this.columns) this.columns=parseInt(this.columns);
70
+ if(this.rows)this.rows=parseInt(this.rows)
71
+ if(this.rowsMax) this.rowsMax=parseInt(this.rowsMax)
22
72
  this.createVector();
73
+ if(fill) {
74
+ if(fill instanceof Function) this.setAll(fill)
75
+ else this.vector.set(fill)
76
+ }
23
77
  return this;
24
78
  }
25
79
  Matrix.prototype.add=function(matrix){
@@ -52,7 +106,7 @@ Matrix.prototype.addRow2Row=function(rowA,rowB,factor=1,startColumn=0,endColumn=
52
106
  return this;
53
107
  }
54
108
  Matrix.prototype.backwardSubstitution=function(){
55
- const vector=new Float32Array(this.rows);
109
+ const vector=new typedArrays[this.dataType](this.rows);
56
110
  for(let row=this.rows-1; row>=0; row--) {
57
111
  vector[row] = this.get(row,this.rows);
58
112
  for(let column=row+1; column<this.rows; column++) {
@@ -101,15 +155,17 @@ Matrix.prototype.createVector=function(){
101
155
  this.sizeMax=this.rowsMax*this.columns;
102
156
  }
103
157
  if(this.columns==null) throw Error("columns not specified")
104
- this.size=this.rows*this.columns
105
- if(this.sizeMax==null) this.sizeMax=this.size
106
158
  } else {
107
159
  if(this.columns==null) throw Error("columns not specified")
160
+ if(this.columns==0) throw Error("columns = 0")
108
161
  if(this.rows==null){
109
162
  this.rows=0;
110
163
  }
111
164
  }
112
- this.vector=new Float32Array(this.sizeMax);
165
+ this.size=this.rows*this.columns
166
+ if(this.sizeMax==null) this.sizeMax=this.size
167
+ if(this.sizeMax==null) throw Error("max size not specified or calculated")
168
+ this.vector=new typedArrays[this.dataType](this.sizeMax);
113
169
  return this;
114
170
  }
115
171
  Matrix.prototype.divideCell=function(row,column,value){
@@ -472,7 +528,6 @@ Matrix.prototype.multiplyRow=function(row,factor){
472
528
  return this;
473
529
  }
474
530
  Matrix.prototype.norm=function(){
475
-
476
531
  return Math.sqrt(this.reduce((aggregate,cell)=>aggregate+cell*cell))
477
532
  }
478
533
  Matrix.prototype.reduce=function(call,aggregate=0){
@@ -560,17 +615,48 @@ Matrix.prototype.set=function(row,column,value){
560
615
  this.vector[this.getIndex(row,column)]=value;
561
616
  return this;
562
617
  }
618
+ Matrix.prototype.setAll=function(call){
619
+ for(let offset=0,row=0;row<this.rows;row++) {
620
+ for(let column=0;column<this.columns;column++) {
621
+ this.vector[offset]=call.apply(this,[row,column,this.vector[offset],this.vector,offset,this]);
622
+ offset++
623
+ }
624
+ }
625
+ this.rows=this.rowsMax
626
+ this.size=this.sizeMax
627
+ return this;
628
+ }
563
629
  Matrix.prototype.setDeterminant=function(){
564
630
  this.determinant=this.getDeterminantUsingRowEchelonForm();
565
631
  return this.determinant;
566
632
  }
633
+ Matrix.prototype.setIdentity=function(){
634
+ if(this.columns!=this.rowsMax) throw Error("number of columns not equal rows")
635
+ this.setZero()
636
+ for(let offset=0;offset<this.size;offset+=this.columns+1) this.vector[offset]=1;
637
+ return this;
638
+ }
639
+ Matrix.prototype.setWithFunction=function(f){
640
+ this.vector[f](this.sizeMax)
641
+ this.rows=this.rowsMax
642
+ this.size=this.sizeMax;
643
+ return this;
644
+ }
645
+ Matrix.prototype.setOne=function(){
646
+ return this.setWithFunction("setOne")
647
+ }
648
+ Matrix.prototype.setRandom=function(){
649
+ return this.setWithFunction("setRandom")
650
+ }
567
651
  Matrix.prototype.setRow=function(vector,row){
568
652
  this.vector.set(vector, row*this.columns);
569
653
  return this;
570
654
  }
571
655
  Matrix.prototype.setRunningSum=function(){
572
656
  this.forEachCellLowerTriangle((cell,row,column,vector,offset,object)=>vector[offset]=1);
573
- return this;
657
+ }
658
+ Matrix.prototype.setZero=function(){
659
+ return this.setWithFunction("setZero")
574
660
  }
575
661
  Matrix.prototype.substract=function(matrix){
576
662
  this.forEachCellPairSet(matrix,(cellA,cellB)=>cellA-cellB)
@@ -610,5 +696,4 @@ Matrix.prototype.transpose=function(){
610
696
  this.forEachCell((cell,row,column)=>matrix.set(column,row,cell))
611
697
  return matrix;
612
698
  }
613
-
614
699
  module.exports=Matrix;
@@ -7,18 +7,20 @@
7
7
  name: {value:null},
8
8
  action: {value: "create",required:true},
9
9
  args: {value:[]},
10
- arg: {value:null},"arg-type": {value:"msg"},
11
10
  call:{value:null},
12
- column: {value:null},"column-type": {value:"num"},
13
- columns: {value:null},"columns-type": {value:"num"},
11
+ column: {value:2},"column-type": {value:"num"},
12
+ columns: {value:2},"columns-type": {value:"num"},
13
+ dataType: {value:"Float32Array"},"columns-type": {value:"Float32Array"},
14
14
  end: {value:null},"end-type": {value:"num"},
15
15
  factor: {value:null},"factor-type": {value:"num"},
16
+ initialState:{value:"setZero"},
16
17
  matrix: {value:"payload"},"matrix-type": {value:"msg"},
17
18
  precision: {value:3},"precision-type": {value:"num"},
18
19
  row: {value:3},"row-type": {value:"num"},
19
20
  rows: {value:3},"rows-type": {value:"num"},
20
21
  rowTarget: {value:null},"rowTarget-type": {value:"num"},
21
22
  source: {value:"_matrix"},"source-type": {value:"msg"},
23
+ sourceArray: {value:"payload"},"sourceArray-type": {value:"msg,json,flow,global"},
22
24
  start: {value:null},"start-type": {value:"num"},
23
25
  target: {value:"_matrix"},"target-type": {value:"msg"},
24
26
  value: {value:"payload"},"value-type": {value:"msg"},
@@ -35,70 +37,70 @@
35
37
  return this.name || ("Matrix "+this.action||"*** new ***");
36
38
  },
37
39
  oneditprepare: function() {
40
+ console.log("+++")
38
41
  const node=this;
39
42
  node.properties=[];
40
43
  node.editors=[];
41
44
  const actions={
42
- define:{label:"Define",show:["target"],args:["rows","columns"]},
43
- defineEmpty:{label:"Define Empty",show:["target"],args:["rows","columns"]},
44
- create:{label:"Create",show:["target"],args:[]},
45
- createLike:{label:"Create Like",show:["source","target"],args:[]},
46
- clone:{label:"Clone",show:["source","target"],args:[]},
47
45
  add:{label:"Add",show:["source"],args:["matrix"]},
48
46
  addRow:{label:"Add Row",show:["source"],args:["row","vector"]},
49
47
  addRow2Row:{label:"Add Row to Row",show:["source"],args:["row","target","factor","start","end"]},
50
48
  addCell:{label:"Add to Cell",show:["source"],args:["row","column","value"]},
51
- subtractCell:{label:"Subtract Cell",show:["source","target"],args:["row","column","value"]},
52
- multiple:{label:"Multiple",show:["source","target"],args:[]},
53
- multipleCell:{label:"Multiple Cell",show:["source","target"],args:["rows","columns","value"]},
54
- divideCell:{label:"Divide Cell",show:["source"],args:["rows","columns","value"]},
55
- divideRow:{label:"Divide Row",show:["source"],args:["row","factor","start","end"]},
56
- transpose:{label:"Transpose",show:["source","target"],args:[]},
57
- getAdjoint:{label:"Adjoint",show:["source","target"],args:[]},
58
- getCofactor:{label:"Cofactor",show:["source","target"],args:[]},
59
- getComplementMinor:{label:"Complement Minor",show:["source","target"],args:[]},
60
- getIdentity:{label:"Identity",show:["source","target"],args:[]},
61
- getInverse:{label:"Inverse",show:["source","target"],args:[]},
62
- getInverseAdjointMethod:{label:"Inverse (Adjoint Method)",show:["source","target"],args:[]},
63
- getInverseGaussJordan:{label:"Inverse (Gauss Jordan Method)",show:["source","target"],args:[]},
64
- norm:{label:"Norm",show:["source","target"],args:[]},
65
- getDeterminant:{label:"Determinant",show:["source","target"],args:[]},
66
- getDeterminantUsingCofactor:{label:"Determinant (Cofactor)",show:["source","target"],args:[]},
67
- getDeterminantUsingCofactor:{label:"Determinant (Row Echelon Form)",show:["source","target"],args:[]},
68
49
  backwardSubstitution:{label:"Backward Substitution",show:["source"],args:[]},
69
- forwardElimination:{label:"Forward Elimination",show:["source"],args:[]},
70
- gaussianElimination:{label:"Gaussian Elimination",show:["source"],args:[]},
71
- reducedRowEchelonForm:{label:"Reduced Row EchelonForm",show:["source"],args:[]},
72
- rowEchelonForm:{label:"Row Echelon Form",show:["source"],args:[]},
73
- equalsNearly:{label:"Nearly Equals",show:["source"],args:[]},
74
- testIsSquare:{label:"Is Square",show:["source"],args:[]},
75
- get:{label:"Get Cell",show:["source","target"],args:[]},
76
- sumRow:{label:"Sum Row",show:["source","target"],args:[]},
77
- swapRows:{label:"Swap Rows",show:["source"],args:[]},
78
- toArray:{label:"To Array Object",show:["source","target"],args:[]},
79
- runningSum:{label:"Running Sum",show:["source","target"],args:[]},
80
- getVandermonde:{label:"Vandermonde",show:["target"],args:["vector","columns"]},
81
- create:{label:"Create",show:[,"target"],args:["rows","columns"]},
50
+ create:{label:"Create", show:["target"],args:["initialState","rows","columns","dataType"]},
51
+ createLike:{label:"Create Like",show:["source","target"],args:[]},
52
+ clone:{label:"Clone",show:["source","target"],args:[]},
82
53
  createForEachCellPairSet:{label:"Create Pair Set Cells",show:["source","target"],args:["matrix","call"],default:{call:"(baseCellValue,matrixCellValue)=>{}"}},
54
+ define:{label:"Define",show:["target"],args:["rows","columns","dataType"]},
55
+ defineEmpty:{label:"Define Empty",show:["target"],args:["rows","columns","dataType"]},
56
+ divideCell:{label:"Divide Cell",show:["source"],args:["rows","columns","value"]},
57
+ divideRow:{label:"Divide Row",show:["source"],args:["row","factor","start","end"]},
58
+ equalsNearly:{label:"Nearly Equals",show:["source"],args:[]},
59
+ fillArray:{label:"Fill",show:["source"],args:["matrix"]},
60
+ findColumnRow:{label:"Find in Column",show:["source"],args:["column","call","start","end"],default:{call:"()=>{}"}},
83
61
  findRowColumn:{label:"Find in Row",show:["source"],args:["row","call","start","end"],default:{call:"(value,row,column,offset,vector)=>true"}},
84
62
  forRowCells:{label:"Row Cells",show:["source"],args:["row","call","start","end"],default:{call:"()=>{}"}},
85
- fillArray:{label:"fill",show:["source"],args:["matrix"]},
86
- findColumnRow:{label:"Find in Column",show:["source"],args:["column","call","start","end"],default:{call:"()=>{}"}},
87
63
  forColumnCells:{label:"Column Cells",show:["source"],args:["column","call","start","end"],default:{call:"()=>{}"}},
88
64
  forEachCell:{label:"For Each Cell",show:["source"],args:["call"],default:{call:"()=>{}"}},
89
65
  forEachRow:{label:"For Each Row",show:["source"],args:["call"],default:{call:"()=>{}"}},
90
66
  forEachCellPairSet:{label:"For Each Cell Pair Set",show:["source"],args:["matrix","call"],default:{call:"()=>{}"}},
67
+ forwardElimination:{label:"Forward Elimination",show:["source"],args:[]},
68
+ gaussianElimination:{label:"Gaussian Elimination",show:["source"],args:[]},
69
+ get:{label:"Get Cell",show:["source","target"],args:[]},
70
+ getAdjoint:{label:"Adjoint",show:["source","target"],args:[]},
71
+ getCofactor:{label:"Cofactor",show:["source","target"],args:[]},
72
+ getComplementMinor:{label:"Complement Minor",show:["source","target"],args:[]},
73
+ getDeterminant:{label:"Determinant",show:["source","target"],args:[]},
74
+ getDeterminantUsingCofactor:{label:"Determinant (Cofactor)",show:["source","target"],args:[]},
75
+ getDeterminantUsingCofactor:{label:"Determinant (Row Echelon Form)",show:["source","target"],args:[]},
76
+ getIdentity:{label:"Identity",show:["source","target"],args:[]},
77
+ getInverse:{label:"Inverse",show:["source","target"],args:[]},
78
+ getInverseAdjointMethod:{label:"Inverse (Adjoint Method)",show:["source","target"],args:[]},
79
+ getInverseGaussJordan:{label:"Inverse (Gauss Jordan Method)",show:["source","target"],args:[]},
91
80
  getIndex:{label:"Get Vector Offset",show:["source","target"],args:["row","column"]},
92
- getZeroed:{label:"Get Zeroed",show:["source","target"],args:["row","column"]},
93
- getMatrix:{label:"get Sub Matrix",show:["source","target"],args:["row","column","rows","columns"]},
81
+ getMatrix:{label:"Get Sub Matrix",show:["source","target"],args:["row","column","rows","columns"]},
94
82
  getRow:{label:"Get Row",show:["source","target"],args:["row"]},
83
+ getVandermonde:{label:"Vandermonde",show:["target"],args:["vector","columns"]},
84
+ getZeroed:{label:"Get Zeroed",show:["source","target"],args:["row","column"]},
95
85
  maxAbsColumn:{label:"Column Maximum Absolute",show:["source","target"],args:["column","start"]},
96
86
  maxColumn:{label:"Column Max",show:["source","target"],args:["column","start"]},
87
+ multiple:{label:"Multiple",show:["source","target"],args:[]},
88
+ multipleCell:{label:"Multiple Cell",show:["source","target"],args:["rows","columns","value"]},
97
89
  multiplyRow:{label:"Multiply Row",show:["source"],args:["row","factor"]},
90
+ norm:{label:"Norm",show:["source","target"],args:[]},
98
91
  reduceRow:{label:"Reduce Row",show:["source","target"],args:["row","call","value"],default:{call:"(agregatevalue,cellValue,row,column)=>agregatevalue+cellValue"}},
92
+ reduce:{label:"Reduce Cells",show:["source","target"],args:["call","value"],default:{call:"()=>{}"}},
93
+ reducedRowEchelonForm:{label:"Reduced Row EchelonForm",show:["source"],args:[]},
94
+ rowEchelonForm:{label:"Row Echelon Form",show:["source"],args:[]},
95
+ runningSum:{label:"Running Sum",show:["source","target"],args:[]},
99
96
  set:{label:"Set Cell",show:["source"],args:["row","column","value"]},
100
97
  setRow:{label:"Set Row",show:["source"],args:["vector","row"]},
101
- reduce:{label:"Reduce Cells",show:["source","target"],args:["call","value"],default:{call:"()=>{}"}}
98
+ subtractCell:{label:"Subtract Cell",show:["source","target"],args:["row","column","value"]},
99
+ sumRow:{label:"Sum Row",show:["source","target"],args:[]},
100
+ swapRows:{label:"Swap Rows",show:["source"],args:[]},
101
+ testIsSquare:{label:"Is Square",show:["source"],args:[]},
102
+ toArray:{label:"To Array Object",show:["source","target"],args:[]},
103
+ transpose:{label:"Transpose",show:["source","target"],args:[]}
102
104
  };
103
105
  const baseDiv=$("#node-inputDynamicBase");
104
106
  function defineProperty(property,...types) {
@@ -118,16 +120,46 @@
118
120
  const inputNode=$('<input type="text" id="node-input-'+property.name+'"/>').val(node[property.name]);
119
121
  const typeNode=$('<input type="hidden" id="node-input-'+property.name+'-type"/>');
120
122
  element.append([inputNode,typeNode]);
121
- const typeValue=node[property.name+"-type"];
122
- if(typeValue) typeNode.val(typeValue);
123
- $("#node-input-"+property.name).typedInput({
124
- type:typeValue||types[0],
125
- types:types,
126
- typeField: "#node-input-"+property.name+"-type"
127
- });
123
+ if(types[0] instanceof Array) {
124
+ $("#node-input-"+property.name).typedInput({
125
+ type:property.name,
126
+ types:[{value: property.name,
127
+ options: types[0]
128
+ }]})
129
+ } else {
130
+ const typeValue=node[property.name+"-type"];
131
+ if(typeValue) typeNode.val(typeValue);
132
+ $("#node-input-"+property.name).typedInput({
133
+ type:typeValue||types[0],
134
+ types:types,
135
+ typeField: "#node-input-"+property.name+"-type"
136
+ });
137
+ }
128
138
  }
129
139
  }
130
- defineProperty({name:"source" ,label:"Source" ,icon:"crosshairs"},"msg","flow","global");
140
+ defineProperty({name:"initialState",label:"Initially" ,icon:"tag"},[
141
+ { value: "setZero", label: "Zeros"},
142
+ { value: "setRandom", label: "Random Numbers"},
143
+ { value: "setIdentity", label: "Identity"},
144
+ { value: "setOne", label: "all 1"},
145
+ ]);
146
+
147
+ defineProperty({name:"dataType",label:"number Type" ,icon:"tag"},[
148
+ { value: "Float32Array", label: "float32 -3.4e38 to 3.4e38" },
149
+ { value: "Float64Array", label: "double/float64 -1.8e308 to 1.8e308" }, { value: "Int8Array", label: "byte -128 to 122" },
150
+ { value: "Uint8Array", label: "octet 0 to 255" },
151
+ { value: "Uint8ClampedArray", label: "octet clamped 0 to 255" },
152
+ { value: "Int16Array", label: "short -32768 to 32767" },
153
+ { value: "Uint16Array", label: "short unsigned 0 to 65535" },
154
+ { value: "Int32Array", label: " long -2147483648 to 2147483647" },
155
+ { value: "Uint32Array", label: "long unsgined 0 to 4294967295" },
156
+ { value: "BigInt64Array", label: "bigint 2**-263 to 2**263" },
157
+ { value: "BigUint64Array", label: "bigint unsigned 0 to 2**264" },
158
+ ]);
159
+
160
+
161
+
162
+ defineProperty({name:"source" ,label:"Source" ,icon:"crosshairs"},"msg","json","flow","global");
131
163
  defineProperty({name:"arg" ,label:"Argument" ,icon:"tag"},"num","json","msg","flow","global","env");
132
164
  defineProperty({name:"matrix" ,label:"Matrix" ,icon:"th"},"msg","flow","global");
133
165
  defineProperty({name:"target" ,label:"Target" ,icon:"save"},"msg","flow","global");
@@ -145,8 +177,10 @@
145
177
  defineProperty({name:"vector" ,label:"Vector" ,icon:"ellipsis-h"},"json","msg","flow","global");
146
178
  defineProperty({name:"call" ,label:"Call" ,icon:"js",mode:"javascript"},"edit");
147
179
 
148
- const options=Object.keys(actions).reduce((previousValue,property)=>previousValue.concat({value:property,label:actions[property].label}),
149
- []);
180
+ const options=Object.keys(actions)
181
+ .sort((a,b) => actions[a].label<actions[b].label?-1:0)
182
+ .reduce((previousValue,property)=>previousValue.concat({value:property,label:actions[property].label}),
183
+ []);
150
184
  const actionNode=$("#node-input-action");
151
185
  actionNode.typedInput({
152
186
  types: [{
@@ -154,7 +188,7 @@
154
188
  options: options
155
189
  }]
156
190
  });
157
- actionNode.change(function() {
191
+ actionNode.change(function() {
158
192
  action=$(this).val();
159
193
  node.args=[];
160
194
  node.properties.forEach(property=>$(".form-row-http-in-"+property).hide());
@@ -162,7 +196,6 @@
162
196
  node.args=actionDef.args;
163
197
  node.args.forEach(property=>$(".form-row-http-in-"+property).show());
164
198
  actionDef.show.forEach(property=>$(".form-row-http-in-"+property).show());
165
-
166
199
  });
167
200
  },
168
201
  oneditsave: function() {
@@ -23,6 +23,7 @@ function evalInFunction(node,propertyName){
23
23
  const property=node[propertyName];
24
24
  if(property==null) throw Error("no value for "+propertyName);
25
25
  const propertyType=propertyName+"-type";
26
+ if(! (propertyType in node)) return evalFunction(propertyName,"()=>node."+property)
26
27
  switch (node[propertyType]){
27
28
  case "num":
28
29
  case "json":
@@ -86,7 +87,11 @@ module.exports = function (RED) {
86
87
  }
87
88
  node.argFunction=[];
88
89
  node.args.forEach(property=>{
89
- node.argFunction.push(evalInFunction(node,property).bind(this));
90
+ try{
91
+ node.argFunction.push(evalInFunction(node,property).bind(this));
92
+ } catch(ex) {
93
+ throw Error("args "+property+" "+ex.message)
94
+ }
90
95
  })
91
96
  function baseProcess(msg){
92
97
  const sourceIn=node.getSource(msg);
@@ -99,14 +104,15 @@ module.exports = function (RED) {
99
104
  node.setData.apply(node,[result,msg]);
100
105
  }
101
106
  function createProcess(msg){
102
- const sourceIn=node.getSource(msg);
103
- if(sourceIn==null) throw Error("source data not found");
104
- const sourceMatrix=(sourceIn instanceof Matrix?sourceIn.clone():new Matrix(sourceIn));
107
+ if(logger.active) logger.sendInfo({label:"create",arg:{rowsMax:node.row,columns:node.column}});
108
+ const sourceMatrix=new Matrix({rowsMax:node.rows,columns:node.columns,dataType:node.dataType});
109
+ if(!(node.initialState in sourceMatrix)) throw Error("Invalid initial state "+node.initialState);
110
+ sourceMatrix[node.initialState]()
105
111
  node.setData.apply(node,[sourceMatrix,msg]);
106
112
  }
107
113
  function defineProcess(msg){
108
114
  if(logger.active) logger.sendInfo({label:"define",arg:{rows:node.row,columns:node.column}});
109
- const sourceMatrix=new Matrix({rows:node.rows,columns:node.columns});
115
+ const sourceMatrix=new Matrix({rows:node.rows,columns:node.columns,dataType:node.dataType});
110
116
  node.setData.apply(node,[sourceMatrix,msg]);
111
117
  }
112
118
  function defineEmptyProcess(msg){
@@ -152,6 +158,7 @@ module.exports = function (RED) {
152
158
  node.msgProcess(msg);
153
159
  node.send(msg);
154
160
  } catch(ex) {
161
+ error(node,ex,"Invalid "+ex.message)
155
162
  msg.error=ex.message;
156
163
  node.send([null,msg]);
157
164
  if(logger.active) logger.send({label:"error",node:node.id,action:node.action,exception:ex.message,stack:ex.stack});
@@ -44,6 +44,7 @@
44
44
  )
45
45
  } catch(ex) {
46
46
  svgUpdate=false
47
+ if(ex.message.startsWith("element id not found")) return
47
48
  console.error(ex.message + " for "+JSON.stringify(nodeDetails[id]))
48
49
  }
49
50
  }
@@ -79,7 +80,7 @@
79
80
  outputLabels: ["out"],
80
81
  icon: "icons8-heart-monitor-40.png",
81
82
  label: function() {
82
- console.error("*****+++++")
83
+ console.log("*****+++++")
83
84
  if(!nodeSvg.hasOwnProperty(this.id)) {
84
85
  nodeSvg[this.id]={element:document.getElementById(this.id),actions:[{action:"text",x:0 ,y:60 ,children:["Waiting Refresh"]}]}
85
86
  }
@@ -155,7 +155,7 @@ let metrics=[]
155
155
  const nodes=[]
156
156
  function getJson(){
157
157
  return nodes.reduce((p,node)=>{
158
- p[node.id]=node.getSendData(metrics[0])
158
+ p[node.id]=metrics.length?node.getSendData(metrics[0]):null
159
159
  return p;
160
160
  },{})
161
161
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-prib-functions",
3
- "version": "0.20.4",
3
+ "version": "0.22.0",
4
4
  "description": "Node-RED added node functions.",
5
5
  "dependencies": {
6
6
  "avsc": ">=5.7.7",
@@ -38,9 +38,13 @@
38
38
  "adjoint",
39
39
  "append",
40
40
  "analysis",
41
+ "autocorrelation",
42
+ "autocovariance",
41
43
  "average",
42
44
  "avg",
43
45
  "AVRO",
46
+ "arima",
47
+ "ARMIA",
44
48
  "arvo",
45
49
  "backward substitution",
46
50
  "compare",
@@ -448,7 +448,7 @@
448
448
  },
449
449
  "node-red-contrib-prib-functions": {
450
450
  "name": "node-red-contrib-prib-functions",
451
- "version": "0.20.2",
451
+ "version": "0.22.0",
452
452
  "local": true,
453
453
  "user": true,
454
454
  "nodes": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "node-red": {
3
3
  "name": "node-red",
4
- "version": "3.1.11",
4
+ "version": "3.1.14",
5
5
  "local": false,
6
6
  "user": false,
7
7
  "nodes": {
@@ -448,7 +448,7 @@
448
448
  },
449
449
  "node-red-contrib-prib-functions": {
450
450
  "name": "node-red-contrib-prib-functions",
451
- "version": "0.20.2",
451
+ "version": "0.21.0",
452
452
  "local": true,
453
453
  "user": true,
454
454
  "nodes": {