@sis-cc/dotstatsuite-components 9.1.0 → 9.2.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 (80) hide show
  1. package/lib/rules/src/preparators/enhanceObservations.js +155 -0
  2. package/lib/rules/src/preparators/formatValue.js +77 -0
  3. package/lib/rules/src/preparators/getDimensions.js +55 -0
  4. package/lib/rules/src/preparators/getDisplay.js +32 -0
  5. package/lib/rules/src/preparators/getObservations.js +27 -0
  6. package/lib/rules/src/table/factories/getCells.js +1 -3
  7. package/lib/rules/src/table/factories/getLayoutData.js +102 -161
  8. package/lib/rules/src/table/factories/getSortedLayoutIndexes.js +118 -0
  9. package/lib/rules/src/table/factories/getTableData.js +12 -10
  10. package/lib/rules/src/table/factories/refineLayoutSize.js +210 -0
  11. package/lib/rules/src/table/preparators/prepareData.js +23 -23
  12. package/lib/rules/src/table/units/appendUnitsInLayoutDataEntry.js +10 -10
  13. package/lib/rules/src/table/units/getAttachmentSeriesIndexes.js +1 -1
  14. package/lib/rules/src/table/units/getUnitsSeries.js +31 -0
  15. package/lib/rules/src/v8-transformer.js +3 -2
  16. package/package.json +2 -2
  17. package/src/rules/src/preparators/enhanceObservations.js +163 -0
  18. package/src/rules/src/preparators/formatValue.js +73 -0
  19. package/src/rules/src/preparators/getDimensions.js +49 -0
  20. package/src/rules/src/preparators/getDisplay.js +20 -0
  21. package/src/rules/src/preparators/getObservations.js +19 -0
  22. package/src/rules/src/table/factories/getCells.js +3 -7
  23. package/src/rules/src/table/factories/getLayoutData.js +135 -184
  24. package/src/rules/src/table/factories/getSortedLayoutIndexes.js +108 -0
  25. package/src/rules/src/table/factories/getTableData.js +10 -10
  26. package/src/rules/src/table/factories/refineLayoutSize.js +224 -0
  27. package/src/rules/src/table/preparators/prepareData.js +23 -32
  28. package/src/rules/src/table/units/appendUnitsInLayoutDataEntry.js +15 -18
  29. package/src/rules/src/table/units/getAttachmentSeriesIndexes.js +2 -1
  30. package/src/rules/src/table/units/getUnitsSeries.js +20 -0
  31. package/src/rules/src/v8-transformer.js +4 -2
  32. package/test/appendUnitsInLayoutDataEntry.test.js +3 -3
  33. package/test/enhanceObservations.test.js +270 -0
  34. package/test/getAttachmentSeriesIndexes.test.js +1 -1
  35. package/test/getCells.test.js +4 -39
  36. package/test/getLayoutData2.test.js +194 -0
  37. package/test/getOneValueDimensions.test.js +1 -1
  38. package/test/getSortedLayoutIndexes.test.js +80 -0
  39. package/test/getUnitsArtefacts.test.js +1 -1
  40. package/test/getUnitsSeries.test.js +64 -0
  41. package/test/mocks/table-layout-multi-hierarchies--layout.json +621 -0
  42. package/test/mocks/table-layout-multi-hierarchies--layoutData.json +32410 -0
  43. package/test/mocks/table-layout-multi-hierarchies--layoutIndexes.json +2760 -0
  44. package/test/mocks/table-layout-multi-hierarchies--observations.json +30688 -0
  45. package/test/mocks/table-layout-multi-hierarchies--sizedIndexes.json +2761 -0
  46. package/test/mocks/table-layout-truncation1--layout.json +27469 -0
  47. package/test/mocks/table-layout-truncation1--layoutData.json +19413 -0
  48. package/test/mocks/table-layout-truncation1--layoutIndexes.json +7512 -0
  49. package/test/mocks/table-layout-truncation1--observations.json +70002 -0
  50. package/test/mocks/table-layout-truncation1--sizedIndexes.json +3010 -0
  51. package/test/mocks/table-prep-multi-hierarchies--attributes.json +44 -0
  52. package/test/mocks/table-prep-multi-hierarchies--dimensions.json +688 -0
  53. package/test/mocks/table-prep-multi-hierarchies--enhancedObservations.json +19696 -0
  54. package/test/mocks/table-prep-multi-hierarchies--observations.json +8246 -0
  55. package/test/mocks/table-prep-multi-hierarchies--sdmxJson.json +2985 -0
  56. package/test/mocks/table-prep-truncation1--dimensions.json +35057 -0
  57. package/test/mocks/table-prep-truncation1--enhancedObservations.json +70002 -0
  58. package/test/mocks/table-prep-truncation1--observations.json +27502 -0
  59. package/test/mocks/table-prep-truncation1--sdmxJson.json +55103 -0
  60. package/test/mocks/table-prep-units--observations.json +284286 -0
  61. package/test/mocks/table-prep-units--unitsSeries.json +41042 -0
  62. package/test/parseAttributes.test.js +1 -1
  63. package/test/refineLayoutSize.test.js +415 -0
  64. package/test/table-layout-perf.test.js +74 -0
  65. package/test/table-prep-perf.test.js +65 -0
  66. package/lib/rules/src/table/factories/getSortedLayoutData.js +0 -145
  67. package/lib/rules/src/table/factories/refineLayoutHierarchy.js +0 -61
  68. package/lib/rules/src/table/preparators/parseObservations.js +0 -76
  69. package/lib/rules/src/table/units/getUnitsSeriesOccurences.js +0 -39
  70. package/src/rules/src/table/factories/getSortedLayoutData.js +0 -133
  71. package/src/rules/src/table/factories/refineLayoutHierarchy.js +0 -64
  72. package/src/rules/src/table/preparators/parseObservations.js +0 -81
  73. package/src/rules/src/table/units/getUnitsSeriesOccurences.js +0 -51
  74. package/test/appendUnitsInLayoutData.test.js +0 -248
  75. package/test/getLayoutData.test.js +0 -311
  76. package/test/getSortedLayoutData.test.js +0 -382
  77. package/test/getUnitsSeriesOccurences.test.js +0 -133
  78. package/test/parseObservations.test.js +0 -116
  79. package/test/refineDimSeriesUnits.test.js +0 -24
  80. package/test/refineLayoutHierarchy.test.js +0 -79
@@ -0,0 +1,270 @@
1
+ import { expect } from 'chai';
2
+ import { enhanceObservations } from '../src/rules/src/preparators/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('orderedDimIndexes test', () => {
11
+ const dimensions = [
12
+ { id: 'D1', values: [{ id: 'v1', __indexPosition: 2 }, { id: 'v2', __indexPosition: 0 }, { id: 'v3', __indexPosition: 1 }] },
13
+ { id: 'D2', values: [{ id: 'v1', __indexPosition: 1 }, { id: 'v2', __indexPosition: 2 }, { id: 'v3', __indexPosition: 0 }] },
14
+ { id: 'D3', values: [{ id: 'v1', __indexPosition: 0 }] }
15
+ ];
16
+ const observations = {
17
+ a: { dimValuesIndexes: [0, 0, 0], value: '1' },
18
+ b: { dimValuesIndexes: [0, 1, 0], value: '2' },
19
+ c: { dimValuesIndexes: [0, 2, 0], value: '3' },
20
+ d: { dimValuesIndexes: [1, 0, 0], value: '4' },
21
+ e: { dimValuesIndexes: [1, 1, 0], value: '5' },
22
+ f: { dimValuesIndexes: [1, 2, 0], value: '6' },
23
+ g: { dimValuesIndexes: [2, 0, 0], value: '7' },
24
+ h: { dimValuesIndexes: [2, 1, 0], value: '8' },
25
+ i: { dimValuesIndexes: [2, 2, 0], value: '9' }
26
+ };
27
+ expect(enhanceObservations(dimensions, observations, [], {})).to.deep.equal({
28
+ a: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [0, 0, 0], orderedDimIndexes: [2, 1, 0], value: '1', formattedValue: '1', indexedDimValIds: { D1: 'v1', D2: 'v1', D3: 'v1' } },
29
+ b: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [0, 1, 0], orderedDimIndexes: [2, 2, 0], value: '2', formattedValue: '2', indexedDimValIds: { D1: 'v1', D2: 'v2', D3: 'v1' } },
30
+ c: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [0, 2, 0], orderedDimIndexes: [2, 0, 0], value: '3', formattedValue: '3', indexedDimValIds: { D1: 'v1', D2: 'v3', D3: 'v1' } },
31
+ d: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [1, 0, 0], orderedDimIndexes: [0, 1, 0], value: '4', formattedValue: '4', indexedDimValIds: { D1: 'v2', D2: 'v1', D3: 'v1' } },
32
+ e: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [1, 1, 0], orderedDimIndexes: [0, 2, 0], value: '5', formattedValue: '5', indexedDimValIds: { D1: 'v2', D2: 'v2', D3: 'v1' } },
33
+ f: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [1, 2, 0], orderedDimIndexes: [0, 0, 0], value: '6', formattedValue: '6', indexedDimValIds: { D1: 'v2', D2: 'v3', D3: 'v1' } },
34
+ g: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [2, 0, 0], orderedDimIndexes: [1, 1, 0], value: '7', formattedValue: '7', indexedDimValIds: { D1: 'v3', D2: 'v1', D3: 'v1' } },
35
+ h: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [2, 1, 0], orderedDimIndexes: [1, 2, 0], value: '8', formattedValue: '8', indexedDimValIds: { D1: 'v3', D2: 'v2', D3: 'v1' } },
36
+ i: { attributes: {}, units: { serieKey: 'x:x:x' }, dimValuesIndexes: [2, 2, 0], orderedDimIndexes: [1, 0, 0], value: '9', formattedValue: '9', indexedDimValIds: { D1: 'v3', D2: 'v3', D3: 'v1' } }
37
+ });
38
+ });
39
+
40
+ it('formatValue test', () => {
41
+ numeral.locale('eObs');
42
+ const attributes = [
43
+ { id: 'A1', values: [] },
44
+ { id: 'A2', values: [{ id: '-1' }, { id: '0' }, { id: '1' }, { id: '3' }, { id: 'Z' }] },
45
+ { id: 'A3', values: [{ id: '0' }, { id: '2' }, { id: '3' }, { id: '5' }, { id: 'A' }] }
46
+ ];
47
+
48
+ const customAttributes = { prefscale: 'A2', decimals: 'A3' };
49
+
50
+ const observations = {
51
+ a: { value: 2, attrValuesIndexes: [null, null, null], dimValuesIndexes: [] },
52
+ c: { value: 10, attrValuesIndexes: [null, 4, null], dimValuesIndexes: [] },
53
+ d: { value: 5, attrValuesIndexes: [null, 1, null], dimValuesIndexes: [] },
54
+ e: { value: 8.3, attrValuesIndexes: [null, 0, null], dimValuesIndexes: [] },
55
+ f: { value: 25.62, attrValuesIndexes: [null, 3, null], dimValuesIndexes: [] },
56
+ g: { value: 3.7, attrValuesIndexes: [null, null, 4], dimValuesIndexes: [] },
57
+ h: { value: 21.1234567, attrValuesIndexes: [null, null, 2], dimValuesIndexes: [] },
58
+ i: { value: 20.1, attrValuesIndexes: [null, null, 3], dimValuesIndexes: [] },
59
+ j: { value: 19.9, attrValuesIndexes: [null, null, 0], dimValuesIndexes: [] },
60
+ k: { value: 16.35, attrValuesIndexes: [null, 2, 1], dimValuesIndexes: [] },
61
+ l: { value: 155062.56, attrValuesIndexes: [null, null, 2], dimValuesIndexes: [] },
62
+ m: { value: 155062.56, attrValuesIndexes: [null, null, 0], dimValuesIndexes: [] },
63
+ n: { value: null, attrValuesIndexes: [null, null, 1], dimValuesIndexes: [] },
64
+ };
65
+
66
+ expect(enhanceObservations([], observations, attributes, { customAttributes })).to.deep.equal({
67
+ a: { attributes: {}, units: { serieKey: '' }, value: 2, formattedValue: '2', attrValuesIndexes: [null, null, null], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
68
+ c: { attributes: {}, units: { serieKey: '' }, value: 10, formattedValue: '10', attrValuesIndexes: [null, 4, null], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
69
+ d: { attributes: {}, units: { serieKey: '' }, value: 5, formattedValue: '5', attrValuesIndexes: [null, 1, null], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
70
+ e: { attributes: {}, units: { serieKey: '' }, value: 8.3, formattedValue: '83', attrValuesIndexes: [null, 0, null], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
71
+ f: { attributes: {}, units: { serieKey: '' }, value: 25.62, formattedValue: '0.02562', attrValuesIndexes: [null, 3, null], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
72
+ g: { attributes: {}, units: { serieKey: '' }, value: 3.7, formattedValue: '3.7', attrValuesIndexes: [null, null, 4], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
73
+ h: { attributes: {}, units: { serieKey: '' }, value: 21.1234567, formattedValue: '21.123', attrValuesIndexes: [null, null, 2], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
74
+ i: { attributes: {}, units: { serieKey: '' }, value: 20.1, formattedValue: '20.10000', attrValuesIndexes: [null, null, 3], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
75
+ j: { attributes: {}, units: { serieKey: '' }, value: 19.9, formattedValue: '20', attrValuesIndexes: [null, null, 0], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
76
+ k: { attributes: {}, units: { serieKey: '' }, value: 16.35, formattedValue: '1.64', attrValuesIndexes: [null, 2, 1], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
77
+ l: { attributes: {}, units: { serieKey: '' }, value: 155062.56, formattedValue: '155,062.560', attrValuesIndexes: [null, null, 2], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
78
+ m: { attributes: {}, units: { serieKey: '' }, value: 155062.56, formattedValue: '155,063', attrValuesIndexes: [null, null, 0], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
79
+ n: { attributes: {}, units: { serieKey: '' }, value: null, formattedValue: '..', attrValuesIndexes: [null, null, 1], dimValuesIndexes: [], orderedDimIndexes: [], indexedDimValIds: {} },
80
+ });
81
+ });
82
+
83
+ it('attributes and units test', () => {
84
+ const attributes = [
85
+ {
86
+ id: 'a0',
87
+ values: [{ id: 'v0' }, { id: 'v1' }, { id: 'v2' }],
88
+ },
89
+ {
90
+ id: 'a1',
91
+ values: [{ id: 'v0' }],
92
+ },
93
+ {
94
+ id: 'a2',
95
+ values: [{ id: 'v0' }, { id: 'v1' }],
96
+ },
97
+ {
98
+ id: 'a3',
99
+ values: [{ id: 'v0' }, { id: 'v1' }],
100
+ },
101
+ {
102
+ id: 'a4',
103
+ values: [{ id: 'v0' }, { id: 'v1' }],
104
+ },
105
+ ];
106
+
107
+ const dimensions = [
108
+ {
109
+ id: 'd0',
110
+ __index: 0,
111
+ values: [
112
+ { id: 'v0', __index: 0, __indexPosition: 0 },
113
+ { id: 'v1', __index: 1, __indexPosition: 1 },
114
+ { id: 'v2', __index: 2, __indexPosition: 2 },
115
+ { id: 'v3', __index: 3, __indexPosition: 3 }
116
+ ]
117
+ },
118
+ {
119
+ id: 'd1',
120
+ __index: 1,
121
+ values: [
122
+ { id: 'v0', __index: 0, __indexPosition: 0 }
123
+ ]
124
+ },
125
+ {
126
+ id: 'd2',
127
+ __index: 2,
128
+ values: [
129
+ { id: 'v0', __index: 0, __indexPosition: 0 }
130
+ ]
131
+ },
132
+ {
133
+ id: 'd3',
134
+ __index: 3,
135
+ values: [
136
+ { id: 'v0', __index: 0, __indexPosition: 0 },
137
+ { id: 'v1', __index: 1, __indexPosition: 1 }
138
+ ]
139
+ },
140
+ {
141
+ id: 'd4',
142
+ __index: 4,
143
+ values: [
144
+ { id: 'v0', __index: 0, __indexPosition: 0 }
145
+ ]
146
+ }
147
+ ];
148
+
149
+
150
+ const observations = {
151
+ a: {
152
+ attrValuesIndexes: [0, 0, 0, 0, 0],
153
+ dimValuesIndexes: [0, 0, 0, 0, 0],
154
+ value: 22,
155
+ },
156
+ b: {
157
+ attrValuesIndexes: [1, 0, 1, 1, 0],
158
+ dimValuesIndexes: [0, 0, 0, 1, 0],
159
+ value: 17,
160
+ },
161
+ c: {
162
+ attrValuesIndexes: [2, 0, null, null, 0],
163
+ dimValuesIndexes: [1, 0, 0, 0, 0],
164
+ value: 55,
165
+ },
166
+ d: {
167
+ attrValuesIndexes: [2, 0, null, null, 1],
168
+ dimValuesIndexes: [2, 0, 0, 0, 0],
169
+ value: 35,
170
+ },
171
+ e: {
172
+ attrValuesIndexes: [2, null, null, null, null],
173
+ dimValuesIndexes: [3, 0, 0, 0, 0],
174
+ value: 35,
175
+ }
176
+ };
177
+
178
+ const options = {
179
+ noDisplayIndexes: [],
180
+ notDisplayedCodes: {
181
+ d0: { values: { v3: 'v3' } },
182
+ a4: { values: { v1: 'v1' } }
183
+ },
184
+ attributesIds: ['a0', 'a1'],
185
+ unitsIds: ['d0', 'a4'],
186
+ };
187
+
188
+ expect(enhanceObservations(dimensions, observations, attributes, options)).to.deep.equal({
189
+ a: {
190
+ attrValuesIndexes: [0, 0, 0, 0, 0],
191
+ dimValuesIndexes: [0, 0, 0, 0, 0],
192
+ orderedDimIndexes: [0, 0, 0, 0, 0],
193
+ value: 22,
194
+ formattedValue: '22',
195
+ units: {
196
+ d0: { id: 'd0', __index: 0, value: { id: 'v0', index: 0, __index: 0, __indexPosition: 0 } },
197
+ a4: { id: 'a4', __index: 4, value: { id: 'v0', index: 0 } },
198
+ serieKey: 'x:x:x:x:x'
199
+ },
200
+ attributes: {
201
+ a0: { id: 'a0', value: { id: 'v0' } },
202
+ a1: { id: 'a1', value: { id: 'v0' } }
203
+ },
204
+ indexedDimValIds: { d0: 'v0', d1: 'v0', d2: 'v0', d3: 'v0', d4: 'v0' }
205
+ },
206
+ b: {
207
+ attrValuesIndexes: [1, 0, 1, 1, 0],
208
+ dimValuesIndexes: [0, 0, 0, 1, 0],
209
+ orderedDimIndexes: [0, 0, 0, 1, 0],
210
+ value: 17,
211
+ formattedValue: '17',
212
+ units: {
213
+ d0: { id: 'd0', __index: 0, value: { id: 'v0', index: 0, __index: 0, __indexPosition: 0 } },
214
+ a4: { id: 'a4', __index: 4, value: { id: 'v0', index: 0 } },
215
+ serieKey: 'x:x:x:x:x'
216
+ },
217
+ attributes: {
218
+ a0: { id: 'a0', value: { id: 'v1' } },
219
+ a1: { id: 'a1', value: { id: 'v0' } }
220
+ },
221
+ indexedDimValIds: { d0: 'v0', d1: 'v0', d2: 'v0', d3: 'v1', d4: 'v0' }
222
+ },
223
+ c: {
224
+ attrValuesIndexes: [2, 0, null, null, 0],
225
+ dimValuesIndexes: [1, 0, 0, 0, 0],
226
+ orderedDimIndexes: [1, 0, 0, 0, 0],
227
+ value: 55,
228
+ formattedValue: '55',
229
+ units: {
230
+ d0: { id: 'd0', __index: 0, value: { id: 'v1', index: 1, __index: 1, __indexPosition: 1 } },
231
+ a4: { id: 'a4', __index: 4, value: { id: 'v0', index: 0 } },
232
+ serieKey: 'x:x:x:x:x'
233
+ },
234
+ attributes: {
235
+ a0: { id: 'a0', value: { id: 'v2' } },
236
+ a1: { id: 'a1', value: { id: 'v0' } }
237
+ },
238
+ indexedDimValIds: { d0: 'v1', d1: 'v0', d2: 'v0', d3: 'v0', d4: 'v0' }
239
+ },
240
+ d: {
241
+ attrValuesIndexes: [2, 0, null, null, 1],
242
+ dimValuesIndexes: [2, 0, 0, 0, 0],
243
+ orderedDimIndexes: [2, 0, 0, 0, 0],
244
+ value: 35,
245
+ formattedValue: '35',
246
+ units: {
247
+ d0: { id: 'd0', __index: 0, value: { id: 'v2', index: 2, __index: 2, __indexPosition: 2 } },
248
+ serieKey: 'x:x:x:x:x'
249
+ },
250
+ attributes: {
251
+ a0: { id: 'a0', value: { id: 'v2' } },
252
+ a1: { id: 'a1', value: { id: 'v0' } }
253
+ },
254
+ indexedDimValIds: { d0: 'v2', d1: 'v0', d2: 'v0', d3: 'v0', d4: 'v0' }
255
+ },
256
+ e: {
257
+ attrValuesIndexes: [2, null, null, null, null],
258
+ dimValuesIndexes: [3, 0, 0, 0, 0],
259
+ orderedDimIndexes: [3, 0, 0, 0, 0],
260
+ value: 35,
261
+ formattedValue: '35',
262
+ units: { serieKey: 'x:x:x:x:x' },
263
+ attributes: {
264
+ a0: { id: 'a0', value: { id: 'v2' } }
265
+ },
266
+ indexedDimValIds: { d0: 'v3', d1: 'v0', d2: 'v0', d3: 'v0', d4: 'v0' }
267
+ }
268
+ });
269
+ });
270
+ });
@@ -30,6 +30,6 @@ describe('getAttachmentSeriesIndexes test', () => {
30
30
  });
31
31
  it('basic test', () => {
32
32
  expect(getAttachmentSeriesIndexes({ dimensions, unitsArtefacts }))
33
- .to.deep.equal([0, 3, 2]);
33
+ .to.deep.equal([0, 2, 3]);
34
34
  });
35
35
  });
@@ -8,49 +8,13 @@ const customAttributes = {
8
8
  footnotes: ['FT1', 'FT2', 'FT3']
9
9
  };
10
10
 
11
- const data = {
12
- observations: {
13
- a: { value: 2, units: {}, indexedDimValIds: {} },
14
- b: { value: 0, units: {}, attributes: { T: { id: 'T', name: 'Toto', value: { id: 'A', name: 'Africa' } } }, indexedDimValIds: {} },
15
- c: { value: 10, units: {}, prefscale: 'Z', indexedDimValIds: {} },
16
- d: { value: 5, units: {}, prefscale: '0', indexedDimValIds: {} },
17
- e: { value: 8.3, units: {}, prefscale: '-1', indexedDimValIds: {} },
18
- f: { value: 25.62, units: {}, prefscale: '3', indexedDimValIds: {} },
19
- g: { value: 3.7, units: {}, decimals: 'AB', indexedDimValIds: {} },
20
- h: { value: 21.1234567, units: {}, decimals: '3', indexedDimValIds: {} },
21
- i: { value: 20.1, units: {}, decimals: '5', indexedDimValIds: {} },
22
- j: { value: 19.9, units: {}, decimals: '0', indexedDimValIds: {} },
23
- k: { value: 16.35, units: {}, decimals: '2', prefscale: '1', indexedDimValIds: {} },
24
- l: { value: 155062.56, units: {}, decimals: '3', indexedDimValIds: {} },
25
- m: { value: 155062.56, units: {}, decimals: '0', indexedDimValIds: {} },
26
- n: { value: null, units: {}, indexedDimValIds: {} },
27
- }
28
- };
29
-
30
11
  describe('getCells tests', () => {
31
- it('value format tests', () => {
32
- expect(getCells(data, 'label', customAttributes)).to.deep.equal({
33
- a: { value: '2', intValue: 2, flags: [], indexedDimValIds: {} },
34
- b: { value: '0', intValue: 0, flags: [{ label: 'Toto: Africa' }], indexedDimValIds: {} },
35
- c: { value: '10', intValue: 10, flags: [], indexedDimValIds: {} },
36
- d: { value: '5', intValue: 5, flags: [], indexedDimValIds: {} },
37
- e: { value: '83', intValue: 8.3, flags: [], indexedDimValIds: {} },
38
- f: { value: '0.02562', intValue: 25.62, flags: [], indexedDimValIds: {} },
39
- g: { value: '3.7', intValue: 3.7, flags: [], indexedDimValIds: {} },
40
- h: { value: '21.123', intValue: 21.1234567, flags: [], indexedDimValIds: {} },
41
- i: { value: '20.10000', intValue: 20.1, flags: [], indexedDimValIds: {} },
42
- j: { value: '20', intValue: 19.9, flags: [], indexedDimValIds: {} },
43
- k: { value: '1.64', intValue: 16.35, flags: [], indexedDimValIds: {} },
44
- l: { value: '155,062.560', intValue: 155062.56, flags: [], indexedDimValIds: {} },
45
- m: { value: '155,063', intValue: 155062.56, flags: [], indexedDimValIds: {} },
46
- n: { value: '..', intValue: null, flags: [], indexedDimValIds: {} },
47
- });
48
- });
49
12
  it('flags display name', () => {
50
13
  expect(getCells({
51
14
  observations: {
52
15
  a: {
53
16
  value: 33,
17
+ formattedValue: '33',
54
18
  attributes: {
55
19
  FL2: { id: 'FL2', name: 'Flag 2', value: { id: 'FL2.1', name: 'Flag 2 Value 1' } },
56
20
  FT1: { id: 'FT1', name: 'Footnote 1', value: { id: 'FT1.1', name: 'Footnote 1 Value 1' } },
@@ -78,6 +42,7 @@ describe('getCells tests', () => {
78
42
  observations: {
79
43
  a: {
80
44
  value: 33,
45
+ formattedValue: '33',
81
46
  attributes: {
82
47
  FL2: { id: 'FL2', name: 'Flag 2', value: { id: 'FL2.1', name: 'Flag 2 Value 1' } },
83
48
  FT1: { id: 'FT1', name: 'Footnote 1', value: { id: 'FT1.1', name: 'Footnote 1 Value 1' } },
@@ -99,7 +64,7 @@ describe('getCells tests', () => {
99
64
  }
100
65
  })
101
66
  });
102
- it('string observation type display test', () => {
67
+ /*it('string observation type display test', () => {
103
68
  expect(getCells({
104
69
  observations: {
105
70
  a: { value: '16.35', units: {}, decimals: '2', prefscale: '1', indexedDimValIds: {} },
@@ -109,5 +74,5 @@ describe('getCells tests', () => {
109
74
  a: { value: '16.35', intValue: '16.35', flags: [], indexedDimValIds: {} },
110
75
  b: { value: '155062.56', intValue: '155062.56', flags: [], indexedDimValIds: {} },
111
76
  })
112
- });
77
+ });*/
113
78
  });
@@ -0,0 +1,194 @@
1
+ import { expect } from 'chai';
2
+ import { getLayoutData } from '../src/rules/src/table/factories/getLayoutData';
3
+
4
+ describe('getLayoutData2 tests', () => {
5
+ it ('simple single row diension case', () => {
6
+ const layout = {
7
+ header: [],
8
+ sections: [],
9
+ rows: [{ id: 'd0', values: [{ id: '0v0' }, { id: '0v1' }] }]
10
+ };
11
+
12
+ const indexes = {
13
+ truncated: false,
14
+ header: [],
15
+ sections: [[[], [[0], [1]]]]
16
+ };
17
+
18
+ const expected = {
19
+ truncated: false,
20
+ headerData: [],
21
+ sectionsData: [
22
+ [
23
+ [],
24
+ [[{ dimension: { id: 'd0' }, value: { id: '0v0' } }], [{ dimension: { id: 'd0' }, value: { id: '0v1' } }]]
25
+ ]
26
+ ]
27
+ };
28
+
29
+ expect(getLayoutData(indexes, layout)).to.deep.equal(expected);
30
+ });
31
+ it('complete case', () => {
32
+ const layout = {
33
+ header: [{ id: 'd0', values: [{ id: '0v0' }, { id: '0v1' }] }],
34
+ sections: [{ id: 'd1', values: [{ id: '1v0' }, { id: '1v1' }] }],
35
+ rows: [
36
+ {
37
+ id: 'd2', values: [
38
+ { id: '2v0', name: '2V0' },
39
+ { id: '2v0.0', name: '2V0.0', parents: ['2v0'] },
40
+ { id: '2v0.0.0', name: '2V0.0.0', parents: ['2v0', '2v0.0'] },
41
+ { id: '2v0.0.1', name: '2V0.0.1', parents: ['2v0', '2v0.0'] }
42
+ ]
43
+ },
44
+ {
45
+ id: 'd3', values: [
46
+ { id: '3v0', name: '3V0' },
47
+ { id: '3v0.0', name: '3V0.0', parents: ['3v0'] },
48
+ { id: '3v0.0.0', name: '3V0.0.0', parents: ['3v0', '3v0.0'] },
49
+ { id: '3v0.0.1', name: '3V0.0.1', parents: ['3v0', '3v0.0'] }
50
+ ]
51
+ },
52
+ ]
53
+ };
54
+
55
+ const indexes = {
56
+ truncated: false,
57
+ header: [[0], [1]],
58
+ sections: [
59
+ [
60
+ [0],
61
+ [
62
+ [0, 0],
63
+ [0, 1],
64
+ [0, 2],
65
+ [0, 3],
66
+ [1, 0],
67
+ [1, 1],
68
+ [1, 2],
69
+ [1, 3],
70
+ [2, 0],
71
+ [2, 1],
72
+ [2, 2],
73
+ [2, 3],
74
+ [3, 0],
75
+ [3, 1],
76
+ [3, 2],
77
+ [3, 3]
78
+ ]
79
+ ],
80
+ [
81
+ [1],
82
+ [
83
+ [0, 1],
84
+ [0, 2],
85
+ [0, 3],
86
+ [3, 3]
87
+ ]
88
+ ]
89
+ ]
90
+ }
91
+
92
+ const expected = {
93
+ truncated: false,
94
+ headerData: [
95
+ [{ dimension: { id: 'd0' }, value: { id: '0v0' } }],
96
+ [{ dimension: { id: 'd0' }, value: { id: '0v1' } }],
97
+ ],
98
+ sectionsData: [
99
+ [
100
+ [{ dimension: { id: 'd1' }, value: { id: '1v0' } }],
101
+ [
102
+ [
103
+ { dimension: { id: 'd2' }, value: { id: '2v0', name: '2V0' } },
104
+ { dimension: { id: 'd3' }, value: { id: '3v0', name: '3V0' } }
105
+ ],
106
+ [
107
+ { dimension: { id: 'd2' }, value: { id: '2v0', name: '2V0' } },
108
+ { dimension: { id: 'd3' }, value: { id: '3v0.0', name: '3V0.0', parents: ['3v0'] } }
109
+ ],
110
+ [
111
+ { dimension: { id: 'd2' }, value: { id: '2v0', name: '2V0' } },
112
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.0', name: '3V0.0.0', parents: ['3v0', '3v0.0'] } }
113
+ ],
114
+ [
115
+ { dimension: { id: 'd2' }, value: { id: '2v0', name: '2V0' } },
116
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.1', name: '3V0.0.1', parents: ['3v0', '3v0.0'] } }
117
+ ],
118
+ [
119
+ { dimension: { id: 'd2' }, value: { id: '2v0.0', name: '2V0.0', parents: ['2v0'] } },
120
+ { dimension: { id: 'd3' }, value: { id: '3v0', name: '3V0' } }
121
+ ],
122
+ [
123
+ { dimension: { id: 'd2' }, value: { id: '2v0.0', name: '2V0.0', parents: ['2v0'] } },
124
+ { dimension: { id: 'd3' }, value: { id: '3v0.0', name: '3V0.0', parents: ['3v0'] } }
125
+ ],
126
+ [
127
+ { dimension: { id: 'd2' }, value: { id: '2v0.0', name: '2V0.0', parents: ['2v0'] } },
128
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.0', name: '3V0.0.0', parents: ['3v0', '3v0.0'] } }
129
+ ],
130
+ [
131
+ { dimension: { id: 'd2' }, value: { id: '2v0.0', name: '2V0.0', parents: ['2v0'] } },
132
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.1', name: '3V0.0.1', parents: ['3v0', '3v0.0'] } }
133
+ ],
134
+ [
135
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.0', name: '2V0.0.0', parents: ['2v0', '2v0.0'] } },
136
+ { dimension: { id: 'd3' }, value: { id: '3v0', name: '3V0' } }
137
+ ],
138
+ [
139
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.0', name: '2V0.0.0', parents: ['2v0', '2v0.0'] } },
140
+ { dimension: { id: 'd3' }, value: { id: '3v0.0', name: '3V0.0', parents: ['3v0'] } }
141
+ ],
142
+ [
143
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.0', name: '2V0.0.0', parents: ['2v0', '2v0.0'] } },
144
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.0', name: '3V0.0.0', parents: ['3v0', '3v0.0'] } }
145
+ ],
146
+ [
147
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.0', name: '2V0.0.0', parents: ['2v0', '2v0.0'] } },
148
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.1', name: '3V0.0.1', parents: ['3v0', '3v0.0'] } }
149
+ ],
150
+ [
151
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.1', name: '2V0.0.1', parents: ['2v0', '2v0.0'] } },
152
+ { dimension: { id: 'd3' }, value: { id: '3v0', name: '3V0' } }
153
+ ],
154
+ [
155
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.1', name: '2V0.0.1', parents: ['2v0', '2v0.0'] } },
156
+ { dimension: { id: 'd3' }, value: { id: '3v0.0', name: '3V0.0', parents: ['3v0'] } }
157
+ ],
158
+ [
159
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.1', name: '2V0.0.1', parents: ['2v0', '2v0.0'] } },
160
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.0', name: '3V0.0.0', parents: ['3v0', '3v0.0'] } }
161
+ ],
162
+ [
163
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.1', name: '2V0.0.1', parents: ['2v0', '2v0.0'] } },
164
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.1', name: '3V0.0.1', parents: ['3v0', '3v0.0'] } }
165
+ ]
166
+ ]
167
+ ],
168
+ [
169
+ [{ dimension: { id: 'd1' }, value: { id: '1v1' } }],
170
+ [
171
+ [
172
+ { dimension: { id: 'd2' }, value: { id: '2v0', name: '2V0' } },
173
+ { dimension: { id: 'd3' }, value: { id: '3v0.0', name: '3V0 > 3V0.0', parents: [] } }
174
+ ],
175
+ [
176
+ { dimension: { id: 'd2' }, value: { id: '2v0', name: '2V0' } },
177
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.0', name: '3V0.0.0', parents: ['3v0.0'] } }
178
+ ],
179
+ [
180
+ { dimension: { id: 'd2' }, value: { id: '2v0', name: '2V0' } },
181
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.1', name: '3V0.0.1', parents: ['3v0.0'] } }
182
+ ],
183
+ [
184
+ { dimension: { id: 'd2' }, value: { id: '2v0.0.1', name: '2V0.0 > 2V0.0.1', parents: ['2v0'] } },
185
+ { dimension: { id: 'd3' }, value: { id: '3v0.0.1', name: '3V0 > 3V0.0 > 3V0.0.1', parents: [] } }
186
+ ]
187
+ ]
188
+ ]
189
+ ]
190
+ }
191
+
192
+ expect(getLayoutData(indexes, layout)).to.deep.equal(expected);
193
+ });
194
+ });
@@ -1,6 +1,6 @@
1
1
  import { expect } from 'chai';
2
2
  import { getOneValueDimensions } from '../src/rules/src/table/preparators/getOneValueDimensions';
3
- import { getDisplay } from '../src/rules/src/table/preparators/getDisplay';
3
+ import { getDisplay } from '../src/rules/src/preparators/getDisplay';
4
4
 
5
5
  const noDisplayIndexes = [0, 2, 4];
6
6
 
@@ -0,0 +1,80 @@
1
+ import { expect } from 'chai';
2
+ import { getSortedLayoutIndexes } from '../src/rules/src/table/factories/getSortedLayoutIndexes';
3
+ import * as R from 'ramda';
4
+
5
+ describe('getSortedLayoutData tests', () => {
6
+ it('basic case', () => {
7
+ const layout = {
8
+ header: [{ id: 'd1', __index: 0 }],
9
+ sections: [{ id: 'd2', __index: 1 }],
10
+ rows: [{ id: 'd3', __index: 2 }],
11
+ };
12
+ const observations = {
13
+ '0:0:0': { orderedDimIndexes: [0, 0, 0] },
14
+ '0:0:1': { orderedDimIndexes: [0, 0, 1] },
15
+ '0:1:0': { orderedDimIndexes: [0, 1, 0] },
16
+ '0:1:1': { orderedDimIndexes: [0, 1, 1] },
17
+ '1:0:0': { orderedDimIndexes: [1, 0, 0] },
18
+ '1:0:1': { orderedDimIndexes: [1, 0, 1] },
19
+ '1:1:0': { orderedDimIndexes: [1, 1, 0] },
20
+ '1:1:1': { orderedDimIndexes: [1, 1, 1] },
21
+ };
22
+
23
+ const layoutIndexes = {
24
+ header: [[0], [1]],
25
+ sections: [
26
+ [[0], [[0], [1]]],
27
+ [[1], [[0], [1]]]
28
+ ]
29
+ };
30
+
31
+ expect(getSortedLayoutIndexes(layout, observations)).to.deep.equal(layoutIndexes);
32
+ });
33
+ it('mixed order dimensions test', () => {
34
+ const layout = {
35
+ header: [
36
+ { id: 'd3', __index: 2 },
37
+ { id: 'd1', __index: 0 }
38
+ ],
39
+ sections: [],
40
+ rows: [{ id: 'd2', __index: 1 }],
41
+ };
42
+
43
+ const layoutIndexes = {
44
+ header: [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]],
45
+ sections: [[[], [[0], [1], [2]]]]
46
+ };
47
+
48
+ const observations = {
49
+ '0:0:0': { orderedDimIndexes: [0, 0, 0] },
50
+ '0:0:1': { orderedDimIndexes: [0, 0, 1] },
51
+ '0:0:2': { orderedDimIndexes: [0, 0, 2] },
52
+ '0:1:0': { orderedDimIndexes: [0, 1, 0] },
53
+ '0:1:1': { orderedDimIndexes: [0, 1, 1] },
54
+ '0:1:2': { orderedDimIndexes: [0, 1, 2] },
55
+ '0:2:0': { orderedDimIndexes: [0, 2, 0] },
56
+ '0:2:1': { orderedDimIndexes: [0, 2, 1] },
57
+ '0:2:2': { orderedDimIndexes: [0, 2, 2] },
58
+ '1:0:0': { orderedDimIndexes: [1, 0, 0] },
59
+ '1:0:1': { orderedDimIndexes: [1, 0, 1] },
60
+ '1:0:2': { orderedDimIndexes: [1, 0, 2] },
61
+ '1:1:0': { orderedDimIndexes: [1, 1, 0] },
62
+ '1:1:1': { orderedDimIndexes: [1, 1, 1] },
63
+ '1:1:2': { orderedDimIndexes: [1, 1, 2] },
64
+ '1:2:0': { orderedDimIndexes: [1, 2, 0] },
65
+ '1:2:1': { orderedDimIndexes: [1, 2, 1] },
66
+ '1:2:2': { orderedDimIndexes: [1, 2, 2] },
67
+ '2:0:0': { orderedDimIndexes: [2, 0, 0] },
68
+ '2:0:1': { orderedDimIndexes: [2, 0, 1] },
69
+ '2:0:2': { orderedDimIndexes: [2, 0, 2] },
70
+ '2:1:0': { orderedDimIndexes: [2, 1, 0] },
71
+ '2:1:1': { orderedDimIndexes: [2, 1, 1] },
72
+ '2:1:2': { orderedDimIndexes: [2, 1, 2] },
73
+ '2:2:0': { orderedDimIndexes: [2, 2, 0] },
74
+ '2:2:1': { orderedDimIndexes: [2, 2, 1] },
75
+ '2:2:2': { orderedDimIndexes: [2, 2, 2] },
76
+ };
77
+
78
+ expect(getSortedLayoutIndexes(layout, observations)).to.deep.equal(layoutIndexes);
79
+ });
80
+ });
@@ -1,6 +1,6 @@
1
1
  import { expect } from 'chai';
2
2
  import { getUnitsArtefacts } from '../src/rules/src/table/units/getUnitsArtefacts';
3
- import { getDisplay } from '../src/rules/src/table/preparators/getDisplay';
3
+ import { getDisplay } from '../src/rules/src/preparators/getDisplay';
4
4
 
5
5
  const noDisplayIndexes = [0, 1];
6
6
  const _getDisplay = getDisplay({ noDisplayIndexes });