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.
Files changed (82) 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 +84 -70
  6. package/dataAnalysis/arrayAllRowsSwap.js +15 -0
  7. package/dataAnalysis/arrayCompareToPrecision.js +34 -0
  8. package/dataAnalysis/arrayDifference.js +14 -0
  9. package/dataAnalysis/arrayDifferenceSeasonal.js +15 -0
  10. package/dataAnalysis/arrayDifferenceSeasonalSecondOrder.js +20 -0
  11. package/dataAnalysis/arrayDifferenceSecondOrder.js +14 -0
  12. package/dataAnalysis/arrayForEachRange.js +38 -0
  13. package/dataAnalysis/arrayOverlay.js +13 -0
  14. package/dataAnalysis/arrayProduct.js +11 -0
  15. package/dataAnalysis/arrayRandom.js +14 -0
  16. package/dataAnalysis/arrayReduceRange.js +11 -0
  17. package/dataAnalysis/arrayScale.js +11 -0
  18. package/dataAnalysis/arraySum.js +11 -0
  19. package/dataAnalysis/arraySumSquared.js +11 -0
  20. package/dataAnalysis/arraySwap.js +11 -0
  21. package/dataAnalysis/dataAnalysis.html +52 -21
  22. package/dataAnalysis/dataAnalysis.js +73 -44
  23. package/dataAnalysis/generateMatrixFunction.js +89 -0
  24. package/dataAnalysis/generateVectorFunction.js +25 -0
  25. package/dataAnalysis/pca.js +472 -325
  26. package/dataAnalysis/svd.js +239 -0
  27. package/documentation/DataAnalysisRealtime.JPG +0 -0
  28. package/documentation/monitorSystem.JPG +0 -0
  29. package/documentation/monitorSystemTest.JPG +0 -0
  30. package/echart/echart.html +68 -0
  31. package/echart/echart.js +85 -0
  32. package/echart/icons/chart-671.png +0 -0
  33. package/echart/lib/echarts.js +95886 -0
  34. package/lib/Chart.js +177 -0
  35. package/lib/Column.js +99 -0
  36. package/lib/GraphDB.js +14 -0
  37. package/lib/Table.js +185 -0
  38. package/lib/objectExtensions.js +361 -0
  39. package/matrix/matrix.js +95 -56
  40. package/matrix/matrixNode.html +88 -55
  41. package/matrix/matrixNode.js +12 -5
  42. package/monitor/BarGauge.js +8 -0
  43. package/monitor/Dataset.js +29 -0
  44. package/monitor/DialGauge.js +109 -0
  45. package/monitor/DialNeedle.js +36 -0
  46. package/monitor/Format.js +74 -0
  47. package/monitor/centerElement.js +14 -0
  48. package/monitor/compareElements.js +95 -0
  49. package/monitor/defs.js +23 -0
  50. package/monitor/extensions.js +906 -0
  51. package/monitor/functions.js +36 -0
  52. package/monitor/json2xml.js +103 -0
  53. package/monitor/monitorSystem.html +199 -0
  54. package/monitor/monitorSystem.js +322 -0
  55. package/monitor/svgHTML.js +179 -0
  56. package/monitor/svgObjects.js +64 -0
  57. package/package.json +20 -6
  58. package/test/00-objectExtensions.js +94 -0
  59. package/test/04-tables.js +33 -0
  60. package/test/data/.config.nodes.json +608 -0
  61. package/test/data/.config.nodes.json.backup +608 -0
  62. package/test/data/.config.runtime.json +4 -0
  63. package/test/data/.config.runtime.json.backup +3 -0
  64. package/test/data/.config.users.json +21 -0
  65. package/test/data/.config.users.json.backup +21 -0
  66. package/test/data/.flow.json.backup +2820 -2003
  67. package/test/data/float32vector10.npy +0 -0
  68. package/test/data/flow.json +2830 -2033
  69. package/test/data/int2matrix2x3.npy +0 -0
  70. package/test/data/package-lock.json +158 -0
  71. package/test/data/package.json +11 -0
  72. package/test/dataAnalysisExtensions.js +471 -0
  73. package/test/dataAnalysisPCA.js +54 -0
  74. package/test/dataAnalysisSVD.js +31 -0
  75. package/test/euclideanDistance.js +2 -2
  76. package/test/transformConfluence.js +1 -1
  77. package/test/transformNumPy.js +132 -0
  78. package/testing/test.html +1 -1
  79. package/testing/test.js +78 -53
  80. package/transform/NumPy.js +303 -0
  81. package/transform/transform.html +12 -0
  82. 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.21.0",
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,471 @@
1
+ const assert=require('assert');
2
+ const m2x2=[[11,12],[21,22]]
3
+ const m2x3=[[11,12,13],[21,22,23]]
4
+
5
+ describe('generatedVectorFunction', function(){
6
+ const generateVectorFunction=require("../dataAnalysis/generateVectorFunction.js");
7
+ it("error gen", function(done){
8
+ assert.throws(()=>generateVectorFunction({
9
+ code:"=a deliberate error in test",
10
+ args:["arg1,arg2"]
11
+ }),Error("code failed"))
12
+ done();
13
+ });
14
+ it("for each", function(done){
15
+ const forEach=generateVectorFunction({
16
+ code:"vector[index]+=(index+1)*10",
17
+ args:["arg1,arg2"]
18
+ })
19
+ const vector=[1,2,3,4]
20
+ forEach(vector)
21
+ assert.deepEqual(vector,[11,22,33,44])
22
+ done();
23
+ });
24
+ it("for each range", function(done){
25
+ const forEach=generateVectorFunction({code:"vector[index]+=(index+1)*10"})
26
+ const vector=[1,2,3,4]
27
+ forEach(vector,1,2)
28
+ assert.deepEqual(vector,[1,22,33,4])
29
+ done();
30
+ });
31
+ it("sumVector", function(done){
32
+ const sumVector=generateVectorFunction({code:"returnValue+=vector[index]",args:[],returnValue:0})
33
+ const vector=[1,2,3,4]
34
+ assert.deepEqual(sumVector(vector),1+2+3+4)
35
+ done();
36
+ });
37
+ it("sumVector range", function(done){
38
+ const sumVector=generateVectorFunction({code:"returnValue+=vector[index]",returnValue:10})
39
+ const vector=[1,2,3,4]
40
+ assert.deepEqual(sumVector(vector,1,2,20),20+2+3)
41
+ done();
42
+ });
43
+ it("mapVector range", function(done){
44
+ const mapVector=generateVectorFunction({
45
+ code:"returnValue[index-startOffset]=vector[index]",
46
+ args:["dataType=Array"],
47
+ returnValue:"new dataType(1+endOffset-startOffset)"
48
+ })
49
+ const vector=[1,2,3,4]
50
+ assert.deepEqual(mapVector(vector,Array,1,2),[2,3])
51
+ done();
52
+ });
53
+ it("mapVector range Float32Array", function(done){
54
+ const mapVector=generateVectorFunction({
55
+ code:"returnValue[index-startOffset]=vector[index]",
56
+ args:["dataType=Array"],returnValue:"new dataType(1+endOffset-startOffset)"
57
+ })
58
+ const vector=[1,2,3,4]
59
+ assert.deepEqual(mapVector(vector,Float32Array,1,2),new Float32Array([2,3]))
60
+ done();
61
+ });
62
+ });
63
+ describe('generateMatrixFunction', function(){
64
+ const generateMatrixFunction=require("../dataAnalysis/generateMatrixFunction.js")
65
+ const breakLogic="\nconsole.log({loop:loop});if(--loop<0) throw Error('break loop');\n"
66
+ const debugScript="console.log({rowOffset:rowOffset,rowEndOffset:rowEndOffset});"+
67
+ "console.log({columnOffset:columnOffset,columnEndOffset:columnEndOffset});"+
68
+ "console.log({elementOffset:elementOffset,matrixEndOffset:matrixEndOffset,element:element});"
69
+ it("error gen", function(done){
70
+ assert.throws(()=>generateMatrixFunction({
71
+ code:"=a deliberate error in test ",
72
+ args:["arg1,arg2"]
73
+ }),Error("code failed"))
74
+ done();
75
+ });
76
+ it("for each", function(done){
77
+ const forEach=generateMatrixFunction({
78
+ code:"row[columnOffset]=rowOffset*10+columnOffset"+breakLogic,
79
+ args:["loop=111"],
80
+ debug:true
81
+ })
82
+ const vector=[[1,2],[3,4]]
83
+ forEach(vector)
84
+ assert.deepEqual(vector,[[0,1],[10,11]])
85
+ done();
86
+ });
87
+ it("for each setElement", function(done){
88
+ const forEach=generateMatrixFunction({
89
+ code:"setElement(rowOffset*10+columnOffset)"
90
+ })
91
+ const vector=[[1,2],[3,4]]
92
+ forEach(vector)
93
+ assert.deepEqual(vector,[[0,1],[10,11]])
94
+ done();
95
+ });
96
+ it("for each vector", function(done){
97
+ const forEach=generateMatrixFunction({
98
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
99
+ args:["loop=111"],
100
+ debug:true
101
+ })
102
+ const vector=new Float32Array([1,2,3,4,5,6])
103
+ try{
104
+ forEach(vector,3,2)
105
+ } catch(ex){
106
+ console.error("error: "+ex.message)
107
+ console.error(ex.stack)
108
+ console.error(forEach.toString())
109
+ done("failed")
110
+ }
111
+ assert.deepEqual(vector,new Float32Array([0,1,10,11,20,21]))
112
+ done();
113
+ });
114
+ it("for each vector range row 1:1", function(done){
115
+ const forEach=generateMatrixFunction({
116
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
117
+ args:["loop=111"],
118
+ debug:true
119
+ })
120
+ const vector=new Float32Array([1,2,3,4,5,6])
121
+ forEach(vector,3,2,111,1,1)
122
+ assert.deepEqual(vector,new Float32Array([1,2,10,11,5,6]))
123
+ done();
124
+ });
125
+ it("for each vector range row 1:1 assign", function(done){
126
+ const forEach=generateMatrixFunction({
127
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
128
+ args:["loop=111"],
129
+ debug:true});
130
+ const vector=new Float32Array([1,2,3,4,5,6])
131
+ forEach(vector,3,2,111,1,1)
132
+ assert.deepEqual(vector,new Float32Array([1,2,10,11,5,6]))
133
+ done();
134
+ });
135
+ it("for each vector", function(done){
136
+ const forEach=generateMatrixFunction({
137
+ code:"console.log(matrix);setElement(rowOffset*10+columnOffset);console.log(matrix)"
138
+ })
139
+ const vector=new Float32Array([1,2,3,4,5,6])
140
+ forEach(vector,3,2)
141
+ assert.deepEqual(vector,new Float32Array([0,1,10,11,20,21]))
142
+ done();
143
+ });
144
+ });
145
+
146
+ describe('sum', function(){
147
+ require("../dataAnalysis/arraySum.js");
148
+ it("array 1 to 4", function(done){
149
+ assert.deepEqual([1,2,3,4].sum(),1+2+3+4)
150
+ done();
151
+ });
152
+ it("array 2 to 4", function(done){
153
+ assert.deepEqual([1,2,3,4].sum(1),2+3+4)
154
+ done();
155
+ });
156
+ it("array 2 to 3", function(done){
157
+ assert.deepEqual([1,2,3,4].sum(1,2),2+3)
158
+ done();
159
+ });
160
+ });
161
+ describe('sumSquared', function(){
162
+ require("../dataAnalysis/arraySumSquared.js");
163
+ it("array 1 to 4", function(done){
164
+ assert.deepEqual([1,2,3,4].sumSquared(),1**2+2**2+3**2+4**2)
165
+ done();
166
+ });
167
+ it("array 2 to 4", function(done){
168
+ assert.deepEqual([1,2,3,4].sumSquared(1),2**2+3**2+4**2)
169
+ done();
170
+ });
171
+ it("array 2 to 3", function(done){
172
+ assert.deepEqual([1,2,3,4].sumSquared(1,2),2**2+3**2)
173
+ done();
174
+ });
175
+ });
176
+ describe('product', function(){
177
+ require("../dataAnalysis/arrayProduct.js");
178
+ it("array 1 to 4", function(done){
179
+ assert.deepEqual([1,2,3,4].product(),1*2*3*4)
180
+ done();
181
+ });
182
+ it("array 2 to 4", function(done){
183
+ assert.deepEqual([1,2,3,4].product(1),2*3*4)
184
+ done();
185
+ });
186
+ it("array 2 to 3", function(done){
187
+ assert.deepEqual([1,2,3,4].product(1,2),2*3)
188
+ done();
189
+ });
190
+ });
191
+ describe('arrayDifference', function(){
192
+ require("../dataAnalysis/arrayDifference.js");
193
+ it("empty", function(done){
194
+ const result=[].difference();
195
+ console.log(result)
196
+ assert.deepEqual(result,[])
197
+ done();
198
+ });
199
+ it("1 value", function(done){
200
+ const result=[1].difference();
201
+ console.log(result)
202
+ assert.deepEqual(result,[])
203
+ done();
204
+ });
205
+ it("zero", function(done){
206
+ const result=[1,1,1,1,1].difference();
207
+ console.log(result)
208
+ assert.deepEqual(result,[0,0,0,0])
209
+ done();
210
+ });
211
+ it("equal 1", function(done){
212
+ const result=[0,1,2,3,4].difference();
213
+ console.log(result)
214
+ assert.deepEqual(result,[1,1,1,1])
215
+ done();
216
+ });
217
+ it("variance", function(done){
218
+ const result=[0,0,1,3,6].difference();
219
+ console.log(result)
220
+ assert.deepEqual(result,[0,1,2,3])
221
+ done();
222
+ });
223
+ });
224
+ describe('arrayDifferenceSecondOrder', function(){
225
+ require("../dataAnalysis/arrayDifferenceSecondOrder.js");
226
+ it("empty", function(done){
227
+ const result=[].differenceSecondOrder();
228
+ console.log(result)
229
+ assert.deepEqual(result,[])
230
+ done();
231
+ });
232
+ it("1 value", function(done){
233
+ const result=[1].differenceSecondOrder();
234
+ console.log(result)
235
+ assert.deepEqual(result,[])
236
+ done();
237
+ });
238
+ it("2 values", function(done){
239
+ const result=[1,2].differenceSecondOrder();
240
+ console.log(result)
241
+ assert.deepEqual(result,[])
242
+ done();
243
+ });
244
+ it("zero", function(done){
245
+ const result=[1,1,1].differenceSecondOrder();
246
+ console.log(result)
247
+ assert.deepEqual(result,[1-1-1+1]) //[0]
248
+ done();
249
+ });
250
+ it("zero x 2", function(done){
251
+ const result=[1,1,1,1].differenceSecondOrder();
252
+ console.log(result)
253
+ assert.deepEqual(result,[0,0])
254
+ done();
255
+ });
256
+ it("one", function(done){
257
+ const result=[0,1,2].differenceSecondOrder();
258
+ console.log(result)
259
+ assert.deepEqual(result,[(0-1)-(1-2)])
260
+ done();
261
+ });
262
+ it("one x 2", function(done){
263
+ const result=[0,1,2,3].differenceSecondOrder();
264
+ console.log(result)
265
+ assert.deepEqual(result,[(0-1)-(1-2),(1-2)-(2-3)])
266
+ done();
267
+ });
268
+ it("variance", function(done){
269
+ const result=[1,2,3,5,9].differenceSecondOrder();
270
+ console.log(result)
271
+ assert.deepEqual(result,[(1-2)-(2-3),(2-3)-(3-5),(3-5)-(5-9)])
272
+ done();
273
+ });
274
+ it("differenceSecondOrder=difference(1)", function(done){
275
+ const result1=[1,2,3,5,9].differenceSecondOrder();
276
+ const result2=[1,2,3,5,9].difference(1);
277
+ console.log(result1,result2)
278
+ assert.deepEqual(result1,result2)
279
+ done();
280
+ });
281
+ });
282
+ describe('arrayDifferenceSeasonal', function(){
283
+ require("../dataAnalysis/arrayDifferenceSeasonal.js");
284
+ it("value=[]", function(done){
285
+ const result=[].differenceSeasonal();
286
+ assert.deepEqual(result,[])
287
+ const result1=[].differenceSeasonal(2);
288
+ assert.deepEqual(result1,[])
289
+ const result11=[].differenceSeasonal(1,1);
290
+ assert.deepEqual(result11,[])
291
+ done();
292
+ });
293
+ it("value=[1]", function(done){
294
+ const v=[1]
295
+ const result=v.differenceSeasonal();
296
+ assert.deepEqual(result,[])
297
+ const result1=v.differenceSeasonal(2);
298
+ assert.deepEqual(result1,[])
299
+ const result11=v.differenceSeasonal(1,1);
300
+ assert.deepEqual(result11,[])
301
+ done();
302
+ });
303
+ it("value=[1,2]", function(done){
304
+ const v=[1,2]
305
+ const result=v.differenceSeasonal();
306
+ assert.deepEqual(result,[1])
307
+ const result1=v.differenceSeasonal(2);
308
+ assert.deepEqual(result1,[])
309
+ const result11=v.differenceSeasonal(1,1);
310
+ assert.deepEqual(result11,[])
311
+ done();
312
+ });
313
+ it("value=[1,2,3,1,2,3] lag 3", function(done){
314
+ const v=[1,2,3,1,2,3]
315
+ const result=v.differenceSeasonal(3);
316
+ assert.deepEqual(result,[0,0,0])
317
+ done();
318
+ });
319
+ it("value=[1,2,3,2,3,4] lag 3", function(done){
320
+ const v=[1,2,3,2,3,4]
321
+ const result=v.differenceSeasonal(3);
322
+ assert.deepEqual(result,[1,1,1])
323
+ done();
324
+ });
325
+ });
326
+ describe('arrayForEachRange', function(){
327
+ require("../dataAnalysis/arrayForEachRange.js");
328
+ it("array 2 to 3", function(done){
329
+ const result=[];
330
+ [0,1,2,3,4].forEachRange(2,3,(v,i,a)=>result.push(v));
331
+ assert.deepEqual(result,[2,3])
332
+ done();
333
+ });
334
+ it("array 3 to 2", function(done){
335
+ const result=[];
336
+ [0,1,2,3,4].forEachRange(3,2,(v,i,a)=>result.push(v));
337
+ assert.deepEqual(result,[3,2])
338
+ done();
339
+ });
340
+ it("array ", function(done){
341
+ const result=[];
342
+ [0,1,2,3,4].forEachRange(2,3,(v,i,a)=>result.push(v));
343
+ assert.deepEqual(result,[2,3])
344
+ done();
345
+ });
346
+ });
347
+ describe('arrayReduceRange', function(){
348
+ require("../dataAnalysis/arrayReduceRange.js");
349
+ it("array 3", function(done){
350
+ const result=[0,1,2,3,4].reduceRange(3,3,(a,value,i,vector)=>a+value);
351
+ assert.deepEqual(result,3)
352
+ done();
353
+ });
354
+ it("array ", function(done){
355
+ const result=[0,1,2,3,4].reduceRange(2,3,(a,value,i,vector)=>a+value);
356
+ assert.deepEqual(result,2+3)
357
+ done();
358
+ });
359
+ });
360
+ describe('arrayRandom', function(){
361
+ require("../dataAnalysis/arrayRandom.js");
362
+ it("array 3", function(done){
363
+ const result=[0,1,2,3,4].random();
364
+ console.log(result)
365
+ assert.notDeepEqual(result,[0,1,2,3,4])
366
+ done();
367
+ });
368
+ });
369
+ describe('arraySwap', function(){
370
+ require("../dataAnalysis/arraySwap.js");
371
+ it("array 2 to 3", function(done){
372
+ const result=[];
373
+ [0,1,2,3,4].swap(2,3);
374
+ assert.deepEqual([0,1,2,3,4].swap(2,3),[0,1,3,2,4])
375
+ done();
376
+ });
377
+ });
378
+ describe('arrayScale', function(){
379
+ require("../dataAnalysis/arrayScale.js");
380
+ it("array all", function(done){
381
+ const result=[];
382
+ [0,1,2,3,4].scale(2);
383
+ assert.deepEqual([0,1,2,3,4].scale(2),[0,1*2,2*2,3*2,4*2])
384
+ done();
385
+ });
386
+ it("array 1,2", function(done){
387
+ const result=[];
388
+ [0,1,2,3,4].scale(2);
389
+ assert.deepEqual([0,1,2,3,4].scale(2,1,2),[0,1*2,2*2,3,4])
390
+ done();
391
+ });
392
+ });
393
+ describe('arrayCompareToPrecision', function(){
394
+ require("../dataAnalysis/arrayCompareToPrecision.js");
395
+ const arrayl=[0.12];
396
+ const array1=[0.12,1.123];
397
+ const array2=[0.12,1.124];
398
+ it("length mismatch", function(done){
399
+ assert.throws(()=>arrayl.compareToPrecision(array1,2))
400
+ done();
401
+ });
402
+ it("vector precision 2", function(done){
403
+ assert.doesNotThrow(()=>array1.compareToPrecision(array2,2))
404
+ done();
405
+ });
406
+ it("vector precision 3", function(done){
407
+ assert.throws(()=>array1.compareToPrecision(array2,4))
408
+ done();
409
+ });
410
+ });
411
+ describe('arrayCompareToPrecision Float', function(){
412
+ require("../dataAnalysis/arrayCompareToPrecision.js");
413
+ const arrayl=new Float32Array([0.12]);
414
+ const array1=new Float32Array([0.12,1.123]);
415
+ const array2=new Float32Array([0.12,1.125]);
416
+ it("length mismatch", function(done){
417
+ assert.throws(()=>arrayl.compareToPrecision(array1,2))
418
+ done();
419
+ });
420
+ it("vector precision 2", function(done){
421
+ assert.doesNotThrow(()=>array1.compareToPrecision(array2,2))
422
+ done();
423
+ });
424
+ it("vector precision 3", function(done){
425
+ assert.throws(()=>array1.compareToPrecision(array2,3))
426
+ done();
427
+ });
428
+ });
429
+ describe('pca', function(){
430
+ const PCA=require("../dataAnalysis/pca.js");
431
+ const pca=new PCA();
432
+ it("getMatrix", function(done){
433
+ assert.equal(JSON.stringify(pca.getMatrix(2,2,1)),"[[1,1],[1,1]]")
434
+ done();
435
+ })
436
+ it("multipe ", function(done){
437
+ assert.equal(JSON.stringify(pca.multiply([[1,2],[3,4],[5,1]],[[2],[4]]))
438
+ ,JSON.stringify([[10],[22],[14]]));
439
+ done();
440
+ })
441
+ it("transpose ", function(done){
442
+ assert.equal(JSON.stringify(pca.transpose([[1,2],[3,4],[5,1]],[[2],[4]]))
443
+ ,JSON.stringify([[1,3,5],[2,4,1]]));
444
+ done();
445
+ })
446
+ it("x 1 matrices", function(done){
447
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,1,1))),JSON.stringify([[23],[43]]));
448
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,2,1))),JSON.stringify([[23,23],[43,43]]));
449
+ assert.equal(JSON.stringify(pca.multiply(m2x3,pca.getMatrix(3,3,1))),JSON.stringify([[36,36,36],[66,66,66]]));
450
+ done();
451
+ })
452
+ const generateVectorFunction=require("../dataAnalysis/generateVectorFunction.js");
453
+ const generateMatrixFunction=require("../dataAnalysis/generateMatrixFunction.js");
454
+
455
+ it("multiplyMatrix", function(done){
456
+ const sumVector=generateVectorFunction({
457
+ code:"returnValue+=vector[index]*matrix[index][column]; console.log({row:index,column:column,returnValue:returnValue})",
458
+ args:["matrix","column"],
459
+ returnValue:"0"
460
+ })
461
+ const multiplyMatrix=generateMatrixFunction({
462
+ code:"setElement(sumVector(element,bMatrix,columnOffset));",
463
+ args:["bMatrix"],
464
+ sumVector:sumVector,
465
+ returnValue:"()=>getMatrix()"
466
+ })
467
+ const matrix=[[1,2],[3,4],[5,6]];
468
+ console.log(multiplyMatrix(matrix,3,2,[[1,1],[1,1]]));
469
+ done();
470
+ })
471
+ });
@@ -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
+ });