node-red-contrib-prib-functions 0.19.2 → 0.21.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/.github/workflows/codeql-analysis.yml +3 -3
- package/.github/workflows/npmpublish.yml +6 -6
- package/.vs/VSWorkspaceState.json +7 -0
- package/.vs/node-red-contrib-prib-functions/v17/.wsuo +0 -0
- package/README.md +84 -70
- package/dataAnalysis/arrayAllRowsSwap.js +15 -0
- package/dataAnalysis/arrayCompareToPrecision.js +34 -0
- package/dataAnalysis/arrayDifference.js +14 -0
- package/dataAnalysis/arrayDifferenceSeasonal.js +15 -0
- package/dataAnalysis/arrayDifferenceSeasonalSecondOrder.js +20 -0
- package/dataAnalysis/arrayDifferenceSecondOrder.js +14 -0
- package/dataAnalysis/arrayForEachRange.js +38 -0
- package/dataAnalysis/arrayOverlay.js +13 -0
- package/dataAnalysis/arrayProduct.js +11 -0
- package/dataAnalysis/arrayRandom.js +14 -0
- package/dataAnalysis/arrayReduceRange.js +11 -0
- package/dataAnalysis/arrayScale.js +11 -0
- package/dataAnalysis/arraySum.js +11 -0
- package/dataAnalysis/arraySumSquared.js +11 -0
- package/dataAnalysis/arraySwap.js +11 -0
- package/dataAnalysis/dataAnalysis.html +52 -21
- package/dataAnalysis/dataAnalysis.js +73 -44
- package/dataAnalysis/generateMatrixFunction.js +89 -0
- package/dataAnalysis/generateVectorFunction.js +25 -0
- package/dataAnalysis/pca.js +472 -325
- package/dataAnalysis/svd.js +239 -0
- package/documentation/DataAnalysisRealtime.JPG +0 -0
- package/documentation/monitorSystem.JPG +0 -0
- package/documentation/monitorSystemTest.JPG +0 -0
- package/echart/echart.html +68 -0
- package/echart/echart.js +85 -0
- package/echart/icons/chart-671.png +0 -0
- package/echart/lib/echarts.js +95886 -0
- package/lib/Chart.js +177 -0
- package/lib/Column.js +99 -0
- package/lib/GraphDB.js +14 -0
- package/lib/Table.js +185 -0
- package/lib/objectExtensions.js +361 -0
- package/matrix/matrix.js +95 -56
- package/matrix/matrixNode.html +88 -55
- package/matrix/matrixNode.js +12 -5
- package/monitor/BarGauge.js +8 -0
- package/monitor/Dataset.js +29 -0
- package/monitor/DialGauge.js +109 -0
- package/monitor/DialNeedle.js +36 -0
- package/monitor/Format.js +74 -0
- package/monitor/centerElement.js +14 -0
- package/monitor/compareElements.js +95 -0
- package/monitor/defs.js +23 -0
- package/monitor/extensions.js +906 -0
- package/monitor/functions.js +36 -0
- package/monitor/json2xml.js +103 -0
- package/monitor/monitorSystem.html +199 -0
- package/monitor/monitorSystem.js +322 -0
- package/monitor/svgHTML.js +179 -0
- package/monitor/svgObjects.js +64 -0
- package/package.json +20 -6
- package/test/00-objectExtensions.js +94 -0
- package/test/04-tables.js +33 -0
- package/test/data/.config.nodes.json +608 -0
- package/test/data/.config.nodes.json.backup +608 -0
- package/test/data/.config.runtime.json +4 -0
- package/test/data/.config.runtime.json.backup +3 -0
- package/test/data/.config.users.json +21 -0
- package/test/data/.config.users.json.backup +21 -0
- package/test/data/.flow.json.backup +2820 -2003
- package/test/data/float32vector10.npy +0 -0
- package/test/data/flow.json +2830 -2033
- package/test/data/int2matrix2x3.npy +0 -0
- package/test/data/package-lock.json +158 -0
- package/test/data/package.json +11 -0
- package/test/dataAnalysisExtensions.js +471 -0
- package/test/dataAnalysisPCA.js +54 -0
- package/test/dataAnalysisSVD.js +31 -0
- package/test/euclideanDistance.js +2 -2
- package/test/transformConfluence.js +1 -1
- package/test/transformNumPy.js +132 -0
- package/testing/test.html +1 -1
- package/testing/test.js +78 -53
- package/transform/NumPy.js +303 -0
- package/transform/transform.html +12 -0
- package/transform/transform.js +34 -2
|
@@ -35,7 +35,7 @@ jobs:
|
|
|
35
35
|
|
|
36
36
|
steps:
|
|
37
37
|
- name: Checkout repository
|
|
38
|
-
uses: actions/checkout@
|
|
38
|
+
uses: actions/checkout@v4
|
|
39
39
|
|
|
40
40
|
# Initializes the CodeQL tools for scanning.
|
|
41
41
|
- name: Initialize CodeQL
|
|
@@ -50,7 +50,7 @@ jobs:
|
|
|
50
50
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
51
51
|
# If this step fails, then you should remove it and run the build manually (see below)
|
|
52
52
|
- name: Autobuild
|
|
53
|
-
uses: github/codeql-action/autobuild@
|
|
53
|
+
uses: github/codeql-action/autobuild@v3
|
|
54
54
|
|
|
55
55
|
# ℹ️ Command-line programs to run using the OS shell.
|
|
56
56
|
# 📚 https://git.io/JvXDl
|
|
@@ -64,4 +64,4 @@ jobs:
|
|
|
64
64
|
# make release
|
|
65
65
|
|
|
66
66
|
- name: Perform CodeQL Analysis
|
|
67
|
-
uses: github/codeql-action/analyze@
|
|
67
|
+
uses: github/codeql-action/analyze@v3
|
|
@@ -11,10 +11,10 @@ jobs:
|
|
|
11
11
|
build:
|
|
12
12
|
runs-on: ubuntu-latest
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
15
|
-
- uses: actions/setup-node@
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
16
|
with:
|
|
17
|
-
node-version:
|
|
17
|
+
node-version: 'latest'
|
|
18
18
|
- run: npm ci
|
|
19
19
|
- run: npm test
|
|
20
20
|
|
|
@@ -22,10 +22,10 @@ jobs:
|
|
|
22
22
|
needs: build
|
|
23
23
|
runs-on: ubuntu-latest
|
|
24
24
|
steps:
|
|
25
|
-
- uses: actions/checkout@
|
|
26
|
-
- uses: actions/setup-node@
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
27
|
with:
|
|
28
|
-
node-version:
|
|
28
|
+
node-version: 'latest'
|
|
29
29
|
registry-url: https://registry.npmjs.org/
|
|
30
30
|
- run: npm ci
|
|
31
31
|
- run: npm publish
|
|
Binary file
|
package/README.md
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
* Data Analysis - statistical metrics that has real time option
|
|
6
6
|
* Matrix
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Transform
|
|
8
|
+
* Test
|
|
9
9
|
* Load Injector
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
|
|
19
19
|
## Data Analysis
|
|
20
20
|
|
|
21
21
|
Real time metrics which are recalculated on single of data point and posted in msg.result.
|
|
22
|
-
Key and value can be selected from msg.payload.
|
|
22
|
+
Key and value can be selected from msg.payload. Includes lag (seasonal) along with delta(defference).
|
|
23
23
|
Sending message with topic"@stats" places message with all stats on second port.
|
|
24
24
|
If realtime metrics then a third port is shown where the message is sent if it is an outlier
|
|
25
25
|
being outside 3 standard deviations from mean. This can be changed to median and number of deviations.
|
|
@@ -27,7 +27,6 @@ being outside 3 standard deviations from mean. This can be changed to median and
|
|
|
27
27
|

|
|
28
28
|

|
|
29
29
|
|
|
30
|
-
|
|
31
30
|
A set of data analysis functions that can be run over an array of data
|
|
32
31
|
|
|
33
32
|
Single value metrics:
|
|
@@ -44,6 +43,9 @@ Single value metrics:
|
|
|
44
43
|
Array metrics:
|
|
45
44
|
* Deltas
|
|
46
45
|
* Deltas Normalised
|
|
46
|
+
* difference
|
|
47
|
+
* difference seasonal
|
|
48
|
+
* difference seasonal second order
|
|
47
49
|
* Moving Average Simple (SMA)
|
|
48
50
|
* Moving Average Cumulative (CMA)
|
|
49
51
|
* Moving Average Weighted (WMA)
|
|
@@ -53,8 +55,9 @@ Array metrics:
|
|
|
53
55
|
|
|
54
56
|
Array data
|
|
55
57
|
* distances
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
+
* distance(s) minimum between points
|
|
59
|
+
* distance(s) maximum between points
|
|
60
|
+
|
|
58
61
|
|
|
59
62
|

|
|
60
63
|
|
|
@@ -74,7 +77,7 @@ example:
|
|
|
74
77
|
|
|
75
78
|
Define a matrix and perform various functions
|
|
76
79
|
|
|
77
|
-
* Define / Define Empty / Create / Create Like/ clone
|
|
80
|
+
* Define / Define Empty / Create / Create Like/ clone
|
|
78
81
|
* Add / Add Row to Row / Add to Cell / Add Row / Subtract Cell
|
|
79
82
|
* Multiple / Multiple Cell / Divide Cell / Divide Row
|
|
80
83
|
* Transpose
|
|
@@ -106,48 +109,48 @@ Messages generates a message for each row or record.
|
|
|
106
109
|
|
|
107
110
|
Transformations:
|
|
108
111
|
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
112
|
+
* Array to CSV
|
|
113
|
+
* Array to HTML
|
|
114
|
+
* Array to ISO8385
|
|
115
|
+
* Array to Messages
|
|
116
|
+
* Array to xlsx / xlsx object (excel uses [xlsx][7])
|
|
117
|
+
* AVRO to JSON (uses [avsc][6])
|
|
115
118
|
* Buffer to comprossed
|
|
116
|
-
*
|
|
119
|
+
* Confluence to JSON
|
|
117
120
|
* Compressed to Buffer
|
|
118
121
|
* Compressed to String
|
|
119
122
|
* COmpressed to JSON
|
|
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
|
-
*
|
|
123
|
+
* CSV to Array
|
|
124
|
+
* CSV to HTML
|
|
125
|
+
* CSV to Messages
|
|
126
|
+
* CSVWithHeader to Array
|
|
127
|
+
* CSVWithHeader to HTML
|
|
128
|
+
* CSVWithHeader to JSON
|
|
129
|
+
* ISO8385 to Array
|
|
130
|
+
* ISO8385 to JSON
|
|
131
|
+
* JSON to Array
|
|
132
|
+
* JSON to Confluence
|
|
133
|
+
* JSON to CSV
|
|
134
|
+
* JSON to AVRO (uses [avsc][6])
|
|
135
|
+
* JSON to ISO8385
|
|
136
|
+
* JSON to Messages
|
|
137
|
+
* JSON to String
|
|
138
|
+
* JSON to xlsx / xlsx object (excel uses [xlsx][7])
|
|
139
|
+
* JSON to XML (uses [fast-xml-parser][4])
|
|
140
|
+
* String to JSON
|
|
141
|
+
* path to Basename
|
|
142
|
+
* path to Dirname
|
|
143
|
+
* path to Extname
|
|
144
|
+
* path to Format
|
|
145
|
+
* path to Is Absolute
|
|
146
|
+
* path to Join
|
|
147
|
+
* path to Parse
|
|
148
|
+
* path to Normalize
|
|
149
|
+
* path to Resolve
|
|
150
|
+
* snappy compress (uses [snappy][5], must install separately)
|
|
151
|
+
* snappy uncompress (uses [snappy][5], must install separately)
|
|
152
|
+
* xlsx / xlsx object to array/JSON (excel uses [xlsx][7])
|
|
153
|
+
* XML to JSON (uses [fast-xml-parser][4])
|
|
151
154
|
|
|
152
155
|
Note, snappy needs to be installed separately as can have issues with auto install as build binaries.
|
|
153
156
|
|
|
@@ -215,7 +218,6 @@ Test example:
|
|
|
215
218
|
|
|
216
219
|

|
|
217
220
|
|
|
218
|
-
|
|
219
221
|
------------------------------------------------------------
|
|
220
222
|
|
|
221
223
|
## Monitor Flow
|
|
@@ -231,34 +233,29 @@ Test example:
|
|
|
231
233
|
|
|
232
234
|
------------------------------------------------------------
|
|
233
235
|
|
|
234
|
-
##
|
|
236
|
+
## Host Available
|
|
235
237
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
Takes in messages that starts a process with ability to add environment values.
|
|
240
|
-
Message can be sent to kill the process.
|
|
238
|
+
Test if host is available sending msg to up or down port so action can be taken.
|
|
239
|
+
Message only sent on state change or if message is sent which doesn't have topic refreshHostAvailable.
|
|
240
|
+
This topic forces a check rather than time check which can be set.
|
|
241
241
|
|
|
242
|
-

|
|
243
243
|
|
|
244
244
|
Test example:
|
|
245
245
|
|
|
246
|
-

|
|
248
247
|
|
|
249
248
|
------------------------------------------------------------
|
|
250
249
|
|
|
251
|
-
##
|
|
250
|
+
## Monitor System
|
|
252
251
|
|
|
253
|
-
|
|
254
|
-
Message only sent on state change or if message is sent which doesn't have topic refreshHostAvailable.
|
|
255
|
-
This topic forces a check rather than time check which can be set.
|
|
252
|
+
System monitoring metrics
|
|
256
253
|
|
|
257
|
-

|
|
258
255
|
|
|
259
256
|
Test example:
|
|
260
257
|
|
|
261
|
-

|
|
262
259
|
|
|
263
260
|
------------------------------------------------------------
|
|
264
261
|
|
|
@@ -274,6 +271,22 @@ Test example:
|
|
|
274
271
|
|
|
275
272
|
------------------------------------------------------------
|
|
276
273
|
|
|
274
|
+
## Spawn Process
|
|
275
|
+
|
|
276
|
+
Spawn process as per node.js manual with ability to set working directory, environment variables
|
|
277
|
+
and argument passed to process. STDOUT and STDERR are sent as individual messages.
|
|
278
|
+
RC port is sent a message on closure.
|
|
279
|
+
Takes in messages that starts a process with ability to add environment values.
|
|
280
|
+
Message can be sent to kill the process.
|
|
281
|
+
|
|
282
|
+

|
|
283
|
+
|
|
284
|
+
Test example:
|
|
285
|
+
|
|
286
|
+

|
|
287
|
+
|
|
288
|
+
------------------------------------------------------------
|
|
289
|
+
|
|
277
290
|
# Install
|
|
278
291
|
|
|
279
292
|
Run the following command in the root directory of your Node-RED install
|
|
@@ -288,15 +301,16 @@ Test/example flow in test/generalTest.json
|
|
|
288
301
|
|
|
289
302
|
# Version
|
|
290
303
|
|
|
304
|
+
0.21.0 Add lag/seasonal to real time data analystics
|
|
305
|
+
|
|
306
|
+
0.20.3 Add difference + monitor system
|
|
307
|
+
|
|
291
308
|
0.19.0 Improve load injector, fix bug in test comparing buffers, add compression tranforms
|
|
292
309
|
|
|
293
310
|
0.18.0 Add matrix node
|
|
294
311
|
|
|
295
312
|
0.17.0 Add finished wire to load injector
|
|
296
313
|
|
|
297
|
-
0.16.0 fix data analysis variance and stddev, add sample, add tests
|
|
298
|
-
|
|
299
|
-
|
|
300
314
|
|
|
301
315
|
# Author
|
|
302
316
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
if(Array.prototype.allRowsSwap==null)
|
|
2
|
+
Object.defineProperty(Array.prototype, "allRowsSwap", {
|
|
3
|
+
value(x,y) {
|
|
4
|
+
const l=this.length;
|
|
5
|
+
for(let i=0; i<l; i++) {
|
|
6
|
+
const row=this[i]
|
|
7
|
+
const temp = row[x];
|
|
8
|
+
row[x] = row[y];
|
|
9
|
+
row[y] = temp;
|
|
10
|
+
}
|
|
11
|
+
return this;
|
|
12
|
+
},
|
|
13
|
+
writable: true,
|
|
14
|
+
configurable: true
|
|
15
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.compareToPrecision==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "compareToPrecision", {
|
|
4
|
+
value(toArray,precision=6) {
|
|
5
|
+
const basePrecision=Math.pow(10,-precision);
|
|
6
|
+
if(this.length!=toArray.length) throw Error("array length different")
|
|
7
|
+
this.forEach((element,index)=>{
|
|
8
|
+
const toElement=toArray[index];
|
|
9
|
+
if(typeof element !== typeof toElement) throw Error("types no same for "+index)
|
|
10
|
+
if(typeof element == "array"){
|
|
11
|
+
element.compareToPrecision(toElement,precision)
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
switch (typeof element) {
|
|
15
|
+
case "array":
|
|
16
|
+
try{
|
|
17
|
+
element.compareRounded(toElement,precision)
|
|
18
|
+
} catch(ex) {
|
|
19
|
+
throw Error(index+","+ex.message)
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
default:
|
|
23
|
+
const diff = Math.abs(element-toElement) ;
|
|
24
|
+
// console.log({diff:diff,basePrecision:basePrecision})
|
|
25
|
+
if(Math.abs(element-toElement)/element > basePrecision)
|
|
26
|
+
throw Error(index+ " failed "+element+" <> "+toElement);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
writable: true,
|
|
31
|
+
configurable: true
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.difference==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "difference", {
|
|
4
|
+
value(order=0) {
|
|
5
|
+
let i=this.length
|
|
6
|
+
if(i<2) return new object()
|
|
7
|
+
const result=new object(i-1)
|
|
8
|
+
while(--i) result[i-1]=this[i]-this[i-1];
|
|
9
|
+
return order?result.difference(--order):result;
|
|
10
|
+
},
|
|
11
|
+
writable: true,
|
|
12
|
+
configurable: true
|
|
13
|
+
});
|
|
14
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
3
|
+
if(object.prototype.differenceSeasonal==null)
|
|
4
|
+
Object.defineProperty(object.prototype, "differenceSeasonal", {
|
|
5
|
+
value(lag=1,order=0) {
|
|
6
|
+
let i=this.length-lag
|
|
7
|
+
if(i<1) return new object()
|
|
8
|
+
const result=new object(i)
|
|
9
|
+
while(--i>=0) result[i]=this[i+lag]-this[i];
|
|
10
|
+
return order?result.difference(--order):result;
|
|
11
|
+
},
|
|
12
|
+
writable: true,
|
|
13
|
+
configurable: true
|
|
14
|
+
});
|
|
15
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.differenceSeasonalSecondOrder==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "differenceSeasonalSecondOrder", {
|
|
4
|
+
value(lag=1) {
|
|
5
|
+
let i=this.length-lag-1
|
|
6
|
+
if(i<1) return new object()
|
|
7
|
+
const result=new object(i)
|
|
8
|
+
let lastDiff=this[i+lag-1]-this[i-1]
|
|
9
|
+
while(--i>=0){
|
|
10
|
+
const newDiff=this[i+lag-1]-this[i-1]
|
|
11
|
+
result[i]=lastDiff-newDiff
|
|
12
|
+
lastDiff=newDiff
|
|
13
|
+
}
|
|
14
|
+
return result
|
|
15
|
+
},
|
|
16
|
+
writable: true,
|
|
17
|
+
configurable: true
|
|
18
|
+
});
|
|
19
|
+
})
|
|
20
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.differenceSecondOrder==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "differenceSecondOrder", {
|
|
4
|
+
value() {
|
|
5
|
+
let i=this.length-1
|
|
6
|
+
if(i<2) return new object()
|
|
7
|
+
const result=new object(i-1)
|
|
8
|
+
while(--i) result[i-1]=this[i-1]-2*this[i]+this[i+1]
|
|
9
|
+
return result;
|
|
10
|
+
},
|
|
11
|
+
writable: true,
|
|
12
|
+
configurable: true
|
|
13
|
+
});
|
|
14
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.forEachRange==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "forEachRange", {
|
|
4
|
+
value(start=0,end=this.length-1,func,o=this) {
|
|
5
|
+
if(start<=end) {
|
|
6
|
+
if(end>=this.length) throw Error("end offset "+end+" >= array length "+this.length);
|
|
7
|
+
if(start<0) throw Error("start offset "+start+"< 0");
|
|
8
|
+
for(let i=start;i<=end;i++) func(this[i],i,this)
|
|
9
|
+
} else {
|
|
10
|
+
if(start>=this.length) throw Error("end<start and start offset "+start+" >= array length "+this.length);
|
|
11
|
+
if(end<0) throw Error("end<start and end offset "+end+"< 0")
|
|
12
|
+
for(let i=start;i>=end;i--) func(this[i],i,this)
|
|
13
|
+
}
|
|
14
|
+
return this;
|
|
15
|
+
},
|
|
16
|
+
writable: true,
|
|
17
|
+
configurable: true
|
|
18
|
+
});
|
|
19
|
+
if(object.prototype.forEachRangeNotTested==null)
|
|
20
|
+
Object.defineProperty(object.prototype, "forEachRangeNotTested", {
|
|
21
|
+
value(start=0,end=this.length-1,func,o=this) {
|
|
22
|
+
if(start<=end) {
|
|
23
|
+
if(end>=this.length) end=this.length-1;
|
|
24
|
+
if(start<0) start=0;
|
|
25
|
+
for(let i=start;i<=end;i++) func(this[i],i,this)
|
|
26
|
+
} else {
|
|
27
|
+
if(start>=this.length) start=this.length-1
|
|
28
|
+
if(end<0) end=0
|
|
29
|
+
for(let i=start;i>=end;i--) func(this[i],i,this)
|
|
30
|
+
}
|
|
31
|
+
return this;
|
|
32
|
+
},
|
|
33
|
+
writable: true,
|
|
34
|
+
configurable: true
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.overlay==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "overlay", {
|
|
4
|
+
value(array) {
|
|
5
|
+
if(array[0] instanceof Array)
|
|
6
|
+
array.forEach((element,index)=>this[index].overlay(element));
|
|
7
|
+
else
|
|
8
|
+
array.forEach((element,index)=>this[index]=element);
|
|
9
|
+
},
|
|
10
|
+
writable: true,
|
|
11
|
+
configurable: true
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.product==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "product", {
|
|
4
|
+
value(i=0,end=this.length-1,product=this[i]) {
|
|
5
|
+
for(i++;i<=end;i++) product*=this[i];
|
|
6
|
+
return product;
|
|
7
|
+
},
|
|
8
|
+
writable: true,
|
|
9
|
+
configurable: true
|
|
10
|
+
});
|
|
11
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
3
|
+
if(object.prototype.random==null)
|
|
4
|
+
Object.defineProperty(object.prototype, "random", {
|
|
5
|
+
value(size=this.length) {
|
|
6
|
+
let i=size
|
|
7
|
+
const result=new object(i)
|
|
8
|
+
while(i--) result[i]=Math.random();
|
|
9
|
+
return result;
|
|
10
|
+
},
|
|
11
|
+
writable: true,
|
|
12
|
+
configurable: true
|
|
13
|
+
})
|
|
14
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.reduceRange==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "reduceRange", {
|
|
4
|
+
value(start=0,end=this.length-1,func=(aggregate,cell,index)=>aggregate+cell,aggregate=0,o=this) {
|
|
5
|
+
for(let i=start;i<=end;i++) aggregate=func(aggregate,this[i],i,this)
|
|
6
|
+
return aggregate;
|
|
7
|
+
},
|
|
8
|
+
writable: true,
|
|
9
|
+
configurable: true
|
|
10
|
+
});
|
|
11
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.scale==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "scale", {
|
|
4
|
+
value(factor,start=0,end=this.length-1) {
|
|
5
|
+
for(let i=start;i<=end;i++) this[i]*=factor;
|
|
6
|
+
return this;
|
|
7
|
+
},
|
|
8
|
+
writable: true,
|
|
9
|
+
configurable: true
|
|
10
|
+
});
|
|
11
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.sum==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "sum", {
|
|
4
|
+
value(i=0,end=this.length-1,sum=0) {
|
|
5
|
+
for(;i<=end;i++) sum+=this[i];
|
|
6
|
+
return sum;
|
|
7
|
+
},
|
|
8
|
+
writable: true,
|
|
9
|
+
configurable: true
|
|
10
|
+
});
|
|
11
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[Array,Float32Array,Float64Array].forEach(object=>{
|
|
2
|
+
if(object.prototype.sumSquared==null)
|
|
3
|
+
Object.defineProperty(object.prototype, "sumSquared", {
|
|
4
|
+
value(i=0,end=this.length-1,sum=0) {
|
|
5
|
+
for(;i<=end;i++) sum+=this[i]**2;
|
|
6
|
+
return sum;
|
|
7
|
+
},
|
|
8
|
+
writable: true,
|
|
9
|
+
configurable: true
|
|
10
|
+
});
|
|
11
|
+
})
|