@sis-cc/dotstatsuite-components 14.2.2 → 14.2.5
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/lib/rules/src/table/units/getUnitsArtefacts.js +1 -1
- package/lib/rules/src/table/units/getUnitsSeries.js +6 -6
- package/lib/rules2/src/hierarchiseDimensionWithNativeHierarchy.js +5 -2
- package/package.json +1 -1
- package/src/rules/src/table/units/getUnitsArtefacts.js +2 -1
- package/src/rules/src/table/units/getUnitsSeries.js +6 -7
- package/src/rules2/src/hierarchiseDimensionWithNativeHierarchy.js +6 -2
- package/test/getUnitsArtefacts.test.js +7 -0
- package/test/hierarchiseDimensionWithNativeHierarchy.test.js +25 -0
|
@@ -53,7 +53,7 @@ var getUnitsArtefacts = exports.getUnitsArtefacts = function getUnitsArtefacts(_
|
|
|
53
53
|
if (length === 0) {
|
|
54
54
|
return acc;
|
|
55
55
|
}
|
|
56
|
-
if (R.path(['relationship', 'primaryMeasure'], attr) === 'OBS_VALUE') {
|
|
56
|
+
if (R.path(['relationship', 'primaryMeasure'], attr) === 'OBS_VALUE' || R.hasPath(['relationship', 'observation'], attr)) {
|
|
57
57
|
return R.assocPath(['series', attr.id], (0, _extends3.default)({}, attr, { index: index, observations: true }), acc);
|
|
58
58
|
}
|
|
59
59
|
var attachedDimensions = R.path(['relationship', 'dimensions'], attr);
|
|
@@ -16,10 +16,10 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
var getIndex = R.path(['value', 'index']);
|
|
19
|
-
var getUnits = function getUnits(
|
|
20
|
-
return R.
|
|
19
|
+
var getUnits = function getUnits(acc, units) {
|
|
20
|
+
return R.mergeWith(function (a, b) {
|
|
21
21
|
return getIndex(a) === getIndex(b) ? a : null;
|
|
22
|
-
}, acc, units)
|
|
22
|
+
}, acc, units);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
var getUnitsSeries = exports.getUnitsSeries = function getUnitsSeries(observations) {
|
|
@@ -31,11 +31,11 @@ var getUnitsSeries = exports.getUnitsSeries = function getUnitsSeries(observatio
|
|
|
31
31
|
return R.map(function (serie) {
|
|
32
32
|
return R.reduce(function (acc, units) {
|
|
33
33
|
var unitsKeys = R.keys(units);
|
|
34
|
-
if (R.isEmpty(acc.unitsKeys)) return { units:
|
|
34
|
+
if (R.isEmpty(acc.unitsKeys)) return { units: units, unitsKeys: unitsKeys };
|
|
35
35
|
var communKeys = R.intersection(acc.unitsKeys, unitsKeys);
|
|
36
36
|
return {
|
|
37
|
-
units: getUnits(communKeys, acc.units, units),
|
|
38
|
-
unitsKeys:
|
|
37
|
+
units: getUnits(R.pick(communKeys, acc.units), R.pick(communKeys, units)),
|
|
38
|
+
unitsKeys: communKeys
|
|
39
39
|
};
|
|
40
40
|
}, { unitsKeys: [], units: {} }, serie).units;
|
|
41
41
|
})(series);
|
|
@@ -13,12 +13,15 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
13
13
|
|
|
14
14
|
var hierarchiseDimensionWithNativeHierarchy = exports.hierarchiseDimensionWithNativeHierarchy = function hierarchiseDimensionWithNativeHierarchy(dimension) {
|
|
15
15
|
var values = R.sortBy(R.prop('__indexPosition'), dimension.values || []);
|
|
16
|
-
var
|
|
16
|
+
var indexed = R.indexBy(R.prop('id'), values);
|
|
17
|
+
var grouped = R.groupBy(function (val) {
|
|
18
|
+
return val.parent && R.has(val.parent, indexed) ? val.parent : '#ROOT';
|
|
19
|
+
}, values);
|
|
17
20
|
|
|
18
21
|
var getChildren = function getChildren(parents) {
|
|
19
22
|
var childs = R.propOr([], R.last(parents) || '#ROOT', grouped);
|
|
20
23
|
return R.reduce(function (acc, child) {
|
|
21
|
-
var refined = R.assoc('parents', parents, child);
|
|
24
|
+
var refined = R.pipe(R.assoc('parents', parents), R.assoc('parent', R.last(parents)))(child);
|
|
22
25
|
var children = getChildren(R.append(child.id, parents));
|
|
23
26
|
return R.concat(acc, R.prepend(refined, children));
|
|
24
27
|
}, [], childs);
|
package/package.json
CHANGED
|
@@ -54,7 +54,8 @@ export const getUnitsArtefacts = ({ unitsDefinitionCodes=[], data }) => {
|
|
|
54
54
|
if (length === 0) {
|
|
55
55
|
return acc;
|
|
56
56
|
}
|
|
57
|
-
if (R.path(['relationship', 'primaryMeasure'], attr) === 'OBS_VALUE')
|
|
57
|
+
if ((R.path(['relationship', 'primaryMeasure'], attr) === 'OBS_VALUE')
|
|
58
|
+
|| (R.hasPath(['relationship', 'observation'], attr))) {
|
|
58
59
|
return R.assocPath(['series', attr.id], { ...attr, index, observations: true }, acc);
|
|
59
60
|
}
|
|
60
61
|
const attachedDimensions = R.path(['relationship', 'dimensions'], attr);
|
|
@@ -5,7 +5,7 @@ import * as R from 'ramda';
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const getIndex = R.path(['value', 'index']);
|
|
8
|
-
const getUnits = (
|
|
8
|
+
const getUnits = (acc, units) => R.mergeWith((a, b) => getIndex(a) === getIndex(b) ? a : null, acc, units)
|
|
9
9
|
|
|
10
10
|
export const getUnitsSeries = (observations) => {
|
|
11
11
|
let series = {};
|
|
@@ -20,13 +20,12 @@ export const getUnitsSeries = (observations) => {
|
|
|
20
20
|
serie => R.reduce(
|
|
21
21
|
(acc, units) => {
|
|
22
22
|
const unitsKeys = R.keys(units);
|
|
23
|
-
if (R.isEmpty(acc.unitsKeys)) return { units
|
|
23
|
+
if (R.isEmpty(acc.unitsKeys)) return { units, unitsKeys }
|
|
24
24
|
const communKeys = R.intersection(acc.unitsKeys, unitsKeys);
|
|
25
|
-
return {
|
|
26
|
-
units: getUnits(communKeys, acc.units, units),
|
|
27
|
-
unitsKeys
|
|
28
|
-
}
|
|
29
|
-
;
|
|
25
|
+
return {
|
|
26
|
+
units: getUnits(R.pick(communKeys, acc.units), R.pick(communKeys, units)),
|
|
27
|
+
unitsKeys: communKeys,
|
|
28
|
+
};
|
|
30
29
|
}, { unitsKeys: [], units: {} }, serie).units
|
|
31
30
|
)(series);
|
|
32
31
|
};
|
|
@@ -2,13 +2,17 @@ import * as R from 'ramda';
|
|
|
2
2
|
|
|
3
3
|
export const hierarchiseDimensionWithNativeHierarchy = (dimension) => {
|
|
4
4
|
const values = R.sortBy(R.prop('__indexPosition'), dimension.values || []);
|
|
5
|
-
const
|
|
5
|
+
const indexed = R.indexBy(R.prop('id'), values);
|
|
6
|
+
const grouped = R.groupBy(val => val.parent && R.has(val.parent, indexed) ? val.parent : '#ROOT', values);
|
|
6
7
|
|
|
7
8
|
const getChildren = (parents) => {
|
|
8
9
|
const childs = R.propOr([], R.last(parents) || '#ROOT', grouped);
|
|
9
10
|
return R.reduce(
|
|
10
11
|
(acc, child) => {
|
|
11
|
-
const refined = R.
|
|
12
|
+
const refined = R.pipe(
|
|
13
|
+
R.assoc('parents', parents),
|
|
14
|
+
R.assoc('parent', R.last(parents)),
|
|
15
|
+
)(child);
|
|
12
16
|
const children = getChildren(R.append(child.id, parents));
|
|
13
17
|
return R.concat(acc, R.prepend(refined, children));
|
|
14
18
|
},
|
|
@@ -17,6 +17,7 @@ const data = {
|
|
|
17
17
|
{ id: 'A7', relationship: { dimensions: ['D1', 'D2'] }, values: [{ id: 'V1' }] },
|
|
18
18
|
{ id: 'A8', relationship: { primaryMeasure: 'OBS_VALUE' }, values: [{ id: 'V1' }, { id: 'V2' }] },
|
|
19
19
|
{ id: 'A9', relationship: { primaryMeasure: 'OBS_VALUE' }, values: [{ id: 'V1' }, { id: 'V2' }], display: false },
|
|
20
|
+
{ id: 'A10', relationship: { observation: {} }, values: [{ id: 'V1' }, { id: 'V2' }] },
|
|
20
21
|
]
|
|
21
22
|
},
|
|
22
23
|
dimensions: {
|
|
@@ -109,4 +110,10 @@ describe('getUnitsArtefacts tests', () => {
|
|
|
109
110
|
dimensions: { header: {}, series: {} },
|
|
110
111
|
});
|
|
111
112
|
});
|
|
113
|
+
it('observation relationship', () => {
|
|
114
|
+
expect(getUnitsArtefacts({ data: { data }, unitsDefinitionCodes: ['A9', 'A10'] })).to.deep.equal({
|
|
115
|
+
attributes: { header: {}, series: { A10: { id: 'A10', observations: true, index: 7, relationship: { observation: {} }, values: [{ id: 'V1' }, { id: 'V2' }] } } },
|
|
116
|
+
dimensions: { header: {}, series: {} },
|
|
117
|
+
});
|
|
118
|
+
});
|
|
112
119
|
});
|
|
@@ -27,6 +27,31 @@ describe('hierarchiseDimensionWithNativeHierarchy tests', () => {
|
|
|
27
27
|
]
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
expect(hierarchiseDimensionWithNativeHierarchy(dimension)).to.deep.equal(expected);
|
|
31
|
+
});
|
|
32
|
+
it ('missing parent test', () => {
|
|
33
|
+
const dimension = {
|
|
34
|
+
id: 'test',
|
|
35
|
+
values: [
|
|
36
|
+
{ id: 'FRA', parent: 'EA', __indexPosition: 101 },
|
|
37
|
+
{ id: 'GER', parent: 'EA', __indexPosition: 100 },
|
|
38
|
+
{ id: 'EA', parent: 'W', __indexPosition: 30 },
|
|
39
|
+
{ id: 'A', parent: 'W', __indexPosition: 20 },
|
|
40
|
+
{ id: 'CHI', parent: undefined, __indexPosition: 0 }
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const expected = {
|
|
45
|
+
id: 'test',
|
|
46
|
+
values: [
|
|
47
|
+
{ id: 'CHI', parent: undefined, parents: [], __indexPosition: 0 },
|
|
48
|
+
{ id: 'A', parent: undefined, parents: [], __indexPosition: 20 },
|
|
49
|
+
{ id: 'EA', parent: undefined, parents: [], __indexPosition: 30 },
|
|
50
|
+
{ id: 'GER', parent: 'EA', parents: ['EA'], __indexPosition: 100 },
|
|
51
|
+
{ id: 'FRA', parent: 'EA', parents: ['EA'], __indexPosition: 101 }
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
|
|
30
55
|
expect(hierarchiseDimensionWithNativeHierarchy(dimension)).to.deep.equal(expected);
|
|
31
56
|
});
|
|
32
57
|
});
|