node-red-contrib-prib-functions 0.23.2 → 0.23.3
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/README.md +139 -141
- package/lib/AlphaBeta.js +32 -0
- package/lib/GraphDB.js +40 -9
- package/lib/MinMax.js +17 -0
- package/lib/Tree.js +64 -0
- package/lib/objectExtensions.js +28 -5
- package/lib/timeDimension.js +36 -0
- package/package.json +4 -3
- package/test/02-graphdb.js +46 -0
- package/test/data/.config.nodes.json +1 -1
- package/test/data/.config.nodes.json.backup +2 -2
- package/test/data/.flow.json.backup +813 -193
- package/test/data/flow.json +809 -191
- package/test/data/package-lock.json +11 -11
- package/test/data/shares/.config.nodes.json +589 -0
- package/test/data/shares/.config.runtime.json +4 -0
- package/test/data/shares/.config.runtime.json.backup +3 -0
- package/test/data/shares/.config.users.json +32 -0
- package/test/data/shares/.config.users.json.backup +29 -0
- package/test/data/shares/.flow.json.backup +230 -0
- package/test/data/shares/.flow_cred.json.backup +3 -0
- package/test/data/shares/flow.json +267 -0
- package/test/data/shares/flow_cred.json +3 -0
- package/test/data/shares/package.json +6 -0
- package/test/data/shares/settings.js +544 -0
- package/testing/test.js +8 -7
- package/transform/transform.html +23 -2
- package/transform/transform.js +239 -283
- package/transform/xlsx2.js +74 -0
package/README.md
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
[Node-Red][1] nodes for various functions:
|
|
4
4
|
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
5
|
+
* Data Analysis - statistical metrics that has real time option
|
|
6
|
+
* Matrix
|
|
7
|
+
* Transform
|
|
8
|
+
* Test
|
|
9
|
+
* Load Injector
|
|
10
|
+
* Monitor Flow
|
|
11
|
+
* append
|
|
12
|
+
* Spawn Process
|
|
13
|
+
* Host Available
|
|
14
|
+
* node.js os metrics
|
|
15
|
+
* Levenshtein Distance
|
|
16
16
|
|
|
17
17
|
------------------------------------------------------------
|
|
18
18
|
|
|
@@ -30,7 +30,8 @@ being outside 3 standard deviations from mean. This can be changed to median and
|
|
|
30
30
|
A set of data analysis functions that can be run over an array of data
|
|
31
31
|
|
|
32
32
|
Single value metrics:
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
* Autocorrelation
|
|
34
35
|
* Autocovariance
|
|
35
36
|
* Average/Mean
|
|
36
37
|
* Maximum
|
|
@@ -43,6 +44,7 @@ Single value metrics:
|
|
|
43
44
|
* Variance
|
|
44
45
|
|
|
45
46
|
Array metrics:
|
|
47
|
+
|
|
46
48
|
* Deltas
|
|
47
49
|
* Deltas Normalised
|
|
48
50
|
* difference
|
|
@@ -56,11 +58,11 @@ Array metrics:
|
|
|
56
58
|
* Standardization (Z-score Normalization)
|
|
57
59
|
|
|
58
60
|
Array data
|
|
59
|
-
|
|
61
|
+
|
|
62
|
+
* distances
|
|
60
63
|
* distance(s) minimum between points
|
|
61
64
|
* distance(s) maximum between points
|
|
62
65
|
|
|
63
|
-
|
|
64
66
|

|
|
65
67
|
|
|
66
68
|
example:
|
|
@@ -69,36 +71,33 @@ example:
|
|
|
69
71
|
|
|
70
72
|

|
|
71
73
|
|
|
72
|
-
|
|
73
74
|

|
|
74
75
|
|
|
75
|
-
|
|
76
76
|
------------------------------------------------------------
|
|
77
77
|
|
|
78
78
|
## Matrix
|
|
79
79
|
|
|
80
80
|
Define a matrix and perform various functions
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
82
|
+
* Define / Define Empty / Create / Create Like/ clone
|
|
83
|
+
* Add / Add Row to Row / Add to Cell / Add Row / Subtract Cell
|
|
84
|
+
* Multiple / Multiple Cell / Divide Cell / Divide Row
|
|
85
|
+
* Transpose
|
|
86
|
+
* Adjoint
|
|
87
|
+
* Cofactor
|
|
88
|
+
* Complement Minor
|
|
89
|
+
* Identity
|
|
90
|
+
* Inverse
|
|
91
|
+
* Determinant
|
|
92
|
+
* Backward Substitution
|
|
93
|
+
* Forward Elimination
|
|
94
|
+
* Gaussian Elimination
|
|
95
|
+
* Reduced Row EchelonForm
|
|
96
|
+
* Row Echelon Form
|
|
97
|
+
* Nearly Equals / Is Square / Get Cell
|
|
98
|
+
* Sum Row
|
|
99
|
+
* Swap Rows
|
|
100
|
+
* To Array Object
|
|
102
101
|
|
|
103
102
|

|
|
104
103
|
|
|
@@ -107,103 +106,102 @@ Define a matrix and perform various functions
|
|
|
107
106
|
## Transform
|
|
108
107
|
|
|
109
108
|
Translates a selected msg property to a target property.
|
|
110
|
-
Messages generates a message for each row or record.
|
|
109
|
+
Messages generates a message for each row or record.
|
|
111
110
|
|
|
112
111
|
Transformations:
|
|
113
112
|
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
*
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
113
|
+
* Array to
|
|
114
|
+
* CSV
|
|
115
|
+
* HTML
|
|
116
|
+
* ISO8385
|
|
117
|
+
* Messages
|
|
118
|
+
* xlsx / xlsx object (excel uses [xlsx][7])
|
|
119
|
+
* AVRO to JSON (uses [avsc][6])
|
|
120
|
+
* Buffer to compressed
|
|
121
|
+
* Confluence to JSON
|
|
122
|
+
* Compressed to
|
|
123
|
+
* Buffer
|
|
124
|
+
* String
|
|
125
|
+
* JSON
|
|
126
|
+
* CSV to
|
|
127
|
+
* Array
|
|
128
|
+
* HTML
|
|
129
|
+
* Messages
|
|
130
|
+
* CSVWithHeader to
|
|
131
|
+
* Array
|
|
132
|
+
* HTML
|
|
133
|
+
* JSON
|
|
134
|
+
* Date to
|
|
135
|
+
* is between
|
|
136
|
+
* ISO string
|
|
137
|
+
* locale string
|
|
138
|
+
* range limit
|
|
139
|
+
* ISO8385 to Array
|
|
140
|
+
* ISO8385 to JSON
|
|
141
|
+
* JSON to
|
|
142
|
+
* Array
|
|
143
|
+
* Confluence
|
|
144
|
+
* CSV
|
|
145
|
+
* AVRO (uses [avsc][6])
|
|
146
|
+
* ISO8385
|
|
147
|
+
* Messages
|
|
148
|
+
* String
|
|
149
|
+
* xlsx / xlsx object (excel uses [xlsx][7])
|
|
150
|
+
* XML (uses [fast-xml-parser][4])
|
|
152
151
|
* Number
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
*
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
*
|
|
206
|
-
* XML to JSON (uses [fast-xml-parser][4])
|
|
152
|
+
* is between
|
|
153
|
+
* range limit
|
|
154
|
+
* path
|
|
155
|
+
* Basename
|
|
156
|
+
* Dirname
|
|
157
|
+
* Extname
|
|
158
|
+
* Format
|
|
159
|
+
* Is Absolute
|
|
160
|
+
* Join
|
|
161
|
+
* Parse
|
|
162
|
+
* Normalize
|
|
163
|
+
* Resolve
|
|
164
|
+
* snappy compress (uses [snappy][5], must install separately)
|
|
165
|
+
* snappy uncompress (uses [snappy][5], must install separately)
|
|
166
|
+
* String to
|
|
167
|
+
* Append
|
|
168
|
+
* Array By Delimiter
|
|
169
|
+
* At
|
|
170
|
+
* Camelize
|
|
171
|
+
* Capitalize
|
|
172
|
+
* Compressed
|
|
173
|
+
* Char At
|
|
174
|
+
* Char Code At"
|
|
175
|
+
* Code Point At
|
|
176
|
+
* Concat
|
|
177
|
+
* Date
|
|
178
|
+
* Delimiter On Case
|
|
179
|
+
* _ to space
|
|
180
|
+
* _ to space Capitilize
|
|
181
|
+
* Drop square bracket prefix
|
|
182
|
+
* Ends With
|
|
183
|
+
* Float
|
|
184
|
+
* Get Word
|
|
185
|
+
* Integer
|
|
186
|
+
* is Between
|
|
187
|
+
* Lower Case
|
|
188
|
+
* Number
|
|
189
|
+
* Prepend
|
|
190
|
+
* JSON
|
|
191
|
+
* Range Limit
|
|
192
|
+
* Split
|
|
193
|
+
* Starts With
|
|
194
|
+
* Timestamp
|
|
195
|
+
* Title
|
|
196
|
+
* Title Grammatical
|
|
197
|
+
* Trim
|
|
198
|
+
* Trim End
|
|
199
|
+
* Trim Start
|
|
200
|
+
* Upper Case
|
|
201
|
+
* Xml String Encode
|
|
202
|
+
|
|
203
|
+
* xlsx / xlsx object to array/JSON (excel uses [xlsx][7])
|
|
204
|
+
* XML to JSON (uses [fast-xml-parser][4])
|
|
207
205
|
|
|
208
206
|
Note, snappy needs to be installed separately as can have issues with auto install as build binaries.
|
|
209
207
|
|
|
@@ -213,13 +211,13 @@ Example AVRO with schema
|
|
|
213
211
|
|
|
214
212
|

|
|
215
213
|
|
|
216
|
-
For Confluence schema contains a list of schemas in form {"
|
|
214
|
+
For Confluence schema contains a list of schemas in form {"\<schema id\>",\<schema\>}
|
|
217
215
|
|
|
218
216
|
------------------------------------------------------------
|
|
219
217
|
|
|
220
218
|
## Test
|
|
221
219
|
|
|
222
|
-
Allows a test case for a message to allow simple testing of nodes. Injects a new message via mouse or message. Message sent to first port which can be consumed by other nodes and returned back to node in a loop. The Test node then checks against detailed expected payload result.
|
|
220
|
+
Allows a test case for a message to allow simple testing of nodes. Injects a new message via mouse or message. Message sent to first port which can be consumed by other nodes and returned back to node in a loop. The Test node then checks against detailed expected payload result.
|
|
223
221
|
|
|
224
222
|

|
|
225
223
|
|
|
@@ -260,11 +258,11 @@ Inject messages for a set period of time with varying think time.
|
|
|
260
258
|
Primary purpose is testing and useful for load/stress testing.
|
|
261
259
|
|
|
262
260
|
Has 3 extra data types
|
|
261
|
+
|
|
263
262
|
1. generated id - Unique id for each message
|
|
264
263
|
2. generated data - string text generated using [dummy-json][3]
|
|
265
264
|
3. generated json - json generated using [dummy-json][3]
|
|
266
265
|
|
|
267
|
-
|
|
268
266
|

|
|
269
267
|
|
|
270
268
|
Test example:
|
|
@@ -300,7 +298,7 @@ Test example:
|
|
|
300
298
|
|
|
301
299
|
------------------------------------------------------------
|
|
302
300
|
|
|
303
|
-
## Monitor System
|
|
301
|
+
## Monitor System
|
|
304
302
|
|
|
305
303
|
System monitoring metrics
|
|
306
304
|
|
|
@@ -330,7 +328,7 @@ Spawn process as per node.js manual with ability to set working directory, envir
|
|
|
330
328
|
and argument passed to process. STDOUT and STDERR are sent as individual messages.
|
|
331
329
|
RC port is sent a message on closure.
|
|
332
330
|
Takes in messages that starts a process with ability to add environment values.
|
|
333
|
-
Message can be sent to kill the process.
|
|
331
|
+
Message can be sent to kill the process.
|
|
334
332
|
|
|
335
333
|

|
|
336
334
|
|
|
@@ -340,19 +338,22 @@ Test example:
|
|
|
340
338
|
|
|
341
339
|
------------------------------------------------------------
|
|
342
340
|
|
|
343
|
-
|
|
341
|
+
## Install
|
|
344
342
|
|
|
345
343
|
Run the following command in the root directory of your Node-RED install
|
|
346
344
|
|
|
347
345
|
npm install node-red-contrib-prib-functions
|
|
348
346
|
|
|
349
|
-
|
|
347
|
+
## Tests
|
|
350
348
|
|
|
351
349
|
Test/example flow in test/generalTest.json
|
|
352
350
|
|
|
353
351
|
------------------------------------------------------------
|
|
354
352
|
|
|
355
|
-
|
|
353
|
+
## Version
|
|
354
|
+
|
|
355
|
+
0.23.3 Removes bug in test, more translation
|
|
356
|
+
|
|
356
357
|
0.23.0 Removes bug in test, more translation
|
|
357
358
|
|
|
358
359
|
0.22.0 Add autocovariance + autocorealationship to real time data analystics, improves test
|
|
@@ -367,8 +368,7 @@ Test/example flow in test/generalTest.json
|
|
|
367
368
|
|
|
368
369
|
0.17.0 Add finished wire to load injector
|
|
369
370
|
|
|
370
|
-
|
|
371
|
-
# Author
|
|
371
|
+
## Author
|
|
372
372
|
|
|
373
373
|
[Peter Prib][3]
|
|
374
374
|
|
|
@@ -385,5 +385,3 @@ Test/example flow in test/generalTest.json
|
|
|
385
385
|
[6]: https://www.npmjs.com/package/avsc "avsc"
|
|
386
386
|
|
|
387
387
|
[7]: https://www.npmjs.com/package/xlsx "xlsx"
|
|
388
|
-
|
|
389
|
-
[8]: https://www.npmjs.com/package/dummy-json "dummy-json"
|
package/lib/AlphaBeta.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function alphabeta(node, depth,
|
|
2
|
+
isTerminalNode=node=>node.children.lenght==0 ,
|
|
3
|
+
forEachChild=call=>this.children.forEach(c=>call(c)),
|
|
4
|
+
getHeuristicValue=node=>node.value,
|
|
5
|
+
alpha=-Infinity, beta=Infinity,
|
|
6
|
+
maximizingPlayer=true
|
|
7
|
+
){
|
|
8
|
+
if( depth == 0 || isTerminalNode(node)) return getHeuristicValue (node)
|
|
9
|
+
const notMaximizingPlayer=!maximizingPlayer
|
|
10
|
+
const minMaxFunction=maximizingPlayer?Math.max:Math.min
|
|
11
|
+
let value=Infinity*(maximizingPlayer?-1:1)
|
|
12
|
+
let loopFunction=maximizingPlayer?
|
|
13
|
+
child=>{
|
|
14
|
+
value = minMaxFunction(value,
|
|
15
|
+
minimax(child,depth-1,isTerminalNode,forEachChild,getHeuristicValue ,alpha, beta, notMaximizingPlayer))
|
|
16
|
+
if(value >= beta ) throw Error("break")
|
|
17
|
+
else alpha = minMaxFunction(alpha, value)
|
|
18
|
+
}:child=>{
|
|
19
|
+
value = minMaxFunction(value,
|
|
20
|
+
minimax(child,depth-1,isTerminalNode,forEachChild,getHeuristicValue ,alpha, beta, notMaximizingPlayer))
|
|
21
|
+
if(value <= alpha) throw Error("break")
|
|
22
|
+
beta = minMaxFunction(beta, value)
|
|
23
|
+
}
|
|
24
|
+
try{
|
|
25
|
+
forEachChild(loopFunction)
|
|
26
|
+
} catch(ex){
|
|
27
|
+
if(ex.message!=="break") throw ex
|
|
28
|
+
}
|
|
29
|
+
return value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports=alphabeta
|
package/lib/GraphDB.js
CHANGED
|
@@ -1,14 +1,45 @@
|
|
|
1
1
|
require("../lib/objectExtensions")
|
|
2
|
+
function Edge(from,to,properties){
|
|
3
|
+
if(!from) throw Error("from vertix is not defined")
|
|
4
|
+
if(!to) throw Error("to vertix is not defined")
|
|
5
|
+
if(!from instanceof Vertex) throw Error("from not type Vertex")
|
|
6
|
+
if(!to instanceof Vertex) throw Error("to not type Vertex")
|
|
7
|
+
Object.assign(this,{_from:from,_to:to},properties)
|
|
8
|
+
from.addTo(this)
|
|
9
|
+
to.addFrom(this)
|
|
10
|
+
}
|
|
11
|
+
function Vertex(properties){
|
|
12
|
+
Object.assign(this,{_to:[],_from:[]},properties)
|
|
13
|
+
}
|
|
14
|
+
Vertex.prototype.addTo=function(r){
|
|
15
|
+
this._to.push(r)
|
|
16
|
+
}
|
|
17
|
+
Vertex.prototype.addFrom=function(r){
|
|
18
|
+
this._from.push(r)
|
|
19
|
+
}
|
|
2
20
|
function GraphDB(properties){
|
|
3
|
-
|
|
4
|
-
|
|
21
|
+
Object.assign(this,{vertices:[],edges:[]},properties)
|
|
22
|
+
}
|
|
23
|
+
GraphDB.prototype.addEdge=function(from,to,properties) {
|
|
24
|
+
const edge=new Edge(from,to,properties)
|
|
25
|
+
this.edges.push(edge)
|
|
26
|
+
return edge
|
|
27
|
+
}
|
|
28
|
+
GraphDB.prototype.addVertex=function(vertexDetails) {
|
|
29
|
+
const vertex=new Vertex(vertexDetails)
|
|
30
|
+
this.vertices.push(vertex)
|
|
31
|
+
return vertex
|
|
32
|
+
}
|
|
33
|
+
GraphDB.prototype.getEdgesCount=function() {
|
|
34
|
+
return this.edges.length
|
|
35
|
+
}
|
|
36
|
+
GraphDB.prototype.getVerticesCount=function() {
|
|
37
|
+
return this.vertices.length
|
|
5
38
|
}
|
|
6
|
-
GraphDB.prototype.
|
|
7
|
-
|
|
39
|
+
GraphDB.prototype.getVertices=function(filterFunction) {
|
|
40
|
+
return this.vertices.filter(filterFunction)
|
|
8
41
|
}
|
|
9
|
-
GraphDB.prototype.
|
|
10
|
-
|
|
42
|
+
GraphDB.prototype.getEdges=function(filterFunction) {
|
|
43
|
+
return this.Edges.filter(filterFunction)
|
|
11
44
|
}
|
|
12
|
-
|
|
13
|
-
this.addErrorFunctions()
|
|
14
|
-
module.exports=GraphDB
|
|
45
|
+
module.exports=GraphDB
|
package/lib/MinMax.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function minimax(node, depth,
|
|
2
|
+
isTerminalNode=node=>node.children.lenght==0 ,
|
|
3
|
+
forEachChild=call=>this.children.forEach(c=>call(c)),
|
|
4
|
+
getHeuristicValue =node=>node.value,
|
|
5
|
+
maximizingPlayer=true
|
|
6
|
+
){
|
|
7
|
+
if( depth == 0 || isTerminalNode(node)) return getHeuristicValue (node)
|
|
8
|
+
const notMaximizingPlayer=!maximizingPlayer
|
|
9
|
+
const minMaxFunction=maximizingPlayer?Math.max:Math.min
|
|
10
|
+
let value=Infinity*(maximizingPlayer?-1:1)
|
|
11
|
+
forEachChild(child=> value = minMaxFunction(value,
|
|
12
|
+
minimax(child,depth-1,isTerminalNode,forEachChild,getHeuristicValue ,notMaximizingPlayer))
|
|
13
|
+
)
|
|
14
|
+
return value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports=minimax
|
package/lib/Tree.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function Level(parent,...children){
|
|
2
|
+
this.children=children
|
|
3
|
+
this.setBTree(10)
|
|
4
|
+
}
|
|
5
|
+
function Leaf(parent,value){
|
|
6
|
+
this.values=[]
|
|
7
|
+
}
|
|
8
|
+
Leaf.prototype.find=function(value,foundCall,notFoundCall=foundCall,notFoundAllCall=v=>notFoundCall(0,v)){
|
|
9
|
+
let i=this.keys.length
|
|
10
|
+
const key=this.getKey(value)
|
|
11
|
+
while (i >= 0){
|
|
12
|
+
const currentKey=this.getKey(this.values[i])
|
|
13
|
+
if(key>currentKey) return notFoundCall(i,key)
|
|
14
|
+
if(key==currentKey) return foundCall(i,key)
|
|
15
|
+
i--
|
|
16
|
+
}
|
|
17
|
+
notFoundAllCall(key)
|
|
18
|
+
}
|
|
19
|
+
Leaf.prototype.getKey=function(node){return node}
|
|
20
|
+
Leaf.prototype.insert=function(value){
|
|
21
|
+
const _this=this
|
|
22
|
+
this.find(value,i=>_this.values.splice(i, 0, value))
|
|
23
|
+
}
|
|
24
|
+
function Tree (root=new Level(null)){
|
|
25
|
+
this.root=root
|
|
26
|
+
}
|
|
27
|
+
Tree.prototype.setDegree=function(v){this.degree=v}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Tree.prototype.insert(key,value) {
|
|
32
|
+
const root = this.root;
|
|
33
|
+
if(root.keys.length === (2 * this.degree - 1)) { // Root is full
|
|
34
|
+
const newRoot = new BTreeNode(false);
|
|
35
|
+
newRoot.children.push(root);
|
|
36
|
+
this.splitChild(newRoot, 0, root);
|
|
37
|
+
this.root = newRoot;
|
|
38
|
+
this.insertNonFull(newRoot, key);
|
|
39
|
+
} else {
|
|
40
|
+
this.insertNonFull(root, key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Tree.prototype.insertNonFull(node, key) {
|
|
45
|
+
let i = node.keys.length - 1;
|
|
46
|
+
if (node.isLeaf) {
|
|
47
|
+
|
|
48
|
+
} else {
|
|
49
|
+
while (i >= 0 && key < node.keys[i]) {
|
|
50
|
+
i--;
|
|
51
|
+
}
|
|
52
|
+
i++;
|
|
53
|
+
if (node.children[i].keys.length === (2 * this.degree - 1)) {
|
|
54
|
+
this.splitChild(node, i, node.children[i]);
|
|
55
|
+
if (key > node.keys[i]) {
|
|
56
|
+
i++;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.insertNonFull(node.children[i], key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
module.exports=Tree
|
package/lib/objectExtensions.js
CHANGED
|
@@ -440,8 +440,26 @@ const nullif=(a,b)=>{return a==b?null:a}
|
|
|
440
440
|
defineMethod(type,"deepClone",function(){ return new type(this)})
|
|
441
441
|
})
|
|
442
442
|
|
|
443
|
+
const getWord=(value,wordPosition)=>value.split(/\s+/g,wordPosition+1)[wordPosition-1]
|
|
444
|
+
|
|
445
|
+
const deepClone=(deepObject) =>{
|
|
446
|
+
if(deepObject==null) return null;
|
|
447
|
+
if(deepObject instanceof Array)
|
|
448
|
+
var newObj=[];
|
|
449
|
+
else if(deepObject instanceof String)
|
|
450
|
+
return new String(deepObject);
|
|
451
|
+
else if(deepObject instanceof Number)
|
|
452
|
+
return new Number(deepObject);
|
|
453
|
+
else if(deepObject instanceof Date)
|
|
454
|
+
return new Date(deepObject);
|
|
455
|
+
else if(typeof deepObject == "object")
|
|
456
|
+
var newObj={};
|
|
457
|
+
else return deepObject;
|
|
458
|
+
for (const i in deepObject)
|
|
459
|
+
newObj[i]=deepClone(deepObject[i]);
|
|
460
|
+
return newObj;
|
|
461
|
+
}
|
|
443
462
|
|
|
444
|
-
//defineMethod(TypedArray,"deepClone",function(){ return new type(this)})
|
|
445
463
|
defineMethod(Array,"deepClone",function(){
|
|
446
464
|
const clone=[]
|
|
447
465
|
for (let i in this)
|
|
@@ -449,11 +467,13 @@ defineMethod(Array,"deepClone",function(){
|
|
|
449
467
|
return clone
|
|
450
468
|
})
|
|
451
469
|
defineMethod(Object,"deepClone",function(){
|
|
452
|
-
const clone={}
|
|
453
|
-
for (let i in this)
|
|
454
|
-
clone[i]=this[i].deepClone()
|
|
455
|
-
return clone
|
|
470
|
+
// const clone={}
|
|
471
|
+
// for (let i in this)
|
|
472
|
+
// clone[i]=this[i].deepClone()
|
|
473
|
+
// return clone
|
|
474
|
+
return deepClone(this)
|
|
456
475
|
})
|
|
476
|
+
const rangeLimit=(value,min=value,max=value)=>value<min?min:value>max?max:value
|
|
457
477
|
defineMethod(Number, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
458
478
|
defineMethod(BigInt, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
459
479
|
defineMethod(Date, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
@@ -465,7 +485,10 @@ module.exports={
|
|
|
465
485
|
coalesce:coalesce,
|
|
466
486
|
colours:colours,
|
|
467
487
|
colourSmallList:colourSmallList,
|
|
488
|
+
deepClone,deepClone,
|
|
489
|
+
getWord,getWord,
|
|
468
490
|
nullif:nullif,
|
|
491
|
+
rangeLimit,rangeLimit,
|
|
469
492
|
toDateType,
|
|
470
493
|
toDateTypeZulu,
|
|
471
494
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const timePeriod={second:1000}
|
|
2
|
+
timePeriod.minute=timePeriod.second*60
|
|
3
|
+
timePeriod.hour=timePeriod.minute*60
|
|
4
|
+
timePeriod.day=timePeriod.hour*24
|
|
5
|
+
timePeriod.week=timePeriod.day*7
|
|
6
|
+
timePeriod.fortnight=timePeriod.week*2
|
|
7
|
+
|
|
8
|
+
const isPeriod={
|
|
9
|
+
second:t=>t%timePeriod.second,
|
|
10
|
+
minute:t=>t%timePeriod.minute
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const timeDimension=(period=timePeriod.second,from=0,to=60,call)=>{
|
|
16
|
+
const fromDate=new Date(from).getMilliseconds%period
|
|
17
|
+
const toDate=new Date(to).getMilliseconds%increment
|
|
18
|
+
const periods=Object.keys(callFunctions)
|
|
19
|
+
for(let i=fromDate;i<toDate;i+increment){
|
|
20
|
+
call(i)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const repeat=(r,call)=>{for(let i=0;i<r; i++) call(i)}
|
|
25
|
+
const secondsInMinute=call=>repeat(60,call)
|
|
26
|
+
const minutesInHour=repeat(60,call)
|
|
27
|
+
const hoursInDay=repeat(24,call)
|
|
28
|
+
const daysInWeek=repeat(7,call)
|
|
29
|
+
|
|
30
|
+
module.exports={
|
|
31
|
+
repeat:repeat,
|
|
32
|
+
secondsInMinute:secondsInMinute,
|
|
33
|
+
minutesInHour:minutesInHour,
|
|
34
|
+
hoursInDay:hoursInDay,
|
|
35
|
+
daysInWeek:daysInWeek
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-prib-functions",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.3",
|
|
4
4
|
"description": "Node-RED added node functions.",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"avsc": ">=5.7.7",
|
|
@@ -26,8 +26,9 @@
|
|
|
26
26
|
"test": "mocha \"test/dataAnalysisE*.js\"",
|
|
27
27
|
"test2": "mocha \"test/transformNum*.js\"",
|
|
28
28
|
"test00": "mocha \"test/00*.js\"",
|
|
29
|
-
"
|
|
30
|
-
"startNodeRed": "node-red --userDir ./test/data --setting ./test/data/settings.js ./test/data/flow.json --title '***test nodered***'"
|
|
29
|
+
"test02": "mocha \"test/02*.js\"",
|
|
30
|
+
"startNodeRed": "node-red --userDir ./test/data --setting ./test/data/settings.js ./test/data/flow.json --title '***test nodered***'",
|
|
31
|
+
"sharesNodeRed": "node-red --userDir ./test/data/shares --setting ./test/data/shares/settings.js ./test/data/shares/flow.json --title '***shares nodered***'"
|
|
31
32
|
},
|
|
32
33
|
"repository": {
|
|
33
34
|
"type": "git",
|