@sis-cc/dotstatsuite-components 14.1.0 → 14.1.1
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.
|
@@ -15,6 +15,13 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
15
15
|
observations = { [obsKey]: { units: { serieKey: '', [id]: { id, name, value } } } };
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
var getIndex = R.path(['value', 'index']);
|
|
19
|
+
var getUnits = function getUnits(keys, acc, units) {
|
|
20
|
+
return R.pick(keys, R.mergeWith(function (a, b) {
|
|
21
|
+
return getIndex(a) === getIndex(b) ? a : null;
|
|
22
|
+
}, acc, units));
|
|
23
|
+
};
|
|
24
|
+
|
|
18
25
|
var getUnitsSeries = exports.getUnitsSeries = function getUnitsSeries(observations) {
|
|
19
26
|
var series = {};
|
|
20
27
|
R.map(function (obs) {
|
|
@@ -23,9 +30,13 @@ var getUnitsSeries = exports.getUnitsSeries = function getUnitsSeries(observatio
|
|
|
23
30
|
|
|
24
31
|
return R.map(function (serie) {
|
|
25
32
|
return R.reduce(function (acc, units) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
var unitsKeys = R.keys(units);
|
|
34
|
+
if (R.isEmpty(acc.unitsKeys)) return { units: getUnits(unitsKeys, acc.units, units), unitsKeys: unitsKeys };
|
|
35
|
+
var communKeys = R.intersection(acc.unitsKeys, unitsKeys);
|
|
36
|
+
return {
|
|
37
|
+
units: getUnits(communKeys, acc.units, units),
|
|
38
|
+
unitsKeys: unitsKeys
|
|
39
|
+
};
|
|
40
|
+
}, { unitsKeys: [], units: {} }, serie).units;
|
|
30
41
|
})(series);
|
|
31
42
|
};
|
package/package.json
CHANGED
|
@@ -4,17 +4,29 @@ import * as R from 'ramda';
|
|
|
4
4
|
observations = { [obsKey]: { units: { serieKey: '', [id]: { id, name, value } } } };
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const getIndex = R.path(['value', 'index']);
|
|
8
|
+
const getUnits = (keys, acc, units) => R.pick(keys, R.mergeWith((a, b) => getIndex(a) === getIndex(b) ? a : null, acc, units))
|
|
9
|
+
|
|
7
10
|
export const getUnitsSeries = (observations) => {
|
|
8
11
|
let series = {};
|
|
9
12
|
R.map(obs => {
|
|
10
|
-
series = R.over(
|
|
13
|
+
series = R.over(
|
|
14
|
+
R.lensProp(obs.units.serieKey),
|
|
15
|
+
R.ifElse(R.isNil, R.always([obs.units]), R.append(obs.units))
|
|
16
|
+
)(series);
|
|
11
17
|
}, observations);
|
|
12
18
|
|
|
13
19
|
return R.map(
|
|
14
20
|
serie => R.reduce(
|
|
15
|
-
(acc, units) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
(acc, units) => {
|
|
22
|
+
const unitsKeys = R.keys(units);
|
|
23
|
+
if (R.isEmpty(acc.unitsKeys)) return { units: getUnits(unitsKeys, acc.units, units), unitsKeys }
|
|
24
|
+
const communKeys = R.intersection(acc.unitsKeys, unitsKeys);
|
|
25
|
+
return {
|
|
26
|
+
units: getUnits(communKeys, acc.units, units),
|
|
27
|
+
unitsKeys
|
|
28
|
+
}
|
|
29
|
+
;
|
|
30
|
+
}, { unitsKeys: [], units: {} }, serie).units
|
|
19
31
|
)(series);
|
|
20
|
-
};
|
|
32
|
+
};
|
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import { getUnitsSeries } from '../src/rules/src/table/units/getUnitsSeries';
|
|
3
3
|
|
|
4
|
-
const observations = {
|
|
5
|
-
0: {
|
|
6
|
-
key: '0:0:0:0',
|
|
7
|
-
units: {
|
|
8
|
-
serieKey: '0:0:x:x',
|
|
9
|
-
A: { value: { index: 0 } },
|
|
10
|
-
B: { value: { index: 0 } },
|
|
11
|
-
C: { value: { index: 0 } }
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
1: {
|
|
15
|
-
key: '0:0:1:0',
|
|
16
|
-
units: {
|
|
17
|
-
serieKey: '0:0:x:x',
|
|
18
|
-
A: { value: { index: 0 } },
|
|
19
|
-
B: { value: { index: 0 } },
|
|
20
|
-
C: { value: { index: 1 } }
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
2: {
|
|
24
|
-
key: '1:0:0:0',
|
|
25
|
-
units: {
|
|
26
|
-
serieKey: '1:0:x:x',
|
|
27
|
-
A: { value: { index: 1 } },
|
|
28
|
-
B: { value: { index: 1 } },
|
|
29
|
-
C: { value: { index: 0 } }
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
3: {
|
|
33
|
-
key: '1:0:1:0',
|
|
34
|
-
units: {
|
|
35
|
-
serieKey: '1:0:x:x',
|
|
36
|
-
A: { value: { index: 1 } },
|
|
37
|
-
B: { value: { index: 1 } },
|
|
38
|
-
C: { value: { index: 0 } }
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
4: {
|
|
42
|
-
key: '2:0:0:0',
|
|
43
|
-
units: {
|
|
44
|
-
serieKey: '2:0:x:x',
|
|
45
|
-
A: { value: { index: 2 } },
|
|
46
|
-
B: { value: { index: 0 } },
|
|
47
|
-
C: { value: { index: 0 } }
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
4
|
|
|
52
5
|
describe('getUnitsSeries tests', () => {
|
|
6
|
+
const observations = {
|
|
7
|
+
0: {
|
|
8
|
+
key: '0:0:0:0',
|
|
9
|
+
units: {
|
|
10
|
+
serieKey: '0:0:x:x',
|
|
11
|
+
A: { value: { index: 0 } },
|
|
12
|
+
B: { value: { index: 0 } },
|
|
13
|
+
C: { value: { index: 0 } }
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
1: {
|
|
17
|
+
key: '0:0:1:0',
|
|
18
|
+
units: {
|
|
19
|
+
serieKey: '0:0:x:x',
|
|
20
|
+
A: { value: { index: 0 } },
|
|
21
|
+
B: { value: { index: 0 } },
|
|
22
|
+
C: { value: { index: 1 } }
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
2: {
|
|
26
|
+
key: '1:0:0:0',
|
|
27
|
+
units: {
|
|
28
|
+
serieKey: '1:0:x:x',
|
|
29
|
+
A: { value: { index: 1 } },
|
|
30
|
+
B: { value: { index: 1 } },
|
|
31
|
+
C: { value: { index: 0 } }
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
3: {
|
|
35
|
+
key: '1:0:1:0',
|
|
36
|
+
units: {
|
|
37
|
+
serieKey: '1:0:x:x',
|
|
38
|
+
A: { value: { index: 1 } },
|
|
39
|
+
B: { value: { index: 1 } },
|
|
40
|
+
C: { value: { index: 0 } }
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
4: {
|
|
44
|
+
key: '2:0:0:0',
|
|
45
|
+
units: {
|
|
46
|
+
serieKey: '2:0:x:x',
|
|
47
|
+
A: { value: { index: 2 } },
|
|
48
|
+
B: { value: { index: 0 } },
|
|
49
|
+
C: { value: { index: 0 } }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
53
|
it('blank test', () => {
|
|
54
54
|
expect(getUnitsSeries({})).to.deep.equal({});
|
|
55
55
|
});
|
|
@@ -62,3 +62,68 @@ describe('getUnitsSeries tests', () => {
|
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
describe('getUnitsSeries tests keys difference', () => {
|
|
67
|
+
const observations = {
|
|
68
|
+
"0:0:0:0:0:0": {
|
|
69
|
+
"key": "0:0:0:0:0:0",
|
|
70
|
+
"units": {
|
|
71
|
+
"UNIT_MEASURE": { "value": { "index": 0 }},
|
|
72
|
+
"UNIT_MULT": { "value": { "index": 0 }},
|
|
73
|
+
"serieKey": "x:x:x:x:0:x"
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
"0:0:0:0:0:1": {
|
|
77
|
+
"key": "0:0:0:0:0:1",
|
|
78
|
+
"units": {
|
|
79
|
+
"UNIT_MEASURE": { "value": { "index": 0 }},
|
|
80
|
+
"UNIT_MULT": { "value": { "index": 0 }},
|
|
81
|
+
"serieKey": "x:x:x:x:0:x"
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
"0:0:0:1:0:0": {
|
|
85
|
+
"key": "0:0:0:1:0:0",
|
|
86
|
+
"units": {
|
|
87
|
+
"UNIT_MEASURE": { "value": { "index": 0 }},
|
|
88
|
+
"serieKey": "x:x:x:x:0:x"
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
"0:0:0:1:0:1": {
|
|
92
|
+
"key": "0:0:0:1:0:1",
|
|
93
|
+
"units": {
|
|
94
|
+
"UNIT_MEASURE": { "value": { "index": 0 }},
|
|
95
|
+
"serieKey": "x:x:x:x:0:x"
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
"0:0:0:2:1:0": {
|
|
99
|
+
"key": "0:0:0:2:1:0",
|
|
100
|
+
"units": {
|
|
101
|
+
"UNIT_MEASURE": { "value": { "index": 1 }},
|
|
102
|
+
"UNIT_MULT": { "value": { "index": 0 }},
|
|
103
|
+
"serieKey": "x:x:x:x:1:x"
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
"0:0:0:2:1:1": {
|
|
107
|
+
"key": "0:0:0:2:1:1",
|
|
108
|
+
"units": {
|
|
109
|
+
"UNIT_MEASURE": { "value": { "index": 1 }},
|
|
110
|
+
"UNIT_MULT": { "value": { "index": 0 }},
|
|
111
|
+
"serieKey": "x:x:x:x:1:x"
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const expected = {
|
|
116
|
+
"x:x:x:x:0:x": {
|
|
117
|
+
"UNIT_MEASURE": { "value": { "index": 0 }},
|
|
118
|
+
"serieKey": "x:x:x:x:0:x"
|
|
119
|
+
},
|
|
120
|
+
"x:x:x:x:1:x": {
|
|
121
|
+
"UNIT_MEASURE": { "value": { "index": 1 }},
|
|
122
|
+
"UNIT_MULT": { "value": { "index": 0 }},
|
|
123
|
+
"serieKey": "x:x:x:x:1:x"
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
it('basic test', () => {
|
|
127
|
+
expect(getUnitsSeries(observations)).to.deep.equal(expected);
|
|
128
|
+
});
|
|
129
|
+
});
|
package/test/invertTime.test.js
CHANGED
|
@@ -8,6 +8,7 @@ describe('invertTime tests', () => {
|
|
|
8
8
|
TIME_PERIOD: {
|
|
9
9
|
id: 'TIME_PERIOD',
|
|
10
10
|
__index: 1,
|
|
11
|
+
role: 'TIME_PERIOD',
|
|
11
12
|
values: [
|
|
12
13
|
{ id: 2000 },
|
|
13
14
|
{ id: 2001 },
|
|
@@ -41,6 +42,7 @@ describe('invertTime tests', () => {
|
|
|
41
42
|
dimensions: {
|
|
42
43
|
TIME_PERIOD: {
|
|
43
44
|
id: 'TIME_PERIOD',
|
|
45
|
+
role: 'TIME_PERIOD',
|
|
44
46
|
__index: 1,
|
|
45
47
|
values: [
|
|
46
48
|
{ id: 2009 },
|