@sis-cc/dotstatsuite-components 15.0.20 → 16.0.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 (167) hide show
  1. package/LICENSE +1 -1
  2. package/lib/rules/src/index.js +1 -145
  3. package/lib/rules/src/table/index.js +0 -42
  4. package/lib/rules/src/v8-transformer.js +6 -5
  5. package/lib/rules2/src/constants.js +3 -1
  6. package/lib/rules2/src/enhanceObservations.js +98 -0
  7. package/lib/rules2/src/getAttributesSeries.js +33 -0
  8. package/lib/rules2/src/getCombinationDefinitions.js +48 -0
  9. package/lib/rules2/src/getHeaderCombinations.js +42 -0
  10. package/lib/rules2/src/getHeaderSubtitle.js +41 -0
  11. package/lib/rules2/src/getManyValuesDimensions.js +39 -0
  12. package/lib/rules2/src/getNotDisplayedIds.js +5 -1
  13. package/lib/rules2/src/getOneValueDimensions.js +46 -0
  14. package/lib/rules2/src/hasCellMetadata.js +1 -1
  15. package/lib/rules2/src/index.js +186 -18
  16. package/lib/rules2/src/parseAttributes.js +50 -0
  17. package/lib/rules2/src/parseCombinations.js +54 -0
  18. package/lib/rules2/src/prepareData.js +74 -0
  19. package/lib/{rules/src/table/preparators/getAttributeValue.js → rules2/src/refineAttributes.js} +13 -11
  20. package/lib/rules2/src/table/getCells.js +74 -0
  21. package/lib/rules2/src/table/getCellsAttributesIds.js +63 -0
  22. package/lib/rules2/src/table/getCombinationDimensionsData.js +47 -0
  23. package/lib/rules2/src/table/getCuratedCells.js +28 -0
  24. package/lib/rules2/src/table/getFlagsAndNotes.js +28 -0
  25. package/lib/rules2/src/table/getIndexedCombinationsByDisplay.js +31 -0
  26. package/lib/rules2/src/table/getLayout.js +93 -0
  27. package/lib/rules2/src/table/getLayoutData.js +202 -0
  28. package/lib/{rules/src/table/factories → rules2/src/table}/getSortedLayoutIndexes.js +55 -40
  29. package/lib/rules2/src/table/getTableProps.js +64 -0
  30. package/lib/rules2/src/table/parseValueHierarchy.js +55 -0
  31. package/lib/{rules/src/table/factories → rules2/src/table}/refineLayoutSize.js +17 -8
  32. package/lib/rules2/src/{hasLayoutEntryMetadata.js → utils.js} +9 -6
  33. package/package.json +1 -1
  34. package/src/rules/src/index.js +1 -19
  35. package/src/rules/src/table/index.js +0 -4
  36. package/src/rules/src/v8-transformer.js +75 -74
  37. package/src/rules2/src/constants.js +2 -0
  38. package/src/rules2/src/enhanceObservations.js +88 -0
  39. package/src/rules2/src/getAttributesSeries.js +29 -0
  40. package/src/rules2/src/getCombinationDefinitions.js +29 -0
  41. package/src/rules2/src/getHeaderCombinations.js +39 -0
  42. package/src/rules2/src/getHeaderSubtitle.js +34 -0
  43. package/src/rules2/src/getManyValuesDimensions.js +34 -0
  44. package/src/rules2/src/getNotDisplayedIds.js +5 -1
  45. package/src/rules2/src/getOneValueDimensions.js +33 -0
  46. package/src/rules2/src/hasCellMetadata.js +1 -1
  47. package/src/rules2/src/index.js +21 -6
  48. package/src/rules2/src/parseAttributes.js +36 -0
  49. package/src/rules2/src/parseCombinations.js +36 -0
  50. package/src/rules2/src/prepareData.js +50 -0
  51. package/src/rules2/src/refineAttributes.js +16 -0
  52. package/src/rules2/src/table/getCells.js +72 -0
  53. package/src/rules2/src/table/getCellsAttributesIds.js +38 -0
  54. package/src/rules2/src/table/getCombinationDimensionsData.js +38 -0
  55. package/src/rules2/src/table/getCuratedCells.js +33 -0
  56. package/src/rules2/src/table/getFlagsAndNotes.js +21 -0
  57. package/src/rules2/src/table/getIndexedCombinationsByDisplay.js +16 -0
  58. package/src/rules2/src/table/getLayout.js +80 -0
  59. package/src/rules2/src/table/getLayoutData.js +183 -0
  60. package/src/rules2/src/table/getSortedLayoutIndexes.js +119 -0
  61. package/src/rules2/src/table/getTableProps.js +36 -0
  62. package/src/rules2/src/table/parseValueHierarchy.js +27 -0
  63. package/src/{rules/src/table/factories → rules2/src/table}/refineLayoutSize.js +24 -8
  64. package/src/rules2/src/utils.js +12 -0
  65. package/test/enhanceObservations2.test.js +219 -0
  66. package/test/getAttributesSeries.test.js +58 -0
  67. package/test/getCells.test.js +6 -40
  68. package/test/getCombinationDimensionsData.test.js +48 -0
  69. package/test/getNotDisplayedIds.test.js +15 -2
  70. package/test/getSortedLayoutIndexes.test.js +1025 -3
  71. package/test/parseAttributes.test.js +17 -62
  72. package/test/parseValueHierarchy.test.js +88 -0
  73. package/test/refineLayoutSize.test.js +2621 -1
  74. package/lib/rules/src/table/factories/getCells.js +0 -97
  75. package/lib/rules/src/table/factories/getConfirmedSeriesAttributesIds.js +0 -26
  76. package/lib/rules/src/table/factories/getCuratedCells.js +0 -45
  77. package/lib/rules/src/table/factories/getLayoutData.js +0 -168
  78. package/lib/rules/src/table/factories/getLayoutWithFlags.js +0 -133
  79. package/lib/rules/src/table/factories/getTableCells.js +0 -24
  80. package/lib/rules/src/table/factories/getTableData.js +0 -98
  81. package/lib/rules/src/table/preparators/getDimensionsAttributesRegisters.js +0 -43
  82. package/lib/rules/src/table/preparators/getManyValuesDimensions.js +0 -33
  83. package/lib/rules/src/table/preparators/getOneValueDimensions.js +0 -24
  84. package/lib/rules/src/table/preparators/getUniqValuesAttributes.js +0 -36
  85. package/lib/rules/src/table/preparators/parseAttributes.js +0 -84
  86. package/lib/rules/src/table/preparators/parseAttributesValuesFromObservations.js +0 -22
  87. package/lib/rules/src/table/preparators/parseDimensionsIds.js +0 -22
  88. package/lib/rules/src/table/preparators/prepareData.js +0 -191
  89. package/lib/rules/src/table/preparators/refineObservationsAttributesValues.js +0 -31
  90. package/lib/rules/src/table/preparators/refineSeriesAttributesValues.js +0 -23
  91. package/lib/rules/src/table/units/appendUnitsInLayoutData.js +0 -82
  92. package/lib/rules/src/table/units/appendUnitsInLayoutDataEntry.js +0 -45
  93. package/lib/rules/src/table/units/cleanUnitsInLayoutData.js +0 -66
  94. package/lib/rules/src/table/units/getAttachmentSeriesIndexes.js +0 -25
  95. package/lib/rules/src/table/units/getHeaderUnits.js +0 -35
  96. package/lib/rules/src/table/units/getUnitsArtefacts.js +0 -85
  97. package/lib/rules/src/table/units/getUnitsCodes.js +0 -23
  98. package/lib/rules/src/table/units/getUnitsDefinition.js +0 -33
  99. package/lib/rules/src/table/units/getUnitsDisplay.js +0 -33
  100. package/lib/rules/src/table/units/getUnitsSerieIndexes.js +0 -23
  101. package/lib/rules/src/table/units/getUnitsSeries.js +0 -49
  102. package/lib/rules/src/table/units/getUnitsinLayout.js +0 -74
  103. package/lib/rules/src/table/units/refineDimSeriesUnits.js +0 -44
  104. package/lib/rules2/src/getAdvancedAttributes.js +0 -124
  105. package/lib/rules2/src/invertTime.js +0 -33
  106. package/src/rules/src/table/factories/getCells.js +0 -102
  107. package/src/rules/src/table/factories/getConfirmedSeriesAttributesIds.js +0 -27
  108. package/src/rules/src/table/factories/getCuratedCells.js +0 -40
  109. package/src/rules/src/table/factories/getLayoutData.js +0 -171
  110. package/src/rules/src/table/factories/getLayoutWithFlags.js +0 -137
  111. package/src/rules/src/table/factories/getSortedLayoutIndexes.js +0 -108
  112. package/src/rules/src/table/factories/getTableCells.js +0 -16
  113. package/src/rules/src/table/factories/getTableData.js +0 -86
  114. package/src/rules/src/table/preparators/getAttributeValue.js +0 -17
  115. package/src/rules/src/table/preparators/getDimensionsAttributesRegisters.js +0 -51
  116. package/src/rules/src/table/preparators/getManyValuesDimensions.js +0 -19
  117. package/src/rules/src/table/preparators/getOneValueDimensions.js +0 -17
  118. package/src/rules/src/table/preparators/getUniqValuesAttributes.js +0 -24
  119. package/src/rules/src/table/preparators/parseAttributes.js +0 -113
  120. package/src/rules/src/table/preparators/parseAttributesValuesFromObservations.js +0 -16
  121. package/src/rules/src/table/preparators/parseDimensionsIds.js +0 -17
  122. package/src/rules/src/table/preparators/prepareData.js +0 -197
  123. package/src/rules/src/table/preparators/refineObservationsAttributesValues.js +0 -22
  124. package/src/rules/src/table/preparators/refineSeriesAttributesValues.js +0 -11
  125. package/src/rules/src/table/units/appendUnitsInLayoutData.js +0 -56
  126. package/src/rules/src/table/units/appendUnitsInLayoutDataEntry.js +0 -38
  127. package/src/rules/src/table/units/cleanUnitsInLayoutData.js +0 -65
  128. package/src/rules/src/table/units/getAttachmentSeriesIndexes.js +0 -27
  129. package/src/rules/src/table/units/getHeaderUnits.js +0 -32
  130. package/src/rules/src/table/units/getUnitsArtefacts.js +0 -90
  131. package/src/rules/src/table/units/getUnitsCodes.js +0 -22
  132. package/src/rules/src/table/units/getUnitsDefinition.js +0 -34
  133. package/src/rules/src/table/units/getUnitsDisplay.js +0 -19
  134. package/src/rules/src/table/units/getUnitsSerieIndexes.js +0 -12
  135. package/src/rules/src/table/units/getUnitsSeries.js +0 -41
  136. package/src/rules/src/table/units/getUnitsinLayout.js +0 -71
  137. package/src/rules/src/table/units/refineDimSeriesUnits.js +0 -26
  138. package/src/rules2/src/getAdvancedAttributes.js +0 -111
  139. package/src/rules2/src/hasLayoutEntryMetadata.js +0 -9
  140. package/src/rules2/src/invertTime.js +0 -22
  141. package/test/advanced-attributes-parsing-perf.test.js +0 -16
  142. package/test/appendUnitsInLayoutDataEntry.test.js +0 -65
  143. package/test/cleanUnitsInLayoutData.test.js +0 -85
  144. package/test/enhanceObservations.test.js +0 -340
  145. package/test/getAttachmentSeriesIndexes.test.js +0 -35
  146. package/test/getConfirmedSeriesAttributesIds.test.js +0 -27
  147. package/test/getDataflowAdvancedAttributes.test.js +0 -32
  148. package/test/getHeaderUnits.test.js +0 -51
  149. package/test/getLayoutData.test.js +0 -206
  150. package/test/getLayoutDataWithFlags.test.js +0 -142
  151. package/test/getOneValueDimensions.test.js +0 -26
  152. package/test/getSeriesAdvancedAttributes.test.js +0 -32
  153. package/test/getSubtitleFlags.test.js +0 -42
  154. package/test/getTableData.test.js +0 -1317
  155. package/test/getUnitsArtefacts.test.js +0 -117
  156. package/test/getUnitsDefinition.test.js +0 -37
  157. package/test/getUnitsInLayout.test.js +0 -77
  158. package/test/getUnitsSeries.test.js +0 -154
  159. package/test/invertTime.test.js +0 -77
  160. package/test/parseAttributesValuesFromObservations.test.js +0 -45
  161. package/test/parseDimensionsIds.test.js +0 -20
  162. package/test/prepareData.test.js +0 -29
  163. package/test/refineObservationsAttributesValues.test.js +0 -33
  164. package/test/table-invert-time-perf.test.js +0 -11
  165. package/test/table-layout-perf.test.js +0 -74
  166. package/test/table-prep-duplicate-perf.test.js +0 -15
  167. package/test/table-prep-perf.test.js +0 -61
@@ -1,90 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getRelevantLength = (attr) => R.pipe(
4
- R.propOr([], 'values'),
5
- R.filter(R.propOr(true, 'display')),
6
- R.length
7
- )(attr);
8
-
9
- export const getUnitsArtefacts = ({ unitsDefinitionCodes=[], data }) => {
10
- const dimensions = R.pathOr([], ['data', 'structure', 'dimensions', 'observation'], data);
11
- const parsedUnitsDimensions = R.addIndex(R.reduce)(
12
- (acc, dimension, index) => {
13
- if (!R.includes(dimension.id, unitsDefinitionCodes)) {
14
- return acc;
15
- }
16
- const length = R.pipe(R.propOr([], 'values'), R.length)(dimension);
17
- if (length === 1) {
18
- return R.evolve({ header: R.assoc(dimension.id, { ...dimension, index, header: true }) }, acc);
19
- }
20
- if (length > 1) {
21
- return R.evolve({ series: R.assoc(dimension.id, { ...dimension, index }) }, acc);
22
- }
23
- return acc;
24
- },
25
- { header: {}, series: {} },
26
- dimensions
27
- );
28
-
29
- const keyedDimensions = R.indexBy(R.prop('id'), dimensions);
30
-
31
- const parsedUnitsAttributes = R.pipe(
32
- R.pathOr([], ['data', 'structure', 'attributes', 'observation']),
33
- R.addIndex(R.reduce)(
34
- (acc, attr, index) => {
35
- if(!R.includes(attr.id, unitsDefinitionCodes) || R.length(R.propOr([], 'values', attr)) === 0
36
- || !R.propOr(true, 'display', attr)) {
37
- return acc;
38
- }
39
- const length = getRelevantLength(attr);
40
- if (length === 0) {
41
- return acc;
42
- }
43
- if (R.hasPath(['relationship', 'none'], attr) || R.hasPath(['relationship', 'dataflow'], attr)) {
44
- return R.assocPath(['header', attr.id], { ...attr, index, datasetLevel: true }, acc);
45
- }
46
- if ((R.path(['relationship', 'primaryMeasure'], attr) === 'OBS_VALUE')
47
- || (R.hasPath(['relationship', 'observation'], attr))) {
48
- return R.assocPath(['series', attr.id], { ...attr, index, observations: true }, acc);
49
- }
50
- const attachedDimensions = R.path(['relationship', 'dimensions'], attr);
51
- if (R.isNil(attachedDimensions)) {
52
- return acc;
53
- }
54
- const filteredAttachedDimensions = R.filter(
55
- (id) => {
56
- const dimension = R.propOr({}, id, keyedDimensions);
57
- const nValues = R.pipe(R.propOr([], 'values'), R.length)(dimension);
58
- return nValues > 1;
59
- },
60
- attachedDimensions
61
- );
62
- const level = R.isEmpty(filteredAttachedDimensions)
63
- ? 'header'
64
- : 'series';
65
- return R.assocPath(
66
- [level, attr.id],
67
- { ...attr, index, relationship: { dimensions: filteredAttachedDimensions } },
68
- acc
69
- );
70
- },
71
- { header: {}, series: {} }
72
- )
73
- )(data);
74
-
75
- const hasSeries = R.pipe(
76
- R.all(R.isEmpty),
77
- R.not
78
- )([parsedUnitsDimensions.series, parsedUnitsAttributes.series]);
79
-
80
- return ({
81
- dimensions: R.evolve({
82
- header: R.when(R.always(hasSeries), R.always({})),
83
- series: R.when(R.always(hasSeries), R.merge(parsedUnitsDimensions.header))
84
- })(parsedUnitsDimensions),
85
- attributes: R.evolve({
86
- header: R.when(R.always(hasSeries), R.always({})),
87
- series: R.when(R.always(hasSeries), R.merge(parsedUnitsAttributes.header))
88
- })(parsedUnitsAttributes)
89
- });
90
- };
@@ -1,22 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getUnitsCodes = ({ data, unitsDefinition }) => {
4
- const dimensionsCodes = R.pipe(
5
- R.pathOr([], ['data', 'structure', 'dimensions', 'observation']),
6
- R.indexBy(R.prop('id')),
7
- R.props(unitsDefinition),
8
- R.pluck('id')
9
- )(data);
10
-
11
- const attributesCodes = R.pipe(
12
- R.pathOr({}, ['data', 'structure', 'attributes']),
13
- R.mapObjIndexed(
14
- R.pipe(
15
- R.filter(R.pipe(R.prop('id'), R.flip(R.includes)(unitsDefinition))),
16
- R.pluck('id')
17
- )
18
- )
19
- )(data);
20
-
21
- return ({ dimensions: dimensionsCodes, attributes: attributesCodes });
22
- };
@@ -1,34 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getUnitsDefinition = ({
4
- data, // sdmxJson
5
- defaultCodes, // [...codelistIds]
6
- annotationsDefinitionCodes // { concepts: [] }
7
- }) => {
8
- const conceptsCodes = R.propOr([], 'concepts', annotationsDefinitionCodes);
9
- if (R.anyPass([R.isNil, R.isEmpty])(conceptsCodes)) {
10
- return defaultCodes;
11
- }
12
-
13
- const datasetAnnotations = R.converge(
14
- R.props,
15
- [
16
- R.pathOr([], ['data', 'dataSets', 0, 'annotations']),
17
- R.pathOr([], ['data', 'structure', 'annotations'])
18
- ]
19
- )(data);
20
-
21
- const keyedDatasetAnnotations = R.indexBy(R.prop('type'), datasetAnnotations);
22
-
23
- const conceptsAnnotation = R.pipe(
24
- R.props(conceptsCodes),
25
- R.find(ann => !R.isNil(ann)),
26
- R.when(R.isNil, R.always({}))
27
- )(keyedDatasetAnnotations);
28
-
29
- return R.pipe(
30
- R.propOr('', 'title'),
31
- R.split(','),
32
- R.when(R.equals(['']), R.always(defaultCodes))
33
- )(conceptsAnnotation);
34
- };
@@ -1,19 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getUnitsDisplay = ({ unitsAttachmentSeriesIds, layoutIds }) => {
4
- if (R.isEmpty(unitsAttachmentSeriesIds)) {
5
- return 'cells';
6
- }
7
- const headerIntersections = R.intersection(layoutIds.header, unitsAttachmentSeriesIds);
8
- if (R.length(headerIntersections) === R.length(unitsAttachmentSeriesIds)) {
9
- return 'header';
10
- }
11
- if (!R.isEmpty(headerIntersections)) {
12
- return 'cells';
13
- }
14
- const sectionsIntersections = R.intersection(layoutIds.sections, unitsAttachmentSeriesIds);
15
- if (R.length(sectionsIntersections) === R.length(unitsAttachmentSeriesIds)) {
16
- return 'sections';
17
- }
18
- return 'rows';
19
- };
@@ -1,12 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- //=> [{ dimension: { __index: 0 }, value: { __index: 0 } }] x { '0:x:x:x': {} }
4
- export const getUnitsSerieIndexes = ({ unitsIndexes, partialUnitSerieIndexes }) => (layoutDataEntry) => R.reduce(
5
- (pUSI, unitIndex) => R.update(
6
- R.path([unitIndex, 'dimension', '__index'], layoutDataEntry),
7
- R.path([unitIndex, 'value', '__index'], layoutDataEntry),
8
- pUSI
9
- ),
10
- partialUnitSerieIndexes,
11
- unitsIndexes
12
- );
@@ -1,41 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- /*
4
- observations = { [obsKey]: { units: { serieKey: '', [id]: { id, name, value } } } };
5
- */
6
-
7
- const getIndex = R.path(['value', 'index']);
8
- const getUnits = (acc, units) => R.mergeWith((a, b) => getIndex(a) === getIndex(b) ? a : null, acc, units)
9
-
10
- export const getUnitsSeries = (observations) => {
11
- let series = {};
12
- R.map(obs => {
13
- series = R.over(
14
- R.lensProp(obs.units.serieKey),
15
- R.ifElse(R.isNil, R.always([obs.units]), R.append(obs.units))
16
- )(series);
17
- }, observations);
18
- return R.reduce(
19
- (_acc, key) => {
20
- const serie = series[key];
21
- const { units } = R.reduce(
22
- (acc, units) => {
23
- const unitsKeys = R.keys(units);
24
- if (R.isEmpty(acc.unitsKeys)) return { units, unitsKeys }
25
- const communKeys = R.intersection(acc.unitsKeys, unitsKeys);
26
- return {
27
- units: getUnits(R.pick(communKeys, acc.units), R.pick(communKeys, units)),
28
- unitsKeys: communKeys,
29
- };
30
- },
31
- { unitsKeys: [], units: {} },
32
- serie
33
- );
34
- if (R.isEmpty(R.dissoc('serieKey', units))) {
35
- return _acc;
36
- }
37
- return R.assoc(key, units, _acc);
38
- },
39
- {}
40
- )(R.keys(series));
41
- };
@@ -1,71 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- const getUnitsIndexesInLayoutEntry = (unitsIds) => R.addIndex(R.reduce)(
4
- (indexes, id, index) => {
5
- if (R.has(id, unitsIds)) {
6
- return R.append(index, indexes);
7
- }
8
- return indexes;
9
- },
10
- [],
11
- );
12
-
13
- export const getUnitsInLayout = ({
14
- layoutIds, // { header: [], sections: [], rows: [] }
15
- unitsAttachmentSeriesIds=[], // [ ...DIM_IDS ]
16
- unitsDefinitionCodes=[],
17
- unitsSeries={}
18
- }) => {
19
- const defaultIndexes = { header: [], sections: [], rows: [] };
20
- if (R.isEmpty(unitsAttachmentSeriesIds) || R.isEmpty(unitsSeries)) {
21
- return {
22
- unitsLevelDisplay: 'cells',
23
- unitsAttachmentIndexesInLayout: defaultIndexes,
24
- unitsIndexesInLayout: defaultIndexes
25
- };
26
- }
27
- const unitsLength = R.length(unitsAttachmentSeriesIds);
28
- const keyedAttUnitsIds = R.indexBy(R.identity, unitsAttachmentSeriesIds);
29
- const keyedUnitsIds = R.indexBy(R.identity, unitsDefinitionCodes);
30
- const headerUnitsIndexes = getUnitsIndexesInLayoutEntry(keyedAttUnitsIds)(R.propOr([], 'header', layoutIds));
31
- if (R.length(headerUnitsIndexes) === unitsLength) {
32
- return {
33
- unitsLevelDisplay: 'header',
34
- unitsAttachmentIndexesInLayout: R.assoc('header', headerUnitsIndexes, defaultIndexes),
35
- unitsIndexesInLayout: R.assoc(
36
- 'header',
37
- getUnitsIndexesInLayoutEntry(keyedUnitsIds)(R.propOr([], 'header', layoutIds)),
38
- defaultIndexes
39
- )
40
- };
41
- }
42
- if (!R.isEmpty(headerUnitsIndexes)) {
43
- return {
44
- unitsLevelDisplay: 'cells',
45
- unitsAttachmentIndexesInLayout: defaultIndexes,
46
- unitsIndexesInLayout: defaultIndexes
47
- };
48
- }
49
- const sectionsAttUnitsIndexes = getUnitsIndexesInLayoutEntry(keyedAttUnitsIds)(R.propOr([], 'sections', layoutIds));
50
- const sectionsUnitsIndexes = getUnitsIndexesInLayoutEntry(keyedUnitsIds)(R.propOr([], 'sections', layoutIds));
51
- if (R.length(sectionsAttUnitsIndexes) === unitsLength) {
52
- return {
53
- unitsLevelDisplay: 'sections',
54
- unitsAttachmentIndexesInLayout: R.assoc('sections', sectionsAttUnitsIndexes, defaultIndexes),
55
- unitsIndexesInLayout: R.assoc('sections', sectionsUnitsIndexes, defaultIndexes)
56
- }
57
- }
58
- const rowsAttUnitsIndexes = getUnitsIndexesInLayoutEntry(keyedAttUnitsIds)(R.propOr([], 'rows', layoutIds));
59
- const rowsUnitsIndexes = getUnitsIndexesInLayoutEntry(keyedUnitsIds)(R.propOr([], 'rows', layoutIds));
60
- return ({
61
- unitsLevelDisplay: 'rows',
62
- unitsAttachmentIndexesInLayout: R.pipe(
63
- R.assoc('sections', sectionsAttUnitsIndexes),
64
- R.assoc('rows', rowsAttUnitsIndexes)
65
- )(defaultIndexes),
66
- unitsIndexesInLayout: R.pipe(
67
- R.assoc('sections', sectionsUnitsIndexes),
68
- R.assoc('rows', rowsUnitsIndexes)
69
- )(defaultIndexes)
70
- });
71
- };
@@ -1,26 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const refineDimSeriesUnits = ({
4
- unitsArtefacts, // careful, here dimensions and attributes are merged,
5
- rejectedValueIds=[]
6
- }) => R.pipe(
7
- R.mapObjIndexed(
8
- ({ observations, ...unitsIndexes }) => R.pipe(
9
- R.filter(R.allPass([
10
- occurences => R.length(occurences) === observations,
11
- occurences => R.pipe(R.uniq, R.length, R.equals(1))(occurences)
12
- ])),
13
- R.mapObjIndexed(
14
- (indexes, artefactId) => {
15
- const artefact = R.propOr({}, artefactId, unitsArtefacts);
16
- const value = R.pathOr({}, ['values', R.head(indexes)], artefact);
17
- return ({ ...R.pick(['id', 'name'], artefact), value });
18
- }
19
- ),
20
- R.reject(
21
- R.pipe(R.prop('value'), R.anyPass([R.isEmpty, val => R.includes(val.id, rejectedValueIds)]))
22
- )
23
- )(unitsIndexes)
24
- ),
25
- R.reject(R.isEmpty)
26
- );
@@ -1,111 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getObservationsAdvancedAttributes = (observations, advancedAttributesIds) => R.pipe(
4
- R.map(obs => ({ attributes: R.pick(advancedAttributesIds, obs.attributes || {}), coordinates: obs.indexedDimValIds || {} })),
5
- R.filter(entry => !R.isEmpty(entry.attributes))
6
- )(observations);
7
-
8
- export const getDataflowAdvancedAttributes = (attributes, dimensions, advancedAttributesIds, dimLength) => {
9
- const advancedAttributes = R.pick(advancedAttributesIds, attributes);
10
- const keyTemplate = R.times(R.always(''), dimLength);
11
- return R.reduce(
12
- (acc, attribute) => {
13
- const value = R.head(attribute.values || []);
14
- const attr = { ...R.pick(['id', 'name'], attribute), value };
15
- let coordinates = {};
16
- let key = keyTemplate;
17
-
18
- if (!R.isEmpty(R.pathOr([], ['relationship', 'dimensions'], attribute))) {
19
- const attrDimensionsIds = R.pathOr([], ['relationship', 'dimensions'], attribute);
20
- const attrDimensions = R.props(attrDimensionsIds, dimensions);
21
- R.forEach(
22
- dim => {
23
- const dId = dim.id;
24
- const dIndex = dim.__index;
25
- const vId = R.path(['values', 0, 'id'], dim);
26
- coordinates = { ...coordinates, [dId]: vId };
27
- key = R.set(R.lensIndex(dIndex), 0)(key);
28
- },
29
- R.reject(R.isNil, attrDimensions)
30
- );
31
- }
32
-
33
- key = R.join(':', key);
34
- return R.over(
35
- R.lensProp(key),
36
- entry => R.isNil(entry)
37
- ? ({ attributes: { [attribute.id]: attr }, coordinates })
38
- : R.over(R.lensProp('attributes'), R.assoc(attribute.id, attr))(entry)
39
- )(acc);
40
- },
41
- {},
42
- R.values(advancedAttributes)
43
- )
44
- };
45
-
46
- /*
47
- {
48
- series: {
49
- '0:0:x:x:x': { attributes: { a2: { id, value } } }
50
- },
51
- dimensions: {
52
- '3:0': { attributes: { a1: { id, value } } },
53
- }
54
- }
55
-
56
- */
57
-
58
- export const getSeriesAdvancedAttributes = (seriesAttributes, dimensions, advancedAttributesIds) => {
59
- const seriesAdvancedAttributes = R.pipe(
60
- R.propOr({}, 'series'),
61
- series => R.reduce(
62
- (acc, key) => {
63
- const serie = series[key];
64
- const advancedAttributes = R.pick(advancedAttributesIds, serie.attributes);
65
- if (R.isEmpty(advancedAttributes)) {
66
- return acc;
67
- }
68
- const splitKey = R.split(':', key);
69
- const { coordinates, refinedKey } = R.addIndex(R.reduce)(
70
- (acc, vInd, dInd) => {
71
- if (vInd === 'x') {
72
- return ({ ...acc, refinedKey: R.append('', acc.refinedKey) });
73
- }
74
- const _refined = R.append(vInd, acc.refinedKey);
75
- const dim = R.nth(dInd, dimensions);
76
- const valId = R.path(['values', Number(vInd), 'id'], dim);
77
- const _coordinates = R.assoc(dim.id, valId, acc.coordinates);
78
- return ({ coordinates: _coordinates, refinedKey: _refined });
79
- },
80
- { coordinates: {}, refinedKey: [] },
81
- splitKey
82
- );
83
- return R.assoc(R.join(':', refinedKey), { attributes: advancedAttributes, coordinates }, acc);
84
- },
85
- {},
86
- R.keys(series)
87
- )
88
- )(seriesAttributes);
89
- const keyTemplate = R.map(R.always(''), dimensions);
90
- const dimensionsAdvancedAttributes = R.pipe(
91
- R.propOr({}, 'dimensions'),
92
- series => R.reduce(
93
- (acc, key) => {
94
- const serie = series[key];
95
- const advancedAttributes = R.pick(advancedAttributesIds, serie.attributes);
96
- if (R.isEmpty(advancedAttributes)) {
97
- return acc;
98
- }
99
- const [dInd, vInd] = R.split(':', key);
100
- const dim = R.nth(Number(dInd), dimensions);
101
- const valId = R.path(['values', Number(vInd), 'id'], dim);
102
- const coordinates = { [dim.id]: valId };
103
- const refinedKey = R.set(R.lensIndex(Number(dInd)), vInd)(keyTemplate);
104
- return R.assoc(R.join(':', refinedKey), { attributes: advancedAttributes, coordinates }, acc);
105
- },
106
- {},
107
- R.keys(series)
108
- )
109
- )(seriesAttributes);
110
- return R.merge(seriesAdvancedAttributes, dimensionsAdvancedAttributes);
111
- };
@@ -1,9 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- /*
4
- const layoutData = [{ dimension: { id: 'D1', __index: 2 }, value: { id: 'V', __index: 0 } }];
5
- */
6
-
7
- export const getLayoutEntryMetadataCoordinates = (layoutData, metadataSeries) => {
8
-
9
- };
@@ -1,22 +0,0 @@
1
- import * as R from 'ramda';
2
- import { isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
3
-
4
- export const invertTime = (data, isTimeInverted) => {
5
- const dimensions = R.pathOr([], ['dimensions', 'many'], data);
6
- const observations = R.propOr({}, 'observations', data);
7
- if (!isTimeInverted) {
8
- return ({ dimensions, observations });
9
- }
10
- const timeD = R.find(isTimePeriodDimension, R.values(dimensions));
11
- if (!timeD) {
12
- return ({ dimensions, observations });
13
- }
14
- const timeLength = R.length(timeD.values);
15
- const timeIndex = timeD.__index;
16
- const invertTimeInObs = R.map(
17
- R.over(R.lensProp('orderedDimIndexes'), R.over(R.lensIndex(timeIndex), i => timeLength - i - 1)),
18
- observations
19
- );
20
- const invertedTimeInDims = R.over(R.lensProp(timeD.id), R.over(R.lensProp('values'), R.reverse))(dimensions);
21
- return ({ dimensions: invertedTimeInDims, observations: invertTimeInObs });
22
- };
@@ -1,16 +0,0 @@
1
- import { expect } from 'chai';
2
- import {
3
- getDataflowAdvancedAttributes,
4
- getObservationsAdvancedAttributes,
5
- getSeriesAdvancedAttributes
6
- } from '../src/rules2/src/getAdvancedAttributes';
7
-
8
- import obsMock from './mocks/table-prep-units--observations.json';
9
- import obsAdvancedAttributes from './mocks/observations-advanced-attributes.json';
10
-
11
- describe('advanced attributes parsing performance tests', () => {
12
- it('1800 observations test', function() {
13
- this.timeout(1500);
14
- expect(getObservationsAdvancedAttributes(obsMock, ['CURRENCY', 'OBS_STATUS'])).to.deep.equal(obsAdvancedAttributes);
15
- });
16
- });
@@ -1,65 +0,0 @@
1
- import { expect } from 'chai';
2
- import { appendUnitsInLayoutDataEntry } from '../src/rules/src/table/units/appendUnitsInLayoutDataEntry';
3
-
4
- const layoutData = [
5
- { dimension: { id: 'D1', __index: 2 }, value: { id: 'V', __index: 0 } },
6
- { dimension: { id: 'D2', __index: 0 }, value: { id: 'V', __index: 0 } },
7
- { dimension: { id: 'D3', __index: 4 }, value: { id: 'V', __index: 0 } }
8
- ];
9
-
10
- const unitsSeries = {
11
- '0:x:0:x:x': {
12
- U1: { id: 'U1', value: { id: 'U1V' } },
13
- U2: { id: 'U2', value: { id: 'U2V' } },
14
- U3: { id: 'U3', value: { id: 'U3V' } }
15
- },
16
- '1:x:1:x:x': {
17
- U1: { id: 'U1', value: { id: 'U1V' } },
18
- U3: { id: 'U3', value: { id: 'U3V' } },
19
- U4: { id: 'U4', value: { id: 'U4V' } },
20
- },
21
- };
22
-
23
- describe('appendUnitsInLayoutDataEntry tests', () => {
24
- it('blank test', () => {
25
- expect(appendUnitsInLayoutDataEntry({
26
- display: 'label',
27
- unitDimension: {},
28
- unitsSeries: {},
29
- unitsDefinitionCodes: [],
30
- unitsIndexes: [],
31
- partialUnitSerieIndexes: []
32
- })([])).to.deep.equal([{ dimension: {}, value: { id: '', unitsLabel: '' } }]);
33
- });
34
- it('complete test', () => {
35
- expect(appendUnitsInLayoutDataEntry({
36
- display: 'code',
37
- unitDimension: { id: 'U' },
38
- unitsSeries,
39
- unitsDefinitionCodes: ['U3', 'U1', 'U4'],
40
- unitsIndexes: [1, 0],
41
- partialUnitSerieIndexes: ['x', 'x', 'x', 'x', 'x']
42
- })(layoutData)).to.deep.equal([
43
- { dimension: { id: 'D1', __index: 2 }, value: { id: 'V', __index: 0 } },
44
- { dimension: { id: 'D2', __index: 0 }, value: { id: 'V', __index: 0 } },
45
- { dimension: { id: 'D3', __index: 4 }, value: { id: 'V', __index: 0 } },
46
- { dimension: { id: 'U' }, value: { id: 'U3V - U1V', unitsLabel: 'U3V, U1V' } }
47
- ]);
48
- });
49
- it('rejectedValues test', () => {
50
- expect(appendUnitsInLayoutDataEntry({
51
- display: 'code',
52
- rejectedValueIds: ['U3V'],
53
- unitDimension: { id: 'U' },
54
- unitsSeries,
55
- unitsDefinitionCodes: ['U3', 'U1', 'U4'],
56
- unitsIndexes: [1, 0],
57
- partialUnitSerieIndexes: ['x', 'x', 'x', 'x', 'x']
58
- })(layoutData)).to.deep.equal([
59
- { dimension: { id: 'D1', __index: 2 }, value: { id: 'V', __index: 0 } },
60
- { dimension: { id: 'D2', __index: 0 }, value: { id: 'V', __index: 0 } },
61
- { dimension: { id: 'D3', __index: 4 }, value: { id: 'V', __index: 0 } },
62
- { dimension: { id: 'U' }, value: { id: 'U1V', unitsLabel: 'U1V' } }
63
- ]);
64
- })
65
- });
@@ -1,85 +0,0 @@
1
- import { expect } from 'chai';
2
- import { cleanUnitsInLayoutData } from '../src/rules/src/table/units/cleanUnitsInLayoutData';
3
-
4
- const headerData = [
5
- { data: [{ id: 0 }, { id: 1 }, { dimension: { label: 'U' }, value: { label: null, unitsLabel: 'U1' } }] },
6
- { data: [{ id: 0 }, { id: 1 }, { dimension: { label: 'U' }, value: { label: 'toto', unitsLabel: 'U2' } }] },
7
- { data: [{ id: 0 }, { id: 1 }, { dimension: { label: 'U' }, value: { unitsLabel: 'U3' } }] },
8
- ];
9
-
10
- const sectionsData1 = [
11
- [
12
- { data: [{ id: 0 }, { id: 1 }, { value: { unitsLabel: 'Units S1' } }] },
13
- [{ data: [{ id: 'r1' }, { id: 'r2' }] }]
14
- ],
15
- [
16
- { data: [{ id: 2 }, { id: 3 }, { value: { unitsLabel: 'Units S2' } }] },
17
- [{ data: [{ id: 'r1' }, { id: 'r2' }] }]
18
- ]
19
- ];
20
-
21
- const sectionsData2 = [
22
- [
23
- { data: [{ id: 0 }, { id: 1 }] },
24
- [
25
- { data: [{ id: 'r1' }, { id: 'r2' }, { value: { unitsLabel: 'Units R1' } }] },
26
- { data: [{ id: 'r1' }, { id: 'r2' }, { value: { unitsLabel: 'Units R2' } }] },
27
- ]
28
- ],
29
- [
30
- { data: [{ id: 2 }, { id: 3 }] },
31
- [
32
- { data: [{ id: 'r1' }, { id: 'r2' }, { value: { unitsLabel: 'Units R3' } }] },
33
- { data: [{ id: 'r1' }, { id: 'r2' }, { value: { unitsLabel: 'Units R4' } }] },
34
- ]
35
- ]
36
- ];
37
-
38
- describe('cleanUnitsInLayoutData tests', () => {
39
- it('header test', () => {
40
- expect(cleanUnitsInLayoutData({ unitsDisplay: 'header', unitsLayoutIndexes: { header: [1] } })({ headerData }))
41
- .to.deep.equal({
42
- headerData: [
43
- { data: [{ id: 0 }, { dimension: { label: 'U' }, value: { label: 'U1', unitsLabel: 'U1' } }] },
44
- { data: [{ id: 0 }, { dimension: { label: 'U' }, value: { label: 'U2', unitsLabel: 'U2' } }] },
45
- { data: [{ id: 0 }, { dimension: { label: 'U' }, value: { label: 'U3', unitsLabel: 'U3' } }] },
46
- ]
47
- })
48
- });
49
- it('sections test', () => {
50
- expect(cleanUnitsInLayoutData({ unitsDisplay: 'sections', unitsLayoutIndexes: { sections: [0] } })({ sectionsData: sectionsData1 }))
51
- .to.deep.equal({
52
- sectionsData: [
53
- [
54
- { data: [{ id: 1 }, { value: { label: 'Units S1', unitsLabel: 'Units S1' } }] },
55
- [{ data: [{ id: 'r1' }, { id: 'r2' }] }]
56
- ],
57
- [
58
- { data: [{ id: 3 }, { value: { label: 'Units S2', unitsLabel: 'Units S2' } }] },
59
- [{ data: [{ id: 'r1' }, { id: 'r2' }] }]
60
- ]
61
- ]
62
- })
63
- });
64
- it('rows test', () => {
65
- expect(cleanUnitsInLayoutData({ unitsDisplay: 'rows', unitsLayoutIndexes: { rows: [0] } })({ sectionsData: sectionsData2 }))
66
- .to.deep.equal({
67
- sectionsData: [
68
- [
69
- { data: [{ id: 0 }, { id: 1 }] },
70
- [
71
- { data: [{ id: 'r2' }, { value: { label: 'Units R1', unitsLabel: 'Units R1' } }] },
72
- { data: [{ id: 'r2' }, { value: { label: 'Units R2', unitsLabel: 'Units R2' } }] },
73
- ]
74
- ],
75
- [
76
- { data: [{ id: 2 }, { id: 3 }] },
77
- [
78
- { data: [{ id: 'r2' }, { value: { label: 'Units R3', unitsLabel: 'Units R3' } }] },
79
- { data: [{ id: 'r2' }, { value: { label: 'Units R4', unitsLabel: 'Units R4' } }] },
80
- ]
81
- ]
82
- ]
83
- })
84
- });
85
- });