@sis-cc/dotstatsuite-components 15.0.15 → 15.0.17
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.
- package/lib/rules/src/preparators/enhanceObservations.js +1 -1
- package/lib/rules/src/preparators/formatValue.js +14 -10
- package/lib/rules/src/table/preparators/parseAttributes.js +7 -2
- package/lib/rules/src/table/preparators/prepareData.js +2 -1
- package/package.json +1 -1
- package/src/rules/src/preparators/enhanceObservations.js +1 -1
- package/src/rules/src/preparators/formatValue.js +18 -8
- package/src/rules/src/table/preparators/parseAttributes.js +3 -2
- package/src/rules/src/table/preparators/prepareData.js +2 -1
- package/test/enhanceObservations.test.js +105 -0
- package/test/parseAttributes.test.js +6 -3
|
@@ -92,7 +92,7 @@ var getAttributeValue = function getAttributeValue(attribute, valueIndex, option
|
|
|
92
92
|
}
|
|
93
93
|
var value = R.pipe(R.propOr([], 'values'), R.nth(valueIndex))(attribute);
|
|
94
94
|
|
|
95
|
-
if (R.isNil(value) || !R.propOr(true, 'display', value)) {
|
|
95
|
+
if (R.isNil(value) || !R.propOr(true, 'display', value) || R.includes(value.id, R.propOr([], 'rejectedValueIds')(options))) {
|
|
96
96
|
return null;
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -18,20 +18,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
19
19
|
|
|
20
20
|
var isValidNumber = R.both(R.is(Number), R.complement(R.equals(NaN)));
|
|
21
|
+
var parseValidNumber = R.pipe(function (v) {
|
|
22
|
+
return R.isNil(v) ? null : Number(v);
|
|
23
|
+
}, function (v) {
|
|
24
|
+
return isNaN(v) ? null : v;
|
|
25
|
+
});
|
|
21
26
|
|
|
22
27
|
var getFormatAttributesValues = function getFormatAttributesValues(observation, formatAttributesIndexes, attributes) {
|
|
23
28
|
return R.mapObjIndexed(function (attributeIndex) {
|
|
24
|
-
var valueIndex =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
var valueIndex = void 0;
|
|
30
|
+
var relationship = R.pipe(R.nth(attributeIndex), R.propOr({}, 'relationship'))(attributes);
|
|
31
|
+
//if (!R.isNil(attributeIndex) && attributeIndex >= R.length(R.propOr([], 'attrValuesIndexes', observation))) {
|
|
32
|
+
if (R.has('none', relationship) || R.has('dataflow', relationship)) {
|
|
33
|
+
valueIndex = 0;
|
|
34
|
+
} else {
|
|
35
|
+
valueIndex = R.pipe(R.propOr([], 'attrValuesIndexes'), R.nth(attributeIndex), parseValidNumber)(observation);
|
|
36
|
+
}
|
|
29
37
|
|
|
30
|
-
return R.pipe(R.path([attributeIndex, 'values', valueIndex, 'id']),
|
|
31
|
-
return R.isNil(v) ? null : Number(v);
|
|
32
|
-
}, function (v) {
|
|
33
|
-
return isNaN(v) ? null : v;
|
|
34
|
-
})(attributes);
|
|
38
|
+
return R.pipe(R.path([attributeIndex, 'values', valueIndex, 'id']), parseValidNumber)(attributes);
|
|
35
39
|
}, formatAttributesIndexes);
|
|
36
40
|
};
|
|
37
41
|
|
|
@@ -17,11 +17,16 @@ var registerAttrId = function registerAttrId(path, id) {
|
|
|
17
17
|
return R.over(R.lensPath(R.prepend('attributesIdsIndexedByTargets', path)), R.ifElse(R.isNil, R.always([id]), R.append(id)));
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
var
|
|
21
|
-
return
|
|
20
|
+
var _registerAttr = function _registerAttr(rejected) {
|
|
21
|
+
return function (attr) {
|
|
22
|
+
return R.set(R.lensPath(['attributesIndexedByIds', attr.id]), R.over(R.lensProp('values'), R.map(function (v) {
|
|
23
|
+
return R.includes(R.prop('id')(v), rejected) ? null : v;
|
|
24
|
+
}))(attr));
|
|
25
|
+
};
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
var getAttributeRegisters = function getAttributeRegisters(attribute, parsedDimensionsIds, customAttributes) {
|
|
29
|
+
var registerAttr = _registerAttr(R.propOr([], 'rejectedValueIds')(customAttributes));
|
|
25
30
|
if (R.propEq('id', customAttributes.prefscale, attribute)) {
|
|
26
31
|
return [registerAttrId(['prefscale'], attribute.id), registerAttr(attribute)];
|
|
27
32
|
}
|
|
@@ -111,7 +111,8 @@ var prepareData = exports.prepareData = function prepareData(sdmxJson, customAtt
|
|
|
111
111
|
attachmentSeriesIndexes: attachmentSeriesIndexes,
|
|
112
112
|
customAttributes: customAttributes,
|
|
113
113
|
attributesIds: R.concat(seriesAttributesIds, observationsAttributesIds),
|
|
114
|
-
unitsIds: obsUnitsIds
|
|
114
|
+
unitsIds: obsUnitsIds,
|
|
115
|
+
rejectedValueIds: rejectedValueIds
|
|
115
116
|
};
|
|
116
117
|
|
|
117
118
|
var _observations = (0, _getObservations.getObservations)(sdmxJson);
|
package/package.json
CHANGED
|
@@ -94,7 +94,7 @@ const getAttributeValue = (attribute, valueIndex, options) => {
|
|
|
94
94
|
R.nth(valueIndex)
|
|
95
95
|
)(attribute);
|
|
96
96
|
|
|
97
|
-
if (R.isNil(value) || !R.propOr(true, 'display', value)) {
|
|
97
|
+
if (R.isNil(value) || !R.propOr(true, 'display', value) || R.includes(value.id,R.propOr([],'rejectedValueIds')(options))) {
|
|
98
98
|
return null;
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -2,20 +2,30 @@ import * as R from 'ramda';
|
|
|
2
2
|
import numeral from 'numeral';
|
|
3
3
|
|
|
4
4
|
const isValidNumber = R.both(R.is(Number), R.complement(R.equals(NaN)));
|
|
5
|
+
const parseValidNumber = R.pipe(
|
|
6
|
+
v => R.isNil(v) ? null : Number(v),
|
|
7
|
+
v => isNaN(v) ? null : v
|
|
8
|
+
);
|
|
5
9
|
|
|
6
10
|
const getFormatAttributesValues = (observation, formatAttributesIndexes, attributes) => R.mapObjIndexed(
|
|
7
11
|
attributeIndex => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let valueIndex;
|
|
13
|
+
const relationship = R.pipe(R.nth(attributeIndex), R.propOr({}, 'relationship'))(attributes);
|
|
14
|
+
//if (!R.isNil(attributeIndex) && attributeIndex >= R.length(R.propOr([], 'attrValuesIndexes', observation))) {
|
|
15
|
+
if (R.has('none', relationship) || R.has('dataflow', relationship)) {
|
|
16
|
+
valueIndex = 0;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
valueIndex = R.pipe(
|
|
20
|
+
R.propOr([], 'attrValuesIndexes'),
|
|
21
|
+
R.nth(attributeIndex),
|
|
22
|
+
parseValidNumber
|
|
23
|
+
)(observation);
|
|
24
|
+
}
|
|
14
25
|
|
|
15
26
|
return R.pipe(
|
|
16
27
|
R.path([attributeIndex, 'values', valueIndex, 'id']),
|
|
17
|
-
|
|
18
|
-
v => isNaN(v) ? null : v
|
|
28
|
+
parseValidNumber
|
|
19
29
|
)(attributes);
|
|
20
30
|
},
|
|
21
31
|
formatAttributesIndexes
|
|
@@ -6,12 +6,13 @@ const registerAttrId = (path, id) => R.over(
|
|
|
6
6
|
R.ifElse(R.isNil, R.always([id]), R.append(id))
|
|
7
7
|
);
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const _registerAttr = rejected=>(attr) => R.set(
|
|
10
10
|
R.lensPath(['attributesIndexedByIds', attr.id]),
|
|
11
|
-
attr
|
|
11
|
+
R.over(R.lensProp('values'),R.map(v=> R.includes(R.prop('id')(v),rejected)? null : v))(attr)
|
|
12
12
|
);
|
|
13
13
|
|
|
14
14
|
const getAttributeRegisters = (attribute, parsedDimensionsIds, customAttributes) => {
|
|
15
|
+
const registerAttr = _registerAttr(R.propOr([],'rejectedValueIds')(customAttributes))
|
|
15
16
|
if (R.propEq('id', customAttributes.prefscale, attribute)) {
|
|
16
17
|
return [registerAttrId(['prefscale'], attribute.id), registerAttr(attribute)];
|
|
17
18
|
}
|
|
@@ -76,7 +76,8 @@ export const prepareData = (sdmxJson, customAttributes, unitsProps={}, _options=
|
|
|
76
76
|
attachmentSeriesIndexes,
|
|
77
77
|
customAttributes,
|
|
78
78
|
attributesIds: R.concat(seriesAttributesIds, observationsAttributesIds),
|
|
79
|
-
unitsIds: obsUnitsIds
|
|
79
|
+
unitsIds: obsUnitsIds,
|
|
80
|
+
rejectedValueIds
|
|
80
81
|
};
|
|
81
82
|
|
|
82
83
|
const _observations = getObservations(sdmxJson);
|
|
@@ -232,4 +232,109 @@ describe('enhanceObservations tests', () => {
|
|
|
232
232
|
}
|
|
233
233
|
});
|
|
234
234
|
});
|
|
235
|
+
it('should not return attributes with rejectedValueIds [v0,v1]',()=> {
|
|
236
|
+
const attributes = [
|
|
237
|
+
{
|
|
238
|
+
id: 'a0',
|
|
239
|
+
values: [{ id: 'v0' }, { id: 'v1' }, { id: 'v2' }],
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
id: 'a1',
|
|
243
|
+
values: [{ id: 'v0' }],
|
|
244
|
+
},
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
const dimensions = [
|
|
248
|
+
{
|
|
249
|
+
id: 'd0',
|
|
250
|
+
__index: 0,
|
|
251
|
+
values: [
|
|
252
|
+
{ id: 'v0', __index: 0, __indexPosition: 0 },
|
|
253
|
+
{ id: 'v1', __index: 1, __indexPosition: 1 },
|
|
254
|
+
{ id: 'v2', __index: 2, __indexPosition: 2 },
|
|
255
|
+
{ id: 'v3', __index: 3, __indexPosition: 3, display: false }
|
|
256
|
+
]
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: 'd1',
|
|
260
|
+
__index: 1,
|
|
261
|
+
values: [
|
|
262
|
+
{ id: 'v0', __index: 0, __indexPosition: 0 }
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
];
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
const observations = {
|
|
269
|
+
a: {
|
|
270
|
+
attrValuesIndexes: [0, 0, 0, 0, 0],
|
|
271
|
+
dimValuesIndexes: [0, 0, 0, 0, 0],
|
|
272
|
+
value: 22,
|
|
273
|
+
},
|
|
274
|
+
b: {
|
|
275
|
+
attrValuesIndexes: [1, 0, 1, 1, 0],
|
|
276
|
+
dimValuesIndexes: [0, 0, 0, 1, 0],
|
|
277
|
+
value: 17,
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const options = {
|
|
282
|
+
noDisplayIndexes: [],
|
|
283
|
+
notDisplayedCodes: {
|
|
284
|
+
d0: { values: { v3: 'v3' } },
|
|
285
|
+
},
|
|
286
|
+
attributesIds: ['a0', 'a1'],
|
|
287
|
+
unitsIds: ['d0'],
|
|
288
|
+
rejectedValueIds: ['v0','v1']
|
|
289
|
+
};
|
|
290
|
+
expect(enhanceObservations(dimensions, observations, attributes, options)).to.deep.equal({
|
|
291
|
+
a: {
|
|
292
|
+
attrValuesIndexes: [0, 0, 0, 0, 0],
|
|
293
|
+
dimValuesIndexes: [0, 0, 0, 0, 0],
|
|
294
|
+
value: 22,
|
|
295
|
+
formattedValue: '22',
|
|
296
|
+
units: {
|
|
297
|
+
serieKey: 'x:x:x:x:x'
|
|
298
|
+
},
|
|
299
|
+
attributes: {},
|
|
300
|
+
indexedDimValIds: { d0: 'v0', d1: 'v0'}
|
|
301
|
+
},
|
|
302
|
+
b: {
|
|
303
|
+
attrValuesIndexes: [1, 0, 1, 1, 0],
|
|
304
|
+
dimValuesIndexes: [0, 0, 0, 1, 0],
|
|
305
|
+
value: 17,
|
|
306
|
+
formattedValue: '17',
|
|
307
|
+
units: {
|
|
308
|
+
serieKey: 'x:x:x:x:x'
|
|
309
|
+
},
|
|
310
|
+
attributes: {},
|
|
311
|
+
indexedDimValIds: { d0: 'v0', d1: 'v0'}
|
|
312
|
+
},
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
it('apply format attrs from dataflow level', () => {
|
|
316
|
+
const observations = {
|
|
317
|
+
a: { value: 2.358, attrValuesIndexes: [], dimValuesIndexes: [] },
|
|
318
|
+
b: { value: 10.578, attrValuesIndexes: [], dimValuesIndexes: [] },
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const attributes = [
|
|
322
|
+
{ id: 'PREF', relationship: { none: {} }, values: [{ id: '-1' }] },
|
|
323
|
+
{ id: 'DEC', relationship: { dataflow: {} }, values: [{ id: '1' }] }
|
|
324
|
+
];
|
|
325
|
+
|
|
326
|
+
const options = {
|
|
327
|
+
noDisplayIndexes: [],
|
|
328
|
+
notDisplayedCodes: {},
|
|
329
|
+
attributesIds: [],
|
|
330
|
+
unitsIds: [],
|
|
331
|
+
rejectedValueIds: [],
|
|
332
|
+
customAttributes: { prefscale: 'PREF', decimals: 'DEC' }
|
|
333
|
+
};
|
|
334
|
+
expect(enhanceObservations([], observations, attributes, options)).to.deep.equal({
|
|
335
|
+
a: { attributes: {}, units: { serieKey: '' }, value: 2.358, formattedValue: '23.6', attrValuesIndexes: [], dimValuesIndexes: [], indexedDimValIds: {} },
|
|
336
|
+
b: { attributes: {}, units: { serieKey: '' }, value: 10.578, formattedValue: '105.8', attrValuesIndexes: [], dimValuesIndexes: [], indexedDimValIds: {} },
|
|
337
|
+
});
|
|
338
|
+
});
|
|
235
339
|
});
|
|
340
|
+
|
|
@@ -27,12 +27,14 @@ const attributes = [
|
|
|
27
27
|
{ id: 'a22', relationship: { observation: {} }, values: [{ id: 'a22v0' }] }, // alternative observation relationship
|
|
28
28
|
{ id: 'REPORTING_YEAR_START_DAY', relationship: { observation: {} }, values: [{ id: 'a22v0' }]},
|
|
29
29
|
{ id: 'REPYEARSTART', relationship: { observation: {} }, values: [{ id: 'a22v0' }]},
|
|
30
|
+
{ id: 'a23', relationship: { observation: {} }, values: [{ id: 'a23v0' },{id : 'a23v1'}]},
|
|
30
31
|
];
|
|
31
32
|
|
|
32
33
|
const customAttributes = {
|
|
33
34
|
prefscale: 'a15',
|
|
34
35
|
decimals: 'a16',
|
|
35
|
-
units: ['d7', 'a20']
|
|
36
|
+
units: ['d7', 'a20'],
|
|
37
|
+
rejectedValueIds:['a23v0']
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
const parsedDimensionsIds = {
|
|
@@ -59,10 +61,11 @@ describe('parseAttributes test', () => {
|
|
|
59
61
|
a18: { id: 'a18', index: 18, relationship: { primaryMeasure: 'OBS_VALUE' }, values: [{ id: 'a18v1' }, null] },
|
|
60
62
|
a19: { id: 'a19', index: 19, relationship: { none: {} }, values: [{ id: 'a19v1' }] },
|
|
61
63
|
a21: { id: 'a21', index: 21, relationship: { dataflow: {} }, values: [{ id: 'a21v0' }] },
|
|
62
|
-
a22: { id: 'a22', index: 22, relationship: { observation: {} }, values: [{ id: 'a22v0' }] },
|
|
64
|
+
a22: { id: 'a22', index: 22, relationship: { observation: {} }, values: [{ id: 'a22v0' }] },
|
|
65
|
+
a23: { id: 'a23', index: 25, relationship: { observation: {} }, values:[null,{id:'a23v1'}] }
|
|
63
66
|
},
|
|
64
67
|
attributesIdsIndexedByTargets: {
|
|
65
|
-
observations: ['a6', 'a18', 'a22'],
|
|
68
|
+
observations: ['a6', 'a18', 'a22','a23'],
|
|
66
69
|
oneValueDimensions: { d1: ['a8', 'a14'] },
|
|
67
70
|
manyValuesDimensions: ['a9', 'a11'],
|
|
68
71
|
dataflow: ['a10', 'a19', 'a21'],
|