@sis-cc/dotstatsuite-components 17.11.0 → 17.12.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.
- package/lib/rules/src/get-values-enhanced.js +142 -0
- package/lib/rules/src/v8-transformer.js +32 -66
- package/lib/rules/test/get-values-enhanced.test.js +126 -0
- package/lib/rules2/src/enhanceObservations.js +1 -1
- package/package.json +1 -1
- package/prettier.config.js +13 -0
- package/src/rules/src/get-values-enhanced.js +138 -0
- package/src/rules/src/v8-transformer.js +90 -116
- package/src/rules/test/get-values-enhanced.test.js +126 -0
- package/src/rules2/src/enhanceObservations.js +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getValuesEnhanced = undefined;
|
|
7
|
+
|
|
8
|
+
var _extends2 = require('babel-runtime/helpers/extends');
|
|
9
|
+
|
|
10
|
+
var _extends3 = _interopRequireDefault(_extends2);
|
|
11
|
+
|
|
12
|
+
var _ramda = require('ramda');
|
|
13
|
+
|
|
14
|
+
var R = _interopRequireWildcard(_ramda);
|
|
15
|
+
|
|
16
|
+
var _dateFns = require('date-fns');
|
|
17
|
+
|
|
18
|
+
var _dateFns2 = _interopRequireDefault(_dateFns);
|
|
19
|
+
|
|
20
|
+
var _dotstatsuiteSdmxjs = require('@sis-cc/dotstatsuite-sdmxjs');
|
|
21
|
+
|
|
22
|
+
var _sdmxData = require('./sdmx-data');
|
|
23
|
+
|
|
24
|
+
var _date = require('./date');
|
|
25
|
+
|
|
26
|
+
var _refineTimePeriod = require('../../rules2/src/refineTimePeriod');
|
|
27
|
+
|
|
28
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
+
|
|
32
|
+
var isNonCoded = R.both(R.has('value'), R.pipe(R.has('id'), R.not));
|
|
33
|
+
|
|
34
|
+
var getId = function getId(value, fallbackId) {
|
|
35
|
+
var valueId = R.prop('id', value);
|
|
36
|
+
if (valueId) return valueId;
|
|
37
|
+
if (isNonCoded(value)) return R.prop('value', value);
|
|
38
|
+
// Fallback (value has no id but is not a non-coded)
|
|
39
|
+
return fallbackId;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var getName = function getName(_ref) {
|
|
43
|
+
var isTimeDimension = _ref.isTimeDimension,
|
|
44
|
+
options = _ref.options,
|
|
45
|
+
locale = _ref.locale,
|
|
46
|
+
start = _ref.start,
|
|
47
|
+
reportYearStart = _ref.reportYearStart;
|
|
48
|
+
return function (value) {
|
|
49
|
+
if (!isTimeDimension) return (0, _dotstatsuiteSdmxjs.getRefinedName)(value);
|
|
50
|
+
return (0, _date.getReportedTimePeriodLabel)(options.frequency, options.timeFormat, locale)(reportYearStart, {
|
|
51
|
+
id: value.id,
|
|
52
|
+
reportedStart: start,
|
|
53
|
+
start: new Date(value.start)
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
var getValuesEnhanced = exports.getValuesEnhanced = function getValuesEnhanced(_ref2) {
|
|
59
|
+
var _ref2$locale = _ref2.locale,
|
|
60
|
+
locale = _ref2$locale === undefined ? '' : _ref2$locale,
|
|
61
|
+
_ref2$annotations = _ref2.annotations,
|
|
62
|
+
annotations = _ref2$annotations === undefined ? [] : _ref2$annotations,
|
|
63
|
+
_ref2$isTimeDimension = _ref2.isTimeDimension,
|
|
64
|
+
isTimeDimension = _ref2$isTimeDimension === undefined ? false : _ref2$isTimeDimension,
|
|
65
|
+
_ref2$parent = _ref2.parent,
|
|
66
|
+
parent = _ref2$parent === undefined ? '' : _ref2$parent,
|
|
67
|
+
reportYearStart = _ref2.reportYearStart,
|
|
68
|
+
_ref2$_hiddenIds = _ref2._hiddenIds,
|
|
69
|
+
_hiddenIds = _ref2$_hiddenIds === undefined ? {} : _ref2$_hiddenIds,
|
|
70
|
+
_ref2$hiddenIds = _ref2.hiddenIds,
|
|
71
|
+
hiddenIds = _ref2$hiddenIds === undefined ? {} : _ref2$hiddenIds,
|
|
72
|
+
_ref2$options = _ref2.options,
|
|
73
|
+
options = _ref2$options === undefined ? {} : _ref2$options;
|
|
74
|
+
|
|
75
|
+
return R.pipe(R.addIndex(R.map)(function (value, __index) {
|
|
76
|
+
var id = getId(value, parent + '-' + __index);
|
|
77
|
+
|
|
78
|
+
var valueAnnotations = R.pipe(R.propOr([], 'annotations'), R.flip(R.props)(annotations))(value);
|
|
79
|
+
|
|
80
|
+
var isHidden = _hiddenIds[parent] && R.includes(value.id, _hiddenIds[parent]) || R.has(parent + '.' + value.id, hiddenIds) || (0, _sdmxData.getIsHidden)(valueAnnotations);
|
|
81
|
+
|
|
82
|
+
var _ref3 = isTimeDimension ? getTimePeriodAttributes({ reportYearStart: reportYearStart, options: options })(value) : { notes: [] },
|
|
83
|
+
start = _ref3.start,
|
|
84
|
+
notes = _ref3.notes;
|
|
85
|
+
|
|
86
|
+
var __indexPosition = NaN;
|
|
87
|
+
if (isNaN(__indexPosition)) {
|
|
88
|
+
__indexPosition = (0, _dotstatsuiteSdmxjs.getCodeOrder)({ annotations: valueAnnotations });
|
|
89
|
+
}
|
|
90
|
+
var res = (0, _extends3.default)({}, R.omit(['names', 'value'], value), {
|
|
91
|
+
id: id,
|
|
92
|
+
display: !isHidden,
|
|
93
|
+
start: start ? start.toISOString() : null,
|
|
94
|
+
notes: notes,
|
|
95
|
+
__indexPosition: __indexPosition,
|
|
96
|
+
__index: __index
|
|
97
|
+
});
|
|
98
|
+
if (!isNonCoded(value)) {
|
|
99
|
+
res = R.assoc('name', getName({ isTimeDimension: isTimeDimension, options: options, locale: locale, start: start, reportYearStart: reportYearStart })(value), res);
|
|
100
|
+
}
|
|
101
|
+
if (isTimeDimension) {
|
|
102
|
+
res = (0, _refineTimePeriod.refineTimePeriod)(res, {
|
|
103
|
+
locale: locale,
|
|
104
|
+
monthlyFormat: options.timeFormat
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return res;
|
|
108
|
+
}),
|
|
109
|
+
// __indexPosition is used for pre-sorting
|
|
110
|
+
R.sortWith(isTimeDimension ? timeDimensionSorts : defaultSorts),
|
|
111
|
+
// __indexPosition is reset after pre-sorting
|
|
112
|
+
R.addIndex(R.map)(function (val, index) {
|
|
113
|
+
return R.assoc('__indexPosition', index, val);
|
|
114
|
+
}),
|
|
115
|
+
// values are re-sorted by __index after __indexPosition settlement
|
|
116
|
+
R.sortBy(R.prop('__index')));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
var getDateForSort = function getDateForSort(key) {
|
|
120
|
+
return function (val) {
|
|
121
|
+
return _dateFns2.default.getTime(new Date(R.prop(key, val)));
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
var byStartDate = R.ascend(getDateForSort('start'));
|
|
125
|
+
var byEndDate = R.descend(getDateForSort('end'));
|
|
126
|
+
var timeDimensionSorts = [byStartDate, byEndDate];
|
|
127
|
+
var byIndexPosition = R.ascend(R.prop('__indexPosition'));
|
|
128
|
+
var byOrder = R.ascend(R.propOr(-1, 'order'));
|
|
129
|
+
var defaultSorts = [byIndexPosition, byOrder];
|
|
130
|
+
|
|
131
|
+
var getTimePeriodAttributes = function getTimePeriodAttributes(_ref4) {
|
|
132
|
+
var reportYearStart = _ref4.reportYearStart,
|
|
133
|
+
options = _ref4.options;
|
|
134
|
+
return function (value) {
|
|
135
|
+
var reported = (0, _date.getReportedTimePeriod)(reportYearStart, value, options.frequency);
|
|
136
|
+
var start = reported.start;
|
|
137
|
+
var end = reported.end;
|
|
138
|
+
var reportTimeNote = (0, _date.getReportedTimePeriodNote)(reportYearStart, start, end, options.frequency, options.isRtl);
|
|
139
|
+
var notes = R.isNil(reportTimeNote) ? [] : R.append(reportTimeNote, []);
|
|
140
|
+
return { start: start, notes: notes };
|
|
141
|
+
};
|
|
142
|
+
};
|
|
@@ -13,21 +13,15 @@ var _ramda = require('ramda');
|
|
|
13
13
|
|
|
14
14
|
var R = _interopRequireWildcard(_ramda);
|
|
15
15
|
|
|
16
|
-
var _dateFns = require('date-fns');
|
|
17
|
-
|
|
18
|
-
var _dateFns2 = _interopRequireDefault(_dateFns);
|
|
19
|
-
|
|
20
16
|
var _dotstatsuiteSdmxjs = require('@sis-cc/dotstatsuite-sdmxjs');
|
|
21
17
|
|
|
22
18
|
var _sdmxData = require('./sdmx-data');
|
|
23
19
|
|
|
24
|
-
var _date = require('./date');
|
|
25
|
-
|
|
26
20
|
var _getReportingYearStart = require('./preparators/getReportingYearStart');
|
|
27
21
|
|
|
28
22
|
var _src = require('../../rules2/src');
|
|
29
23
|
|
|
30
|
-
var
|
|
24
|
+
var _getValuesEnhanced = require('./get-values-enhanced');
|
|
31
25
|
|
|
32
26
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
33
27
|
|
|
@@ -54,60 +48,6 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
|
|
|
54
48
|
|
|
55
49
|
var hiddenIds = (0, _src.getNotDisplayedIds)(dataSetsAnnotations);
|
|
56
50
|
|
|
57
|
-
//--------------------------------------------------------------------------------------------------
|
|
58
|
-
var getValues = function getValues(values, parent) {
|
|
59
|
-
return R.map(function (value) {
|
|
60
|
-
var valAnnotations = R.props(value.annotations || [], annotations);
|
|
61
|
-
return (0, _extends3.default)({}, value, {
|
|
62
|
-
display: !R.has(parent + '.' + value.id, hiddenIds) && !(0, _sdmxData.getIsHidden)(valAnnotations),
|
|
63
|
-
name: (0, _dotstatsuiteSdmxjs.getRefinedName)(value)
|
|
64
|
-
});
|
|
65
|
-
}, values);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
var getValuesEnhanced = function getValuesEnhanced(locale, annotations, isTimeDimension, parent) {
|
|
69
|
-
return R.pipe(R.addIndex(R.map)(function (value, __index) {
|
|
70
|
-
var valueAnnotations = R.pipe(R.propOr([], 'annotations'), R.flip(R.props)(annotations))(value);
|
|
71
|
-
var isHidden = _hiddenIds[parent] && R.includes(value.id, _hiddenIds[parent]) || R.has(parent + '.' + value.id, hiddenIds) || (0, _sdmxData.getIsHidden)(valueAnnotations);
|
|
72
|
-
var name = (0, _dotstatsuiteSdmxjs.getRefinedName)(value);
|
|
73
|
-
var __indexPosition = NaN;
|
|
74
|
-
var notes = [];
|
|
75
|
-
var start = null;
|
|
76
|
-
var end = null;
|
|
77
|
-
if (isTimeDimension) {
|
|
78
|
-
var reported = (0, _date.getReportedTimePeriod)(reportYearStart, value, options.frequency);
|
|
79
|
-
start = reported.start;
|
|
80
|
-
end = reported.end;
|
|
81
|
-
var reportTimeNote = (0, _date.getReportedTimePeriodNote)(reportYearStart, start, end, options.frequency, options.isRtl);
|
|
82
|
-
notes = R.isNil(reportTimeNote) ? notes : R.append(reportTimeNote, notes);
|
|
83
|
-
}
|
|
84
|
-
if (isNaN(__indexPosition)) {
|
|
85
|
-
__indexPosition = (0, _dotstatsuiteSdmxjs.getCodeOrder)({ annotations: valueAnnotations });
|
|
86
|
-
}
|
|
87
|
-
var timeFormat = R.prop('timeFormat', options);
|
|
88
|
-
var res = (0, _extends3.default)({}, value, {
|
|
89
|
-
id: R.when(R.isNil, R.always(parent + '-' + __index))(value.id),
|
|
90
|
-
display: !isHidden,
|
|
91
|
-
name: R.when(R.always(isTimeDimension), R.always((0, _date.getReportedTimePeriodLabel)(options.frequency, timeFormat, locale)(reportYearStart, { id: value.id, reportedStart: start, start: new Date(value.start) })))(name),
|
|
92
|
-
start: start ? start.toISOString() : null,
|
|
93
|
-
notes: notes,
|
|
94
|
-
__indexPosition: __indexPosition,
|
|
95
|
-
__index: __index
|
|
96
|
-
});
|
|
97
|
-
return isTimeDimension ? (0, _refineTimePeriod.refineTimePeriod)(res, { locale: locale, monthlyFormat: timeFormat }) : res;
|
|
98
|
-
}), R.ifElse(R.always(isTimeDimension), R.pipe(R.sortWith([R.ascend(function (val) {
|
|
99
|
-
return _dateFns2.default.getTime(new Date(R.prop('start', val)));
|
|
100
|
-
}), R.descend(function (val) {
|
|
101
|
-
return _dateFns2.default.getTime(new Date(R.prop('end', val)));
|
|
102
|
-
})]), R.addIndex(R.map)(function (val, ind) {
|
|
103
|
-
return R.assoc('__indexcPosition', ind, val);
|
|
104
|
-
})), R.sortWith([R.ascend(R.prop('__indexPosition')), R.ascend(R.propOr(-1, 'order'))])), R.addIndex(R.map)(function (val, index) {
|
|
105
|
-
return R.assoc('__indexPosition', index, val);
|
|
106
|
-
}),
|
|
107
|
-
/* NEW */
|
|
108
|
-
R.sortBy(R.prop('__index')));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
51
|
//--------------------------------------------------------------------------------------------Header
|
|
112
52
|
var getMeta = R.propOr({}, 'meta');
|
|
113
53
|
var meta = getMeta(dataNew);
|
|
@@ -132,7 +72,15 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
|
|
|
132
72
|
__index: index,
|
|
133
73
|
display: !R.has(observation.id, hiddenIds) && !(0, _sdmxData.getIsHidden)(obsAnnotations),
|
|
134
74
|
name: (0, _dotstatsuiteSdmxjs.getRefinedName)(observation),
|
|
135
|
-
values:
|
|
75
|
+
values: (0, _getValuesEnhanced.getValuesEnhanced)({
|
|
76
|
+
locale: locale,
|
|
77
|
+
annotations: annotations,
|
|
78
|
+
parent: observation.id,
|
|
79
|
+
reportYearStart: reportYearStart,
|
|
80
|
+
_hiddenIds: _hiddenIds,
|
|
81
|
+
hiddenIds: hiddenIds,
|
|
82
|
+
options: options
|
|
83
|
+
})(R.propOr([], 'values', observation)),
|
|
136
84
|
roles: !R.isNil(observation.role) ? R.head(observation.role) : null
|
|
137
85
|
});
|
|
138
86
|
}, attrObservations);
|
|
@@ -142,7 +90,14 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
|
|
|
142
90
|
return (0, _extends3.default)({}, attr, {
|
|
143
91
|
display: !R.has(attr.id, hiddenIds) && !(0, _sdmxData.getIsHidden)(attrAnnotations),
|
|
144
92
|
name: (0, _dotstatsuiteSdmxjs.getRefinedName)(attr),
|
|
145
|
-
values:
|
|
93
|
+
values: (0, _getValuesEnhanced.getValuesEnhanced)({
|
|
94
|
+
locale: locale,
|
|
95
|
+
annotations: annotations,
|
|
96
|
+
parent: attr.id,
|
|
97
|
+
_hiddenIds: _hiddenIds,
|
|
98
|
+
hiddenIds: hiddenIds,
|
|
99
|
+
options: options
|
|
100
|
+
})(R.propOr([], 'values', attr))
|
|
146
101
|
});
|
|
147
102
|
}, R.propOr([], 'dataSet', attributes));
|
|
148
103
|
|
|
@@ -161,8 +116,16 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
|
|
|
161
116
|
return R.addIndex(R.reduce)(function (acc, observation, obsIndex) {
|
|
162
117
|
var id = R.prop('id')(observation);
|
|
163
118
|
var dimAnnotations = (0, _sdmxData.getRelationnalAnnotations)(R.propOr([], 'annotations')(observation))(annotations);
|
|
164
|
-
var
|
|
165
|
-
var values =
|
|
119
|
+
var isTimeDimension = (0, _dotstatsuiteSdmxjs.isTimePeriodDimension)(observation);
|
|
120
|
+
var values = (0, _getValuesEnhanced.getValuesEnhanced)({
|
|
121
|
+
locale: locale,
|
|
122
|
+
annotations: annotations,
|
|
123
|
+
isTimeDimension: isTimeDimension,
|
|
124
|
+
parent: id,
|
|
125
|
+
_hiddenIds: _hiddenIds,
|
|
126
|
+
hiddenIds: hiddenIds,
|
|
127
|
+
options: options
|
|
128
|
+
})(R.propOr([], 'values', observation));
|
|
166
129
|
var _idHidden = _hiddenIds[id] && R.isEmpty(R.difference(R.pluck('id')(values), _hiddenIds[id]));
|
|
167
130
|
var isHidden = _idHidden || R.has(id, hiddenIds) || (0, _sdmxData.getIsHidden)(dimAnnotations);
|
|
168
131
|
return {
|
|
@@ -198,5 +161,8 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
|
|
|
198
161
|
return (0, _sdmxData.setAnnotationsLayout)(title, acc)([dataSetsAnnotation]);
|
|
199
162
|
}, {})(dataSetsAnnotations);
|
|
200
163
|
|
|
201
|
-
return {
|
|
164
|
+
return {
|
|
165
|
+
data: { header: resHeader, dataSets: dataSets, structure: resStructure },
|
|
166
|
+
layout: R.mergeRight(dimensionsLayout, dataSetsLayout)
|
|
167
|
+
};
|
|
202
168
|
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _extends2 = require('babel-runtime/helpers/extends');
|
|
4
|
+
|
|
5
|
+
var _extends3 = _interopRequireDefault(_extends2);
|
|
6
|
+
|
|
7
|
+
var _ramda = require('ramda');
|
|
8
|
+
|
|
9
|
+
var R = _interopRequireWildcard(_ramda);
|
|
10
|
+
|
|
11
|
+
var _chai = require('chai');
|
|
12
|
+
|
|
13
|
+
var _getValuesEnhanced = require('../src/get-values-enhanced');
|
|
14
|
+
|
|
15
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
var values = [{
|
|
20
|
+
id: 'A',
|
|
21
|
+
order: 0,
|
|
22
|
+
name: 'Code A',
|
|
23
|
+
names: {
|
|
24
|
+
en: 'Code A'
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
id: 'B',
|
|
28
|
+
order: 1,
|
|
29
|
+
name: 'Code B',
|
|
30
|
+
names: {
|
|
31
|
+
en: 'Code B'
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
id: 'C',
|
|
35
|
+
order: 2,
|
|
36
|
+
name: 'Code C',
|
|
37
|
+
names: {
|
|
38
|
+
en: 'Code C'
|
|
39
|
+
}
|
|
40
|
+
}];
|
|
41
|
+
|
|
42
|
+
var timeValues = [{
|
|
43
|
+
start: '2020-01-01T00:00:00',
|
|
44
|
+
end: '2020-12-31T23:59:59',
|
|
45
|
+
id: '2020',
|
|
46
|
+
name: '2020',
|
|
47
|
+
names: {
|
|
48
|
+
en: '2020'
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
start: '2021-01-01T00:00:00',
|
|
52
|
+
end: '2021-12-31T23:59:59',
|
|
53
|
+
id: '2021',
|
|
54
|
+
name: '2021',
|
|
55
|
+
names: {
|
|
56
|
+
en: '2021'
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
start: '2022-01-01T00:00:00',
|
|
60
|
+
end: '2022-12-31T23:59:59',
|
|
61
|
+
id: '2022',
|
|
62
|
+
name: '2022',
|
|
63
|
+
names: {
|
|
64
|
+
en: '2022'
|
|
65
|
+
}
|
|
66
|
+
}];
|
|
67
|
+
|
|
68
|
+
var expectedTimeValues = [{
|
|
69
|
+
start: '2020-01-01T00:00:00.000Z',
|
|
70
|
+
end: '2020-12-31T23:59:59.000Z',
|
|
71
|
+
id: '2020',
|
|
72
|
+
name: '2020'
|
|
73
|
+
}, {
|
|
74
|
+
start: '2021-01-01T00:00:00.000Z',
|
|
75
|
+
end: '2021-12-31T23:59:59.000Z',
|
|
76
|
+
id: '2021',
|
|
77
|
+
name: '2021'
|
|
78
|
+
}, {
|
|
79
|
+
start: '2022-01-01T00:00:00.000Z',
|
|
80
|
+
end: '2022-12-31T23:59:59.000Z',
|
|
81
|
+
id: '2022',
|
|
82
|
+
name: '2022'
|
|
83
|
+
}];
|
|
84
|
+
|
|
85
|
+
var nonCodedValues = [{ value: 'A' }, { value: 'B' }, { value: 'C' }];
|
|
86
|
+
|
|
87
|
+
var expectedValues = function expectedValues() {
|
|
88
|
+
var skippedValueEntries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
89
|
+
return R.addIndex(R.map)(function (value, index) {
|
|
90
|
+
return (0, _extends3.default)({}, R.omit(R.prepend('names', skippedValueEntries), value), {
|
|
91
|
+
__index: index,
|
|
92
|
+
__indexPosition: index,
|
|
93
|
+
display: true,
|
|
94
|
+
notes: [],
|
|
95
|
+
start: R.propOr(null, 'start', value)
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
describe('get values enhanced method', function () {
|
|
101
|
+
it('should pass with coded values', function () {
|
|
102
|
+
var enhancedValues = (0, _getValuesEnhanced.getValuesEnhanced)({
|
|
103
|
+
locale: 'en',
|
|
104
|
+
parent: 'ID'
|
|
105
|
+
})(values);
|
|
106
|
+
(0, _chai.expect)(enhancedValues).to.deep.equal(expectedValues()(values));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should pass with non-coded values', function () {
|
|
110
|
+
var enhancedValues = (0, _getValuesEnhanced.getValuesEnhanced)({
|
|
111
|
+
locale: 'en',
|
|
112
|
+
parent: 'ID'
|
|
113
|
+
})(nonCodedValues);
|
|
114
|
+
(0, _chai.expect)(enhancedValues).to.deep.equal(expectedValues(['name', 'order', 'value'])(values));
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should pass with time values', function () {
|
|
118
|
+
var enhancedValues = (0, _getValuesEnhanced.getValuesEnhanced)({
|
|
119
|
+
locale: 'en',
|
|
120
|
+
parent: 'ID',
|
|
121
|
+
isTimeDimension: true,
|
|
122
|
+
reportYearStart: { month: '01', day: '01' }
|
|
123
|
+
})(timeValues);
|
|
124
|
+
(0, _chai.expect)(enhancedValues).to.deep.equal(expectedValues()(expectedTimeValues));
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -83,7 +83,7 @@ var enhanceObservations = exports.enhanceObservations = function enhanceObservat
|
|
|
83
83
|
var formatAttributesIndexes = getFormatAttributesIndexes(attributes, R.propOr({}, 'customAttributes', options));
|
|
84
84
|
var indexedDimensions = R.indexBy(R.prop('id'), dimensions);
|
|
85
85
|
|
|
86
|
-
return R.
|
|
86
|
+
return R.map(function (observation) {
|
|
87
87
|
var dimValuesIndexes = observation.dimValuesIndexes;
|
|
88
88
|
|
|
89
89
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
printWidth: 80,
|
|
3
|
+
tabWidth: 2,
|
|
4
|
+
useTabs: false,
|
|
5
|
+
singleQuote: true,
|
|
6
|
+
trailingComma: 'all',
|
|
7
|
+
bracketSameLine: false,
|
|
8
|
+
bracketSpacing: true,
|
|
9
|
+
semi: true,
|
|
10
|
+
arrowParens: 'always',
|
|
11
|
+
endOfLine: 'lf',
|
|
12
|
+
jsxSingleQuote: false,
|
|
13
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import dateFns from 'date-fns';
|
|
3
|
+
import { getCodeOrder, getRefinedName } from '@sis-cc/dotstatsuite-sdmxjs';
|
|
4
|
+
import { getIsHidden } from './sdmx-data';
|
|
5
|
+
import {
|
|
6
|
+
getReportedTimePeriodLabel,
|
|
7
|
+
getReportedTimePeriodNote,
|
|
8
|
+
getReportedTimePeriod,
|
|
9
|
+
} from './date';
|
|
10
|
+
import { refineTimePeriod } from '../../rules2/src/refineTimePeriod';
|
|
11
|
+
|
|
12
|
+
const isNonCoded = R.both(R.has('value'), R.pipe(R.has('id'), R.not));
|
|
13
|
+
|
|
14
|
+
const getId = (value, fallbackId) => {
|
|
15
|
+
const valueId = R.prop('id', value);
|
|
16
|
+
if (valueId) return valueId;
|
|
17
|
+
if (isNonCoded(value)) return R.prop('value', value);
|
|
18
|
+
// Fallback (value has no id but is not a non-coded)
|
|
19
|
+
return fallbackId;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getName =
|
|
23
|
+
({ isTimeDimension, options, locale, start, reportYearStart }) =>
|
|
24
|
+
(value) => {
|
|
25
|
+
if (!isTimeDimension) return getRefinedName(value);
|
|
26
|
+
return getReportedTimePeriodLabel(
|
|
27
|
+
options.frequency,
|
|
28
|
+
options.timeFormat,
|
|
29
|
+
locale,
|
|
30
|
+
)(reportYearStart, {
|
|
31
|
+
id: value.id,
|
|
32
|
+
reportedStart: start,
|
|
33
|
+
start: new Date(value.start),
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getValuesEnhanced = ({
|
|
38
|
+
locale = '',
|
|
39
|
+
annotations = [],
|
|
40
|
+
isTimeDimension = false,
|
|
41
|
+
parent = '',
|
|
42
|
+
reportYearStart,
|
|
43
|
+
_hiddenIds = {},
|
|
44
|
+
hiddenIds = {},
|
|
45
|
+
options = {},
|
|
46
|
+
}) => {
|
|
47
|
+
return R.pipe(
|
|
48
|
+
R.addIndex(R.map)((value, __index) => {
|
|
49
|
+
const id = getId(value, `${parent}-${__index}`);
|
|
50
|
+
|
|
51
|
+
const valueAnnotations = R.pipe(
|
|
52
|
+
R.propOr([], 'annotations'),
|
|
53
|
+
R.flip(R.props)(annotations),
|
|
54
|
+
)(value);
|
|
55
|
+
|
|
56
|
+
const isHidden =
|
|
57
|
+
(_hiddenIds[parent] && R.includes(value.id, _hiddenIds[parent])) ||
|
|
58
|
+
R.has(`${parent}.${value.id}`, hiddenIds) ||
|
|
59
|
+
getIsHidden(valueAnnotations);
|
|
60
|
+
|
|
61
|
+
const { start, notes } = isTimeDimension
|
|
62
|
+
? getTimePeriodAttributes({ reportYearStart, options })(value)
|
|
63
|
+
: { notes: [] };
|
|
64
|
+
|
|
65
|
+
let __indexPosition = NaN;
|
|
66
|
+
if (isNaN(__indexPosition)) {
|
|
67
|
+
__indexPosition = getCodeOrder({ annotations: valueAnnotations });
|
|
68
|
+
}
|
|
69
|
+
let res = {
|
|
70
|
+
// names is explicitely skipped because of metadata "standard"
|
|
71
|
+
// not completely aligned with NSI "standard"
|
|
72
|
+
// value is explicitely skipped (non-coded) into id
|
|
73
|
+
...R.omit(['names', 'value'], value),
|
|
74
|
+
id,
|
|
75
|
+
display: !isHidden,
|
|
76
|
+
start: start ? start.toISOString() : null,
|
|
77
|
+
notes,
|
|
78
|
+
__indexPosition,
|
|
79
|
+
__index,
|
|
80
|
+
};
|
|
81
|
+
if (!isNonCoded(value)) {
|
|
82
|
+
res = R.assoc(
|
|
83
|
+
'name',
|
|
84
|
+
getName({ isTimeDimension, options, locale, start, reportYearStart })(
|
|
85
|
+
value,
|
|
86
|
+
),
|
|
87
|
+
res,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (isTimeDimension) {
|
|
91
|
+
res = refineTimePeriod(res, {
|
|
92
|
+
locale,
|
|
93
|
+
monthlyFormat: options.timeFormat,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return res;
|
|
97
|
+
}),
|
|
98
|
+
// __indexPosition is used for pre-sorting
|
|
99
|
+
R.sortWith(isTimeDimension ? timeDimensionSorts : defaultSorts),
|
|
100
|
+
// __indexPosition is reset after pre-sorting
|
|
101
|
+
R.addIndex(R.map)((val, index) => R.assoc('__indexPosition', index, val)),
|
|
102
|
+
// values are re-sorted by __index after __indexPosition settlement
|
|
103
|
+
R.sortBy(R.prop('__index')),
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const getDateForSort = (key) => (val) => {
|
|
108
|
+
return dateFns.getTime(new Date(R.prop(key, val)));
|
|
109
|
+
};
|
|
110
|
+
const byStartDate = R.ascend(getDateForSort('start'));
|
|
111
|
+
const byEndDate = R.descend(getDateForSort('end'));
|
|
112
|
+
const timeDimensionSorts = [byStartDate, byEndDate];
|
|
113
|
+
const byIndexPosition = R.ascend(R.prop('__indexPosition'));
|
|
114
|
+
const byOrder = R.ascend(R.propOr(-1, 'order'));
|
|
115
|
+
const defaultSorts = [byIndexPosition, byOrder];
|
|
116
|
+
|
|
117
|
+
const getTimePeriodAttributes =
|
|
118
|
+
({ reportYearStart, options }) =>
|
|
119
|
+
(value) => {
|
|
120
|
+
const reported = getReportedTimePeriod(
|
|
121
|
+
reportYearStart,
|
|
122
|
+
value,
|
|
123
|
+
options.frequency,
|
|
124
|
+
);
|
|
125
|
+
const start = reported.start;
|
|
126
|
+
const end = reported.end;
|
|
127
|
+
const reportTimeNote = getReportedTimePeriodNote(
|
|
128
|
+
reportYearStart,
|
|
129
|
+
start,
|
|
130
|
+
end,
|
|
131
|
+
options.frequency,
|
|
132
|
+
options.isRtl,
|
|
133
|
+
);
|
|
134
|
+
const notes = R.isNil(reportTimeNote)
|
|
135
|
+
? []
|
|
136
|
+
: R.append(reportTimeNote, []);
|
|
137
|
+
return { start, notes };
|
|
138
|
+
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as R from 'ramda';
|
|
2
|
-
import dateFns from 'date-fns';
|
|
3
|
-
import { getCodeOrder, getRefinedName, isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
|
|
4
2
|
import {
|
|
5
|
-
|
|
3
|
+
getRefinedName,
|
|
4
|
+
isTimePeriodDimension,
|
|
5
|
+
} from '@sis-cc/dotstatsuite-sdmxjs';
|
|
6
|
+
import {
|
|
7
|
+
getRelationnalAnnotations,
|
|
8
|
+
setAnnotationsLayout,
|
|
9
|
+
getIsHidden,
|
|
6
10
|
} from './sdmx-data';
|
|
7
|
-
import { getReportedTimePeriodLabel, getReportedTimePeriodNote, getReportedTimePeriod } from './date';
|
|
8
11
|
import { getReportingYearStart } from './preparators/getReportingYearStart';
|
|
9
12
|
import { getNotDisplayedIds } from '../../rules2/src';
|
|
10
|
-
import {
|
|
13
|
+
import { getValuesEnhanced } from './get-values-enhanced';
|
|
11
14
|
|
|
12
15
|
const TIME_PERIOD_ID = 'TIME_PERIOD';
|
|
13
16
|
|
|
@@ -23,81 +26,13 @@ export const dataTransformer = (dataNew, options = {}) => {
|
|
|
23
26
|
const getDataSets = R.pathOr({}, ['data', 'dataSets']);
|
|
24
27
|
const dataSets = getDataSets(dataNew);
|
|
25
28
|
|
|
26
|
-
const dataSetsAnnotations = R.props(
|
|
29
|
+
const dataSetsAnnotations = R.props(
|
|
30
|
+
R.pathOr([], [0, 'annotations'], dataSets),
|
|
31
|
+
annotations,
|
|
32
|
+
);
|
|
27
33
|
|
|
28
34
|
const hiddenIds = getNotDisplayedIds(dataSetsAnnotations);
|
|
29
35
|
|
|
30
|
-
//--------------------------------------------------------------------------------------------------
|
|
31
|
-
const getValues = (values, parent) => R.map((value) => {
|
|
32
|
-
const valAnnotations = R.props(value.annotations || [], annotations);
|
|
33
|
-
return ({
|
|
34
|
-
...value,
|
|
35
|
-
display: !R.has(`${parent}.${value.id}`, hiddenIds) && !getIsHidden(valAnnotations),
|
|
36
|
-
name: getRefinedName(value)
|
|
37
|
-
});
|
|
38
|
-
}, values);
|
|
39
|
-
|
|
40
|
-
const getValuesEnhanced = (locale, annotations, isTimeDimension, parent) =>
|
|
41
|
-
R.pipe(
|
|
42
|
-
R.addIndex(R.map)((value, __index) => {
|
|
43
|
-
const valueAnnotations = R.pipe(
|
|
44
|
-
R.propOr([], 'annotations'),
|
|
45
|
-
R.flip(R.props)(annotations)
|
|
46
|
-
)(value);
|
|
47
|
-
const isHidden = (_hiddenIds[parent] && R.includes(value.id, _hiddenIds[parent])) || R.has(`${parent}.${value.id}`, hiddenIds) || getIsHidden(valueAnnotations);
|
|
48
|
-
const name = getRefinedName(value);
|
|
49
|
-
let __indexPosition = NaN;
|
|
50
|
-
let notes = [];
|
|
51
|
-
let start = null;
|
|
52
|
-
let end = null;
|
|
53
|
-
if (isTimeDimension) {
|
|
54
|
-
const reported = getReportedTimePeriod(reportYearStart, value, options.frequency);
|
|
55
|
-
start = reported.start;
|
|
56
|
-
end = reported.end;
|
|
57
|
-
const reportTimeNote = getReportedTimePeriodNote(reportYearStart, start, end, options.frequency, options.isRtl);
|
|
58
|
-
notes = R.isNil(reportTimeNote) ? notes : R.append(reportTimeNote, notes);
|
|
59
|
-
}
|
|
60
|
-
if (isNaN(__indexPosition)) {
|
|
61
|
-
__indexPosition = getCodeOrder({ annotations: valueAnnotations });
|
|
62
|
-
}
|
|
63
|
-
const timeFormat = R.prop('timeFormat', options);
|
|
64
|
-
const res = ({
|
|
65
|
-
...value,
|
|
66
|
-
id: R.when(
|
|
67
|
-
R.isNil,
|
|
68
|
-
R.always(`${parent}-${__index}`)
|
|
69
|
-
)(value.id),
|
|
70
|
-
display: !isHidden,
|
|
71
|
-
name: R.when(
|
|
72
|
-
R.always(isTimeDimension),
|
|
73
|
-
R.always(getReportedTimePeriodLabel(options.frequency, timeFormat, locale)(reportYearStart, { id: value.id, reportedStart: start, start: new Date(value.start) }))
|
|
74
|
-
)(name),
|
|
75
|
-
start: start ? start.toISOString() : null,
|
|
76
|
-
notes,
|
|
77
|
-
__indexPosition,
|
|
78
|
-
__index,
|
|
79
|
-
});
|
|
80
|
-
return isTimeDimension ? refineTimePeriod(res, { locale, monthlyFormat: timeFormat }) : res;
|
|
81
|
-
}),
|
|
82
|
-
R.ifElse(
|
|
83
|
-
R.always(isTimeDimension),
|
|
84
|
-
R.pipe(
|
|
85
|
-
R.sortWith([
|
|
86
|
-
R.ascend(val => dateFns.getTime(new Date(R.prop('start', val)))),
|
|
87
|
-
R.descend(val => dateFns.getTime(new Date(R.prop('end', val)))),
|
|
88
|
-
]),
|
|
89
|
-
R.addIndex(R.map)((val, ind) => R.assoc('__indexcPosition', ind, val))
|
|
90
|
-
),
|
|
91
|
-
R.sortWith([
|
|
92
|
-
R.ascend(R.prop('__indexPosition')),
|
|
93
|
-
R.ascend(R.propOr(-1, 'order'))
|
|
94
|
-
])
|
|
95
|
-
),
|
|
96
|
-
R.addIndex(R.map)((val, index) => R.assoc('__indexPosition', index, val)),
|
|
97
|
-
/* NEW */
|
|
98
|
-
R.sortBy(R.prop('__index'))
|
|
99
|
-
);
|
|
100
|
-
|
|
101
36
|
//--------------------------------------------------------------------------------------------Header
|
|
102
37
|
const getMeta = R.propOr({}, 'meta');
|
|
103
38
|
const meta = getMeta(dataNew);
|
|
@@ -119,32 +54,45 @@ export const dataTransformer = (dataNew, options = {}) => {
|
|
|
119
54
|
|
|
120
55
|
const resAttrObservations = R.addIndex(R.map)((observation, index) => {
|
|
121
56
|
const obsAnnotations = R.props(observation.annotations || [], annotations);
|
|
122
|
-
return
|
|
57
|
+
return {
|
|
123
58
|
...observation,
|
|
124
59
|
__index: index,
|
|
125
|
-
display:
|
|
60
|
+
display:
|
|
61
|
+
!R.has(observation.id, hiddenIds) && !getIsHidden(obsAnnotations),
|
|
126
62
|
name: getRefinedName(observation),
|
|
127
|
-
values: getValuesEnhanced(
|
|
63
|
+
values: getValuesEnhanced({
|
|
64
|
+
locale,
|
|
65
|
+
annotations,
|
|
66
|
+
parent: observation.id,
|
|
67
|
+
reportYearStart,
|
|
68
|
+
_hiddenIds,
|
|
69
|
+
hiddenIds,
|
|
70
|
+
options,
|
|
71
|
+
})(R.propOr([], 'values', observation)),
|
|
128
72
|
roles: !R.isNil(observation.role) ? R.head(observation.role) : null,
|
|
129
|
-
}
|
|
73
|
+
};
|
|
130
74
|
}, attrObservations);
|
|
131
75
|
|
|
132
|
-
const datasetAttributes = R.map(
|
|
133
|
-
(attr
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
76
|
+
const datasetAttributes = R.map((attr) => {
|
|
77
|
+
const attrAnnotations = R.props(attr.annotations || [], annotations);
|
|
78
|
+
return {
|
|
79
|
+
...attr,
|
|
80
|
+
display: !R.has(attr.id, hiddenIds) && !getIsHidden(attrAnnotations),
|
|
81
|
+
name: getRefinedName(attr),
|
|
82
|
+
values: getValuesEnhanced({
|
|
83
|
+
locale,
|
|
84
|
+
annotations,
|
|
85
|
+
parent: attr.id,
|
|
86
|
+
_hiddenIds,
|
|
87
|
+
hiddenIds,
|
|
88
|
+
options,
|
|
89
|
+
})(R.propOr([], 'values', attr)),
|
|
90
|
+
};
|
|
91
|
+
}, R.propOr([], 'dataSet', attributes));
|
|
144
92
|
|
|
145
93
|
const resAttributes = {
|
|
146
94
|
...attributes,
|
|
147
|
-
observation: R.concat(resAttrObservations, datasetAttributes)
|
|
95
|
+
observation: R.concat(resAttrObservations, datasetAttributes),
|
|
148
96
|
};
|
|
149
97
|
|
|
150
98
|
//----------------------------------------------------------------------------------------Dimensions
|
|
@@ -154,28 +102,51 @@ export const dataTransformer = (dataNew, options = {}) => {
|
|
|
154
102
|
const getDimObservations = R.propOr([], 'observation');
|
|
155
103
|
const dimObservations = getDimObservations(dimensions);
|
|
156
104
|
|
|
157
|
-
const getObservations = locale
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
105
|
+
const getObservations = (locale) =>
|
|
106
|
+
R.addIndex(R.reduce)(
|
|
107
|
+
(acc, observation, obsIndex) => {
|
|
108
|
+
const id = R.prop('id')(observation);
|
|
109
|
+
const dimAnnotations = getRelationnalAnnotations(
|
|
110
|
+
R.propOr([], 'annotations')(observation),
|
|
111
|
+
)(annotations);
|
|
112
|
+
const isTimeDimension = isTimePeriodDimension(observation);
|
|
113
|
+
const values = getValuesEnhanced({
|
|
114
|
+
locale,
|
|
115
|
+
annotations,
|
|
116
|
+
isTimeDimension,
|
|
117
|
+
parent: id,
|
|
118
|
+
_hiddenIds,
|
|
119
|
+
hiddenIds,
|
|
120
|
+
options,
|
|
121
|
+
})(R.propOr([], 'values', observation));
|
|
122
|
+
const _idHidden =
|
|
123
|
+
_hiddenIds[id] &&
|
|
124
|
+
R.isEmpty(R.difference(R.pluck('id')(values), _hiddenIds[id]));
|
|
125
|
+
const isHidden =
|
|
126
|
+
_idHidden || R.has(id, hiddenIds) || getIsHidden(dimAnnotations);
|
|
127
|
+
return {
|
|
128
|
+
observation: R.append({
|
|
129
|
+
...observation,
|
|
130
|
+
display: !isHidden,
|
|
131
|
+
__index: obsIndex,
|
|
132
|
+
name: getRefinedName(observation),
|
|
133
|
+
values: _idHidden ? [] : values,
|
|
134
|
+
role: isTime
|
|
135
|
+
? TIME_PERIOD_ID
|
|
136
|
+
: R.head(R.propOr([], 'roles', observation)),
|
|
137
|
+
})(acc.observation),
|
|
138
|
+
dimensionsLayout: setAnnotationsLayout(
|
|
139
|
+
id,
|
|
140
|
+
acc.dimensionsLayout,
|
|
141
|
+
)(dimAnnotations),
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
{ observation: [], dimensionsLayout: {} },
|
|
145
|
+
);
|
|
176
146
|
|
|
177
147
|
//-----------------------------------------------------------------------------------------Structure
|
|
178
|
-
const { dimensionsLayout, observation } =
|
|
148
|
+
const { dimensionsLayout, observation } =
|
|
149
|
+
getObservations(locale)(dimObservations);
|
|
179
150
|
const resStructure = {
|
|
180
151
|
...structure,
|
|
181
152
|
name: getRefinedName({ ...structure, id: options.dataflowId }),
|
|
@@ -188,8 +159,11 @@ export const dataTransformer = (dataNew, options = {}) => {
|
|
|
188
159
|
const dataSetsLayout = R.reduce((acc, dataSetsAnnotation) => {
|
|
189
160
|
const title = R.propOr('', 'title')(dataSetsAnnotation);
|
|
190
161
|
if (R.isEmpty(title)) return acc;
|
|
191
|
-
return setAnnotationsLayout(title, acc)([dataSetsAnnotation])
|
|
162
|
+
return setAnnotationsLayout(title, acc)([dataSetsAnnotation]);
|
|
192
163
|
}, {})(dataSetsAnnotations);
|
|
193
164
|
|
|
194
|
-
return
|
|
165
|
+
return {
|
|
166
|
+
data: { header: resHeader, dataSets, structure: resStructure },
|
|
167
|
+
layout: R.mergeRight(dimensionsLayout, dataSetsLayout),
|
|
168
|
+
};
|
|
195
169
|
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { getValuesEnhanced } from '../src/get-values-enhanced';
|
|
4
|
+
|
|
5
|
+
const values = [
|
|
6
|
+
{
|
|
7
|
+
id: 'A',
|
|
8
|
+
order: 0,
|
|
9
|
+
name: 'Code A',
|
|
10
|
+
names: {
|
|
11
|
+
en: 'Code A',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: 'B',
|
|
16
|
+
order: 1,
|
|
17
|
+
name: 'Code B',
|
|
18
|
+
names: {
|
|
19
|
+
en: 'Code B',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'C',
|
|
24
|
+
order: 2,
|
|
25
|
+
name: 'Code C',
|
|
26
|
+
names: {
|
|
27
|
+
en: 'Code C',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const timeValues = [
|
|
33
|
+
{
|
|
34
|
+
start: '2020-01-01T00:00:00',
|
|
35
|
+
end: '2020-12-31T23:59:59',
|
|
36
|
+
id: '2020',
|
|
37
|
+
name: '2020',
|
|
38
|
+
names: {
|
|
39
|
+
en: '2020',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
start: '2021-01-01T00:00:00',
|
|
44
|
+
end: '2021-12-31T23:59:59',
|
|
45
|
+
id: '2021',
|
|
46
|
+
name: '2021',
|
|
47
|
+
names: {
|
|
48
|
+
en: '2021',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
start: '2022-01-01T00:00:00',
|
|
53
|
+
end: '2022-12-31T23:59:59',
|
|
54
|
+
id: '2022',
|
|
55
|
+
name: '2022',
|
|
56
|
+
names: {
|
|
57
|
+
en: '2022',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const expectedTimeValues = [
|
|
63
|
+
{
|
|
64
|
+
start: '2020-01-01T00:00:00.000Z',
|
|
65
|
+
end: '2020-12-31T23:59:59.000Z',
|
|
66
|
+
id: '2020',
|
|
67
|
+
name: '2020',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
start: '2021-01-01T00:00:00.000Z',
|
|
71
|
+
end: '2021-12-31T23:59:59.000Z',
|
|
72
|
+
id: '2021',
|
|
73
|
+
name: '2021',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
start: '2022-01-01T00:00:00.000Z',
|
|
77
|
+
end: '2022-12-31T23:59:59.000Z',
|
|
78
|
+
id: '2022',
|
|
79
|
+
name: '2022',
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const nonCodedValues = [{ value: 'A' }, { value: 'B' }, { value: 'C' }];
|
|
84
|
+
|
|
85
|
+
const expectedValues = (skippedValueEntries = []) => R.addIndex(R.map)((value, index) => {
|
|
86
|
+
return {
|
|
87
|
+
...R.omit(R.prepend('names', skippedValueEntries), value),
|
|
88
|
+
__index: index,
|
|
89
|
+
__indexPosition: index,
|
|
90
|
+
display: true,
|
|
91
|
+
notes: [],
|
|
92
|
+
start: R.propOr(null, 'start', value),
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('get values enhanced method', () => {
|
|
97
|
+
it('should pass with coded values', () => {
|
|
98
|
+
const enhancedValues = getValuesEnhanced({
|
|
99
|
+
locale: 'en',
|
|
100
|
+
parent: 'ID',
|
|
101
|
+
})(values);
|
|
102
|
+
expect(enhancedValues).to.deep.equal(expectedValues()(values));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should pass with non-coded values', () => {
|
|
106
|
+
const enhancedValues = getValuesEnhanced({
|
|
107
|
+
locale: 'en',
|
|
108
|
+
parent: 'ID',
|
|
109
|
+
})(nonCodedValues);
|
|
110
|
+
expect(enhancedValues).to.deep.equal(
|
|
111
|
+
expectedValues(['name', 'order', 'value'])(values),
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should pass with time values', () => {
|
|
116
|
+
const enhancedValues = getValuesEnhanced({
|
|
117
|
+
locale: 'en',
|
|
118
|
+
parent: 'ID',
|
|
119
|
+
isTimeDimension: true,
|
|
120
|
+
reportYearStart: { month: '01', day: '01' },
|
|
121
|
+
})(timeValues);
|
|
122
|
+
expect(enhancedValues).to.deep.equal(
|
|
123
|
+
expectedValues()(expectedTimeValues),
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -64,7 +64,7 @@ export const enhanceObservations = (dimensions = [], observations = {}, attribut
|
|
|
64
64
|
const formatAttributesIndexes = getFormatAttributesIndexes(attributes, R.propOr({}, 'customAttributes', options));
|
|
65
65
|
const indexedDimensions = R.indexBy(R.prop('id'), dimensions);
|
|
66
66
|
|
|
67
|
-
return R.
|
|
67
|
+
return R.map(
|
|
68
68
|
(observation) => {
|
|
69
69
|
const { dimValuesIndexes } = observation;
|
|
70
70
|
|