@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
@@ -0,0 +1,33 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const getOneValueDimensions = (dimensions, attributes) => {
4
+ const indexedRelevantAttributes = R.reduce(
5
+ (acc, attr) => {
6
+ if (!attr.header || !attr.display || R.length(attr.relationship || []) !== 1) {
7
+ return acc;
8
+ }
9
+ const value = R.path(['values', 0], attr);
10
+ if (R.isNil(value) || !R.prop('display', value)) {
11
+ return acc;
12
+ }
13
+ const dim = R.head(attr.relationship);
14
+ return R.over(R.lensProp(dim), (values = {}) => ({
15
+ ...values,
16
+ [attr.id]: { ...attr, value },
17
+ }))(acc);
18
+ },
19
+ {},
20
+ attributes,
21
+ );
22
+ return R.reduce(
23
+ (acc, dim) => {
24
+ if (R.length(dim.values || []) !== 1) {
25
+ return acc;
26
+ }
27
+ const attrValues = R.propOr({}, dim.id, indexedRelevantAttributes);
28
+ return R.append({ ...dim, attrValues }, acc);
29
+ },
30
+ [],
31
+ dimensions,
32
+ );
33
+ };
@@ -4,7 +4,7 @@ export const hasCellMetadata = (metadataCoordinates, cellCoordinates) => {
4
4
  return R.pipe(
5
5
  R.find(coordinates => {
6
6
  const mergedCoord = R.mergeLeft(coordinates, cellCoordinates);
7
- return R.equals(mergedCoord, cellCoordinates);
7
+ return !R.isEmpty(coordinates) && R.equals(mergedCoord, cellCoordinates);
8
8
  }),
9
9
  R.complement(R.isNil)
10
10
  )(metadataCoordinates);
@@ -13,13 +13,28 @@ export { getHCodelistsRefs, getHCodelistsRefsInData } from './getHCodelistsRefsI
13
13
  export { parseHierarchicalCodelist } from './parseHierarchicalCodelist';
14
14
  export { refinePartialHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy';
15
15
  export { getMetadataCoordinates } from './getMetadataCoordinates';
16
- export {
17
- getDataflowAdvancedAttributes,
18
- getObservationsAdvancedAttributes,
19
- getSeriesAdvancedAttributes
20
- } from './getAdvancedAttributes';
21
16
  export { duplicateObs } from './duplicateObservations';
22
17
  export { hierarchiseDimensionWithAdvancedHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy';
23
18
  export { hierarchiseDimensionWithNativeHierarchy } from './hierarchiseDimensionWithNativeHierarchy';
24
19
  export { getDimensionValuesIndexes } from './getDimensionValuesIndexes';
25
-
20
+ export { getCombinationDefinitions } from './getCombinationDefinitions';
21
+ export { parseAttributes } from './parseAttributes';
22
+ export { parseCombinations } from './parseCombinations';
23
+ export { refineAttributes } from './refineAttributes';
24
+ export { enhanceObservations } from './enhanceObservations';
25
+ export { getAttributesSeries } from './getAttributesSeries';
26
+ export { getManyValuesDimensions } from './getManyValuesDimensions';
27
+ export { getOneValueDimensions } from './getOneValueDimensions';
28
+ export { getHeaderSubtitle } from './getHeaderSubtitle';
29
+ export { getHeaderCombinations } from './getHeaderCombinations';
30
+ export { getLayout } from './table/getLayout';
31
+ export { getSortedLayoutIndexes } from './table/getSortedLayoutIndexes';
32
+ export { refineLayoutSize } from './table/refineLayoutSize';
33
+ export { getFlagsAndNotes } from './table/getFlagsAndNotes';
34
+ export { getLayoutData } from './table/getLayoutData';
35
+ export { getCellsAttributesIds } from './table/getCellsAttributesIds';
36
+ export { getIndexedCombinationsByDisplay } from './table/getIndexedCombinationsByDisplay';
37
+ export { getCells } from './table/getCells';
38
+ export { getCuratedCells } from './table/getCuratedCells';
39
+ export { prepareData } from './prepareData';
40
+ export { getTableProps } from './table/getTableProps';
@@ -0,0 +1,36 @@
1
+ import * as R from 'ramda';
2
+ import { REPORTING_YEAR_START_DAY, REPYEARSTART } from './constants';
3
+
4
+ export const parseAttributes = (attributes, dimensions, customAttributes) => {
5
+ const indexedDimensions = R.indexBy(R.prop('id'), dimensions);
6
+ return R.addIndex(R.map)((attr, index) => {
7
+ let res = R.assoc('index', index, attr);
8
+ if (R.isEmpty(attr.values || []) || !R.propOr(true, 'display', attr)
9
+ || attr.id === REPORTING_YEAR_START_DAY || attr.id === REPYEARSTART) {
10
+ return R.assoc('display', false, res);
11
+ }
12
+ if (R.propEq('id', customAttributes.prefscale, attr)) {
13
+ return R.assoc('prefscale', true, res);
14
+ }
15
+ if (R.propEq('id', customAttributes.decimals, attr)) {
16
+ return R.assoc('decimals', true, res);
17
+ }
18
+ if (R.hasPath(['relationship', 'none'], attr) || R.hasPath(['relationship', 'dataflow'], attr)) {
19
+ return { ...res, header: true, relationship: [] };
20
+ }
21
+ if (R.hasPath(['relationship', 'primaryMeasure'], attr) || R.hasPath(['relationship', 'observation'], attr)) {
22
+ return { ...res, series: true, relationship: [] };
23
+ }
24
+ const seriesDimensions = R.pipe(
25
+ R.pathOr([], ['relationship', 'dimensions']),
26
+ R.filter(id => {
27
+ const values = R.path([id, 'values'], indexedDimensions);
28
+ return R.length(values) > 1;
29
+ }),
30
+ )(attr);
31
+ if (R.length(seriesDimensions) > 0) {
32
+ return { ...res, series: true, relationship: seriesDimensions };
33
+ }
34
+ return { ...res, header: true, relationship: R.prop('dimensions', attr.relationship || []) };
35
+ }, attributes);
36
+ };
@@ -0,0 +1,36 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const parseCombinations = (combinations, parsedAttributes, dimensions) => {
4
+ const indexedDimensions = R.indexBy(R.prop('id'), dimensions);
5
+ const indexedAttributes = R.indexBy(R.prop('id'), parsedAttributes);
6
+
7
+ return R.map(comb => {
8
+ let relationship = [];
9
+ let ids = {};
10
+ const seriesConcepts = R.filter(concept => {
11
+ if (R.has(concept, ids)) {
12
+ return false;
13
+ }
14
+ if (R.has(concept, indexedDimensions)) {
15
+ const values = R.path([concept, 'values'], indexedDimensions);
16
+ relationship = R.length(values) > 1 ? R.append(concept, relationship) : relationship;
17
+ ids = { ...ids, [concept]: concept };
18
+ return R.length(values) > 1;
19
+ }
20
+ const attribute = R.prop(concept, indexedAttributes);
21
+ relationship = attribute.series
22
+ ? R.pipe(
23
+ R.reject(id => R.has(id, ids)),
24
+ R.concat(relationship),
25
+ )(attribute.relationship)
26
+ : relationship;
27
+ ids = attribute.series ? { ...ids, ...R.indexBy(R.identity, attribute.relationship) } : ids;
28
+ return true;
29
+ }, comb.concepts);
30
+
31
+ if (R.isEmpty(seriesConcepts) || R.isEmpty(relationship)) {
32
+ return { ...comb, header: true };
33
+ }
34
+ return { ...comb, series: true, relationship };
35
+ }, combinations);
36
+ };
@@ -0,0 +1,50 @@
1
+ import * as R from 'ramda';
2
+ import { getObservations } from '../../rules/src';
3
+ import { enhanceObservations } from './enhanceObservations';
4
+ import { parseAttributes } from './parseAttributes';
5
+ import { getCombinationDefinitions } from './getCombinationDefinitions';
6
+ import { parseCombinations } from './parseCombinations';
7
+ import { refineAttributes } from './refineAttributes';
8
+ import { duplicateObs } from './duplicateObservations';
9
+ import { getMetadataCoordinates } from './getMetadataCoordinates';
10
+ import { getAttributesSeries } from './getAttributesSeries';
11
+ import { getManyValuesDimensions } from './getManyValuesDimensions';
12
+ import { getOneValueDimensions } from './getOneValueDimensions';
13
+ import { hierarchiseDimensionWithNativeHierarchy } from './hierarchiseDimensionWithNativeHierarchy';
14
+ import { hierarchiseDimensionWithAdvancedHierarchy } from './hierarchiseDimensionWithAdvancedHierarchy';
15
+
16
+ export const prepareData = (sdmxJson, customAttributes, locale, hierarchies) => {
17
+ const dimensions = R.pathOr([], ['data', 'structure', 'dimensions', 'observation'], sdmxJson);
18
+ const attributes = R.pathOr([], ['data', 'structure', 'attributes', 'observation'], sdmxJson);
19
+ const annotations = R.pathOr([], ['data', 'structure', 'annotations'], sdmxJson);
20
+ const observations = getObservations(sdmxJson);
21
+ const combinations = getCombinationDefinitions(annotations, locale);
22
+ const metadataCoordinates = getMetadataCoordinates(sdmxJson);
23
+
24
+ const parsedAttributes = parseAttributes(attributes, dimensions, customAttributes);
25
+ const parsedCombinations = parseCombinations(combinations, parsedAttributes, dimensions);
26
+ const seriesCombinations = R.filter(R.prop('series'), parsedCombinations);
27
+ const refinedAttributes = refineAttributes(parsedAttributes, seriesCombinations);
28
+
29
+ const enhancedObservations = enhanceObservations(dimensions, observations, refinedAttributes, { customAttributes });
30
+ const attributesSeries = getAttributesSeries(enhancedObservations);
31
+ const manyValuesDimensions = getManyValuesDimensions(dimensions, attributesSeries, customAttributes, seriesCombinations);
32
+ const oneValueDimensions = getOneValueDimensions(dimensions, parsedAttributes);
33
+ const hierarchisedDimensions = R.map(dim => {
34
+ if (R.isEmpty(R.propOr({}, dim.id, hierarchies))) {
35
+ return hierarchiseDimensionWithNativeHierarchy(dim);
36
+ }
37
+ return hierarchiseDimensionWithAdvancedHierarchy(dim, R.prop(dim.id, hierarchies));
38
+ }, manyValuesDimensions)
39
+ const duplicatedObservations = duplicateObs(R.values(hierarchisedDimensions), enhancedObservations);
40
+
41
+ return ({
42
+ observations: duplicatedObservations,
43
+ dimensions: hierarchisedDimensions,
44
+ combinations: parsedCombinations,
45
+ oneValueDimensions,
46
+ attributesSeries,
47
+ metadataCoordinates,
48
+ attributes: refinedAttributes
49
+ });
50
+ };
@@ -0,0 +1,16 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const refineAttributes = (parsedAttributes, seriesCombinations) => {
4
+ const indexedRelationships = R.reduce(
5
+ (acc, comb) =>
6
+ R.reduce((_acc, concept) => R.assoc(concept, comb.relationship, _acc), acc, comb.concepts),
7
+ {},
8
+ seriesCombinations,
9
+ );
10
+ return R.map(attr => {
11
+ if (R.has(attr.id, indexedRelationships)) {
12
+ return { ...attr, series: true, relationship: R.prop(attr.id, indexedRelationships) };
13
+ }
14
+ return attr;
15
+ }, parsedAttributes);
16
+ };
@@ -0,0 +1,72 @@
1
+ import * as R from 'ramda';
2
+ import { getFlagsAndNotes } from './getFlagsAndNotes';
3
+ import { hasCellMetadata } from '../hasCellMetadata';
4
+ import { trimedProps } from '../utils';
5
+
6
+ export const getCellRelevantAttributes = (attributes, attributesSeries, cellAttributeIds) => R.filter(
7
+ (attr) => {
8
+ if (R.has(attr.id, cellAttributeIds)) {
9
+ return true;
10
+ }
11
+ const attrInSerie = R.path([attr.serieKey, attr.id], attributesSeries);
12
+ return R.isNil(attrInSerie);
13
+ },
14
+ attributes
15
+ );
16
+
17
+ export const getCellCombinedAttributes = (attributes, combinations) => R.reduce(
18
+ (acc, comb) => {
19
+ const values = trimedProps(comb.concepts, attributes);
20
+ if (R.isEmpty(values)) {
21
+ return acc;
22
+ }
23
+ return R.append({ ...R.pick(['id', 'name'], comb), values: R.pluck('value', values) }, acc);
24
+ },
25
+ [],
26
+ combinations
27
+ )
28
+
29
+ // combinations = { cells, layout };
30
+ export const getCells = (customAttributes, cellsAttributesId, combinations, attributesSeries, metadataCoordinates) => observations => {
31
+ const attributesInLayoutCombination = R.pipe(
32
+ R.propOr([], 'layout'),
33
+ R.pluck('concepts'),
34
+ R.unnest
35
+ )(combinations);
36
+
37
+ const attributesInCellsCombination = R.pipe(
38
+ R.propOr([], 'cells'),
39
+ R.pluck('concepts'),
40
+ R.unnest
41
+ )(combinations);
42
+
43
+ const _customAttributes = R.over(
44
+ R.lensProp('notes'),
45
+ notes => R.concat(notes || [], attributesInLayoutCombination)
46
+ )(customAttributes);
47
+
48
+ return R.mapObjIndexed(
49
+ obs => {
50
+ const relevantAttributes = getCellRelevantAttributes(obs.attributes, attributesSeries, cellsAttributesId);
51
+ const flagsAndNotes = getFlagsAndNotes(relevantAttributes, _customAttributes);
52
+ const combinedAttributes = getCellCombinedAttributes(relevantAttributes, combinations.cells || []);
53
+
54
+ const hasAdvancedAttributes = R.pipe(
55
+ R.omit(R.unnest([_customAttributes.flags || [], _customAttributes.notes || [], attributesInCellsCombination])),
56
+ R.isEmpty,
57
+ R.not
58
+ )(relevantAttributes);
59
+
60
+ const hasMetadata = hasCellMetadata(metadataCoordinates, obs.indexedDimValIds);
61
+
62
+ return ({
63
+ ...R.pick(['indexedDimValIds', 'key'], obs),
64
+ flags: R.concat(flagsAndNotes, combinedAttributes),
65
+ sideProps: hasAdvancedAttributes || hasMetadata ? { hasAdvancedAttributes, hasMetadata, coordinates: obs.indexedDimValIds } : null,
66
+ intValue: R.is(Number, obs.value) ? obs.value : null,
67
+ value: obs.formattedValue,
68
+ });
69
+ },
70
+ observations
71
+ );
72
+ };
@@ -0,0 +1,38 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const getCellsAttributesIds = (layoutIds, attributes) => {
4
+ return R.reduce(
5
+ (acc, attr) => {
6
+ if (!attr.series) {
7
+ return acc;
8
+ }
9
+ if (R.isEmpty(attr.relationship || [])) {
10
+ return R.assoc(attr.id, attr.id, acc);
11
+ }
12
+ const indexedHeaderIds = R.indexBy(R.identity, layoutIds.header);
13
+ const indexedSectionsIds = R.indexBy(R.identity, layoutIds.sections);
14
+ const indexedRowsIds = { ...indexedSectionsIds, ...R.indexBy(R.identity, layoutIds.rows) };
15
+ const [idsInHeader, rest] = R.partition(
16
+ id => R.has(id, indexedHeaderIds),
17
+ attr.relationship,
18
+ );
19
+ if (R.isEmpty(rest)) {
20
+ return acc;
21
+ } else if (!R.isEmpty(idsInHeader)) {
22
+ return R.assoc(attr.id, attr.id, acc);
23
+ } else {
24
+ const idsNotInSections = R.reject(id => R.has(id, indexedSectionsIds), attr.relationship);
25
+ if (R.isEmpty(idsNotInSections)) {
26
+ return acc;
27
+ }
28
+ const idsNotInRows = R.reject(id => R.has(id, indexedRowsIds), idsNotInSections);
29
+ if (R.isEmpty(idsNotInRows)) {
30
+ return acc;
31
+ }
32
+ }
33
+ return R.assoc(attr.id, attr.id, acc);
34
+ },
35
+ {},
36
+ attributes,
37
+ );
38
+ };
@@ -0,0 +1,38 @@
1
+ import * as R from 'ramda';
2
+ import { parseValueHierarchy } from './parseValueHierarchy';
3
+
4
+ export const getCombinationDimensionsData = (indexes, combination, previous, sameSerie) => {
5
+ let coordinates = {};
6
+ let ids = [];
7
+ let _sameSerie = sameSerie;
8
+ let hasAdvancedAttributes = false;
9
+
10
+ const { dimensions=[] } = combination;
11
+ const dimValues = R.addIndex(R.reduce)(
12
+ (acc, valIndex, dimIndex) => {
13
+ const dimension = R.nth(dimIndex, dimensions);
14
+ const value = R.nth(Math.abs(valIndex), R.propOr([], 'values', dimension));
15
+ hasAdvancedAttributes = !hasAdvancedAttributes ? value.hasAdvancedAttributes : true;
16
+ if (!value) {
17
+ return acc;
18
+ }
19
+ coordinates = R.assoc(dimension.id, value.id, coordinates);
20
+ ids = R.append(`${dimension.id}=${value.id}`, ids);
21
+ const previousValue = R.propOr({}, dimension.id, previous);
22
+ if (value.id === R.prop('id', previousValue || {}) && _sameSerie) {
23
+ return R.assoc(dimension.id, previousValue, acc);
24
+ }
25
+ else {
26
+ const parsedValue = parseValueHierarchy(value, _sameSerie ? previousValue || {} : {}, dimension.indexedValues);
27
+ if (!R.isNil(previous)) {
28
+ _sameSerie = false;
29
+ }
30
+ return R.assoc(dimension.id, parsedValue, acc);
31
+ }
32
+ },
33
+ {},
34
+ indexes
35
+ );
36
+
37
+ return ({ dimValues, coordinates, ids, sameSerie: _sameSerie, hasAdvancedAttributes });
38
+ };
@@ -0,0 +1,33 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const getCuratedCells = (cells, layout) => {
4
+ const layoutIds = R.map(
5
+ R.pipe(
6
+ R.map(entry =>
7
+ R.has('dimensions', entry) ? R.pluck('id', entry.dimensions || []) : entry.id,
8
+ ),
9
+ R.unnest,
10
+ ),
11
+ )(layout);
12
+ return R.pipe(
13
+ R.values,
14
+ R.reduce((acc, cell) => {
15
+ const keys = R.map(
16
+ R.pipe(
17
+ R.map(dim => {
18
+ const val = R.prop(dim, cell.indexedDimValIds);
19
+ return `${dim}=${val}`;
20
+ }),
21
+ R.join(':'),
22
+ ),
23
+ layoutIds,
24
+ );
25
+
26
+ return R.over(
27
+ R.lensPath(R.props(['header', 'sections', 'rows'], keys)),
28
+ cells => (R.isNil(cells) ? [cell] : R.append(cell, cells)),
29
+ acc,
30
+ );
31
+ }, {}),
32
+ )(cells);
33
+ };
@@ -0,0 +1,21 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const getFlagsAndNotes = (attributesValues, customAttributes) => {
4
+ const flagsIds = R.propOr([], 'flags', customAttributes);
5
+ const notesIds = R.propOr([], 'notes', customAttributes);
6
+
7
+ return R.addIndex(R.reduce)(
8
+ (acc, id, index) => {
9
+ if (!R.has(id, attributesValues)) {
10
+ return acc;
11
+ }
12
+ const attr = R.prop(id, attributesValues);
13
+ if (R.isNil(attr.value)) {
14
+ return acc;
15
+ }
16
+ return R.append(index < flagsIds.length ? R.assoc('code', R.path(['value', 'id'], attr), attr) : attr, acc);
17
+ },
18
+ [],
19
+ R.concat(flagsIds, notesIds)
20
+ );
21
+ };
@@ -0,0 +1,16 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const getIndexedCombinationsByDisplay = (layout, combinations) => {
4
+ const layoutIds = R.pipe(
5
+ R.map(R.pluck('id')),
6
+ R.values,
7
+ R.unnest,
8
+ R.indexBy(R.identity),
9
+ )(layout);
10
+
11
+ const [combsInLayout, combsInCells] = R.partition(
12
+ comb => R.has(comb.id, layoutIds),
13
+ combinations,
14
+ );
15
+ return { cells: combsInCells, layout: combsInLayout };
16
+ };
@@ -0,0 +1,80 @@
1
+ import * as R from 'ramda';
2
+ import { isTimePeriodDimension } from '@sis-cc/dotstatsuite-sdmxjs';
3
+ import { trimedProps } from '../utils';
4
+
5
+ export const getLayout = (layoutIds, dimensions, combinations, isTimeInverted, fixedDimensions) => {
6
+ const indexedDimensions = R.pipe(
7
+ R.indexBy(R.prop('id')),
8
+ R.map(d => (isTimePeriodDimension(d) && isTimeInverted ? R.assoc('isInverted', true, d) : d)),
9
+ )(dimensions);
10
+ const indexedFixedDimsValues = R.reduce(
11
+ (acc, dim) => {
12
+ const value = R.head(dim.values);
13
+ return !dim.display || !value.display ? acc : R.assoc(dim.id, R.head(dim.values), acc);
14
+ },
15
+ {},
16
+ fixedDimensions,
17
+ );
18
+ const indexedHeaderIds = R.indexBy(R.identity, layoutIds.header);
19
+ const indexedSectionsIds = R.indexBy(R.identity, layoutIds.sections);
20
+ const indexedRowsIds = { ...indexedSectionsIds, ...R.indexBy(R.identity, layoutIds.rows) };
21
+ let layout = { header: [], sections: [], rows: [] };
22
+ R.forEach(comb => {
23
+ if (R.isEmpty(comb.relationship)) {
24
+ return;
25
+ }
26
+ const [idsInHeader, rest] = R.partition(id => R.has(id, indexedHeaderIds), comb.relationship);
27
+ if (R.isEmpty(rest)) {
28
+ layout = R.over(
29
+ R.lensProp('header'),
30
+ R.append({
31
+ ...comb,
32
+ dimensions: trimedProps(comb.concepts, indexedDimensions),
33
+ fixedDimValues: R.pick(comb.concepts, indexedFixedDimsValues),
34
+ }),
35
+ )(layout);
36
+ } else if (!R.isEmpty(idsInHeader)) {
37
+ return;
38
+ } else {
39
+ const idsNotInSections = R.reject(id => R.has(id, indexedSectionsIds), comb.relationship);
40
+ if (R.isEmpty(idsNotInSections)) {
41
+ layout = R.over(
42
+ R.lensProp('sections'),
43
+ R.append({
44
+ ...comb,
45
+ dimensions: trimedProps(comb.concepts, indexedDimensions),
46
+ fixedDimValues: R.pick(comb.concepts, indexedFixedDimsValues),
47
+ }),
48
+ )(layout);
49
+ } else {
50
+ const idsNotInRows = R.reject(id => R.has(id, indexedRowsIds), comb.relationship);
51
+ if (R.isEmpty(idsNotInRows)) {
52
+ layout = R.over(
53
+ R.lensProp('rows'),
54
+ R.append({
55
+ ...comb,
56
+ dimensions: R.pipe(R.omit(layoutIds.sections), o => trimedProps(comb.concepts, o))(
57
+ indexedDimensions,
58
+ ),
59
+ fixedDimValues: R.pick(comb.concepts, indexedFixedDimsValues),
60
+ }),
61
+ )(layout);
62
+ }
63
+ }
64
+ }
65
+ }, combinations);
66
+ return R.mapObjIndexed((combs, key) => {
67
+ const conceptIds = R.pipe(R.pluck('concepts'), R.unnest, R.indexBy(R.identity))(combs);
68
+ const rest = R.reduce(
69
+ (acc, id) => {
70
+ if (R.has(id, conceptIds)) {
71
+ return acc;
72
+ }
73
+ return R.append(R.prop(id, indexedDimensions), acc);
74
+ },
75
+ [],
76
+ layoutIds[key],
77
+ );
78
+ return R.concat(rest, combs);
79
+ }, layout);
80
+ };