@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,183 @@
1
+ import * as R from 'ramda';
2
+ import { getFlagsAndNotes } from './getFlagsAndNotes';
3
+ import { hasCellMetadata } from '../hasCellMetadata';
4
+ import { getCombinationDimensionsData } from './getCombinationDimensionsData';
5
+ import { parseValueHierarchy } from './parseValueHierarchy';
6
+
7
+ const getSubLayoutData = (series, _definition, { metadataCoordinates, attributesSeries, customAttributes }) => {
8
+ const getHasAdvancedAttributes = (attrValues) => R.pipe(
9
+ R.omit(R.concat(customAttributes.flags, customAttributes.notes)),
10
+ R.isEmpty,
11
+ R.not
12
+ )(attrValues);
13
+
14
+ const combinationConceptIds = R.reduce(
15
+ (acc, def) => {
16
+ const concepts = R.propOr([], 'concepts', def);
17
+ if (R.isEmpty(concepts)) {
18
+ return acc;
19
+ }
20
+ return R.concat(acc, concepts);
21
+ },
22
+ [],
23
+ _definition
24
+ );
25
+
26
+ const definition = R.map( //used for parseValueHierarchy ...
27
+ (entry) => {
28
+ if (R.has('dimensions', entry)) {
29
+ return ({
30
+ ...entry,
31
+ dimensions: R.map(
32
+ dim => R.assoc('indexedValues', R.indexBy(R.prop('id'), dim.values || []), dim),
33
+ entry.dimensions
34
+ )
35
+ });
36
+ }
37
+ return R.assoc('indexedValues', R.indexBy(R.prop('id'), entry.values || []), entry);
38
+ },
39
+ _definition
40
+ );
41
+
42
+ const { res } = R.reduce(
43
+ (acc, serie) => {
44
+ let data = [];
45
+ let next = [];
46
+ let sameSerie = true;
47
+ let i = 0;
48
+ let hasAdvancedAttributes = false;
49
+ let coordinates = {};
50
+ let ids = [];
51
+ while (i < serie.length) {
52
+ const entry = serie[i];
53
+ if (R.is(Array, entry)) {
54
+ const combination = definition[i];
55
+ const previousDimValues = R.nth(i, acc.previous);
56
+ const combData = getCombinationDimensionsData(entry, combination, previousDimValues, sameSerie);
57
+ data = R.append({
58
+ dimension: R.pick(['id', 'name'], combination),
59
+ dimValues: combData.dimValues
60
+ }, data);
61
+ next = R.append(combData.dimValues, next);
62
+ hasAdvancedAttributes = !hasAdvancedAttributes ? combData.hasAdvancedAttributes : true;
63
+ sameSerie = combData.sameSerie;
64
+ coordinates = { ...coordinates, ...combData.coordinates };
65
+ ids = R.concat(ids, combData.ids);
66
+ }
67
+ else {
68
+ const dimension = definition[i];
69
+ const value = R.nth(Math.abs(entry), dimension.values || []);
70
+ const previousValue = R.nth(i, acc.previous) || {};
71
+ coordinates = R.assoc(dimension.id, value.id, coordinates);
72
+ ids = R.append(`${dimension.id}=${value.id}`, ids);
73
+ if (value.id === R.prop('id', previousValue || {}) && sameSerie) {
74
+ next = R.append(previousValue, next);
75
+ data = R.append({
76
+ dimension: R.pick(['id', 'name', '__index'], dimension),
77
+ value: previousValue,
78
+ }, data);
79
+ }
80
+ else {
81
+ hasAdvancedAttributes = !hasAdvancedAttributes ? value.hasAdvancedAttributes : true;
82
+ const parsedValue = parseValueHierarchy(value, sameSerie ? previousValue || {} : {}, dimension.indexedValues);
83
+ next = R.append(parsedValue, next);
84
+ data = R.append({
85
+ dimension: R.pick(['id', 'name', '__index'], dimension),
86
+ value: parsedValue,
87
+ }, data);
88
+ if (!R.isNil(acc.previous)) {
89
+ sameSerie = false;
90
+ }
91
+ }
92
+ }
93
+ i++;
94
+ }
95
+
96
+ const attributesValues = R.reduce(
97
+ (acc, key) => {
98
+ const splitKey = R.split(':', key);
99
+ const isValid = R.all(entry => {
100
+ const [d, v] = R.split('=', entry);
101
+ return R.propEq(d, v, coordinates);
102
+ }, splitKey);
103
+ return isValid ? { ...acc, ...(R.length(splitKey) === 1 ? R.pick(combinationConceptIds, R.prop(key, attributesSeries)) : R.prop(key, attributesSeries)) } : acc;
104
+ },
105
+ {},
106
+ R.keys(attributesSeries)
107
+ );
108
+
109
+ data = R.addIndex(R.map)(
110
+ (entry, ind) => {
111
+ if (!R.has('dimValues', entry)) {
112
+ return entry;
113
+ }
114
+ const { dimValues, dimension } = entry;
115
+ const def = R.nth(ind, definition);
116
+ const fixedDimValues = R.propOr([], 'fixedDimValues', def);
117
+ const values = R.reduce(
118
+ (_acc, id) => {
119
+ if (R.has(id, dimValues)) {
120
+ return R.append(R.prop(id, dimValues), _acc);
121
+ }
122
+ if (R.has(id, fixedDimValues)) {
123
+ return R.append(R.prop(id, fixedDimValues), _acc);
124
+ }
125
+ if (!R.has(id, attributesValues)) {
126
+ return _acc;
127
+ }
128
+ return R.append(R.path([id, 'value'], attributesValues), _acc);
129
+ },
130
+ [],
131
+ def.concepts
132
+ );
133
+ return ({ dimension, values });
134
+ },
135
+ data
136
+ );
137
+
138
+ const layoutAttrValues = R.pipe(
139
+ R.omit(combinationConceptIds),
140
+ R.reject(R.prop('isObs'))
141
+ )(attributesValues);
142
+
143
+ const flags = getFlagsAndNotes(layoutAttrValues, customAttributes);
144
+ const hasMetadata = hasCellMetadata(metadataCoordinates, coordinates);
145
+
146
+ if (!hasAdvancedAttributes) {
147
+ hasAdvancedAttributes = getHasAdvancedAttributes(layoutAttrValues);
148
+ }
149
+
150
+ const sideProps = hasMetadata || hasAdvancedAttributes
151
+ ? { hasMetadata, hasAdvancedAttributes, coordinates } : null;
152
+
153
+ return {
154
+ res: R.append({ data, key: R.join(':', ids), flags, sideProps }, acc.res),
155
+ previous: next,
156
+ };
157
+ },
158
+ { res: [], previous: [] },
159
+ series
160
+ );
161
+
162
+ return res;
163
+ };
164
+
165
+ export const getLayoutData = (layoutIndexes, layout, { metadataCoordinates, attributesSeries, customAttributes }) => {
166
+ const { header, sections, ...rest } = layoutIndexes;
167
+ const opts = { metadataCoordinates, attributesSeries, customAttributes };
168
+ const headerData = getSubLayoutData(header, layout.header, opts);
169
+ const sectionsData = R.pipe(
170
+ R.transpose,
171
+ ([sections, sectionsRows]) => {
172
+ if (R.isNil(sections)) {
173
+ return [];
174
+ }
175
+ const _sectionsData = getSubLayoutData(sections, layout.sections, opts);
176
+ const rowsData = R.map(rows => getSubLayoutData(rows, layout.rows, opts), sectionsRows);
177
+
178
+ return R.transpose([_sectionsData, rowsData]);
179
+ }
180
+ )(sections);
181
+
182
+ return ({ headerData, sectionsData, ...rest });
183
+ };
@@ -0,0 +1,119 @@
1
+ import * as R from 'ramda';
2
+
3
+ /*
4
+ const layout = {
5
+ header: [
6
+ { id, __index },
7
+ { id: COMB, dimensions: [{ id, __index }] }
8
+ ],
9
+ sections: [],
10
+ rows: []
11
+ }
12
+
13
+ */
14
+
15
+ const getLayoutPivots = layoutEntry => {
16
+ const valIndexGetter = d => R.pipe(
17
+ R.nth(R.prop('__index', d)),
18
+ ind => d.isInverted ? R.negate(ind) : ind
19
+ );
20
+ return indexes => R.map(
21
+ R.ifElse(
22
+ R.has('dimensions'),
23
+ c => R.map(d => valIndexGetter(d)(indexes), R.prop('dimensions', c)),
24
+ d => valIndexGetter(d)(indexes)
25
+ ),
26
+ layoutEntry
27
+ );
28
+ };
29
+
30
+ const comparator = (a, b) => {
31
+ const size = R.length(a);
32
+ let i = 0;
33
+ while (i < size) {
34
+ if (R.is(Array, a[i])) {
35
+ const _a = a[i];
36
+ const _b = b[i];
37
+ const _size = R.length(_a);
38
+ let j = 0;
39
+ while (_a[j] === _b[j] && j < _size) {
40
+ j++;
41
+ }
42
+ if (_a[j] !== _b[j]) {
43
+ return _a[j] - _b[j];
44
+ }
45
+ }
46
+ else if (a[i] !== b[i]) {
47
+ return a[i] - b[i];
48
+ }
49
+ i++;
50
+ }
51
+ return a[i] - b[i];
52
+ };
53
+
54
+ // simple call to ramda uniq method is very slow regarding performance
55
+ const uniqIndexes = (indexes) => R.pipe(
56
+ R.reduce(
57
+ (acc, i) => {
58
+ const key = R.join(':', R.unnest(i));
59
+ if (R.has(key, acc.keys)) {
60
+ return acc;
61
+ }
62
+ return ({
63
+ indexes: R.append(i, acc.indexes),
64
+ keys: R.assoc(key, key, acc.keys)
65
+ });
66
+ },
67
+ { indexes: [], keys: {} },
68
+ ),
69
+ R.prop('indexes')
70
+ )(indexes);
71
+
72
+ export const getSortedLayoutIndexes = (layout, observations) => {
73
+ const dimIndexes = R.pipe(R.values, R.map(R.propOr([], 'orderedDimIndexes')))(observations);
74
+
75
+ const headerPivots = getLayoutPivots(layout.header);
76
+ const sectionsPivots = getLayoutPivots(R.concat(layout.sections, layout.rows));
77
+
78
+ const sectionLength = R.length(layout.sections);
79
+ const { header, sections } = R.pipe(
80
+ R.reduce(
81
+ (acc, indexes) => {
82
+ const headerIndexes = headerPivots(indexes);
83
+ const sectionsIndexes = sectionsPivots(indexes);
84
+
85
+ return ({
86
+ header: R.append(headerIndexes, acc.header),
87
+ sections: R.append(sectionsIndexes, acc.sections)
88
+ });
89
+ },
90
+ { header: [], sections: [] },
91
+ ),
92
+ R.mapObjIndexed(uniqIndexes),
93
+ R.evolve({
94
+ header: R.sort(comparator),
95
+ sections: R.sort(comparator)
96
+ }),
97
+ indexes => ({
98
+ ...indexes,
99
+ sections: R.reduce(
100
+ (acc, i) => {
101
+ const [sectionIndexes, rowIndexes] = R.splitAt(sectionLength, i);
102
+ const previousSecIndexes = R.pipe(R.nth(-1), i => R.isNil(i) ? null : R.head(i))(acc);
103
+ if (R.equals(R.unnest(sectionIndexes), previousSecIndexes ? R.unnest(previousSecIndexes) : null)) { //perhaps a bit dirty ...
104
+ return R.over(
105
+ R.lensIndex(-1),
106
+ R.over(R.lensIndex(1), R.append(rowIndexes))
107
+ )(acc);
108
+ }
109
+
110
+ return R.append([sectionIndexes, [rowIndexes]], acc);
111
+ },
112
+ [],
113
+ indexes.sections
114
+ )
115
+ })
116
+ )(dimIndexes);
117
+
118
+ return ({ header, sections });
119
+ };
@@ -0,0 +1,36 @@
1
+ import * as R from 'ramda';
2
+ import { getLayout } from './getLayout';
3
+ import { getSortedLayoutIndexes } from './getSortedLayoutIndexes';
4
+ import { refineLayoutSize } from './refineLayoutSize';
5
+ import { getLayoutData } from './getLayoutData';
6
+ import { getCellsAttributesIds } from './getCellsAttributesIds';
7
+ import { getIndexedCombinationsByDisplay } from './getIndexedCombinationsByDisplay';
8
+ import { getCells } from './getCells';
9
+ import { getCuratedCells } from './getCuratedCells';
10
+
11
+ export const getTableProps = ({ data, layoutIds, customAttributes, limit, isTimeInverted }) => {
12
+ const {
13
+ observations,
14
+ dimensions,
15
+ combinations,
16
+ oneValueDimensions,
17
+ attributesSeries,
18
+ metadataCoordinates,
19
+ attributes
20
+ } = data;
21
+
22
+ const seriesCombinations = R.filter(R.prop('series'), combinations);
23
+ const layout = getLayout(layoutIds, dimensions, seriesCombinations, isTimeInverted, oneValueDimensions);
24
+ const layoutIndexes = getSortedLayoutIndexes(layout, observations);
25
+ const refinedLayoutIndexes = refineLayoutSize({ layout, observations, limit })(layoutIndexes);
26
+ const layoutData = getLayoutData(refinedLayoutIndexes, layout, { metadataCoordinates, attributesSeries, customAttributes });
27
+
28
+ const cellsAttributesIds = getCellsAttributesIds(layoutIds, attributes);
29
+ const indexedCombinations = getIndexedCombinationsByDisplay(layout, seriesCombinations);
30
+ const cells = getCells(customAttributes, cellsAttributesIds, indexedCombinations, attributesSeries, metadataCoordinates)(observations);
31
+
32
+ return ({
33
+ ...layoutData,
34
+ cells: getCuratedCells(cells, layout)
35
+ });
36
+ };
@@ -0,0 +1,27 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const parseValueHierarchy = (value, previousValue, indexedValues) => {
4
+ const parentsIds = R.propOr([], 'parents', value);
5
+ if (R.isEmpty(parentsIds)) {
6
+ return value;
7
+ }
8
+ const _previousParentsIds = R.propOr([], 'parentsIds', previousValue);
9
+ const previousParentsIds = R.isNil(previousValue) ? [] : R.append(R.prop('id', previousValue), _previousParentsIds);
10
+ const [presentIds, missingIds] = R.addIndex(R.splitWhen)((val, ind) => R.nth(ind, previousParentsIds) !== val, parentsIds);
11
+ //console.log({ presentIds, missingIds });
12
+ const _previousParents = R.propOr([], 'parents', previousValue);
13
+ const previousParents = R.isNil(previousValue) ? [] : R.append(R.pick(['id', 'name'], previousValue), _previousParents);
14
+ //console.log('previousParents', previousParents);
15
+ const parents = R.takeWhile(p => R.includes(p.id, presentIds), previousParents);
16
+ const missingParents = R.concat(
17
+ R.includes(R.prop('id', previousValue), presentIds)
18
+ ? [] : R.takeWhile(p => R.includes(p.id, presentIds), R.propOr([], 'missingParents', previousValue)),
19
+ R.props(missingIds, indexedValues)
20
+ );
21
+ return ({
22
+ ...value,
23
+ parents,
24
+ parentsIds,
25
+ missingParents
26
+ });
27
+ };
@@ -1,5 +1,14 @@
1
1
  import * as R from 'ramda';
2
2
 
3
+ const toKey = indexes => R.reduce(
4
+ (acc, _ind) => {
5
+ const ind = R.is(Array, _ind) ? toKey(_ind) : Math.abs(_ind);
6
+ return R.isEmpty(acc) ? String(ind) : `${acc}:${ind}`
7
+ },
8
+ '',
9
+ indexes
10
+ );
11
+
3
12
  const getPivotKey = indexes => R.pipe(
4
13
  R.props(indexes),
5
14
  R.join(':')
@@ -7,7 +16,13 @@ const getPivotKey = indexes => R.pipe(
7
16
 
8
17
  const getPivots = (layout, shape) => R.pipe(
9
18
  R.props(shape),
10
- R.map(R.pipe(R.pluck('__index'), getPivotKey))
19
+ R.map(
20
+ R.pipe(
21
+ R.map(entry => R.has('dimensions', entry) ? R.pluck('__index', entry.dimensions || []) : entry.__index),
22
+ R.unnest,
23
+ getPivotKey
24
+ )
25
+ )
11
26
  )(layout);
12
27
 
13
28
  const indexWithPivots = (pivots, observations) => R.pipe(
@@ -35,12 +50,12 @@ export const getCuratedCells = ({ layout, observations, shape }) => {
35
50
  export const refineSections = (sections, extractedKeys, curatedObs) => R.pipe(
36
51
  R.map(
37
52
  (section) => {
38
- const sectionKey = R.join(':', R.head(section) || []);
53
+ const sectionKey = toKey(R.head(section) || []);
39
54
  return R.over(
40
55
  R.lensIndex(1),
41
56
  R.filter(
42
57
  rowData => {
43
- const rowKey = R.join(':', rowData);
58
+ const rowKey = toKey(rowData);
44
59
  return R.pipe(
45
60
  R.path([sectionKey, rowKey]),
46
61
  R.omit(extractedKeys),
@@ -59,7 +74,7 @@ export const refineSections = (sections, extractedKeys, curatedObs) => R.pipe(
59
74
 
60
75
  export const refineHeader = (header, extractedKeys, curatedObs) => R.filter( // extracted : { [sectionKey]: [...rowKeys] }
61
76
  (header) => {
62
- const headerKey = R.join(':', header);
77
+ const headerKey = toKey(header);
63
78
  return R.pipe(
64
79
  R.prop(headerKey),
65
80
  (sections) => {
@@ -86,17 +101,17 @@ export const truncateSectionRows = (n, sectionsData) => {
86
101
  const lastSection = R.last(truncated);
87
102
  const rows = lastSection[1];
88
103
  const rowsLength = R.length(rows);
89
- const sectionKey = R.join(':', R.head(lastSection));
104
+ const sectionKey = toKey(R.head(lastSection));
90
105
  if (rowsLength > _n) {
91
106
  const [rest, extracted] = R.splitAt(R.negate(_n), rows);
92
107
  const updatedSection = R.set(R.lensIndex(1), rest)(lastSection);
93
108
  truncated = R.set(R.lensIndex(-1), updatedSection)(truncated);
94
- extractedKeys = { ...extractedKeys, [sectionKey]: R.map(R.join(':'), extracted) };
109
+ extractedKeys = { ...extractedKeys, [sectionKey]: R.map(toKey, extracted) };
95
110
  _n = 0;
96
111
  }
97
112
  else {
98
113
  truncated = R.dropLast(1, truncated);
99
- extractedKeys = { ...extractedKeys, [sectionKey]: R.map(R.join(':'), rows) };
114
+ extractedKeys = { ...extractedKeys, [sectionKey]: R.map(toKey, rows) };
100
115
  _n = _n - rowsLength;
101
116
  }
102
117
  }
@@ -105,7 +120,7 @@ export const truncateSectionRows = (n, sectionsData) => {
105
120
 
106
121
  export const truncateHeader = (n, headerData) => {
107
122
  const [truncated, extracted] = R.splitAt(R.negate(n))(headerData);
108
- return ({ truncated, extractedKeys: R.map(R.join(':'), extracted) });
123
+ return ({ truncated, extractedKeys: R.map(toKey, extracted) });
109
124
  };
110
125
 
111
126
  const truncateLayout = (isVertical) => R.ifElse(
@@ -218,6 +233,7 @@ export const refineLayoutSize = ({ layout, observations, limit }) => layoutIndex
218
233
  (shape) => getCuratedCells({ layout, observations, shape })
219
234
  )(isVertical);
220
235
 
236
+
221
237
  const refined = refineLayout(isVertical)(toRefine, extractedKeys, curatedObs);
222
238
 
223
239
  const result = getRefinedLayout(isVertical, truncated, refined);
@@ -0,0 +1,12 @@
1
+ import * as R from 'ramda';
2
+
3
+ export const trimedProps = (properties, obj) => R.reduce(
4
+ (acc, prop) => {
5
+ if (!R.has(prop, obj)) {
6
+ return acc;
7
+ }
8
+ return R.append(obj[prop], acc);
9
+ },
10
+ [],
11
+ properties,
12
+ );
@@ -0,0 +1,219 @@
1
+ import { expect } from 'chai';
2
+ import { enhanceObservations } from '../src/rules2/src/enhanceObservations';
3
+ import numeral from 'numeral';
4
+
5
+ numeral.register('locale', 'eObs', { delimiters: { thousands: ",", decimal: "." } });
6
+ describe('enhanceObservations tests', () => {
7
+ it('blank test', () => {
8
+ expect(enhanceObservations([], {}, [], {})).to.deep.equal({});
9
+ });
10
+ it('formatValue test', () => {
11
+ numeral.locale('eObs');
12
+ const attributes = [
13
+ { id: 'A1', values: [] },
14
+ { id: 'A2', values: [{ id: '-1' }, { id: '0' }, { id: '1' }, { id: '3' }, { id: 'Z' }] },
15
+ { id: 'A3', values: [{ id: '0' }, { id: '2' }, { id: '3' }, { id: '5' }, { id: 'A' }] }
16
+ ];
17
+
18
+ const customAttributes = { prefscale: 'A2', decimals: 'A3' };
19
+
20
+ const observations = {
21
+ a: { value: 2, attrValuesIndexes: [null, null, null], dimValuesIndexes: [] },
22
+ c: { value: 10, attrValuesIndexes: [null, 4, null], dimValuesIndexes: [] },
23
+ d: { value: 5, attrValuesIndexes: [null, 1, null], dimValuesIndexes: [] },
24
+ e: { value: 8.3, attrValuesIndexes: [null, 0, null], dimValuesIndexes: [] },
25
+ f: { value: 25.62, attrValuesIndexes: [null, 3, null], dimValuesIndexes: [] },
26
+ g: { value: 3.7, attrValuesIndexes: [null, null, 4], dimValuesIndexes: [] },
27
+ h: { value: 21.1234567, attrValuesIndexes: [null, null, 2], dimValuesIndexes: [] },
28
+ i: { value: 20.1, attrValuesIndexes: [null, null, 3], dimValuesIndexes: [] },
29
+ j: { value: 19.9, attrValuesIndexes: [null, null, 0], dimValuesIndexes: [] },
30
+ k: { value: 16.35, attrValuesIndexes: [null, 2, 1], dimValuesIndexes: [] },
31
+ l: { value: 155062.56, attrValuesIndexes: [null, null, 2], dimValuesIndexes: [] },
32
+ m: { value: 155062.56, attrValuesIndexes: [null, null, 0], dimValuesIndexes: [] },
33
+ n: { value: null, attrValuesIndexes: [null, null, 1], dimValuesIndexes: [] },
34
+ };
35
+
36
+ expect(enhanceObservations([], observations, attributes, { customAttributes })).to.deep.equal({
37
+ a: { attributes: {}, value: 2, formattedValue: '2', attrValuesIndexes: [null, null, null], dimValuesIndexes: [], indexedDimValIds: {} },
38
+ c: { attributes: {}, value: 10, formattedValue: '10', attrValuesIndexes: [null, 4, null], dimValuesIndexes: [], indexedDimValIds: {} },
39
+ d: { attributes: {}, value: 5, formattedValue: '5', attrValuesIndexes: [null, 1, null], dimValuesIndexes: [], indexedDimValIds: {} },
40
+ e: { attributes: {}, value: 8.3, formattedValue: '83', attrValuesIndexes: [null, 0, null], dimValuesIndexes: [], indexedDimValIds: {} },
41
+ f: { attributes: {}, value: 25.62, formattedValue: '0.02562', attrValuesIndexes: [null, 3, null], dimValuesIndexes: [], indexedDimValIds: {} },
42
+ g: { attributes: {}, value: 3.7, formattedValue: '3.7', attrValuesIndexes: [null, null, 4], dimValuesIndexes: [], indexedDimValIds: {} },
43
+ h: { attributes: {}, value: 21.1234567, formattedValue: '21.123', attrValuesIndexes: [null, null, 2], dimValuesIndexes: [], indexedDimValIds: {} },
44
+ i: { attributes: {}, value: 20.1, formattedValue: '20.10000', attrValuesIndexes: [null, null, 3], dimValuesIndexes: [], indexedDimValIds: {} },
45
+ j: { attributes: {}, value: 19.9, formattedValue: '20', attrValuesIndexes: [null, null, 0], dimValuesIndexes: [], indexedDimValIds: {} },
46
+ k: { attributes: {}, value: 16.35, formattedValue: '1.64', attrValuesIndexes: [null, 2, 1], dimValuesIndexes: [], indexedDimValIds: {} },
47
+ l: { attributes: {}, value: 155062.56, formattedValue: '155,062.560', attrValuesIndexes: [null, null, 2], dimValuesIndexes: [], indexedDimValIds: {} },
48
+ m: { attributes: {}, value: 155062.56, formattedValue: '155,063', attrValuesIndexes: [null, null, 0], dimValuesIndexes: [], indexedDimValIds: {} },
49
+ n: { attributes: {}, value: null, formattedValue: '..', attrValuesIndexes: [null, null, 1], dimValuesIndexes: [], indexedDimValIds: {} },
50
+ });
51
+ });
52
+ it('attributes', () => {
53
+ const attributes = [
54
+ {
55
+ id: 'a0',
56
+ values: [{ id: 'v0' }, { id: 'v1' }, { id: 'v2' }],
57
+ relationship: ['d0', 'd1'],
58
+ series: true
59
+ },
60
+ {
61
+ id: 'a1',
62
+ values: [{ id: 'v0' }],
63
+ },
64
+ {
65
+ id: 'a2',
66
+ values: [{ id: 'v0' }, { id: 'v1' }],
67
+ relationship: []
68
+ },
69
+ {
70
+ id: 'a3',
71
+ values: [{ id: 'v0' }, { id: 'v1' }],
72
+ relationship: ['d2', 'd3'],
73
+ series: true
74
+ },
75
+ {
76
+ id: 'a4',
77
+ values: [{ id: 'v0' }, { id: 'v1', display: false }],
78
+ relationship: ['d4'],
79
+ series: true
80
+ },
81
+ ];
82
+
83
+ const dimensions = [
84
+ {
85
+ id: 'd0',
86
+ __index: 0,
87
+ values: [
88
+ { id: 'v0', __index: 0, __indexPosition: 0 },
89
+ { id: 'v1', __index: 1, __indexPosition: 1 },
90
+ { id: 'v2', __index: 2, __indexPosition: 2 },
91
+ { id: 'v3', __index: 3, __indexPosition: 3, display: false }
92
+ ]
93
+ },
94
+ {
95
+ id: 'd1',
96
+ __index: 1,
97
+ values: [
98
+ { id: 'v0', __index: 0, __indexPosition: 0 }
99
+ ]
100
+ },
101
+ {
102
+ id: 'd2',
103
+ __index: 2,
104
+ values: [
105
+ { id: 'v0', __index: 0, __indexPosition: 0 }
106
+ ]
107
+ },
108
+ {
109
+ id: 'd3',
110
+ __index: 3,
111
+ values: [
112
+ { id: 'v0', __index: 0, __indexPosition: 0 },
113
+ { id: 'v1', __index: 1, __indexPosition: 1 }
114
+ ]
115
+ },
116
+ {
117
+ id: 'd4',
118
+ __index: 4,
119
+ values: [
120
+ { id: 'v0', __index: 0, __indexPosition: 0 }
121
+ ]
122
+ }
123
+ ];
124
+
125
+
126
+ const observations = {
127
+ a: {
128
+ attrValuesIndexes: [0, 0, 0, 0, 0],
129
+ dimValuesIndexes: [0, 0, 0, 0, 0],
130
+ value: 22,
131
+ },
132
+ b: {
133
+ attrValuesIndexes: [1, 0, 1, 1, 0],
134
+ dimValuesIndexes: [0, 0, 0, 1, 0],
135
+ value: 17,
136
+ },
137
+ c: {
138
+ attrValuesIndexes: [2, 0, null, null, 0],
139
+ dimValuesIndexes: [1, 0, 0, 0, 0],
140
+ value: 55,
141
+ },
142
+ d: {
143
+ attrValuesIndexes: [2, 0, null, null, null],
144
+ dimValuesIndexes: [2, 0, 0, 0, 0],
145
+ value: 35,
146
+ },
147
+ e: {
148
+ attrValuesIndexes: [2, null, null, null, null],
149
+ dimValuesIndexes: [3, 0, 0, 0, 0],
150
+ value: 35,
151
+ }
152
+ };
153
+
154
+
155
+ expect(enhanceObservations(dimensions, observations, attributes, {})).to.deep.equal({
156
+ a: {
157
+ attrValuesIndexes: [0, 0, 0, 0, 0],
158
+ dimValuesIndexes: [0, 0, 0, 0, 0],
159
+ value: 22,
160
+ formattedValue: '22',
161
+ attributes: {
162
+ a0: { id: 'a0', relationship: ['d0', 'd1'], value: { id: 'v0' }, serieKey: 'd0=v0:d1=v0', coordinates: { d0: 'v0', d1: 'v0' }, isObs: false },
163
+ a3: { id: 'a3', relationship: ['d2', 'd3'], value: { id: 'v0' }, serieKey: 'd2=v0:d3=v0', coordinates: { d2: 'v0', d3: 'v0' }, isObs: false },
164
+ a4: { id: 'a4', relationship: ['d4'], value: { id: 'v0' }, serieKey: 'd4=v0', coordinates: { d4: 'v0' }, isObs: false },
165
+ },
166
+ indexedDimValIds: { d0: 'v0', d1: 'v0', d2: 'v0', d3: 'v0', d4: 'v0' }
167
+ },
168
+ b: {
169
+ attrValuesIndexes: [1, 0, 1, 1, 0],
170
+ dimValuesIndexes: [0, 0, 0, 1, 0],
171
+ value: 17,
172
+ formattedValue: '17',
173
+ attributes: {
174
+ a0: { id: 'a0', relationship: ['d0', 'd1'], value: { id: 'v1' }, serieKey: 'd0=v0:d1=v0', coordinates: { d0: 'v0', d1: 'v0' }, isObs: false },
175
+ a3: { id: 'a3', relationship: ['d2', 'd3'], value: { id: 'v1' }, serieKey: 'd2=v0:d3=v1', coordinates: { d2: 'v0', d3: 'v1' }, isObs: false },
176
+ a4: { id: 'a4', relationship: ['d4'], value: { id: 'v0' }, serieKey: 'd4=v0', coordinates: { d4: 'v0' }, isObs: false },
177
+ },
178
+ indexedDimValIds: { d0: 'v0', d1: 'v0', d2: 'v0', d3: 'v1', d4: 'v0' }
179
+ },
180
+ c: {
181
+ attrValuesIndexes: [2, 0, null, null, 0],
182
+ dimValuesIndexes: [1, 0, 0, 0, 0],
183
+ value: 55,
184
+ formattedValue: '55',
185
+ attributes: {
186
+ a0: { id: 'a0', relationship: ['d0', 'd1'], value: { id: 'v2' }, serieKey: 'd0=v1:d1=v0', coordinates: { d0: 'v1', d1: 'v0' }, isObs: false },
187
+ a3: { id: 'a3', relationship: ['d2', 'd3'], value: undefined, serieKey: 'd2=v0:d3=v0', coordinates: { d2: 'v0', d3: 'v0' }, isObs: false },
188
+ a4: { id: 'a4', relationship: ['d4'], value: { id: 'v0' }, serieKey: 'd4=v0', coordinates: { d4: 'v0' }, isObs: false },
189
+ },
190
+ indexedDimValIds: { d0: 'v1', d1: 'v0', d2: 'v0', d3: 'v0', d4: 'v0' }
191
+ },
192
+ d: {
193
+ attrValuesIndexes: [2, 0, null, null, null],
194
+ dimValuesIndexes: [2, 0, 0, 0, 0],
195
+ value: 35,
196
+ formattedValue: '35',
197
+ attributes: {
198
+ a0: { id: 'a0', relationship: ['d0', 'd1'], value: { id: 'v2' }, serieKey: 'd0=v2:d1=v0', coordinates: { d0: 'v2', d1: 'v0' }, isObs: false },
199
+ a3: { id: 'a3', relationship: ['d2', 'd3'], value: undefined, serieKey: 'd2=v0:d3=v0', coordinates: { d2: 'v0', d3: 'v0' }, isObs: false },
200
+ a4: { id: 'a4', relationship: ['d4'], value: undefined, serieKey: 'd4=v0', coordinates: { d4: 'v0' }, isObs: false },
201
+ },
202
+ indexedDimValIds: { d0: 'v2', d1: 'v0', d2: 'v0', d3: 'v0', d4: 'v0' }
203
+ },
204
+ e: {
205
+ attrValuesIndexes: [2, null, null, null, null],
206
+ dimValuesIndexes: [3, 0, 0, 0, 0],
207
+ value: 35,
208
+ formattedValue: '35',
209
+ attributes: {
210
+ a0: { id: 'a0', relationship: ['d0', 'd1'], value: { id: 'v2' }, serieKey: 'd0=v3:d1=v0', coordinates: { d0: 'v3', d1: 'v0' }, isObs: false },
211
+ a3: { id: 'a3', relationship: ['d2', 'd3'], value: undefined, serieKey: 'd2=v0:d3=v0', coordinates: { d2: 'v0', d3: 'v0' }, isObs: false },
212
+ a4: { id: 'a4', relationship: ['d4'], value: undefined, serieKey: 'd4=v0', coordinates: { d4: 'v0' }, isObs: false },
213
+ },
214
+ indexedDimValIds: { d0: 'v3', d1: 'v0', d2: 'v0', d3: 'v0', d4: 'v0' }
215
+ }
216
+ });
217
+ });
218
+ });
219
+