@sis-cc/dotstatsuite-components 14.2.1 → 14.2.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.
- package/lib/rules/src/preparators/getReportingYearStart.js +4 -2
- 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/preparators/getReportingYearStart.js +1 -1
- package/src/rules/src/table/units/getUnitsSeries.js +6 -7
- package/src/rules2/src/hierarchiseDimensionWithNativeHierarchy.js +6 -2
- package/test/getReportingYearStart.test.js +16 -0
- package/test/hierarchiseDimensionWithNativeHierarchy.test.js +25 -0
|
@@ -43,8 +43,10 @@ var getReportingYearStart = exports.getReportingYearStart = function getReportin
|
|
|
43
43
|
|
|
44
44
|
var _R$match = R.match(/[\d]{2}/g, reportYearStart),
|
|
45
45
|
_R$match2 = (0, _slicedToArray3.default)(_R$match, 2),
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
_R$match2$ = _R$match2[0],
|
|
47
|
+
month = _R$match2$ === undefined ? '01' : _R$match2$,
|
|
48
|
+
_R$match2$2 = _R$match2[1],
|
|
49
|
+
day = _R$match2$2 === undefined ? '01' : _R$match2$2;
|
|
48
50
|
|
|
49
51
|
return { month: month, day: day };
|
|
50
52
|
};
|
|
@@ -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
|
@@ -11,6 +11,6 @@ export const getReportingYearStart = (sdmxJson) => {
|
|
|
11
11
|
return id === REPORTING_YEAR_START_DAY || id === REPYEARSTART;
|
|
12
12
|
}, attributes) || {};
|
|
13
13
|
const reportYearStart = R.pathOr('--01-01', ['values', 0, 'name'], reportYearStartAttr);
|
|
14
|
-
const [month, day] = R.match(/[\d]{2}/g, reportYearStart);
|
|
14
|
+
const [month = '01', day = '01'] = R.match(/[\d]{2}/g, reportYearStart);
|
|
15
15
|
return ({ month, day });
|
|
16
16
|
};
|
|
@@ -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
|
},
|
|
@@ -5,6 +5,22 @@ describe('getReportingYearStart tests', () => {
|
|
|
5
5
|
it('no data', () => {
|
|
6
6
|
expect(getReportingYearStart()).to.deep.equal({ month: '01', day: '01' });
|
|
7
7
|
});
|
|
8
|
+
it('unexpected data in REPYEARSTART attr: "0"', () => {
|
|
9
|
+
const data = {
|
|
10
|
+
data: {
|
|
11
|
+
structure: {
|
|
12
|
+
attributes: {
|
|
13
|
+
observation: [
|
|
14
|
+
{ "id": "REPYEARSTART",
|
|
15
|
+
"values": [{ "name": "0", "names": { "en": "0" } }]
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
expect(getReportingYearStart(data)).to.deep.equal({ month: '01', day: '01' });
|
|
23
|
+
});
|
|
8
24
|
it('REPORTING_YEAR_START_DAY', () => {
|
|
9
25
|
const dataReportingYearStartDay = {
|
|
10
26
|
data: {
|
|
@@ -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
|
});
|