@sis-cc/dotstatsuite-components 9.1.3 → 9.2.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/preparators/enhanceObservations.js +155 -0
- package/lib/rules/src/preparators/formatValue.js +77 -0
- package/lib/rules/src/preparators/getDimensions.js +55 -0
- package/lib/rules/src/preparators/getDisplay.js +32 -0
- package/lib/rules/src/preparators/getObservations.js +27 -0
- package/lib/rules/src/table/factories/getCells.js +1 -3
- package/lib/rules/src/table/factories/getLayoutData.js +102 -161
- package/lib/rules/src/table/factories/getSortedLayoutIndexes.js +118 -0
- package/lib/rules/src/table/factories/getTableData.js +12 -10
- package/lib/rules/src/table/factories/refineLayoutSize.js +210 -0
- package/lib/rules/src/table/preparators/prepareData.js +23 -23
- package/lib/rules/src/table/units/getAttachmentSeriesIndexes.js +1 -1
- package/lib/rules/src/table/units/getUnitsSeries.js +31 -0
- package/lib/rules/src/v8-transformer.js +2 -1
- package/package.json +1 -1
- package/src/rules/src/preparators/enhanceObservations.js +163 -0
- package/src/rules/src/preparators/formatValue.js +73 -0
- package/src/rules/src/preparators/getDimensions.js +49 -0
- package/src/rules/src/preparators/getDisplay.js +20 -0
- package/src/rules/src/preparators/getObservations.js +19 -0
- package/src/rules/src/table/factories/getCells.js +3 -7
- package/src/rules/src/table/factories/getLayoutData.js +135 -184
- package/src/rules/src/table/factories/getSortedLayoutIndexes.js +108 -0
- package/src/rules/src/table/factories/getTableData.js +10 -10
- package/src/rules/src/table/factories/refineLayoutSize.js +224 -0
- package/src/rules/src/table/preparators/prepareData.js +23 -32
- package/src/rules/src/table/units/getAttachmentSeriesIndexes.js +2 -1
- package/src/rules/src/table/units/getUnitsSeries.js +20 -0
- package/src/rules/src/v8-transformer.js +2 -1
- package/test/appendUnitsInLayoutDataEntry.test.js +3 -3
- package/test/enhanceObservations.test.js +270 -0
- package/test/getAttachmentSeriesIndexes.test.js +1 -1
- package/test/getCells.test.js +4 -39
- package/test/getLayoutData2.test.js +194 -0
- package/test/getOneValueDimensions.test.js +1 -1
- package/test/getSortedLayoutIndexes.test.js +80 -0
- package/test/getUnitsArtefacts.test.js +1 -1
- package/test/getUnitsSeries.test.js +64 -0
- package/test/mocks/table-layout-multi-hierarchies--layout.json +621 -0
- package/test/mocks/table-layout-multi-hierarchies--layoutData.json +32410 -0
- package/test/mocks/table-layout-multi-hierarchies--layoutIndexes.json +2760 -0
- package/test/mocks/table-layout-multi-hierarchies--observations.json +30688 -0
- package/test/mocks/table-layout-multi-hierarchies--sizedIndexes.json +2761 -0
- package/test/mocks/table-layout-truncation1--layout.json +27469 -0
- package/test/mocks/table-layout-truncation1--layoutData.json +19413 -0
- package/test/mocks/table-layout-truncation1--layoutIndexes.json +7512 -0
- package/test/mocks/table-layout-truncation1--observations.json +70002 -0
- package/test/mocks/table-layout-truncation1--sizedIndexes.json +3010 -0
- package/test/mocks/table-prep-multi-hierarchies--attributes.json +44 -0
- package/test/mocks/table-prep-multi-hierarchies--dimensions.json +688 -0
- package/test/mocks/table-prep-multi-hierarchies--enhancedObservations.json +19696 -0
- package/test/mocks/table-prep-multi-hierarchies--observations.json +8246 -0
- package/test/mocks/table-prep-multi-hierarchies--sdmxJson.json +2985 -0
- package/test/mocks/table-prep-truncation1--dimensions.json +35057 -0
- package/test/mocks/table-prep-truncation1--enhancedObservations.json +70002 -0
- package/test/mocks/table-prep-truncation1--observations.json +27502 -0
- package/test/mocks/table-prep-truncation1--sdmxJson.json +55103 -0
- package/test/mocks/table-prep-units--observations.json +284286 -0
- package/test/mocks/table-prep-units--unitsSeries.json +41042 -0
- package/test/parseAttributes.test.js +1 -1
- package/test/refineLayoutSize.test.js +415 -0
- package/test/table-layout-perf.test.js +74 -0
- package/test/table-prep-perf.test.js +65 -0
- package/lib/rules/src/table/factories/getSortedLayoutData.js +0 -145
- package/lib/rules/src/table/factories/refineLayoutHierarchy.js +0 -61
- package/lib/rules/src/table/preparators/parseObservations.js +0 -76
- package/lib/rules/src/table/units/getUnitsSeriesOccurences.js +0 -39
- package/src/rules/src/table/factories/getSortedLayoutData.js +0 -133
- package/src/rules/src/table/factories/refineLayoutHierarchy.js +0 -64
- package/src/rules/src/table/preparators/parseObservations.js +0 -81
- package/src/rules/src/table/units/getUnitsSeriesOccurences.js +0 -51
- package/test/appendUnitsInLayoutData.test.js +0 -248
- package/test/getLayoutData.test.js +0 -311
- package/test/getSortedLayoutData.test.js +0 -382
- package/test/getUnitsSeriesOccurences.test.js +0 -133
- package/test/parseObservations.test.js +0 -116
- package/test/refineDimSeriesUnits.test.js +0 -24
- package/test/refineLayoutHierarchy.test.js +0 -79
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.refineLayoutSize = exports.truncateHeader = exports.truncateSectionRows = exports.refineHeader = exports.refineSections = exports.getCuratedCells = undefined;
|
|
7
|
+
|
|
8
|
+
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
|
|
9
|
+
|
|
10
|
+
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
|
|
11
|
+
|
|
12
|
+
var _extends3 = require('babel-runtime/helpers/extends');
|
|
13
|
+
|
|
14
|
+
var _extends4 = _interopRequireDefault(_extends3);
|
|
15
|
+
|
|
16
|
+
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
|
|
17
|
+
|
|
18
|
+
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
|
|
19
|
+
|
|
20
|
+
var _ramda = require('ramda');
|
|
21
|
+
|
|
22
|
+
var R = _interopRequireWildcard(_ramda);
|
|
23
|
+
|
|
24
|
+
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; } }
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
var getPivotKey = function getPivotKey(indexes) {
|
|
29
|
+
return R.pipe(R.props(indexes), R.join(':'));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var getPivots = function getPivots(layout, shape) {
|
|
33
|
+
return R.pipe(R.props(shape), R.map(R.pipe(R.pluck('__index'), getPivotKey)))(layout);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var indexWithPivots = function indexWithPivots(pivots, observations) {
|
|
37
|
+
return R.pipe(R.values, R.reduce(function (acc, obs) {
|
|
38
|
+
var path = R.map(function (pivot) {
|
|
39
|
+
return pivot(obs.orderedDimIndexes);
|
|
40
|
+
}, pivots);
|
|
41
|
+
return R.over(R.lensPath(path), R.ifElse(R.isNil, R.always([obs]), R.append(obs)))(acc);
|
|
42
|
+
}, {}))(observations);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var getCuratedCells = exports.getCuratedCells = function getCuratedCells(_ref) {
|
|
46
|
+
var layout = _ref.layout,
|
|
47
|
+
observations = _ref.observations,
|
|
48
|
+
shape = _ref.shape;
|
|
49
|
+
|
|
50
|
+
var pivots = getPivots(layout, shape);
|
|
51
|
+
return indexWithPivots(pivots, observations);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var refineSections = exports.refineSections = function refineSections(sections, extractedKeys, curatedObs) {
|
|
55
|
+
return R.pipe(R.map(function (section) {
|
|
56
|
+
var sectionKey = R.join(':', R.head(section) || []);
|
|
57
|
+
return R.over(R.lensIndex(1), R.filter(function (rowData) {
|
|
58
|
+
var rowKey = R.join(':', rowData);
|
|
59
|
+
return R.pipe(R.path([sectionKey, rowKey]), R.omit(extractedKeys), R.isEmpty, R.not)(curatedObs);
|
|
60
|
+
}))(section);
|
|
61
|
+
}), R.filter(R.pipe(R.nth(1), R.isEmpty, R.not)))(sections);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
var refineHeader = exports.refineHeader = function refineHeader(header, extractedKeys, curatedObs) {
|
|
65
|
+
return R.filter( // extracted : { [sectionKey]: [...rowKeys] }
|
|
66
|
+
function (header) {
|
|
67
|
+
var headerKey = R.join(':', header);
|
|
68
|
+
return R.pipe(R.prop(headerKey), function (sections) {
|
|
69
|
+
return R.pickBy(function (rows, section) {
|
|
70
|
+
return R.pipe(R.omit(R.propOr([], section, extractedKeys)), R.isEmpty, R.not)(rows);
|
|
71
|
+
}, sections);
|
|
72
|
+
}, R.isEmpty, R.not)(curatedObs);
|
|
73
|
+
})(header);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
var truncateSectionRows = exports.truncateSectionRows = function truncateSectionRows(n, sectionsData) {
|
|
77
|
+
var _R$pipe = R.pipe(R.last, // last section
|
|
78
|
+
R.nth(1), // rows
|
|
79
|
+
R.splitAt(R.negate(n)) // truncate from the end
|
|
80
|
+
)(sectionsData),
|
|
81
|
+
_R$pipe2 = (0, _slicedToArray3.default)(_R$pipe, 2),
|
|
82
|
+
rest = _R$pipe2[0],
|
|
83
|
+
extracted = _R$pipe2[1];
|
|
84
|
+
|
|
85
|
+
var truncatedData = R.isEmpty(rest) ? R.dropLast(1, sectionsData) // remove section if no more rows
|
|
86
|
+
: R.adjust(-1, R.adjust(1, R.always(rest)), sectionsData);
|
|
87
|
+
|
|
88
|
+
var sectionKey = R.join(':', R.pipe(R.last, R.head)(sectionsData) || []);
|
|
89
|
+
var rowKeys = R.map(R.join(':'), extracted);
|
|
90
|
+
|
|
91
|
+
var extractedLength = R.length(extracted);
|
|
92
|
+
if (extractedLength < n) {
|
|
93
|
+
var _truncateSectionRows = truncateSectionRows(n - extractedLength, truncatedData),
|
|
94
|
+
truncated = _truncateSectionRows.truncated,
|
|
95
|
+
extractedKeys = _truncateSectionRows.extractedKeys;
|
|
96
|
+
|
|
97
|
+
return { truncated: truncated, extractedKeys: (0, _extends4.default)({}, extractedKeys, (0, _defineProperty3.default)({}, sectionKey, rowKeys)) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return { truncated: truncatedData, extractedKeys: (0, _defineProperty3.default)({}, sectionKey, rowKeys) };
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
var truncateHeader = exports.truncateHeader = function truncateHeader(n, headerData) {
|
|
104
|
+
var _R$splitAt = R.splitAt(R.negate(n))(headerData),
|
|
105
|
+
_R$splitAt2 = (0, _slicedToArray3.default)(_R$splitAt, 2),
|
|
106
|
+
truncated = _R$splitAt2[0],
|
|
107
|
+
extracted = _R$splitAt2[1];
|
|
108
|
+
|
|
109
|
+
return { truncated: truncated, extractedKeys: R.map(R.join(':'), extracted) };
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
var refineLength = function refineLength(length) {
|
|
113
|
+
return length === 0 ? 1 : length;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
var truncateLayout = function truncateLayout(isVertical) {
|
|
117
|
+
return R.ifElse(R.always(isVertical), truncateSectionRows, truncateHeader);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
var refineLayout = function refineLayout(isVertical) {
|
|
121
|
+
return R.ifElse(R.always(isVertical), refineHeader, refineSections);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
var getShape = function getShape(isVertical) {
|
|
125
|
+
return isVertical ? ['header', 'sections', 'rows'] : ['sections', 'rows', 'header'];
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
var getRefinedLayout = function getRefinedLayout(isVertical, truncated, refined) {
|
|
129
|
+
return R.ifElse(R.always(isVertical), R.pipe(R.assoc('sections', truncated), R.assoc('header', refined)), R.pipe(R.assoc('header', truncated), R.assoc('sections', refined)))({});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
var segregateLayout = function segregateLayout(isVertical) {
|
|
133
|
+
return R.ifElse(R.always(isVertical), R.props(['sections', 'header']), R.props(['header', 'sections']));
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
var refineLayoutSize = exports.refineLayoutSize = function refineLayoutSize(_ref2) {
|
|
137
|
+
var layout = _ref2.layout,
|
|
138
|
+
observations = _ref2.observations,
|
|
139
|
+
limit = _ref2.limit;
|
|
140
|
+
return function (layoutIndexes) {
|
|
141
|
+
var header = layoutIndexes.header,
|
|
142
|
+
sections = layoutIndexes.sections;
|
|
143
|
+
|
|
144
|
+
if (R.isNil(limit) || limit === 0 || R.all(R.isEmpty, [header, sections])) {
|
|
145
|
+
return R.assoc('truncated', false, layoutIndexes);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//number of dimensions in header
|
|
149
|
+
var headerDimCount = R.pipe(R.head, // first column
|
|
150
|
+
R.when(R.isNil, R.always([])), R.length // number of dims
|
|
151
|
+
)(header);
|
|
152
|
+
|
|
153
|
+
//number of columns for values
|
|
154
|
+
var headerValuesCount = R.pipe(R.length, R.when(R.equals(0), R.always(1)))(header);
|
|
155
|
+
|
|
156
|
+
//total of cells in header
|
|
157
|
+
var headerCellsCount = headerDimCount * (headerValuesCount + 1);
|
|
158
|
+
|
|
159
|
+
// number of dimensions in a row
|
|
160
|
+
var rowDimCount = R.pipe(R.head, // firstSection
|
|
161
|
+
R.last, // rows,
|
|
162
|
+
R.head, // first row
|
|
163
|
+
R.length)(sections);
|
|
164
|
+
|
|
165
|
+
// number of cells in a row
|
|
166
|
+
var rowCellsCount = rowDimCount + headerValuesCount + 1;
|
|
167
|
+
|
|
168
|
+
// number of rows
|
|
169
|
+
var rowsCount = R.pipe(R.map(R.last), R.unnest, R.length, R.add(1))(sections);
|
|
170
|
+
|
|
171
|
+
// total of cells in all rows
|
|
172
|
+
var rowsCellsCount = rowCellsCount * rowsCount;
|
|
173
|
+
|
|
174
|
+
// number of sections cells
|
|
175
|
+
var sectionsCellsCount = R.ifElse(R.pipe(R.head, R.head, R.length, R.equals(0)), R.always(0), R.length)(sections);
|
|
176
|
+
|
|
177
|
+
var total = rowsCellsCount + sectionsCellsCount + headerCellsCount;
|
|
178
|
+
|
|
179
|
+
var excess = total - limit;
|
|
180
|
+
if (excess <= 0) {
|
|
181
|
+
return R.assoc('truncated', false, layoutIndexes);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// total of cells in one column
|
|
185
|
+
var columnCellsCount = headerDimCount + rowsCount;
|
|
186
|
+
|
|
187
|
+
var isVertical = columnCellsCount > rowCellsCount;
|
|
188
|
+
|
|
189
|
+
var _segregateLayout = segregateLayout(isVertical)(layoutIndexes),
|
|
190
|
+
_segregateLayout2 = (0, _slicedToArray3.default)(_segregateLayout, 2),
|
|
191
|
+
toTruncate = _segregateLayout2[0],
|
|
192
|
+
toRefine = _segregateLayout2[1];
|
|
193
|
+
|
|
194
|
+
var cutLength = R.pipe(R.ifElse(R.identity, R.always(rowCellsCount), R.always(columnCellsCount)), R.divide(excess), Math.ceil)(isVertical);
|
|
195
|
+
|
|
196
|
+
var _truncateLayout = truncateLayout(isVertical)(cutLength, toTruncate),
|
|
197
|
+
truncated = _truncateLayout.truncated,
|
|
198
|
+
extractedKeys = _truncateLayout.extractedKeys;
|
|
199
|
+
|
|
200
|
+
var curatedObs = R.pipe(getShape, function (shape) {
|
|
201
|
+
return getCuratedCells({ layout: layout, observations: observations, shape: shape });
|
|
202
|
+
})(isVertical);
|
|
203
|
+
|
|
204
|
+
var refined = refineLayout(isVertical)(toRefine, extractedKeys, curatedObs);
|
|
205
|
+
|
|
206
|
+
var result = getRefinedLayout(isVertical, truncated, refined);
|
|
207
|
+
|
|
208
|
+
return R.assoc('truncated', true, result);
|
|
209
|
+
};
|
|
210
|
+
};
|
|
@@ -17,16 +17,12 @@ var _getNoDisplayAnnotationsIndexes = require('./getNoDisplayAnnotationsIndexes'
|
|
|
17
17
|
|
|
18
18
|
var _getNoDisplayCodes = require('./getNoDisplayCodes');
|
|
19
19
|
|
|
20
|
-
var _getDisplay2 = require('./getDisplay');
|
|
21
|
-
|
|
22
20
|
var _parseAttributes2 = require('./parseAttributes');
|
|
23
21
|
|
|
24
22
|
var _getDimensionsAttributesRegisters = require('./getDimensionsAttributesRegisters');
|
|
25
23
|
|
|
26
24
|
var _parseAttributesValuesFromObservations = require('./parseAttributesValuesFromObservations');
|
|
27
25
|
|
|
28
|
-
var _parseObservations = require('./parseObservations');
|
|
29
|
-
|
|
30
26
|
var _getOneValueDimensions = require('./getOneValueDimensions');
|
|
31
27
|
|
|
32
28
|
var _getManyValuesDimensions = require('./getManyValuesDimensions');
|
|
@@ -43,9 +39,13 @@ var _getHeaderUnits = require('../units/getHeaderUnits');
|
|
|
43
39
|
|
|
44
40
|
var _getAttachmentSeriesIndexes = require('../units/getAttachmentSeriesIndexes');
|
|
45
41
|
|
|
46
|
-
var
|
|
42
|
+
var _getUnitsSeries = require('../units/getUnitsSeries');
|
|
43
|
+
|
|
44
|
+
var _getDisplay2 = require('../../preparators/getDisplay');
|
|
47
45
|
|
|
48
|
-
var
|
|
46
|
+
var _getObservations = require('../../preparators/getObservations');
|
|
47
|
+
|
|
48
|
+
var _enhanceObservations = require('../../preparators/enhanceObservations');
|
|
49
49
|
|
|
50
50
|
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; } }
|
|
51
51
|
|
|
@@ -64,9 +64,7 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, customAtt
|
|
|
64
64
|
defaultCodes: defaultCodes, annotationsDefinitionCodes: annotationsDefinitionCodes, data: sdmxJson
|
|
65
65
|
});
|
|
66
66
|
var _customAttributes = R.assoc('units', unitsDefinitionCodes, customAttributes);
|
|
67
|
-
var dimensions = R.
|
|
68
|
-
return R.assoc('__index', index, dim);
|
|
69
|
-
}))(sdmxJson);
|
|
67
|
+
var dimensions = R.pathOr([], ['data', 'structure', 'dimensions', 'observation'], sdmxJson);
|
|
70
68
|
|
|
71
69
|
var dimensionsIndexedByIds = R.indexBy(R.prop('id'), dimensions);
|
|
72
70
|
|
|
@@ -91,8 +89,10 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, customAtt
|
|
|
91
89
|
var attachmentSeriesIndexes = (0, _getAttachmentSeriesIndexes.getAttachmentSeriesIndexes)({ dimensions: _dimensions, unitsArtefacts: unitsArtefacts });
|
|
92
90
|
//------------------------------------------------------------------
|
|
93
91
|
|
|
92
|
+
var attributes = R.pathOr([], ['data', 'structure', 'attributes', 'observation'], sdmxJson);
|
|
93
|
+
|
|
94
94
|
var _parseAttributes = (0, _parseAttributes2.parseAttributes)({
|
|
95
|
-
attributes: R.concat(
|
|
95
|
+
attributes: R.concat(attributes, R.pathOr([], ['data', 'structure', 'attributes', 'dataSet'], sdmxJson)),
|
|
96
96
|
parsedDimensionsIds: parsedDimensionsIds,
|
|
97
97
|
getDisplay: _getDisplay,
|
|
98
98
|
customAttributes: _customAttributes
|
|
@@ -102,19 +102,19 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, customAtt
|
|
|
102
102
|
|
|
103
103
|
var seriesAttributesIds = R.propOr([], 'series', attributesIdsIndexedByTargets);
|
|
104
104
|
var observationsAttributesIds = R.propOr([], 'observations', attributesIdsIndexedByTargets);
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
var options = {
|
|
106
|
+
attachmentSeriesIndexes: attachmentSeriesIndexes,
|
|
107
|
+
customAttributes: customAttributes,
|
|
108
|
+
noDisplayIndexes: noDisplayIndexes,
|
|
109
|
+
notDisplayedCodes: notDisplayedCodes,
|
|
110
|
+
attributesIds: R.concat(seriesAttributesIds, observationsAttributesIds),
|
|
111
|
+
unitsIds: unitsDefinitionCodes
|
|
112
|
+
};
|
|
113
113
|
|
|
114
|
-
var
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
var _observations = (0, _getObservations.getObservations)(sdmxJson);
|
|
115
|
+
var observations = (0, _enhanceObservations.enhanceObservations)(dimensions, _observations, attributes, options);
|
|
116
|
+
//------------------------------------------------------------------
|
|
117
|
+
var unitsSeries = (0, _getUnitsSeries.getUnitsSeries)(observations);
|
|
118
118
|
var unitsAttachmentSeriesIds = R.pipe(R.props(attachmentSeriesIndexes), R.pluck('id'))(dimensions);
|
|
119
119
|
//------------------------------------------------------------------
|
|
120
120
|
var attributesRegisters = (0, _getDimensionsAttributesRegisters.getDimensionsAttributesRegisters)(attributesIdsIndexedByTargets, attributesIndexedByIds);
|
|
@@ -144,7 +144,7 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, customAtt
|
|
|
144
144
|
unitsAttachmentSeriesIds: unitsAttachmentSeriesIds,
|
|
145
145
|
unitsSeries: unitsSeries
|
|
146
146
|
},
|
|
147
|
-
observations:
|
|
147
|
+
observations: observations,
|
|
148
148
|
observationsType: (0, _getObservationsType.getObservationsType)(sdmxJson.data),
|
|
149
149
|
dataflowAttributes: dataflowAttributes,
|
|
150
150
|
dataflowName: R.path(['data', 'structure', 'name'], sdmxJson),
|
|
@@ -21,5 +21,5 @@ var getAttachmentSeriesIndexes = exports.getAttachmentSeriesIndexes = function g
|
|
|
21
21
|
|
|
22
22
|
return R.pipe(R.props(R.concat(unitsDimensionsCodes, targettedDimensionsCodes)), R.filter(function (dim) {
|
|
23
23
|
return !R.isNil(dim);
|
|
24
|
-
}), R.pluck('index'), R.uniq)(dimensions);
|
|
24
|
+
}), R.pluck('index'), R.uniq, R.sortBy(R.identity))(dimensions);
|
|
25
25
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getUnitsSeries = undefined;
|
|
7
|
+
|
|
8
|
+
var _ramda = require('ramda');
|
|
9
|
+
|
|
10
|
+
var R = _interopRequireWildcard(_ramda);
|
|
11
|
+
|
|
12
|
+
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; } }
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
observations = { [obsKey]: { units: { serieKey: '', [id]: { id, name, value } } } };
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
var getUnitsSeries = exports.getUnitsSeries = function getUnitsSeries(observations) {
|
|
19
|
+
var series = {};
|
|
20
|
+
R.map(function (obs) {
|
|
21
|
+
series = R.over(R.lensProp(obs.units.serieKey), R.ifElse(R.isNil, R.always([obs.units]), R.append(obs.units)))(series);
|
|
22
|
+
}, observations);
|
|
23
|
+
|
|
24
|
+
return R.map(function (serie) {
|
|
25
|
+
return R.reduce(function (acc, units) {
|
|
26
|
+
return R.mergeWith(function (a, b) {
|
|
27
|
+
return R.path(['value', 'index'], a) === R.path(['value', 'index'], b) ? a : null;
|
|
28
|
+
}, acc, units);
|
|
29
|
+
}, {}, serie);
|
|
30
|
+
})(series);
|
|
31
|
+
};
|
|
@@ -123,7 +123,7 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
|
|
|
123
123
|
var dimObservations = getDimObservations(dimensions);
|
|
124
124
|
|
|
125
125
|
var getObservations = function getObservations(locale) {
|
|
126
|
-
return R.reduce(function (acc, observation) {
|
|
126
|
+
return R.addIndex(R.reduce)(function (acc, observation, obsIndex) {
|
|
127
127
|
var id = R.prop('id')(observation);
|
|
128
128
|
var dimAnnotations = (0, _sdmxData.getRelationnalAnnotations)(R.propOr([], 'annotations')(observation))(annotations);
|
|
129
129
|
var isHidden = R.includes(id)(hiddenIds) ? _sdmxData.hiddenFormat : (0, _sdmxData.getIsHidden)(dimAnnotations);
|
|
@@ -153,6 +153,7 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
|
|
|
153
153
|
|
|
154
154
|
return {
|
|
155
155
|
observation: R.append((0, _extends3.default)({}, observation, {
|
|
156
|
+
__index: obsIndex,
|
|
156
157
|
name: getLocalisedProp('names', observation),
|
|
157
158
|
values: sortedValues,
|
|
158
159
|
role: R.isNil(observation.roles) ? null : R.head(observation.roles)
|
package/package.json
CHANGED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import { getDisplay } from './getDisplay';
|
|
3
|
+
import { formatValue } from './formatValue';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
options = {
|
|
7
|
+
attachmentSeriesIndexes, //units
|
|
8
|
+
customAttributes: {
|
|
9
|
+
decimals: id,
|
|
10
|
+
prefscale: id,
|
|
11
|
+
},
|
|
12
|
+
noDisplayIndexes,
|
|
13
|
+
notDisplayedCodes,
|
|
14
|
+
unitsArtefacts,
|
|
15
|
+
obsAttributes,
|
|
16
|
+
rejectedValueIds,
|
|
17
|
+
}
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const getSerieKey = (dimValuesIndexes, options) => {
|
|
21
|
+
let indexes = R.propOr([], 'attachmentSeriesIndexes', options);
|
|
22
|
+
return R.pipe(
|
|
23
|
+
R.addIndex(R.map)((valueIndex, dimIndex) => {
|
|
24
|
+
if (dimIndex === R.head(indexes)) {
|
|
25
|
+
indexes = R.tail(indexes);
|
|
26
|
+
return valueIndex;
|
|
27
|
+
}
|
|
28
|
+
return 'x';
|
|
29
|
+
}),
|
|
30
|
+
R.join(':')
|
|
31
|
+
)(dimValuesIndexes);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getUnitsValues = (indexes, options) => R.reduce(
|
|
35
|
+
(acc, codelist) => {
|
|
36
|
+
const { id } = codelist;
|
|
37
|
+
if (!R.includes(id, R.propOr([], 'unitsIds', options))) {
|
|
38
|
+
return acc;
|
|
39
|
+
}
|
|
40
|
+
const valueIndex = R.prop(codelist.__index, indexes);
|
|
41
|
+
if (R.isNil(valueIndex) || !getDisplay(options)(codelist)) {
|
|
42
|
+
return acc;
|
|
43
|
+
}
|
|
44
|
+
const value = R.path(['values', Number(valueIndex)], codelist);
|
|
45
|
+
if (R.isNil(value) || R.includes(value.id, R.propOr([], 'rejectedValueIds', options))
|
|
46
|
+
|| !getDisplay(options)({ ...value, parent: codelist.id })) {
|
|
47
|
+
return acc;
|
|
48
|
+
}
|
|
49
|
+
return R.assoc(
|
|
50
|
+
id,
|
|
51
|
+
{
|
|
52
|
+
...R.pick(['id', 'name', '__index'], codelist),
|
|
53
|
+
value: R.when(R.complement(R.isNil), R.assoc('index', Number(valueIndex)))(value)
|
|
54
|
+
},
|
|
55
|
+
acc
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
{}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const getObservationUnits = (observation, dimensions, attributes, options) => {
|
|
62
|
+
const dimensionsUnits = getUnitsValues(
|
|
63
|
+
R.propOr([], 'dimValuesIndexes', observation),
|
|
64
|
+
options
|
|
65
|
+
)(dimensions);
|
|
66
|
+
|
|
67
|
+
const attributesUnits = getUnitsValues(
|
|
68
|
+
R.propOr([], 'attrValuesIndexes', observation),
|
|
69
|
+
options
|
|
70
|
+
)(attributes);
|
|
71
|
+
|
|
72
|
+
const serieKey = getSerieKey(R.propOr([], 'dimValuesIndexes', observation), options);
|
|
73
|
+
|
|
74
|
+
return ({ ...dimensionsUnits, ...attributesUnits, serieKey });
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getOrderedDimensionsIndexes = (dimensions, indexes) => R.addIndex(R.map)(
|
|
78
|
+
(valueIndex, dimensionIndex) => R.path([dimensionIndex, 'values', valueIndex, '__indexPosition'], dimensions),
|
|
79
|
+
indexes
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const getFormatAttributesIndexes = (attributes, customAttributes) => R.addIndex(R.reduce)(
|
|
83
|
+
(acc, attribute, index) => {
|
|
84
|
+
if (R.equals(attribute.id, customAttributes.decimals)) {
|
|
85
|
+
return ({ ...acc, decimals: index });
|
|
86
|
+
}
|
|
87
|
+
if (R.equals(attribute.id, customAttributes.prefscale)) {
|
|
88
|
+
return ({ ...acc, prefscale: index });
|
|
89
|
+
}
|
|
90
|
+
return acc;
|
|
91
|
+
},
|
|
92
|
+
{ prefscale: null, decimals: null },
|
|
93
|
+
attributes
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const getAttributeValue = (attribute, valueIndex, options) => {
|
|
97
|
+
if (!getDisplay(options)(attribute)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const value = R.pipe(
|
|
101
|
+
R.propOr([], 'values'),
|
|
102
|
+
R.nth(valueIndex)
|
|
103
|
+
)(attribute);
|
|
104
|
+
|
|
105
|
+
if (R.isNil(value) || !getDisplay(options)({ ...value, parent: attribute.id })) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return ({
|
|
110
|
+
...R.pick(['id', 'name'], attribute),
|
|
111
|
+
value: R.pick(['id', 'name'], value)
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
export const enhanceObservations = (dimensions = [], observations = {}, attributes = [], options = {}) => {
|
|
117
|
+
const formatAttributesIndexes = getFormatAttributesIndexes(attributes, R.propOr({}, 'customAttributes', options));
|
|
118
|
+
const _attributes = R.addIndex(R.map)((attr, index) => R.assoc('__index', index, attr), attributes);
|
|
119
|
+
const _obsAttributes = R.pipe(
|
|
120
|
+
R.indexBy(R.prop('id')),
|
|
121
|
+
R.props(options.attributesIds || [])
|
|
122
|
+
)(_attributes);
|
|
123
|
+
|
|
124
|
+
const seriesDimensions = R.filter(R.pipe(R.propOr([], 'values'), R.length, R.lt(1)), dimensions);
|
|
125
|
+
|
|
126
|
+
return R.mapObjIndexed(
|
|
127
|
+
(observation) => {
|
|
128
|
+
const { attrValuesIndexes, dimValuesIndexes } = observation;
|
|
129
|
+
const obsAttributes = R.reduce(
|
|
130
|
+
(acc, attribute) => {
|
|
131
|
+
const attrValue = getAttributeValue(attribute, R.nth(attribute.__index, attrValuesIndexes), options);
|
|
132
|
+
if (R.isNil(attrValue)) {
|
|
133
|
+
return acc;
|
|
134
|
+
}
|
|
135
|
+
return R.assoc(attribute.id, attrValue, acc);
|
|
136
|
+
},
|
|
137
|
+
{},
|
|
138
|
+
_obsAttributes
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const indexedDimValIds = R.addIndex(R.reduce)(
|
|
142
|
+
(acc, dimension, dimensionIndex) => {
|
|
143
|
+
const id = dimension.id;
|
|
144
|
+
const valueIndex = R.nth(dimensionIndex, dimValuesIndexes);
|
|
145
|
+
const valueId = R.path(['values', Number(valueIndex), 'id'], dimension);
|
|
146
|
+
return R.assoc(id, valueId, acc);
|
|
147
|
+
},
|
|
148
|
+
{},
|
|
149
|
+
dimensions
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return ({
|
|
153
|
+
...observation,
|
|
154
|
+
attributes: obsAttributes,
|
|
155
|
+
formattedValue: formatValue(observation, formatAttributesIndexes, attributes),
|
|
156
|
+
orderedDimIndexes: getOrderedDimensionsIndexes(dimensions, dimValuesIndexes),
|
|
157
|
+
units: getObservationUnits(observation, seriesDimensions, _attributes, options),
|
|
158
|
+
indexedDimValIds,
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
observations
|
|
162
|
+
);
|
|
163
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import numeral from 'numeral';
|
|
3
|
+
|
|
4
|
+
const isValidNumber = R.both(R.is(Number), R.complement(R.equals(NaN)));
|
|
5
|
+
|
|
6
|
+
const getFormatAttributesValues = (observation, formatAttributesIndexes, attributes) => R.mapObjIndexed(
|
|
7
|
+
attributeIndex => {
|
|
8
|
+
const valueIndex = R.pipe(
|
|
9
|
+
R.propOr([], 'attrValuesIndexes'),
|
|
10
|
+
R.nth(attributeIndex),
|
|
11
|
+
v => R.isNil(v) ? null : Number(v),
|
|
12
|
+
v => isNaN(v) ? null : v
|
|
13
|
+
)(observation);
|
|
14
|
+
|
|
15
|
+
return R.pipe(
|
|
16
|
+
R.path([attributeIndex, 'values', valueIndex, 'id']),
|
|
17
|
+
v => R.isNil(v) ? null : Number(v),
|
|
18
|
+
v => isNaN(v) ? null : v
|
|
19
|
+
)(attributes);
|
|
20
|
+
},
|
|
21
|
+
formatAttributesIndexes
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const formatValue = (observation, formatAttributesIndexes, attributes) => {
|
|
25
|
+
const value = R.prop('value', observation);
|
|
26
|
+
if (R.is(Boolean, value)) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
if (R.is(String, value)) {
|
|
30
|
+
const monthMatch = value.match(/^\-\-([\d]{2})$/);
|
|
31
|
+
if (R.is(Array, monthMatch)) {
|
|
32
|
+
return R.nth(1, monthMatch);
|
|
33
|
+
}
|
|
34
|
+
const monthDayMatch = value.match(/^\-\-([\d]{2}\-[\d]{2})$/);
|
|
35
|
+
if (R.is(Array, monthDayMatch)) {
|
|
36
|
+
return R.nth(1, monthDayMatch);
|
|
37
|
+
}
|
|
38
|
+
const dayMatch = value.match(/^\-\-\-([\d]{2})$/);
|
|
39
|
+
if (R.is(Array, dayMatch)) {
|
|
40
|
+
return R.nth(1, dayMatch);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { prefscale, decimals } = getFormatAttributesValues(
|
|
46
|
+
observation,
|
|
47
|
+
formatAttributesIndexes,
|
|
48
|
+
attributes
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const formatScale = R.when(
|
|
52
|
+
R.always(isValidNumber(prefscale)),
|
|
53
|
+
value => numeral(value).multiply(Math.pow(10, -1 * Number(prefscale))).value(),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const formatSeparator = value => numeral(value).format(`0,0.[0000000]`);
|
|
57
|
+
const formatDecimals = R.ifElse(
|
|
58
|
+
R.always(isValidNumber(decimals)),
|
|
59
|
+
value => numeral(value).format(
|
|
60
|
+
R.ifElse(R.equals(0), R.always('0,0'), d => `0,0.${R.join('', R.times(R.always('0'), d))}`)(decimals)
|
|
61
|
+
),
|
|
62
|
+
formatSeparator
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return R.ifElse(
|
|
66
|
+
isValidNumber,
|
|
67
|
+
R.pipe(
|
|
68
|
+
formatScale,
|
|
69
|
+
formatDecimals,
|
|
70
|
+
),
|
|
71
|
+
R.always('..')
|
|
72
|
+
)(observation.value);
|
|
73
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import {
|
|
3
|
+
getCodeOrder,
|
|
4
|
+
isTimePeriodDimension
|
|
5
|
+
} from '@sis-cc/dotstatsuite-sdmxjs';
|
|
6
|
+
|
|
7
|
+
export const isDisplayedFromOwnAnnotations = artefact => {
|
|
8
|
+
const artefactAnnotations = R.propOr([], 'annotations', artefact);
|
|
9
|
+
return R.pipe(
|
|
10
|
+
R.propOr([], 'annotations'),
|
|
11
|
+
R.find(R.propEq('type', 'NOT_DISPLAYED')),
|
|
12
|
+
R.isNil
|
|
13
|
+
)(artefact);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// sdmxJson
|
|
17
|
+
|
|
18
|
+
export const getDimensions = sdmxJson => {
|
|
19
|
+
const annotations = R.pathOr([], ['data', 'structure', 'annotations'], sdmxJson);
|
|
20
|
+
const locale = R.path([], ['meta', 'contentLanguage'], sdmxJson);
|
|
21
|
+
|
|
22
|
+
const enhanceValues = R.addIndex(R.map)((val, __index) => {
|
|
23
|
+
const annotationsIndexes = R.propOr([], 'annotations', val);
|
|
24
|
+
const valueAnnotations = R.props(annotationsIndexes, annotations);
|
|
25
|
+
|
|
26
|
+
return ({
|
|
27
|
+
...value,
|
|
28
|
+
__index,
|
|
29
|
+
annotations: valueAnnotations,
|
|
30
|
+
name: R.pathOr(`[${val.id}]`, ['names', locale], val),
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return R.pipe(
|
|
35
|
+
R.pathOr([], ['data', 'structure', 'dimensions']),
|
|
36
|
+
R.addIndex(R.map)((dimension, __index) => {
|
|
37
|
+
const annotationsIndexes = R.propOr([], 'annotations', dimension);
|
|
38
|
+
const dimensionAnnotations = R.props(annotationsIndexes, annotations);
|
|
39
|
+
|
|
40
|
+
return ({
|
|
41
|
+
...dimension,
|
|
42
|
+
__index,
|
|
43
|
+
name: R.pathOr(`[${val.id}]`, ['names', locale], val),
|
|
44
|
+
annotations: dimensionAnnotations,
|
|
45
|
+
values: enhanceValues(R.propOr([], 'values', dimension))
|
|
46
|
+
});
|
|
47
|
+
})
|
|
48
|
+
)(sdmxJson);
|
|
49
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
|
|
3
|
+
export const getDisplay = ({ noDisplayIndexes = [], notDisplayedCodes = {} }) => {
|
|
4
|
+
const annotationsValidator = R.pipe(
|
|
5
|
+
R.propOr([], 'annotations'),
|
|
6
|
+
R.intersection(noDisplayIndexes),
|
|
7
|
+
R.isEmpty
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
const blacklistValidator = R.ifElse(
|
|
11
|
+
R.has('values'),
|
|
12
|
+
({ id }) => R.anyPass([
|
|
13
|
+
R.complement(R.has)(id),
|
|
14
|
+
R.hasPath([id, 'values'])
|
|
15
|
+
])(notDisplayedCodes),
|
|
16
|
+
({ id, parent }) => R.complement(R.hasPath)([parent, 'values', id], notDisplayedCodes)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return R.allPass([annotationsValidator, blacklistValidator]);
|
|
20
|
+
};
|