@sis-cc/dotstatsuite-components 14.0.0 → 14.1.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.
Files changed (49) hide show
  1. package/lib/rules/src/preparators/enhanceObservations.js +0 -7
  2. package/lib/rules/src/table/factories/getCells.js +1 -1
  3. package/lib/rules/src/table/factories/getCuratedCells.js +2 -3
  4. package/lib/rules/src/table/factories/getTableData.js +6 -11
  5. package/lib/rules/src/table/preparators/prepareData.js +30 -5
  6. package/lib/rules/src/v8-transformer.js +4 -22
  7. package/lib/rules2/src/duplicateObservations.js +51 -0
  8. package/lib/rules2/src/getDimensionValuesIndexes.js +19 -0
  9. package/lib/rules2/src/getDimensionsSimpleHierarchies.js +42 -0
  10. package/lib/rules2/src/getHCodelistsRefsInData.js +46 -0
  11. package/lib/rules2/src/hierarchiseDimension.js +47 -0
  12. package/lib/rules2/src/index.js +24 -0
  13. package/lib/rules2/src/invertTime.js +33 -0
  14. package/lib/rules2/src/parseHierarchicalCodelist.js +22 -0
  15. package/package.json +1 -1
  16. package/src/rules/src/preparators/enhanceObservations.js +0 -6
  17. package/src/rules/src/table/factories/getCells.js +2 -1
  18. package/src/rules/src/table/factories/getCuratedCells.js +3 -4
  19. package/src/rules/src/table/factories/getTableData.js +3 -22
  20. package/src/rules/src/table/preparators/prepareData.js +20 -3
  21. package/src/rules/src/v8-transformer.js +4 -26
  22. package/src/rules2/src/duplicateObservations.js +45 -0
  23. package/src/rules2/src/getDimensionValuesIndexes.js +13 -0
  24. package/src/rules2/src/getDimensionsSimpleHierarchies.js +34 -0
  25. package/src/rules2/src/getHCodelistsRefsInData.js +23 -0
  26. package/src/rules2/src/hierarchiseDimension.js +38 -0
  27. package/src/rules2/src/index.js +2 -0
  28. package/src/rules2/src/invertTime.js +22 -0
  29. package/src/rules2/src/parseHierarchicalCodelist.js +14 -0
  30. package/test/duplicateObservations.test.js +108 -0
  31. package/test/enhanceObservations.test.js +13 -48
  32. package/test/getCells.test.js +4 -11
  33. package/test/getDimensionValuesIndexes.test.js +33 -0
  34. package/test/getHCodelistsRefs.test.js +20 -0
  35. package/test/hierarchiseDimension.test.js +87 -0
  36. package/test/invertTime.test.js +75 -0
  37. package/test/mocks/h-codelist.json +2095 -0
  38. package/test/mocks/table-invert-time--data.json +80211 -0
  39. package/test/mocks/table-invert-time--inverted.json +80076 -0
  40. package/test/mocks/table-prep-multi-duplicate--duplicated.json +26938 -0
  41. package/test/mocks/table-prep-multi-duplicate--indexes.json +1417 -0
  42. package/test/mocks/table-prep-multi-duplicate--observations.json +20330 -0
  43. package/test/mocks/table-prep-simple-duplicate--duplicated.json +77502 -0
  44. package/test/mocks/table-prep-simple-duplicate--indexes.json +274 -0
  45. package/test/mocks/table-prep-simple-duplicate--observations.json +60002 -0
  46. package/test/parseHierarchicalCodelist.test.js +76 -0
  47. package/test/table-invert-time-perf.test.js +11 -0
  48. package/test/table-prep-duplicate-perf.test.js +21 -0
  49. package/test/table-prep-perf.test.js +5 -2
@@ -74,12 +74,6 @@ var getObservationUnits = function getObservationUnits(observation, dimensions,
74
74
  return (0, _extends3.default)({}, dimensionsUnits, attributesUnits, { serieKey: serieKey });
75
75
  };
76
76
 
77
- var getOrderedDimensionsIndexes = function getOrderedDimensionsIndexes(dimensions, indexes) {
78
- return R.addIndex(R.map)(function (valueIndex, dimensionIndex) {
79
- return R.path([dimensionIndex, 'values', valueIndex, '__indexPosition'], dimensions);
80
- }, indexes);
81
- };
82
-
83
77
  var getFormatAttributesIndexes = function getFormatAttributesIndexes(attributes, customAttributes) {
84
78
  return R.addIndex(R.reduce)(function (acc, attribute, index) {
85
79
  if (R.equals(attribute.id, customAttributes.decimals)) {
@@ -141,7 +135,6 @@ var enhanceObservations = exports.enhanceObservations = function enhanceObservat
141
135
  return (0, _extends3.default)({}, observation, {
142
136
  attributes: obsAttributes,
143
137
  formattedValue: (0, _formatValue.formatValue)(observation, formatAttributesIndexes, attributes),
144
- orderedDimIndexes: getOrderedDimensionsIndexes(dimensions, dimValuesIndexes),
145
138
  units: getObservationUnits(observation, dimensions, _attributes, options),
146
139
  indexedDimValIds: indexedDimValIds
147
140
  });
@@ -92,6 +92,6 @@ var getSideProps = function getSideProps(_ref2, customAttributes, metadataCoordi
92
92
 
93
93
  var getCells = exports.getCells = function getCells(data, display, customAttributes, unitsProps, metadataCoordinates) {
94
94
  return R.mapObjIndexed(function (observation) {
95
- return R.pipe(R.set(R.lensProp('flags'), getFlags(customAttributes, (0, _dimensionUtils.dimensionValueDisplay)(display), unitsProps)(observation)), R.set(R.lensProp('intValue'), R.prop('value', observation)), R.set(R.lensProp('value'), R.prop('formattedValue', observation)), R.assoc('indexedDimValIds', R.prop('indexedDimValIds', observation)), R.assoc('sideProps', getSideProps(observation, customAttributes, metadataCoordinates)))({});
95
+ return R.pipe(R.set(R.lensProp('flags'), getFlags(customAttributes, (0, _dimensionUtils.dimensionValueDisplay)(display), unitsProps)(observation)), R.set(R.lensProp('intValue'), R.prop('value', observation)), R.set(R.lensProp('value'), R.prop('formattedValue', observation)), R.assoc('indexedDimValIds', R.prop('indexedDimValIds', observation)), R.assoc('sideProps', getSideProps(observation, customAttributes, metadataCoordinates)), R.set(R.lensProp('key'), R.prop('key', observation)))({});
96
96
  }, R.propOr({}, 'observations', data));
97
97
  };
@@ -26,12 +26,11 @@ var getPivots = function getPivots(layout, shape) {
26
26
  };
27
27
 
28
28
  var indexWithPivots = function indexWithPivots(pivots, observations) {
29
- return R.pipe(R.keys, R.reduce(function (acc, obsKey) {
30
- var splitKey = R.split(':', obsKey);
29
+ return R.pipe(R.values, R.reduce(function (acc, obs) {
30
+ var splitKey = R.split(':', obs.key);
31
31
  var path = R.map(function (pivot) {
32
32
  return pivot(splitKey);
33
33
  }, pivots);
34
- var obs = R.prop(obsKey, observations);
35
34
  return R.over(R.lensPath(path), R.ifElse(R.isNil, R.always([obs]), R.append(obs)))(acc);
36
35
  }, {}))(observations);
37
36
  };
@@ -13,8 +13,6 @@ var _ramda = require('ramda');
13
13
 
14
14
  var R = _interopRequireWildcard(_ramda);
15
15
 
16
- var _dotstatsuiteSdmxjs = require('@sis-cc/dotstatsuite-sdmxjs');
17
-
18
16
  var _getCells = require('./getCells');
19
17
 
20
18
  var _getConfirmedSeriesAttributesIds = require('./getConfirmedSeriesAttributesIds');
@@ -37,6 +35,8 @@ var _getLayoutData = require('./getLayoutData');
37
35
 
38
36
  var _refineMetadataCoordinates = require('../../../../rules2/src/refineMetadataCoordinates');
39
37
 
38
+ var _invertTime2 = require('../../../../rules2/src/invertTime');
39
+
40
40
  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; } }
41
41
 
42
42
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -76,14 +76,9 @@ var getTableProps = exports.getTableProps = function getTableProps(_ref) {
76
76
  unitDimension: unitDimension, rejectedValueIds: rejectedValueIds, layoutDimsIds: layoutDimsIds
77
77
  }, refinedMetadataCoordinates.cells, data.observationsType);
78
78
 
79
- var dimensions = R.mapObjIndexed(R.pipe(R.when( // invert TimeDimension Values
80
- R.allPass([_dotstatsuiteSdmxjs.isTimePeriodDimension, R.always(isTimeInverted)]), function (dim) {
81
- return R.over(R.lensProp('values'), R.map(R.over(R.lensProp('__indexPosition'), R.negate)))(dim);
82
- }), function (dim) {
83
- return R.over( // sort values
84
- R.lensProp('values'), R.sortWith([R.ascend(R.prop('__indexPosition')), R.ascend(R.prop('order'))]))(dim);
85
- }, R.when( // refine hierarchy on rows
86
- R.pipe(R.prop('id'), R.flip(R.includes)(R.propOr([], 'rows', layoutIds))), _dotstatsuiteSdmxjs.withFlatHierarchy)), R.pathOr({}, ['dimensions', 'many'], data));
79
+ var _invertTime = (0, _invertTime2.invertTime)(data, isTimeInverted),
80
+ dimensions = _invertTime.dimensions,
81
+ observations = _invertTime.observations;
87
82
 
88
83
  var seriesAttributesValues = R.propOr({}, 'seriesAttributesValues', data);
89
84
  var layout = R.pipe(R.mergeRight({ header: [], sections: [], rows: [] }), R.mapObjIndexed(R.flip(R.props)(dimensions)))(layoutIds);
@@ -96,7 +91,7 @@ var getTableProps = exports.getTableProps = function getTableProps(_ref) {
96
91
  display: display, unitDimension: unitDimension, unitsDisplay: unitsLevelDisplay, unitsSeries: unitsSeries,
97
92
  unitsDefinitionCodes: unitsDefinitionCodes, unitsIndexes: unitsAttachmentIndexesInLayout,
98
93
  partialUnitSerieIndexes: partialUnitSerieIndexes, rejectedValueIds: rejectedValueIds, layoutIds: layoutIds
99
- }), (0, _getLayoutWithFlags.getLayoutDataWithFlags)(seriesAttributesValues, display, customAttributes, refinedMetadataCoordinates, unitDimension.id), (0, _cleanUnitsInLayoutData.cleanUnitsInLayoutData)({ unitsDisplay: unitsLevelDisplay, unitsLayoutIndexes: unitsIndexesInLayout }))(layout, R.propOr({}, 'observations', data));
94
+ }), (0, _getLayoutWithFlags.getLayoutDataWithFlags)(seriesAttributesValues, display, customAttributes, refinedMetadataCoordinates, unitDimension.id), (0, _cleanUnitsInLayoutData.cleanUnitsInLayoutData)({ unitsDisplay: unitsLevelDisplay, unitsLayoutIndexes: unitsIndexesInLayout }))(layout, observations);
100
95
 
101
96
  return (0, _extends3.default)({
102
97
  cells: (0, _getCuratedCells.getCuratedCells)({ layout: layout, observations: cells, shape: ['header', 'sections', 'rows'] }),
@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.prepareData = undefined;
7
7
 
8
- var _extends2 = require('babel-runtime/helpers/extends');
8
+ var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
9
9
 
10
- var _extends3 = _interopRequireDefault(_extends2);
10
+ var _defineProperty3 = _interopRequireDefault(_defineProperty2);
11
+
12
+ var _extends3 = require('babel-runtime/helpers/extends');
13
+
14
+ var _extends4 = _interopRequireDefault(_extends3);
11
15
 
12
16
  var _ramda = require('ramda');
13
17
 
@@ -49,6 +53,14 @@ var _getMetadataCoordinates = require('../../../../rules2/src/getMetadataCoordin
49
53
 
50
54
  var _getAdvancedAttributes = require('../../../../rules2/src/getAdvancedAttributes');
51
55
 
56
+ var _getDimensionsSimpleHierarchies = require('../../../../rules2/src/getDimensionsSimpleHierarchies');
57
+
58
+ var _duplicateObservations = require('../../../../rules2/src/duplicateObservations');
59
+
60
+ var _hierarchiseDimension = require('../../../../rules2/src/hierarchiseDimension');
61
+
62
+ var _getDimensionValuesIndexes = require('../../../../rules2/src/getDimensionValuesIndexes');
63
+
52
64
  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; } }
53
65
 
54
66
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -56,6 +68,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
56
68
  var prepareData = exports.prepareData = function prepareData(sdmxJson, customAttributes) {
57
69
  var unitsProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
58
70
 
71
+ var _options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
72
+
59
73
  var _R$pick = R.pick(['defaultCodes', 'annotationsDefinitionCodes', 'rejectedValueIds'], unitsProps),
60
74
  _R$pick$defaultCodes = _R$pick.defaultCodes,
61
75
  defaultCodes = _R$pick$defaultCodes === undefined ? [] : _R$pick$defaultCodes,
@@ -70,6 +84,8 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, customAtt
70
84
  var _customAttributes = R.assoc('units', unitsDefinitionCodes, customAttributes);
71
85
  var dimensions = R.pathOr([], ['data', 'structure', 'dimensions', 'observation'], sdmxJson);
72
86
 
87
+ var simpleHierarchies = (0, _getDimensionsSimpleHierarchies.getDimensionsSimpleHierarchies)(dimensions);
88
+ var hierarchies = R.mergeRight(simpleHierarchies, _options.hierarchies || {});
73
89
  var dimensionsIndexedByIds = R.indexBy(R.prop('id'), dimensions);
74
90
 
75
91
  var parsedDimensionsIds = (0, _parseDimensionsIds.parseDimensionsIds)(dimensions);
@@ -150,10 +166,19 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, customAtt
150
166
 
151
167
  var seriesAdvancedAttributes = (0, _getAdvancedAttributes.getSeriesAdvancedAttributes)(seriesAttributesValues, dimensions, seriesAdvancedAttributesIds);
152
168
 
169
+ var hierarchisedDimensions = R.map(function (dim) {
170
+ return (0, _hierarchiseDimension.hierarchiseDimension)(dim, R.propOr({}, dim.id, hierarchies));
171
+ })(manyValuesDimensions);
172
+ var valuesIndexes = R.reduce(function (acc, dim) {
173
+ return (0, _extends4.default)({}, acc, (0, _defineProperty3.default)({}, dim.__index, (0, _getDimensionValuesIndexes.getDimensionValuesIndexes)(dim.values)));
174
+ }, {}, R.values(hierarchisedDimensions));
175
+
176
+ var duplicatedObservations = (0, _duplicateObservations.duplicateObservations)(observations, valuesIndexes);
177
+
153
178
  return {
154
179
  dimensions: {
155
180
  one: oneValueDimensions,
156
- many: manyValuesDimensions,
181
+ many: hierarchisedDimensions,
157
182
  length: R.length(dimensions)
158
183
  },
159
184
  units: {
@@ -164,8 +189,8 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, customAtt
164
189
  unitsSeries: unitsSeries
165
190
  },
166
191
  metadataCoordinates: metadataCoordinates,
167
- advancedAttributes: (0, _extends3.default)({}, dataflowAdvancedAttributes, observationsAdvancedAttributes, seriesAdvancedAttributes),
168
- observations: observations,
192
+ advancedAttributes: (0, _extends4.default)({}, dataflowAdvancedAttributes, observationsAdvancedAttributes, seriesAdvancedAttributes),
193
+ observations: duplicatedObservations,
169
194
  observationsType: (0, _getObservationsType.getObservationsType)(sdmxJson.data),
170
195
  dataflowAttributes: dataflowAttributes,
171
196
  dataflowName: R.path(['data', 'structure', 'name'], sdmxJson),
@@ -94,7 +94,9 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
94
94
  });
95
95
  }), R.sortWith([R.ascend(R.prop('__indexPosition')), R.ascend(R.propOr(-1, 'order'))]), R.addIndex(R.map)(function (val, index) {
96
96
  return R.assoc('__indexPosition', index, val);
97
- }));
97
+ }),
98
+ /* NEW */
99
+ R.sortBy(R.prop('__index')));
98
100
  };
99
101
 
100
102
  //--------------------------------------------------------------------------------------------Header
@@ -154,33 +156,13 @@ var dataTransformer = exports.dataTransformer = function dataTransformer(dataNew
154
156
  var isHidden = R.has(id, hiddenIds) || (0, _sdmxData.getIsHidden)(dimAnnotations);
155
157
  var isTime = observation.id === timePeriodId;
156
158
  var values = getValuesEnhanced(locale, annotations, isTime, id)(R.propOr([], 'values', observation));
157
- var ids = R.pipe(R.pluck('id'), R.indexBy(R.identity))(values);
158
- var groupedByParentsValues = R.groupBy(function (val) {
159
- var parentId = R.propOr('##ROOT', 'parent', val);
160
- if (parentId !== '##ROOT' && !R.has(parentId, ids)) {
161
- return '##ROOT';
162
- }
163
- return parentId;
164
- }, values);
165
- var sortedGroupedValues = R.mapObjIndexed(R.sortWith([R.ascend(R.prop('__indexPosition')), R.ascend(R.prop('__index'))]), groupedByParentsValues);
166
-
167
- var getReccursiveChildren = function getReccursiveChildren(parent) {
168
- var children = R.propOr([], parent, sortedGroupedValues);
169
- return R.map(function (child) {
170
- return R.prepend(child, getReccursiveChildren(child.id));
171
- }, children);
172
- };
173
-
174
- var sortedValues = R.pipe(getReccursiveChildren, R.flatten, R.addIndex(R.map)(function (value, index) {
175
- return R.assoc('__indexPosition', index, value);
176
- }), R.sortBy(R.prop('__index')))('##ROOT');
177
159
 
178
160
  return {
179
161
  observation: R.append((0, _extends3.default)({}, observation, {
180
162
  display: !isHidden,
181
163
  __index: obsIndex,
182
164
  name: (0, _dotstatsuiteSdmxjs.getRefinedName)(observation),
183
- values: sortedValues,
165
+ values: values,
184
166
  role: isTime ? TIME_PERIOD_ID : R.head(R.propOr([], 'roles', observation))
185
167
  }))(acc.observation),
186
168
  dimensionsLayout: (0, _sdmxData.setAnnotationsLayout)(id, acc.dimensionsLayout)(dimAnnotations)
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.duplicateObservations = 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
+ 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; } }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ var duplicateObservations = exports.duplicateObservations = function duplicateObservations(observations, indexes) {
21
+ return R.addIndex(R.reduce)(function (acc, obs, i) {
22
+
23
+ var orderedIndexes = R.addIndex(R.map)(function (valueIndex, dimIndex) {
24
+ return R.pathOr([Number(valueIndex)], [dimIndex, valueIndex], indexes);
25
+ }, R.propOr([], 'dimValuesIndexes', obs));
26
+
27
+ var cartesian = void 0;
28
+
29
+ if (R.any(function (is) {
30
+ return R.length(is) > 1;
31
+ })(orderedIndexes)) {
32
+ cartesian = R.reduce(function (acc, oInds) {
33
+ var r = R.map(function (i) {
34
+ return R.map(function (is) {
35
+ return R.append(i, is);
36
+ }, acc);
37
+ }, oInds);
38
+ return R.unnest(r);
39
+ }, R.pipe(R.head, R.map(R.of))(orderedIndexes), R.tail(orderedIndexes));
40
+ } else {
41
+ cartesian = [R.unnest(orderedIndexes)];
42
+ }
43
+
44
+ var duplicatedObs = R.reduce(function (acc, orderedDimIndexes) {
45
+ var key = R.join(':', orderedDimIndexes);
46
+ return R.assoc(key, (0, _extends3.default)({}, obs, { orderedDimIndexes: orderedDimIndexes }), acc);
47
+ }, {}, cartesian);
48
+
49
+ return R.mergeRight(acc, duplicatedObs);
50
+ }, {}, R.values(observations));
51
+ };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDimensionValuesIndexes = 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
+ var getDimensionValuesIndexes = exports.getDimensionValuesIndexes = function getDimensionValuesIndexes(values) {
15
+ return R.addIndex(R.reduce)(function (acc, value, position) {
16
+ var sdmxIndex = value.__index;
17
+ return R.over(R.lensProp(String(sdmxIndex)), R.ifElse(R.isNil, R.always([position]), R.append(position)))(acc);
18
+ }, {}, values);
19
+ };
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDimensionsSimpleHierarchies = 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
+ var getDimensionSimpleHierarchy = function getDimensionSimpleHierarchy(_ref) {
15
+ var values = _ref.values;
16
+
17
+ var indexed = R.indexBy(R.prop('id'), values);
18
+ return R.pipe(R.reduce(function (acc, value) {
19
+ var id = value.id,
20
+ parent = value.parent;
21
+
22
+ var _parent = R.isNil(parent) || !R.has(parent, indexed) ? '#ROOT' : parent;
23
+ return R.over(R.lensProp(_parent), function (ids) {
24
+ return R.isNil(ids) ? [id] : R.append(id, ids);
25
+ })(acc);
26
+ }, {}), R.map(R.sortBy(function (id) {
27
+ return R.pathOr(-1, [id, '__indexPosition'], indexed);
28
+ })))(values);
29
+ };
30
+
31
+ var getDimensionsSimpleHierarchies = exports.getDimensionsSimpleHierarchies = function getDimensionsSimpleHierarchies(dimensions) {
32
+ return R.reduce(function (acc, dim) {
33
+ var id = dim.id,
34
+ values = dim.values;
35
+
36
+ if (R.length(values) < 2) {
37
+ return acc;
38
+ }
39
+ var hierarchy = getDimensionSimpleHierarchy(dim);
40
+ return R.assoc(id, hierarchy, acc);
41
+ }, {}, dimensions);
42
+ };
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getHCodelistsRefsInData = exports.getHCodelistsRefs = undefined;
7
+
8
+ var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
9
+
10
+ var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
11
+
12
+ var _ramda = require('ramda');
13
+
14
+ var R = _interopRequireWildcard(_ramda);
15
+
16
+ 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; } }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ var getHCodelistsRefs = exports.getHCodelistsRefs = function getHCodelistsRefs(annotations) {
21
+ return R.reduce(function (acc, annotation) {
22
+ if (annotation.type !== 'HIER_CONTEXT') {
23
+ return acc;
24
+ }
25
+ var reference = annotation.text || '';
26
+ var match = reference.match(/([\w@_.]+):([\w@_.]+):([\w@_.]+)\(([\d.]+)\).([\w@_.]+)$/);
27
+ if (R.isNil(match)) {
28
+ return acc;
29
+ }
30
+
31
+ var _R$tail = R.tail(match),
32
+ _R$tail2 = (0, _slicedToArray3.default)(_R$tail, 5),
33
+ codelistId = _R$tail2[0],
34
+ agencyId = _R$tail2[1],
35
+ code = _R$tail2[2],
36
+ version = _R$tail2[3],
37
+ hierarchy = _R$tail2[4];
38
+
39
+ return R.assoc(codelistId, { agencyId: agencyId, code: code, version: version, hierarchy: hierarchy, codelistId: codelistId }, acc);
40
+ }, {}, annotations);
41
+ };
42
+
43
+ var getHCodelistsRefsInData = exports.getHCodelistsRefsInData = function getHCodelistsRefsInData(sdmxJson) {
44
+ var annotations = R.pathOr([], ['data', 'structure', 'annotations'], sdmxJson);
45
+ return getHCodelistsRefs(annotations);
46
+ };
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hierarchiseDimension = 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
+ 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; } }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ var hierarchiseDimension = exports.hierarchiseDimension = function hierarchiseDimension(dimension, hierarchy) {
21
+ var indexed = R.indexBy(R.prop('id'), dimension.values);
22
+ var _hierarchy = hierarchy;
23
+ if (!R.has('#ROOT', hierarchy)) {
24
+ var indexes = R.pluck('id', dimension.values);
25
+ var refinedHierarchy = R.pick(indexes, _hierarchy);
26
+ var childrenIds = R.pipe(R.values, R.unnest, R.indexBy(R.identity))(refinedHierarchy);
27
+ var rootIds = R.pipe(R.reject(function (val) {
28
+ return R.has(val.id, childrenIds);
29
+ }), R.sortBy(R.prop('__indexPosition')), R.pluck('id'))(dimension.values);
30
+ _hierarchy = R.assoc('#ROOT', rootIds, hierarchy);
31
+ }
32
+
33
+ var getChildren = function getChildren(parents) {
34
+ return R.pipe(function (ids) {
35
+ return R.props(ids, indexed);
36
+ }, R.filter(R.identity), R.map(function (val) {
37
+ var _val = (0, _extends3.default)({}, val, {
38
+ parent: R.last(parents),
39
+ parents: parents
40
+ });
41
+ var children = getChildren(R.append(val.id, parents));
42
+ return R.prepend(_val, children);
43
+ }))(R.propOr([], R.last(parents) || '#ROOT', _hierarchy));
44
+ };
45
+
46
+ return R.set(R.lensProp('values'), R.flatten(getChildren([])))(dimension);
47
+ };
@@ -71,4 +71,28 @@ Object.defineProperty(exports, 'getNotDisplayedIds', {
71
71
  get: function get() {
72
72
  return _getNotDisplayedIds.getNotDisplayedIds;
73
73
  }
74
+ });
75
+
76
+ var _getHCodelistsRefsInData = require('./getHCodelistsRefsInData');
77
+
78
+ Object.defineProperty(exports, 'getHCodelistsRefs', {
79
+ enumerable: true,
80
+ get: function get() {
81
+ return _getHCodelistsRefsInData.getHCodelistsRefs;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, 'getHCodelistsRefsInData', {
85
+ enumerable: true,
86
+ get: function get() {
87
+ return _getHCodelistsRefsInData.getHCodelistsRefsInData;
88
+ }
89
+ });
90
+
91
+ var _parseHierarchicalCodelist = require('./parseHierarchicalCodelist');
92
+
93
+ Object.defineProperty(exports, 'parseHierarchicalCodelist', {
94
+ enumerable: true,
95
+ get: function get() {
96
+ return _parseHierarchicalCodelist.parseHierarchicalCodelist;
97
+ }
74
98
  });
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.invertTime = undefined;
7
+
8
+ var _ramda = require('ramda');
9
+
10
+ var R = _interopRequireWildcard(_ramda);
11
+
12
+ var _dotstatsuiteSdmxjs = require('@sis-cc/dotstatsuite-sdmxjs');
13
+
14
+ 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; } }
15
+
16
+ var invertTime = exports.invertTime = function invertTime(data, isTimeInverted) {
17
+ var dimensions = R.pathOr([], ['dimensions', 'many'], data);
18
+ var observations = R.propOr({}, 'observations', data);
19
+ if (!isTimeInverted) {
20
+ return { dimensions: dimensions, observations: observations };
21
+ }
22
+ var timeD = R.find(_dotstatsuiteSdmxjs.isTimePeriodDimension, R.values(dimensions));
23
+ if (!timeD) {
24
+ return { dimensions: dimensions, observations: observations };
25
+ }
26
+ var timeLength = R.length(timeD.values);
27
+ var timeIndex = timeD.__index;
28
+ var invertTimeInObs = R.map(R.over(R.lensProp('orderedDimIndexes'), R.over(R.lensIndex(timeIndex), function (i) {
29
+ return timeLength - i - 1;
30
+ })), observations);
31
+ var invertedTimeInDims = R.over(R.lensProp(timeD.id), R.over(R.lensProp('values'), R.reverse))(dimensions);
32
+ return { dimensions: invertedTimeInDims, observations: invertTimeInObs };
33
+ };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseHierarchicalCodelist = 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
+ var parseHierarchicalCodelist = exports.parseHierarchicalCodelist = function parseHierarchicalCodelist(sdmxJson, hierarchyId) {
15
+ var hCodelist = R.pathOr({}, ['data', 'hierarchicalCodelists', 0], sdmxJson);
16
+ var hierarchy = R.find(R.propEq('id', hierarchyId), hCodelist.hierarchies || []);
17
+
18
+ return R.pipe(R.propOr([], 'hierarchicalCodes'), R.reduce(function (acc, parentCode) {
19
+ var children = R.pluck('id', parentCode.hierarchicalCodes || []);
20
+ return R.assoc(parentCode.id, children, acc);
21
+ }, {}))(hierarchy);
22
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sis-cc/dotstatsuite-components",
3
3
  "description": "Set components based on React.",
4
- "version": "14.0.0",
4
+ "version": "14.1.0",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -71,11 +71,6 @@ const getObservationUnits = (observation, dimensions, attributes, options) => {
71
71
  return ({ ...dimensionsUnits, ...attributesUnits, serieKey });
72
72
  };
73
73
 
74
- const getOrderedDimensionsIndexes = (dimensions, indexes) => R.addIndex(R.map)(
75
- (valueIndex, dimensionIndex) => R.path([dimensionIndex, 'values', valueIndex, '__indexPosition'], dimensions),
76
- indexes
77
- );
78
-
79
74
  const getFormatAttributesIndexes = (attributes, customAttributes) => R.addIndex(R.reduce)(
80
75
  (acc, attribute, index) => {
81
76
  if (R.equals(attribute.id, customAttributes.decimals)) {
@@ -148,7 +143,6 @@ export const enhanceObservations = (dimensions = [], observations = {}, attribut
148
143
  ...observation,
149
144
  attributes: obsAttributes,
150
145
  formattedValue: formatValue(observation, formatAttributesIndexes, attributes),
151
- orderedDimIndexes: getOrderedDimensionsIndexes(dimensions, dimValuesIndexes),
152
146
  units: getObservationUnits(observation, dimensions, _attributes, options),
153
147
  indexedDimValIds,
154
148
  });
@@ -95,7 +95,8 @@ export const getCells = (data, display, customAttributes, unitsProps, metadataCo
95
95
  R.set(R.lensProp('intValue'), R.prop('value', observation)),
96
96
  R.set(R.lensProp('value'), R.prop('formattedValue', observation)),
97
97
  R.assoc('indexedDimValIds', R.prop('indexedDimValIds', observation)),
98
- R.assoc('sideProps', getSideProps(observation, customAttributes, metadataCoordinates))
98
+ R.assoc('sideProps', getSideProps(observation, customAttributes, metadataCoordinates)),
99
+ R.set(R.lensProp('key'), R.prop('key', observation)),
99
100
  )({}),
100
101
  R.propOr({}, 'observations', data)
101
102
  );
@@ -17,15 +17,14 @@ const getPivots = (layout, shape) => R.pipe(
17
17
  )(layout);
18
18
 
19
19
  const indexWithPivots = (pivots, observations) => R.pipe(
20
- R.keys,
20
+ R.values,
21
21
  R.reduce(
22
- (acc, obsKey) => {
23
- const splitKey = R.split(':', obsKey);
22
+ (acc, obs) => {
23
+ const splitKey = R.split(':', obs.key);
24
24
  const path = R.map(
25
25
  pivot => pivot(splitKey),
26
26
  pivots
27
27
  );
28
- const obs = R.prop(obsKey, observations);
29
28
  return R.over(
30
29
  R.lensPath(path),
31
30
  R.ifElse(R.isNil, R.always([obs]), R.append(obs))
@@ -1,5 +1,4 @@
1
1
  import * as R from 'ramda';
2
- import { withFlatHierarchy, isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
3
2
  import { getCells } from './getCells';
4
3
  import { getConfirmedSeriesAttributesIds } from './getConfirmedSeriesAttributesIds';
5
4
  import { getCuratedCells } from './getCuratedCells';
@@ -14,6 +13,7 @@ import { getSortedLayoutIndexes } from './getSortedLayoutIndexes';
14
13
  import { refineLayoutSize } from './refineLayoutSize';
15
14
  import { getLayoutData } from './getLayoutData';
16
15
  import { refineMetadataCoordinates } from '../../../../rules2/src/refineMetadataCoordinates';
16
+ import { invertTime } from '../../../../rules2/src/invertTime';
17
17
 
18
18
  export const getTableProps = ({ data, layoutIds, display, customAttributes, limit, isTimeInverted }) => {
19
19
  const seriesAttributes = R.propOr({}, 'seriesAttributes', data);
@@ -56,26 +56,7 @@ export const getTableProps = ({ data, layoutIds, display, customAttributes, limi
56
56
  data.observationsType,
57
57
  );
58
58
 
59
- const dimensions = R.mapObjIndexed(
60
- R.pipe(
61
- R.when( // invert TimeDimension Values
62
- R.allPass([isTimePeriodDimension, R.always(isTimeInverted)]),
63
- (dim) => R.over(
64
- R.lensProp('values'),
65
- R.map(R.over(R.lensProp('__indexPosition'), R.negate))
66
- )(dim),
67
- ),
68
- (dim) => R.over( // sort values
69
- R.lensProp('values'),
70
- R.sortWith([R.ascend(R.prop('__indexPosition')), R.ascend(R.prop('order'))]),
71
- )(dim),
72
- R.when( // refine hierarchy on rows
73
- R.pipe(R.prop('id'), R.flip(R.includes)(R.propOr([], 'rows', layoutIds))),
74
- withFlatHierarchy
75
- )
76
- ),
77
- R.pathOr({}, ['dimensions', 'many'], data)
78
- );
59
+ const { dimensions, observations } = invertTime(data, isTimeInverted);
79
60
 
80
61
  const seriesAttributesValues = R.propOr({}, 'seriesAttributesValues', data);
81
62
  const layout = R.pipe(
@@ -99,7 +80,7 @@ export const getTableProps = ({ data, layoutIds, display, customAttributes, limi
99
80
  }),
100
81
  getLayoutDataWithFlags(seriesAttributesValues, display, customAttributes, refinedMetadataCoordinates, unitDimension.id),
101
82
  cleanUnitsInLayoutData({ unitsDisplay: unitsLevelDisplay, unitsLayoutIndexes: unitsIndexesInLayout }),
102
- )(layout, R.propOr({}, 'observations', data));
83
+ )(layout, observations);
103
84
 
104
85
  return ({
105
86
  cells: getCuratedCells({ layout, observations: cells, shape: ['header', 'sections', 'rows'] }),