node-red-contrib-prib-functions 0.19.2 → 0.20.4

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.
Files changed (75) hide show
  1. package/.github/workflows/codeql-analysis.yml +3 -3
  2. package/.github/workflows/npmpublish.yml +6 -6
  3. package/.vs/VSWorkspaceState.json +7 -0
  4. package/.vs/node-red-contrib-prib-functions/v17/.wsuo +0 -0
  5. package/README.md +6 -2
  6. package/arima/index.js +18 -0
  7. package/dataAnalysis/arrayAllRowsSwap.js +15 -0
  8. package/dataAnalysis/arrayCompareToPrecision.js +34 -0
  9. package/dataAnalysis/arrayDifference.js +14 -0
  10. package/dataAnalysis/arrayDifferenceSeasonal.js +15 -0
  11. package/dataAnalysis/arrayDifferenceSeasonalSecondOrder.js +20 -0
  12. package/dataAnalysis/arrayDifferenceSecondOrder.js +14 -0
  13. package/dataAnalysis/arrayForEachRange.js +38 -0
  14. package/dataAnalysis/arrayOverlay.js +13 -0
  15. package/dataAnalysis/arrayProduct.js +11 -0
  16. package/dataAnalysis/arrayRandom.js +14 -0
  17. package/dataAnalysis/arrayReduceRange.js +11 -0
  18. package/dataAnalysis/arrayScale.js +11 -0
  19. package/dataAnalysis/arraySum.js +11 -0
  20. package/dataAnalysis/arraySumSquared.js +11 -0
  21. package/dataAnalysis/arraySwap.js +11 -0
  22. package/dataAnalysis/dataAnalysis.html +31 -14
  23. package/dataAnalysis/dataAnalysis.js +10 -1
  24. package/dataAnalysis/generateMatrixFunction.js +89 -0
  25. package/dataAnalysis/generateVectorFunction.js +25 -0
  26. package/dataAnalysis/pca.js +472 -325
  27. package/dataAnalysis/svd.js +239 -0
  28. package/echart/echart.html +68 -0
  29. package/echart/echart.js +85 -0
  30. package/echart/icons/chart-671.png +0 -0
  31. package/echart/lib/echarts.js +95886 -0
  32. package/lib/Chart.js +177 -0
  33. package/lib/Column.js +99 -0
  34. package/lib/GraphDB.js +14 -0
  35. package/lib/Table.js +185 -0
  36. package/lib/objectExtensions.js +361 -0
  37. package/matrix/matrix.js +2 -48
  38. package/monitor/BarGauge.js +8 -0
  39. package/monitor/Dataset.js +29 -0
  40. package/monitor/DialGauge.js +109 -0
  41. package/monitor/DialNeedle.js +36 -0
  42. package/monitor/Format.js +74 -0
  43. package/monitor/centerElement.js +14 -0
  44. package/monitor/compareElements.js +95 -0
  45. package/monitor/defs.js +23 -0
  46. package/monitor/extensions.js +906 -0
  47. package/monitor/functions.js +36 -0
  48. package/monitor/json2xml.js +103 -0
  49. package/monitor/monitorSystem.html +198 -0
  50. package/monitor/monitorSystem.js +322 -0
  51. package/monitor/svgHTML.js +179 -0
  52. package/monitor/svgObjects.js +64 -0
  53. package/package.json +18 -6
  54. package/test/00-objectExtensions.js +94 -0
  55. package/test/04-tables.js +33 -0
  56. package/test/data/.config.nodes.json +608 -0
  57. package/test/data/.config.nodes.json.backup +608 -0
  58. package/test/data/.config.runtime.json +4 -0
  59. package/test/data/.config.runtime.json.backup +3 -0
  60. package/test/data/.config.users.json +21 -0
  61. package/test/data/.config.users.json.backup +21 -0
  62. package/test/data/.flow.json.backup +2448 -2207
  63. package/test/data/float32vector10.npy +0 -0
  64. package/test/data/flow.json +2412 -2191
  65. package/test/data/int2matrix2x3.npy +0 -0
  66. package/test/data/package-lock.json +158 -0
  67. package/test/data/package.json +11 -0
  68. package/test/dataAnalysisExtensions.js +472 -0
  69. package/test/dataAnalysisPCA.js +54 -0
  70. package/test/dataAnalysisSVD.js +31 -0
  71. package/test/euclideanDistance.js +2 -2
  72. package/test/transformNumPy.js +132 -0
  73. package/transform/NumPy.js +303 -0
  74. package/transform/transform.html +12 -0
  75. package/transform/transform.js +34 -2
Binary file
@@ -0,0 +1,158 @@
1
+ {
2
+ "name": "node-red-project",
3
+ "version": "0.0.1",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "node-red-project",
9
+ "version": "0.0.1",
10
+ "dependencies": {
11
+ "node-red-contrib-prib-functions": "file:../..",
12
+ "node-red-node-data-generator": "~1.0.1",
13
+ "node-red-project": "file:"
14
+ }
15
+ },
16
+ "../..": {
17
+ "version": "0.20.4",
18
+ "license": "GPL-3.0",
19
+ "dependencies": {
20
+ "avsc": ">=5.7.7",
21
+ "compressiontool": "*",
22
+ "fast-xml-parser": "^4.2.5",
23
+ "node": ">=0.6.13",
24
+ "node-red-contrib-logger": "latest",
25
+ "node-red-contrib-noderedbase": ">=0.0.16",
26
+ "node-red-contrib-prib-functions": "file:",
27
+ "npm": "^10.9.0",
28
+ "xlsx": "*"
29
+ },
30
+ "devDependencies": {
31
+ "@node-red/runtime": ">=1.2.8",
32
+ "axios": ">=0.21.1",
33
+ "bcrypt": "^5.0.1",
34
+ "bl": "^5.0.0",
35
+ "mocha": "^9.2.2",
36
+ "node-red": "^3.0.2",
37
+ "node-red-node-test-helper": "^0.3.0"
38
+ }
39
+ },
40
+ "node_modules/bignumber.js": {
41
+ "version": "8.1.1",
42
+ "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-8.1.1.tgz",
43
+ "integrity": "sha512-QD46ppGintwPGuL1KqmwhR0O+N2cZUg8JG/VzwI2e28sM9TqHjQB10lI4QAaMHVbLzwVLLAwEglpKPViWX+5NQ==",
44
+ "engines": {
45
+ "node": "*"
46
+ }
47
+ },
48
+ "node_modules/dummy-json": {
49
+ "version": "3.0.5",
50
+ "resolved": "https://registry.npmjs.org/dummy-json/-/dummy-json-3.0.5.tgz",
51
+ "integrity": "sha512-g+DRLULk7jOqnFEZGBKJ4S0EiFqZETkof4V954I9Xoftq/g728Qf3D7TVmgboW1Y7ROe2Y+cZzUDAYstNqXwsg==",
52
+ "dependencies": {
53
+ "fecha": "^3.0.3",
54
+ "handlebars": "^4.7.6",
55
+ "numbro": "^2.3.1",
56
+ "seedrandom": "^3.0.5"
57
+ },
58
+ "bin": {
59
+ "dummyjson": "cli.js"
60
+ }
61
+ },
62
+ "node_modules/fecha": {
63
+ "version": "3.0.3",
64
+ "resolved": "https://registry.npmjs.org/fecha/-/fecha-3.0.3.tgz",
65
+ "integrity": "sha512-6LQK/1jud/FZnfEEZJ7y81vw7ge81DNd/XEsX0hgMUjhS+QMljkb1C0czBaP7dMNRVrd5mw/J2J7qI2Nw+TWZw=="
66
+ },
67
+ "node_modules/handlebars": {
68
+ "version": "4.7.8",
69
+ "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz",
70
+ "integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==",
71
+ "dependencies": {
72
+ "minimist": "^1.2.5",
73
+ "neo-async": "^2.6.2",
74
+ "source-map": "^0.6.1",
75
+ "wordwrap": "^1.0.0"
76
+ },
77
+ "bin": {
78
+ "handlebars": "bin/handlebars"
79
+ },
80
+ "engines": {
81
+ "node": ">=0.4.7"
82
+ },
83
+ "optionalDependencies": {
84
+ "uglify-js": "^3.1.4"
85
+ }
86
+ },
87
+ "node_modules/minimist": {
88
+ "version": "1.2.8",
89
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
90
+ "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
91
+ "funding": {
92
+ "url": "https://github.com/sponsors/ljharb"
93
+ }
94
+ },
95
+ "node_modules/neo-async": {
96
+ "version": "2.6.2",
97
+ "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
98
+ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw=="
99
+ },
100
+ "node_modules/node-red-contrib-prib-functions": {
101
+ "resolved": "../..",
102
+ "link": true
103
+ },
104
+ "node_modules/node-red-node-data-generator": {
105
+ "version": "1.0.1",
106
+ "resolved": "https://registry.npmjs.org/node-red-node-data-generator/-/node-red-node-data-generator-1.0.1.tgz",
107
+ "integrity": "sha512-ISO7/JWzyB2MIRuASosi6PkUfAgLHVfyyk28Jqn0R2GkrgX7PCGiUBcsDOwseIAnHEtAM/1/8+LeqGV3qOYjfQ==",
108
+ "dependencies": {
109
+ "dummy-json": "^3.0.5"
110
+ }
111
+ },
112
+ "node_modules/node-red-project": {
113
+ "resolved": "",
114
+ "link": true
115
+ },
116
+ "node_modules/numbro": {
117
+ "version": "2.3.6",
118
+ "resolved": "https://registry.npmjs.org/numbro/-/numbro-2.3.6.tgz",
119
+ "integrity": "sha512-pxpoTT3hVxQGaOA2RTzXR/muonQNd1K1HPJbWo7QOmxPwiPmoFCFfsG9XXgW3uqjyzezJ0P9IvCPDXUtJexjwg==",
120
+ "dependencies": {
121
+ "bignumber.js": "^8.1.1"
122
+ },
123
+ "engines": {
124
+ "node": "*"
125
+ }
126
+ },
127
+ "node_modules/seedrandom": {
128
+ "version": "3.0.5",
129
+ "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
130
+ "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
131
+ },
132
+ "node_modules/source-map": {
133
+ "version": "0.6.1",
134
+ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
135
+ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
136
+ "engines": {
137
+ "node": ">=0.10.0"
138
+ }
139
+ },
140
+ "node_modules/uglify-js": {
141
+ "version": "3.17.4",
142
+ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz",
143
+ "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==",
144
+ "optional": true,
145
+ "bin": {
146
+ "uglifyjs": "bin/uglifyjs"
147
+ },
148
+ "engines": {
149
+ "node": ">=0.8.0"
150
+ }
151
+ },
152
+ "node_modules/wordwrap": {
153
+ "version": "1.0.0",
154
+ "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
155
+ "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q=="
156
+ }
157
+ }
158
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "node-red-project",
3
+ "description": "A Node-RED Project",
4
+ "version": "0.0.1",
5
+ "private": true,
6
+ "dependencies": {
7
+ "node-red-contrib-prib-functions": "file:../..",
8
+ "node-red-node-data-generator": "~1.0.1",
9
+ "node-red-project": "file:"
10
+ }
11
+ }
@@ -0,0 +1,472 @@
1
+ const assert=require('assert');
2
+ const should=require("should");
3
+ const m2x2=[[11,12],[21,22]]
4
+ const m2x3=[[11,12,13],[21,22,23]]
5
+
6
+ describe('generatedVectorFunction', function(){
7
+ const generateVectorFunction=require("../dataAnalysis/generateVectorFunction.js");
8
+ it("error gen", function(done){
9
+ assert.throws(()=>generateVectorFunction({
10
+ code:"=a deliberate error in test",
11
+ args:["arg1,arg2"]
12
+ }),Error("code failed"))
13
+ done();
14
+ });
15
+ it("for each", function(done){
16
+ const forEach=generateVectorFunction({
17
+ code:"vector[index]+=(index+1)*10",
18
+ args:["arg1,arg2"]
19
+ })
20
+ const vector=[1,2,3,4]
21
+ forEach(vector)
22
+ assert.deepEqual(vector,[11,22,33,44])
23
+ done();
24
+ });
25
+ it("for each range", function(done){
26
+ const forEach=generateVectorFunction({code:"vector[index]+=(index+1)*10"})
27
+ const vector=[1,2,3,4]
28
+ forEach(vector,1,2)
29
+ assert.deepEqual(vector,[1,22,33,4])
30
+ done();
31
+ });
32
+ it("sumVector", function(done){
33
+ const sumVector=generateVectorFunction({code:"returnValue+=vector[index]",args:[],returnValue:0})
34
+ const vector=[1,2,3,4]
35
+ assert.deepEqual(sumVector(vector),1+2+3+4)
36
+ done();
37
+ });
38
+ it("sumVector range", function(done){
39
+ const sumVector=generateVectorFunction({code:"returnValue+=vector[index]",returnValue:10})
40
+ const vector=[1,2,3,4]
41
+ assert.deepEqual(sumVector(vector,1,2,20),20+2+3)
42
+ done();
43
+ });
44
+ it("mapVector range", function(done){
45
+ const mapVector=generateVectorFunction({
46
+ code:"returnValue[index-startOffset]=vector[index]",
47
+ args:["dataType=Array"],
48
+ returnValue:"new dataType(1+endOffset-startOffset)"
49
+ })
50
+ const vector=[1,2,3,4]
51
+ assert.deepEqual(mapVector(vector,Array,1,2),[2,3])
52
+ done();
53
+ });
54
+ it("mapVector range Float32Array", function(done){
55
+ const mapVector=generateVectorFunction({
56
+ code:"returnValue[index-startOffset]=vector[index]",
57
+ args:["dataType=Array"],returnValue:"new dataType(1+endOffset-startOffset)"
58
+ })
59
+ const vector=[1,2,3,4]
60
+ assert.deepEqual(mapVector(vector,Float32Array,1,2),new Float32Array([2,3]))
61
+ done();
62
+ });
63
+ });
64
+ describe('generateMatrixFunction', function(){
65
+ const generateMatrixFunction=require("../dataAnalysis/generateMatrixFunction.js")
66
+ const breakLogic="\nconsole.log({loop:loop});if(--loop<0) throw Error('break loop');\n"
67
+ const debugScript="console.log({rowOffset:rowOffset,rowEndOffset:rowEndOffset});"+
68
+ "console.log({columnOffset:columnOffset,columnEndOffset:columnEndOffset});"+
69
+ "console.log({elementOffset:elementOffset,matrixEndOffset:matrixEndOffset,element:element});"
70
+ it("error gen", function(done){
71
+ assert.throws(()=>generateMatrixFunction({
72
+ code:"=a deliberate error in test ",
73
+ args:["arg1,arg2"]
74
+ }),Error("code failed"))
75
+ done();
76
+ });
77
+ it("for each", function(done){
78
+ const forEach=generateMatrixFunction({
79
+ code:"row[columnOffset]=rowOffset*10+columnOffset"+breakLogic,
80
+ args:["loop=111"],
81
+ debug:true
82
+ })
83
+ const vector=[[1,2],[3,4]]
84
+ forEach(vector)
85
+ assert.deepEqual(vector,[[0,1],[10,11]])
86
+ done();
87
+ });
88
+ it("for each setElement", function(done){
89
+ const forEach=generateMatrixFunction({
90
+ code:"setElement(rowOffset*10+columnOffset)"
91
+ })
92
+ const vector=[[1,2],[3,4]]
93
+ forEach(vector)
94
+ assert.deepEqual(vector,[[0,1],[10,11]])
95
+ done();
96
+ });
97
+ it("for each vector", function(done){
98
+ const forEach=generateMatrixFunction({
99
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
100
+ args:["loop=111"],
101
+ debug:true
102
+ })
103
+ const vector=new Float32Array([1,2,3,4,5,6])
104
+ try{
105
+ forEach(vector,3,2)
106
+ } catch(ex){
107
+ console.error("error: "+ex.message)
108
+ console.error(ex.stack)
109
+ console.error(forEach.toString())
110
+ done("failed")
111
+ }
112
+ assert.deepEqual(vector,new Float32Array([0,1,10,11,20,21]))
113
+ done();
114
+ });
115
+ it("for each vector range row 1:1", function(done){
116
+ const forEach=generateMatrixFunction({
117
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
118
+ args:["loop=111"],
119
+ debug:true
120
+ })
121
+ const vector=new Float32Array([1,2,3,4,5,6])
122
+ forEach(vector,3,2,111,1,1)
123
+ assert.deepEqual(vector,new Float32Array([1,2,10,11,5,6]))
124
+ done();
125
+ });
126
+ it("for each vector range row 1:1 assign", function(done){
127
+ const forEach=generateMatrixFunction({
128
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
129
+ args:["loop=111"],
130
+ debug:true});
131
+ const vector=new Float32Array([1,2,3,4,5,6])
132
+ forEach(vector,3,2,111,1,1)
133
+ assert.deepEqual(vector,new Float32Array([1,2,10,11,5,6]))
134
+ done();
135
+ });
136
+ it("for each vector", function(done){
137
+ const forEach=generateMatrixFunction({
138
+ code:"console.log(matrix);setElement(rowOffset*10+columnOffset);console.log(matrix)"
139
+ })
140
+ const vector=new Float32Array([1,2,3,4,5,6])
141
+ forEach(vector,3,2)
142
+ assert.deepEqual(vector,new Float32Array([0,1,10,11,20,21]))
143
+ done();
144
+ });
145
+ });
146
+
147
+ describe('sum', function(){
148
+ require("../dataAnalysis/arraySum.js");
149
+ it("array 1 to 4", function(done){
150
+ assert.deepEqual([1,2,3,4].sum(),1+2+3+4)
151
+ done();
152
+ });
153
+ it("array 2 to 4", function(done){
154
+ assert.deepEqual([1,2,3,4].sum(1),2+3+4)
155
+ done();
156
+ });
157
+ it("array 2 to 3", function(done){
158
+ assert.deepEqual([1,2,3,4].sum(1,2),2+3)
159
+ done();
160
+ });
161
+ });
162
+ describe('sumSquared', function(){
163
+ require("../dataAnalysis/arraySumSquared.js");
164
+ it("array 1 to 4", function(done){
165
+ assert.deepEqual([1,2,3,4].sumSquared(),1**2+2**2+3**2+4**2)
166
+ done();
167
+ });
168
+ it("array 2 to 4", function(done){
169
+ assert.deepEqual([1,2,3,4].sumSquared(1),2**2+3**2+4**2)
170
+ done();
171
+ });
172
+ it("array 2 to 3", function(done){
173
+ assert.deepEqual([1,2,3,4].sumSquared(1,2),2**2+3**2)
174
+ done();
175
+ });
176
+ });
177
+ describe('product', function(){
178
+ require("../dataAnalysis/arrayProduct.js");
179
+ it("array 1 to 4", function(done){
180
+ assert.deepEqual([1,2,3,4].product(),1*2*3*4)
181
+ done();
182
+ });
183
+ it("array 2 to 4", function(done){
184
+ assert.deepEqual([1,2,3,4].product(1),2*3*4)
185
+ done();
186
+ });
187
+ it("array 2 to 3", function(done){
188
+ assert.deepEqual([1,2,3,4].product(1,2),2*3)
189
+ done();
190
+ });
191
+ });
192
+ describe('arrayDifference', function(){
193
+ require("../dataAnalysis/arrayDifference.js");
194
+ it("empty", function(done){
195
+ const result=[].difference();
196
+ console.log(result)
197
+ assert.deepEqual(result,[])
198
+ done();
199
+ });
200
+ it("1 value", function(done){
201
+ const result=[1].difference();
202
+ console.log(result)
203
+ assert.deepEqual(result,[])
204
+ done();
205
+ });
206
+ it("zero", function(done){
207
+ const result=[1,1,1,1,1].difference();
208
+ console.log(result)
209
+ assert.deepEqual(result,[0,0,0,0])
210
+ done();
211
+ });
212
+ it("equal 1", function(done){
213
+ const result=[0,1,2,3,4].difference();
214
+ console.log(result)
215
+ assert.deepEqual(result,[1,1,1,1])
216
+ done();
217
+ });
218
+ it("variance", function(done){
219
+ const result=[0,0,1,3,6].difference();
220
+ console.log(result)
221
+ assert.deepEqual(result,[0,1,2,3])
222
+ done();
223
+ });
224
+ });
225
+ describe('arrayDifferenceSecondOrder', function(){
226
+ require("../dataAnalysis/arrayDifferenceSecondOrder.js");
227
+ it("empty", function(done){
228
+ const result=[].differenceSecondOrder();
229
+ console.log(result)
230
+ assert.deepEqual(result,[])
231
+ done();
232
+ });
233
+ it("1 value", function(done){
234
+ const result=[1].differenceSecondOrder();
235
+ console.log(result)
236
+ assert.deepEqual(result,[])
237
+ done();
238
+ });
239
+ it("2 values", function(done){
240
+ const result=[1,2].differenceSecondOrder();
241
+ console.log(result)
242
+ assert.deepEqual(result,[])
243
+ done();
244
+ });
245
+ it("zero", function(done){
246
+ const result=[1,1,1].differenceSecondOrder();
247
+ console.log(result)
248
+ assert.deepEqual(result,[1-1-1+1]) //[0]
249
+ done();
250
+ });
251
+ it("zero x 2", function(done){
252
+ const result=[1,1,1,1].differenceSecondOrder();
253
+ console.log(result)
254
+ assert.deepEqual(result,[0,0])
255
+ done();
256
+ });
257
+ it("one", function(done){
258
+ const result=[0,1,2].differenceSecondOrder();
259
+ console.log(result)
260
+ assert.deepEqual(result,[(0-1)-(1-2)])
261
+ done();
262
+ });
263
+ it("one x 2", function(done){
264
+ const result=[0,1,2,3].differenceSecondOrder();
265
+ console.log(result)
266
+ assert.deepEqual(result,[(0-1)-(1-2),(1-2)-(2-3)])
267
+ done();
268
+ });
269
+ it("variance", function(done){
270
+ const result=[1,2,3,5,9].differenceSecondOrder();
271
+ console.log(result)
272
+ assert.deepEqual(result,[(1-2)-(2-3),(2-3)-(3-5),(3-5)-(5-9)])
273
+ done();
274
+ });
275
+ it("differenceSecondOrder=difference(1)", function(done){
276
+ const result1=[1,2,3,5,9].differenceSecondOrder();
277
+ const result2=[1,2,3,5,9].difference(1);
278
+ console.log(result1,result2)
279
+ assert.deepEqual(result1,result2)
280
+ done();
281
+ });
282
+ });
283
+ describe('arrayDifferenceSeasonal', function(){
284
+ require("../dataAnalysis/arrayDifferenceSeasonal.js");
285
+ it("value=[]", function(done){
286
+ const result=[].differenceSeasonal();
287
+ assert.deepEqual(result,[])
288
+ const result1=[].differenceSeasonal(2);
289
+ assert.deepEqual(result1,[])
290
+ const result11=[].differenceSeasonal(1,1);
291
+ assert.deepEqual(result11,[])
292
+ done();
293
+ });
294
+ it("value=[1]", function(done){
295
+ const v=[1]
296
+ const result=v.differenceSeasonal();
297
+ assert.deepEqual(result,[])
298
+ const result1=v.differenceSeasonal(2);
299
+ assert.deepEqual(result1,[])
300
+ const result11=v.differenceSeasonal(1,1);
301
+ assert.deepEqual(result11,[])
302
+ done();
303
+ });
304
+ it("value=[1,2]", function(done){
305
+ const v=[1,2]
306
+ const result=v.differenceSeasonal();
307
+ assert.deepEqual(result,[1])
308
+ const result1=v.differenceSeasonal(2);
309
+ assert.deepEqual(result1,[])
310
+ const result11=v.differenceSeasonal(1,1);
311
+ assert.deepEqual(result11,[])
312
+ done();
313
+ });
314
+ it("value=[1,2,3,1,2,3] lag 3", function(done){
315
+ const v=[1,2,3,1,2,3]
316
+ const result=v.differenceSeasonal(3);
317
+ assert.deepEqual(result,[0,0,0])
318
+ done();
319
+ });
320
+ it("value=[1,2,3,2,3,4] lag 3", function(done){
321
+ const v=[1,2,3,2,3,4]
322
+ const result=v.differenceSeasonal(3);
323
+ assert.deepEqual(result,[1,1,1])
324
+ done();
325
+ });
326
+ });
327
+ describe('arrayForEachRange', function(){
328
+ require("../dataAnalysis/arrayForEachRange.js");
329
+ it("array 2 to 3", function(done){
330
+ const result=[];
331
+ [0,1,2,3,4].forEachRange(2,3,(v,i,a)=>result.push(v));
332
+ assert.deepEqual(result,[2,3])
333
+ done();
334
+ });
335
+ it("array 3 to 2", function(done){
336
+ const result=[];
337
+ [0,1,2,3,4].forEachRange(3,2,(v,i,a)=>result.push(v));
338
+ assert.deepEqual(result,[3,2])
339
+ done();
340
+ });
341
+ it("array ", function(done){
342
+ const result=[];
343
+ [0,1,2,3,4].forEachRange(2,3,(v,i,a)=>result.push(v));
344
+ assert.deepEqual(result,[2,3])
345
+ done();
346
+ });
347
+ });
348
+ describe('arrayReduceRange', function(){
349
+ require("../dataAnalysis/arrayReduceRange.js");
350
+ it("array 3", function(done){
351
+ const result=[0,1,2,3,4].reduceRange(3,3,(a,value,i,vector)=>a+value);
352
+ assert.deepEqual(result,3)
353
+ done();
354
+ });
355
+ it("array ", function(done){
356
+ const result=[0,1,2,3,4].reduceRange(2,3,(a,value,i,vector)=>a+value);
357
+ assert.deepEqual(result,2+3)
358
+ done();
359
+ });
360
+ });
361
+ describe('arrayRandom', function(){
362
+ require("../dataAnalysis/arrayRandom.js");
363
+ it("array 3", function(done){
364
+ const result=[0,1,2,3,4].random();
365
+ console.log(result)
366
+ assert.notDeepEqual(result,[0,1,2,3,4])
367
+ done();
368
+ });
369
+ });
370
+ describe('arraySwap', function(){
371
+ require("../dataAnalysis/arraySwap.js");
372
+ it("array 2 to 3", function(done){
373
+ const result=[];
374
+ [0,1,2,3,4].swap(2,3);
375
+ assert.deepEqual([0,1,2,3,4].swap(2,3),[0,1,3,2,4])
376
+ done();
377
+ });
378
+ });
379
+ describe('arrayScale', function(){
380
+ require("../dataAnalysis/arrayScale.js");
381
+ it("array all", function(done){
382
+ const result=[];
383
+ [0,1,2,3,4].scale(2);
384
+ assert.deepEqual([0,1,2,3,4].scale(2),[0,1*2,2*2,3*2,4*2])
385
+ done();
386
+ });
387
+ it("array 1,2", function(done){
388
+ const result=[];
389
+ [0,1,2,3,4].scale(2);
390
+ assert.deepEqual([0,1,2,3,4].scale(2,1,2),[0,1*2,2*2,3,4])
391
+ done();
392
+ });
393
+ });
394
+ describe('arrayCompareToPrecision', function(){
395
+ require("../dataAnalysis/arrayCompareToPrecision.js");
396
+ const arrayl=[0.12];
397
+ const array1=[0.12,1.123];
398
+ const array2=[0.12,1.124];
399
+ it("length mismatch", function(done){
400
+ assert.throws(()=>arrayl.compareToPrecision(array1,2))
401
+ done();
402
+ });
403
+ it("vector precision 2", function(done){
404
+ assert.doesNotThrow(()=>array1.compareToPrecision(array2,2))
405
+ done();
406
+ });
407
+ it("vector precision 3", function(done){
408
+ assert.throws(()=>array1.compareToPrecision(array2,4))
409
+ done();
410
+ });
411
+ });
412
+ describe('arrayCompareToPrecision Float', function(){
413
+ require("../dataAnalysis/arrayCompareToPrecision.js");
414
+ const arrayl=new Float32Array([0.12]);
415
+ const array1=new Float32Array([0.12,1.123]);
416
+ const array2=new Float32Array([0.12,1.125]);
417
+ it("length mismatch", function(done){
418
+ assert.throws(()=>arrayl.compareToPrecision(array1,2))
419
+ done();
420
+ });
421
+ it("vector precision 2", function(done){
422
+ assert.doesNotThrow(()=>array1.compareToPrecision(array2,2))
423
+ done();
424
+ });
425
+ it("vector precision 3", function(done){
426
+ assert.throws(()=>array1.compareToPrecision(array2,3))
427
+ done();
428
+ });
429
+ });
430
+ describe('pca', function(){
431
+ const PCA=require("../dataAnalysis/pca.js");
432
+ const pca=new PCA();
433
+ it("getMatrix", function(done){
434
+ assert.equal(JSON.stringify(pca.getMatrix(2,2,1)),"[[1,1],[1,1]]")
435
+ done();
436
+ })
437
+ it("multipe ", function(done){
438
+ assert.equal(JSON.stringify(pca.multiply([[1,2],[3,4],[5,1]],[[2],[4]]))
439
+ ,JSON.stringify([[10],[22],[14]]));
440
+ done();
441
+ })
442
+ it("transpose ", function(done){
443
+ assert.equal(JSON.stringify(pca.transpose([[1,2],[3,4],[5,1]],[[2],[4]]))
444
+ ,JSON.stringify([[1,3,5],[2,4,1]]));
445
+ done();
446
+ })
447
+ it("x 1 matrices", function(done){
448
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,1,1))),JSON.stringify([[23],[43]]));
449
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,2,1))),JSON.stringify([[23,23],[43,43]]));
450
+ assert.equal(JSON.stringify(pca.multiply(m2x3,pca.getMatrix(3,3,1))),JSON.stringify([[36,36,36],[66,66,66]]));
451
+ done();
452
+ })
453
+ const generateVectorFunction=require("../dataAnalysis/generateVectorFunction.js");
454
+ const generateMatrixFunction=require("../dataAnalysis/generateMatrixFunction.js");
455
+
456
+ it("multiplyMatrix", function(done){
457
+ const sumVector=generateVectorFunction({
458
+ code:"returnValue+=vector[index]*matrix[index][column]; console.log({row:index,column:column,returnValue:returnValue})",
459
+ args:["matrix","column"],
460
+ returnValue:"0"
461
+ })
462
+ const multiplyMatrix=generateMatrixFunction({
463
+ code:"setElement(sumVector(element,bMatrix,columnOffset));",
464
+ args:["bMatrix"],
465
+ sumVector:sumVector,
466
+ returnValue:"()=>getMatrix()"
467
+ })
468
+ const matrix=[[1,2],[3,4],[5,6]];
469
+ console.log(multiplyMatrix(matrix,3,2,[[1,1],[1,1]]));
470
+ done();
471
+ })
472
+ });
@@ -0,0 +1,54 @@
1
+ const assert=require('assert');
2
+ const should=require("should");
3
+ require("../dataAnalysis/arrayCompareToPrecision.js");
4
+ const PCA=require("../dataAnalysis/pca.js");
5
+ const pca=new PCA();
6
+
7
+ const m2x2=[[11,12],[21,22]]
8
+ const m2x3=[[11,12,13],[21,22,23]]
9
+
10
+ describe('pca', function(){
11
+ it("getMatrix", function(done){
12
+ assert.equal(JSON.stringify(pca.getMatrix(2,2,1)),"[[1,1],[1,1]]")
13
+ done();
14
+ })
15
+ it("multipe ", function(done){
16
+ assert.equal(JSON.stringify(pca.multiply([[1,2],[3,4],[5,1]],[[2],[4]]))
17
+ ,JSON.stringify([[10],[22],[14]]));
18
+ done();
19
+ })
20
+ it("transpose ", function(done){
21
+ assert.equal(JSON.stringify(pca.transpose([[1,2],[3,4],[5,1]],[[2],[4]]))
22
+ ,JSON.stringify([[1,3,5],[2,4,1]]));
23
+ done();
24
+ })
25
+ it("x 1 matrices", function(done){
26
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,1,1))),JSON.stringify([[23],[43]]));
27
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,2,1))),JSON.stringify([[23,23],[43,43]]));
28
+ assert.equal(JSON.stringify(pca.multiply(m2x3,pca.getMatrix(3,3,1))),JSON.stringify([[36,36,36],[66,66,66]]));
29
+ done();
30
+ })
31
+ it("getEigenVectors", function(done){
32
+ const data = [[40,50,60],[50,70,60],[80,70,90],[50,60,80]];
33
+ const expected=
34
+ [{
35
+ "eigenvalue": 520.0992658908312,
36
+ "vector": [0.744899700771276, 0.2849796479974595, 0.6032503924724023]
37
+ }, {
38
+ "eigenvalue": 78.10455398035167,
39
+ "vector": [0.2313199078283626, 0.7377809866160473, -0.6341689964277106]
40
+ }, {
41
+ "eigenvalue": 18.462846795484058,
42
+ "vector": [0.6257919271076777, -0.6119361208615616, -0.4836513702572988]
43
+ }];
44
+ const expectedEigenvalues=expected.map(element=>element.eigenvalue);
45
+ const expectedVectors=expected.map(element=>element.vector);
46
+ const result = pca.getEigenVectors(data);
47
+ console.log(result);
48
+ const eigenvalues=result.map(element=>element.eigenvalue);
49
+ const vectors=result.map(element=>element.vector);
50
+ expectedEigenvalues.compareToPrecision(eigenvalues,6);
51
+ expectedVectors.compareToPrecision(vectors,6);
52
+ done();
53
+ });
54
+ });