@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,27 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getConfirmedSeriesAttributesIds = (attributes, layoutIds) => R.reduce(
4
- (acc, attribute) => {
5
- const targetDimensions = R.pathOr([], ['relationship', 'dimensions'], attribute);
6
-
7
- const headerTargets = R.intersection(targetDimensions, R.propOr([], 'header', layoutIds));
8
- const sectionsAndRows = R.pipe(
9
- R.props(['sections', 'rows']),
10
- R.map(R.when(R.isNil, R.always([]))),
11
- R.unnest
12
- )(layoutIds);
13
- const rowsTargets = R.intersection(targetDimensions, sectionsAndRows);
14
-
15
- const isValid = R.pipe(
16
- R.reject(R.isEmpty),
17
- R.length,
18
- R.equals(1),
19
- )([headerTargets, rowsTargets]);
20
-
21
- return R.when(
22
- R.always(isValid),
23
- R.append(attribute.id)
24
- )(acc);
25
- },
26
- []
27
- )(attributes);
@@ -1,40 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- /*
4
-
5
- example shape = ['header', 'sections', 'rows']
6
-
7
- */
8
-
9
- const getPivotKey = indexes => R.pipe(
10
- R.props(indexes),
11
- R.join(':')
12
- );
13
-
14
- const getPivots = (layout, shape) => R.pipe(
15
- R.props(shape),
16
- R.map(R.pipe(R.pluck('__index'), getPivotKey))
17
- )(layout);
18
-
19
- const indexWithPivots = (pivots, observations) => R.pipe(
20
- R.values,
21
- R.reduce(
22
- (acc, obs) => {
23
- const splitKey = R.split(':', obs.key);
24
- const path = R.map(
25
- pivot => pivot(splitKey),
26
- pivots
27
- );
28
- return R.over(
29
- R.lensPath(path),
30
- R.ifElse(R.isNil, R.always([obs]), R.append(obs))
31
- )(acc);
32
- },
33
- {}
34
- )
35
- )(observations);
36
-
37
- export const getCuratedCells = ({ layout, observations, shape }) => {
38
- const pivots = getPivots(layout, shape);
39
- return indexWithPivots(pivots, observations);
40
- };
@@ -1,171 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- const indexesToLayoutData = (dimensions, indexes) => R.addIndex(R.map)(
4
- (valueIndex, dimensionIndex) => {
5
- const dimension = R.nth(dimensionIndex, dimensions);
6
- return ({
7
- dimension: R.pick(['id', 'name', '__index'], dimension),
8
- value: R.nth(Number(valueIndex), R.propOr([], 'values', dimension))
9
- });
10
- },
11
- indexes
12
- );
13
-
14
- const parseParents = (value, previous) => {
15
- const previousParents = R.pathOr([], ['value', 'parents'], previous);
16
- const indexedParents = R.indexBy(R.identity, value.parents);
17
-
18
- const refinedParents = R.reduce(
19
- (acc, id) => {
20
- if (R.has(id, indexedParents)) {
21
- return R.append(id, acc);
22
- }
23
- return acc;
24
- },
25
- [],
26
- R.append(R.path(['value', 'id'], previous), previousParents)
27
- );
28
- const lastParent = R.last(refinedParents);
29
- const missingParents = R.takeLastWhile(id => id !== lastParent, value.parents);
30
-
31
- return ({ parents: refinedParents, missingIds: missingParents });
32
- };
33
-
34
- const getRowData = (indexes, dimension) => {
35
- return R.pipe(
36
- R.propOr([], 'values'),
37
- R.props(indexes),
38
- R.reduce(
39
- ({ data, missingParents }, _value) => {
40
- if (R.isNil(_value)) {
41
- return ({ data, missingParents: {} });
42
- }
43
- const raw = {
44
- dimension: R.pick(['id', 'name', '__index'], dimension),
45
- value: _value,
46
- };
47
- if (R.isNil(_value.parents) || R.isEmpty(_value.parents)) {
48
- return ({ data: R.append([raw], data), missingParents: {} });
49
- }
50
- const previous = R.head(R.last(data) || []);
51
- if (R.last(_value.parents) === R.path(['value', 'id'], previous)) { //previous is parent
52
- const value = R.set(
53
- R.lensPath(['value', 'parents']),
54
- R.append(
55
- R.path(['value', 'id'], previous),
56
- R.pathOr([], ['value', 'parents'], previous)
57
- )
58
- )(raw);
59
- return ({ data: R.append([value], data), missingParents: {} });
60
- }
61
-
62
- const previousParent = R.pipe(R.pathOr([], ['value', 'parents']), R.last)(previous);
63
- if (R.last(_value.parents) === previousParent) { //previous is bro
64
- const value = R.set(
65
- R.lensPath(['value']),
66
- {
67
- ..._value,
68
- name: R.isEmpty(missingParents) ? _value.name : `${missingParents.name} > ${_value.name}`,
69
- parents: R.pathOr([], ['value', 'parents'], previous)
70
- }
71
- )(raw);
72
- return ({ data: R.append([value], data), missingParents });
73
- }
74
- const { parents, missingIds } = parseParents(_value, previous);
75
- const _missingParents = R.reduce(
76
- (acc, value) => {
77
- if (value.id !== R.head(acc.missingIds)) {
78
- return acc;
79
- }
80
- const _missingIds = R.tail(acc.missingIds);
81
- if (R.isEmpty(acc.name)) {
82
- return ({ name: value.name, missingIds: _missingIds });
83
- }
84
- return ({
85
- name: `${acc.name} > ${value.name}`,
86
- missingIds: _missingIds
87
- });
88
- },
89
- { name: '', missingIds },
90
- dimension.values
91
- );
92
-
93
- const value = R.set(
94
- R.lensProp('value'),
95
- {
96
- ..._value,
97
- parents,
98
- name: R.isEmpty(missingIds) ? _value.name : `${_missingParents.name} > ${_value.name}`,
99
- }
100
- )(raw);
101
-
102
- return ({ data: R.append([value], data), missingParents: R.isEmpty(missingIds) ? {} : _missingParents });
103
- },
104
- { data: [], missingParents: {} }
105
- ),
106
- R.prop('data')
107
- )(dimension);
108
- };
109
-
110
- const getRowsData = (rowsIndexes, dimensions) => {
111
- const dimension = R.head(dimensions);
112
-
113
- if (R.length(dimensions) === 1) {
114
- return getRowData(R.unnest(rowsIndexes), R.head(dimensions));
115
- }
116
-
117
- const groupedIndexes = R.reduce(
118
- (acc, indexes) => {
119
- const headIndex = R.head(indexes);
120
- const last = R.last(acc.heads);
121
- if (last === headIndex) {
122
- return ({
123
- ...acc,
124
- tails: R.over(
125
- R.lensIndex(-1),
126
- R.append(R.tail(indexes))
127
- )(acc.tails)
128
- });
129
- }
130
- return ({
131
- heads: R.append(headIndex, acc.heads),
132
- tails: R.append([R.tail(indexes)], acc.tails)
133
- });
134
- },
135
- { heads: [], tails: [] },
136
- rowsIndexes
137
- );
138
-
139
- const headsDatas = getRowData(groupedIndexes.heads, R.head(dimensions));
140
-
141
- const res = R.addIndex(R.map)(
142
- (tail, i) => {
143
- const tailData = getRowsData(tail, R.tail(dimensions));
144
- return R.map(
145
- R.prepend(R.head(headsDatas[i])),
146
- tailData
147
- );
148
- },
149
- groupedIndexes.tails
150
- );
151
-
152
- return R.unnest(res);
153
- };
154
-
155
- export const getLayoutData = (layoutIndexes, layout) => {
156
- const { header, sections, ...rest } = layoutIndexes;
157
- const headerData = R.map(i => R.pipe(indexesToLayoutData, R.filter(R.prop('value')))(layout.header, i), header);
158
-
159
- const sectionsData = R.map(
160
- ([sectionIndexes, rows]) => {
161
- const sectionData = R.pipe(indexesToLayoutData, R.filter(R.prop('value')))(layout.sections, sectionIndexes);
162
-
163
-
164
- const rowsData = getRowsData(rows, layout.rows);
165
-
166
- return [sectionData, rowsData];
167
- },
168
- sections
169
- );
170
- return ({ headerData, sectionsData, ...rest });
171
- };
@@ -1,137 +0,0 @@
1
- import * as R from 'ramda';
2
- import { getFlags } from './getCells';
3
- import { dimensionValueDisplay } from '../../dimension-utils';
4
- import { hasCellMetadata } from '../../../../rules2/src/hasCellMetadata';
5
-
6
- export const getLayoutSerieAttributes = (layoutSerie, seriesAttributes) => {
7
- const length = R.length(layoutSerie);
8
- if (length === 0) {
9
- return null;
10
- }
11
-
12
- const serieIndexes = R.reduce(
13
- (acc, entry) => {
14
- const dimIndex = R.pathOr(null, ['dimension', '__index'], entry);
15
- const valIndex = R.pathOr(null, ['value', '__index'], entry);
16
-
17
- if (R.isNil(dimIndex) || R.isNil(valIndex)) {
18
- return acc;
19
- }
20
-
21
- return R.assoc(String(dimIndex), String(valIndex))(acc);
22
- },
23
- {},
24
- layoutSerie
25
- );
26
-
27
- return R.pipe(
28
- R.filter(
29
- R.pipe(
30
- R.propOr([], 'serie'),
31
- R.addIndex(R.all)((valIndex, dimIndex) => {
32
- if (valIndex === 'x') {
33
- return true;
34
- }
35
- return R.propEq(String(dimIndex), String(valIndex), serieIndexes);
36
- }),
37
- ),
38
- )
39
- )(seriesAttributes);
40
- };
41
-
42
- const getFlagsFromSeriesAttributes = (display, customAttributes) => R.pipe(
43
- R.values,
44
- R.pluck('attributes'),
45
- R.mergeAll,
46
- (attributes) => getFlags(customAttributes, dimensionValueDisplay(display))({ attributes })
47
- );
48
-
49
- const formatCell = (display, customAttributes) => R.converge(
50
- (label, flags, others) => ({ label, flags, ...others }),
51
- [
52
- dimensionValueDisplay(display),
53
- getFlags(customAttributes, dimensionValueDisplay(display)),
54
- R.pick(['parents', 'unitsLabel', 'id'])
55
- ]
56
- );
57
-
58
- export const getSublayoutDataCells = (display, customAttributes) => R.map(
59
- R.evolve({
60
- dimension: formatCell(display, customAttributes),
61
- value: formatCell(display, customAttributes)
62
- })
63
- );
64
-
65
- const getSerieKey = R.pipe(R.reduce(
66
- (acc, entry) => {
67
- const index = R.pathOr(null, ['value', '__index'], entry);
68
- if (R.isNil(index)) {
69
- return acc;
70
- }
71
- return R.append(index, acc);
72
- },
73
- []
74
- ), R.join(':'));
75
-
76
- const getCoordinates = (data, unitsId) => R.reduce(
77
- (acc, entry) => {
78
- const dimId = R.path(['dimension', 'id'], entry);
79
- const valId = R.path(['value', 'id'], entry);
80
- if (dimId === unitsId) {
81
- return acc;
82
- }
83
- return R.assoc(dimId, valId, acc);
84
- },
85
- {},
86
- data
87
- );
88
-
89
- export const getLayoutDataWithFlags = (seriesAttributes, display, customAttributes, metadataCoordinates, unitsId) => {
90
- const regularAttrsIds = R.concat(customAttributes.flags || [], customAttributes.notes || []);
91
- const formatSublayout = (getAttributes, mCoordinates = [], supplData = []) => data => {
92
- const attributes = getAttributes(data);
93
- const key = getSerieKey(data);
94
- const cells = getSublayoutDataCells(display, customAttributes)(data);
95
- const flags = getFlagsFromSeriesAttributes(display, customAttributes)(attributes);
96
- const coordinates = getCoordinates(R.concat(supplData, data), unitsId);
97
- const hasMetadata = hasCellMetadata(mCoordinates, coordinates);
98
- const dataAdvancedAttrs = R.reduce(
99
- (acc, { dimension, value }) => {
100
- const attrs = { ...dimension.attributes || {}, ...value.attributes || {}};
101
- const advAttrs = R.omit(regularAttrsIds, attrs);
102
- return ({ ...acc, ...advAttrs })
103
- },
104
- {},
105
- data
106
- );
107
- const advancedAttributesSeries = R.isNil(attributes)
108
- ? {}
109
- : R.filter(
110
- serie => !R.isEmpty(R.omit(regularAttrsIds, R.propOr({}, 'attributes', serie))),
111
- attributes
112
- );
113
- const hasAdvancedAttributes = !R.isEmpty(advancedAttributesSeries) || !R.isEmpty(dataAdvancedAttrs);
114
- const sideProps = hasMetadata || hasAdvancedAttributes ? { hasAdvancedAttributes, hasMetadata, coordinates } : null;
115
-
116
- return ({ data: cells, key, flags, sideProps });
117
- };
118
-
119
- return R.evolve({
120
- headerData: R.map(formatSublayout(data => getLayoutSerieAttributes(data, seriesAttributes), metadataCoordinates.header)),
121
- sectionsData: R.map(
122
- sectionData => {
123
- const sectionSerie = R.head(sectionData);
124
- const sectionAttributes = getLayoutSerieAttributes(sectionSerie, seriesAttributes);
125
- return ([
126
- formatSublayout(() => sectionAttributes, metadataCoordinates.sections)(sectionSerie),
127
- R.map(
128
- formatSublayout(
129
- rowData => getLayoutSerieAttributes(R.concat(sectionSerie, rowData), R.omit(R.keys(sectionAttributes), seriesAttributes)),
130
- metadataCoordinates.rows,
131
- sectionSerie)
132
- )(R.last(sectionData))
133
- ]);
134
- }
135
- )
136
- });
137
- }
@@ -1,108 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- /*
4
-
5
- const layout = {
6
- header: [
7
- { ...dim, values: [] } // values already sorted regarding order annotation
8
- ],
9
- rows: [],
10
- sections: []
11
- };
12
-
13
- const observations = {
14
- [obsKey]: {
15
- ...obs,
16
- orderedDimIndexes: [sortedValIndex]
17
- }
18
- }
19
-
20
- */
21
-
22
- const getLayoutPivots = layout => {
23
- return R.mapObjIndexed(
24
- dimensions => R.props(R.pluck('__index', dimensions)),
25
- )(layout);
26
- };
27
-
28
- const comparator = size => (a, b) => {
29
- let i = 0;
30
- while (a[i] === b[i] && i < size) {
31
- i++;
32
- }
33
- return a[i] - b[i];
34
- };
35
-
36
- // simple call to ramda uniq method is very slow regarding performance
37
- const uniqIndexes = (indexes) => R.pipe(
38
- R.reduce(
39
- (acc, i) => {
40
- const key = R.join(':', i);
41
- if (R.has(key, acc.keys)) {
42
- return acc;
43
- }
44
- return ({
45
- indexes: R.append(i, acc.indexes),
46
- keys: R.assoc(key, key, acc.keys)
47
- });
48
- },
49
- { indexes: [], keys: {} },
50
- ),
51
- R.prop('indexes')
52
- )(indexes);
53
-
54
- export const getSortedLayoutIndexes = (layout, observations) => {
55
- const dimIndexes = R.pipe(R.values, R.map(R.propOr([], 'orderedDimIndexes')))(observations);
56
-
57
- const headerLength = R.length(layout.header);
58
-
59
- const sectionLength = R.length(layout.sections);
60
- const rowLength = R.length(layout.rows);
61
-
62
- const layoutPivots = getLayoutPivots(layout);
63
-
64
- const { header, sections } = R.pipe(
65
- R.reduce(
66
- (acc, indexes) => {
67
- const headerIndexes = layoutPivots.header(indexes);
68
- const sectionsIndexes = layoutPivots.sections(indexes);
69
- const rowsIndexes = layoutPivots.rows(indexes);
70
-
71
- return ({
72
- header: R.append(headerIndexes, acc.header),
73
- sections: R.append(
74
- R.concat(sectionsIndexes, rowsIndexes),
75
- acc.sections
76
- )
77
- });
78
- },
79
- { header: [], sections: [] },
80
- ),
81
- R.mapObjIndexed(uniqIndexes),
82
- R.evolve({
83
- header: R.sort(comparator(headerLength)),
84
- sections: R.sort(comparator(sectionLength + rowLength))
85
- }),
86
- indexes => ({
87
- ...indexes,
88
- sections: R.reduce(
89
- (acc, i) => {
90
- const [sectionIndexes, rowIndexes] = R.splitAt(sectionLength, i);
91
- const previousSecIndexes = R.pipe(R.nth(-1), i => R.isNil(i) ? null : R.head(i))(acc);
92
- if (R.equals(sectionIndexes, previousSecIndexes)) {
93
- return R.over(
94
- R.lensIndex(-1),
95
- R.over(R.lensIndex(1), R.append(rowIndexes))
96
- )(acc);
97
- }
98
-
99
- return R.append([sectionIndexes, [rowIndexes]], acc);
100
- },
101
- [],
102
- indexes.sections
103
- )
104
- })
105
- )(dimIndexes);
106
-
107
- return ({ header, sections });
108
- };
@@ -1,16 +0,0 @@
1
- import * as R from 'ramda';
2
- import { getCells } from './getCells';
3
- import { getCuratedCells } from './getCuratedCells';
4
-
5
- export const getTableCells = (data, layoutIds, display, customAttributes) => {
6
- const cells = getCells(data, layoutIds, display, customAttributes);
7
-
8
- const layout = R.pipe(
9
- R.mergeRight({ header: [], sections: [], rows: [] }),
10
- R.mapObjIndexed(
11
- R.flip(R.props)(R.pathOr({}, ['dimensions', 'many'], data))
12
- )
13
- )(layoutIds);
14
-
15
- return getCuratedCells({ layout, observations: cells, shape: ['header', 'sections', 'rows'] });
16
- };
@@ -1,86 +0,0 @@
1
- import * as R from 'ramda';
2
- import { getCells } from './getCells';
3
- import { getConfirmedSeriesAttributesIds } from './getConfirmedSeriesAttributesIds';
4
- import { getCuratedCells } from './getCuratedCells';
5
- import { getLayoutDataWithFlags } from './getLayoutWithFlags';
6
-
7
- import { getUnitsInLayout } from '../units/getUnitsinLayout';
8
- import { appendUnitsInLayoutData } from '../units/appendUnitsInLayoutData';
9
- import { cleanUnitsInLayoutData } from '../units/cleanUnitsInLayoutData';
10
-
11
-
12
- import { getSortedLayoutIndexes } from './getSortedLayoutIndexes';
13
- import { refineLayoutSize } from './refineLayoutSize';
14
- import { getLayoutData } from './getLayoutData';
15
- import { refineMetadataCoordinates } from '../../../../rules2/src/refineMetadataCoordinates';
16
- import { invertTime } from '../../../../rules2/src/invertTime';
17
-
18
- export const getTableProps = ({ data, layoutIds, display, customAttributes, limit, isTimeInverted }) => {
19
- const seriesAttributes = R.propOr({}, 'seriesAttributes', data);
20
-
21
- const confirmedSeriesAttributesIds = getConfirmedSeriesAttributesIds(
22
- seriesAttributes,
23
- layoutIds
24
- );
25
-
26
- const refinedMetadataCoordinates = refineMetadataCoordinates(data.metadataCoordinates, layoutIds);
27
-
28
- const {
29
- rejectedValueIds,
30
- unitDimension,
31
- unitsAttachmentSeriesIds,
32
- unitsDefinitionCodes,
33
- unitsSeries,
34
- } = R.propOr({}, 'units', data);
35
- const {
36
- unitsLevelDisplay,
37
- unitsAttachmentIndexesInLayout,
38
- unitsIndexesInLayout
39
- } = getUnitsInLayout({ layoutIds, unitsAttachmentSeriesIds, unitsDefinitionCodes, unitsSeries });
40
-
41
- const layoutDimsIds = R.pipe(R.pathOr({}, ['dimensions', 'many']), R.keys)(data);
42
-
43
- const cells = getCells(
44
- data,
45
- display,
46
- R.assoc('rejected', confirmedSeriesAttributesIds, customAttributes),
47
- {
48
- unitsDefinitionCodes, unitsSeries, unitsDisplay: unitsLevelDisplay,
49
- unitDimension, rejectedValueIds, layoutDimsIds
50
- },
51
- refinedMetadataCoordinates.cells,
52
- data.observationsType,
53
- );
54
-
55
- const { dimensions, observations } = invertTime(data, isTimeInverted);
56
-
57
- const seriesAttributesValues = R.propOr({}, 'seriesAttributesValues', data);
58
- const layout = R.pipe(
59
- R.mergeRight({ header: [], sections: [], rows: [] }),
60
- R.mapObjIndexed(R.flip(R.props)(dimensions)),
61
- )(layoutIds);
62
-
63
- const partialUnitSerieIndexes = R.pipe(
64
- R.pathOr(0, ['dimensions', 'length']),
65
- R.times(R.always('x'))
66
- )(data);
67
-
68
- const layoutData = R.pipe(
69
- getSortedLayoutIndexes,
70
- refineLayoutSize({ layout, observations: data.observations, limit: R.when(R.isNil, R.always(0))(limit) }),
71
- indexes => getLayoutData(indexes, layout),
72
- appendUnitsInLayoutData({
73
- display, unitDimension, unitsDisplay: unitsLevelDisplay, unitsSeries,
74
- unitsDefinitionCodes, unitsIndexes: unitsAttachmentIndexesInLayout,
75
- partialUnitSerieIndexes, rejectedValueIds, layoutIds
76
- }),
77
- getLayoutDataWithFlags(seriesAttributesValues, display, customAttributes, refinedMetadataCoordinates, unitDimension.id),
78
- cleanUnitsInLayoutData({ unitsDisplay: unitsLevelDisplay, unitsLayoutIndexes: unitsIndexesInLayout }),
79
- )(layout, observations);
80
-
81
- return ({
82
- cells: getCuratedCells({ layout, observations: cells, shape: ['header', 'sections', 'rows'] }),
83
- layout,
84
- ...layoutData
85
- });
86
- };
@@ -1,17 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getAttributeValue = (attribute, valueIndex) => {
4
- const value = R.pipe(
5
- R.propOr([], 'values'),
6
- R.nth(valueIndex)
7
- )(attribute);
8
-
9
- if (R.isNil(value)) {
10
- return null;
11
- }
12
-
13
- return ({
14
- ...R.pick(['id', 'name'], attribute),
15
- value: R.pick(['id', 'name'], value)
16
- });
17
- };
@@ -1,51 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- const getSerieRegisterPath = (attribute, obsDimValuesIndexes) => {
4
- const serieKey = R.pipe(
5
- R.addIndex(R.map)(
6
- (dimensionValueIndex, dimensionIndex) => R.when(
7
- R.always(!R.has(String(dimensionIndex), attribute.targetIndexes)),
8
- R.always('x')
9
- )(dimensionValueIndex)
10
- ),
11
- R.join(':')
12
- )(obsDimValuesIndexes);
13
-
14
- return ['series', serieKey, attribute.id];
15
- };
16
-
17
- const getDimensionRegisterPath = (attribute, obsDimValuesIndexes) => {
18
- const dimensionIndex = attribute.targetIndex;
19
- const dimensionValueIndex = R.nth(dimensionIndex, obsDimValuesIndexes);
20
-
21
- return ['dimensions', `${dimensionIndex}:${dimensionValueIndex}`, attribute.id];
22
- };
23
-
24
- const getAttributesRegisters = (getPath) => R.map(
25
- (attribute) => (observation) => {
26
- const valueIndex = R.nth(attribute.index, R.propOr([], 'attrValuesIndexes', observation));
27
-
28
- const registerPath = getPath(attribute, R.propOr([], 'dimValuesIndexes', observation));
29
-
30
- return R.over(
31
- R.lensPath(registerPath),
32
- R.ifElse(R.isNil, R.always([valueIndex]), R.append(valueIndex))
33
- );
34
- }
35
- );
36
-
37
- export const getDimensionsAttributesRegisters = (attributesIds, attributesByIds) => R.converge(
38
- R.concat,
39
- [
40
- R.pipe(
41
- R.propOr([], 'series'),
42
- R.flip(R.props)(attributesByIds),
43
- getAttributesRegisters(getSerieRegisterPath)
44
- ),
45
- R.pipe(
46
- R.propOr([], 'manyValuesDimensions'),
47
- R.flip(R.props)(attributesByIds),
48
- getAttributesRegisters(getDimensionRegisterPath)
49
- )
50
- ]
51
- )(attributesIds);
@@ -1,19 +0,0 @@
1
- import * as R from 'ramda';
2
- import { refineObservationsAttributesValues } from './refineObservationsAttributesValues';
3
-
4
- export const getManyValuesDimensions = (dimensionsByIds, dimensionsIds, attributeValues, attributes) => R.mapObjIndexed(
5
- (dimension) => {
6
- const dimensionIndex = R.prop(dimension.id, dimensionsIds);
7
- const values = R.map(
8
- value => {
9
- const valueAttributes = refineObservationsAttributesValues(attributes)
10
- (R.propOr({}, `${dimensionIndex}:${value.__index}`, attributeValues));
11
- return ({
12
- ...R.pick(['id', 'name', '__indexPosition', 'parent', '__index', 'notes'], value),
13
- attributes: valueAttributes,
14
- });
15
- }, dimension.values);
16
- return R.assoc('values', values, dimension);
17
- },
18
- R.pick(R.keys(dimensionsIds), dimensionsByIds)
19
- );
@@ -1,17 +0,0 @@
1
- import * as R from 'ramda';
2
- import { getAttributeValue } from './getAttributeValue';
3
-
4
- export const getOneValueDimensions = (dimensions, attributesIds, attributes) => R.map(
5
- (dimension) => {
6
- const dimensionAttributes = R.pipe(
7
- R.mapObjIndexed(attr => getAttributeValue(attr, 0)),
8
- R.filter(R.complement(R.isNil))
9
- )(R.pick(R.propOr([], dimension.id, attributesIds), attributes));
10
-
11
- return R.over(
12
- R.lensPath(['values', 0]),
13
- R.assoc('attributes', dimensionAttributes)
14
- )(dimension);
15
- },
16
- dimensions
17
- );