@sis-cc/dotstatsuite-components 9.1.1 → 9.2.1

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 (78) 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/getAttachmentSeriesIndexes.js +1 -1
  13. package/lib/rules/src/table/units/getUnitsSeries.js +31 -0
  14. package/lib/rules/src/v8-transformer.js +3 -2
  15. package/package.json +2 -2
  16. package/src/rules/src/preparators/enhanceObservations.js +163 -0
  17. package/src/rules/src/preparators/formatValue.js +73 -0
  18. package/src/rules/src/preparators/getDimensions.js +49 -0
  19. package/src/rules/src/preparators/getDisplay.js +20 -0
  20. package/src/rules/src/preparators/getObservations.js +19 -0
  21. package/src/rules/src/table/factories/getCells.js +3 -7
  22. package/src/rules/src/table/factories/getLayoutData.js +135 -184
  23. package/src/rules/src/table/factories/getSortedLayoutIndexes.js +108 -0
  24. package/src/rules/src/table/factories/getTableData.js +10 -10
  25. package/src/rules/src/table/factories/refineLayoutSize.js +224 -0
  26. package/src/rules/src/table/preparators/prepareData.js +23 -32
  27. package/src/rules/src/table/units/getAttachmentSeriesIndexes.js +2 -1
  28. package/src/rules/src/table/units/getUnitsSeries.js +20 -0
  29. package/src/rules/src/v8-transformer.js +4 -2
  30. package/test/appendUnitsInLayoutDataEntry.test.js +3 -3
  31. package/test/enhanceObservations.test.js +270 -0
  32. package/test/getAttachmentSeriesIndexes.test.js +1 -1
  33. package/test/getCells.test.js +4 -39
  34. package/test/getLayoutData2.test.js +194 -0
  35. package/test/getOneValueDimensions.test.js +1 -1
  36. package/test/getSortedLayoutIndexes.test.js +80 -0
  37. package/test/getUnitsArtefacts.test.js +1 -1
  38. package/test/getUnitsSeries.test.js +64 -0
  39. package/test/mocks/table-layout-multi-hierarchies--layout.json +621 -0
  40. package/test/mocks/table-layout-multi-hierarchies--layoutData.json +32410 -0
  41. package/test/mocks/table-layout-multi-hierarchies--layoutIndexes.json +2760 -0
  42. package/test/mocks/table-layout-multi-hierarchies--observations.json +30688 -0
  43. package/test/mocks/table-layout-multi-hierarchies--sizedIndexes.json +2761 -0
  44. package/test/mocks/table-layout-truncation1--layout.json +27469 -0
  45. package/test/mocks/table-layout-truncation1--layoutData.json +19413 -0
  46. package/test/mocks/table-layout-truncation1--layoutIndexes.json +7512 -0
  47. package/test/mocks/table-layout-truncation1--observations.json +70002 -0
  48. package/test/mocks/table-layout-truncation1--sizedIndexes.json +3010 -0
  49. package/test/mocks/table-prep-multi-hierarchies--attributes.json +44 -0
  50. package/test/mocks/table-prep-multi-hierarchies--dimensions.json +688 -0
  51. package/test/mocks/table-prep-multi-hierarchies--enhancedObservations.json +19696 -0
  52. package/test/mocks/table-prep-multi-hierarchies--observations.json +8246 -0
  53. package/test/mocks/table-prep-multi-hierarchies--sdmxJson.json +2985 -0
  54. package/test/mocks/table-prep-truncation1--dimensions.json +35057 -0
  55. package/test/mocks/table-prep-truncation1--enhancedObservations.json +70002 -0
  56. package/test/mocks/table-prep-truncation1--observations.json +27502 -0
  57. package/test/mocks/table-prep-truncation1--sdmxJson.json +55103 -0
  58. package/test/mocks/table-prep-units--observations.json +284286 -0
  59. package/test/mocks/table-prep-units--unitsSeries.json +41042 -0
  60. package/test/parseAttributes.test.js +1 -1
  61. package/test/refineLayoutSize.test.js +415 -0
  62. package/test/table-layout-perf.test.js +74 -0
  63. package/test/table-prep-perf.test.js +65 -0
  64. package/lib/rules/src/table/factories/getSortedLayoutData.js +0 -145
  65. package/lib/rules/src/table/factories/refineLayoutHierarchy.js +0 -61
  66. package/lib/rules/src/table/preparators/parseObservations.js +0 -76
  67. package/lib/rules/src/table/units/getUnitsSeriesOccurences.js +0 -39
  68. package/src/rules/src/table/factories/getSortedLayoutData.js +0 -133
  69. package/src/rules/src/table/factories/refineLayoutHierarchy.js +0 -64
  70. package/src/rules/src/table/preparators/parseObservations.js +0 -81
  71. package/src/rules/src/table/units/getUnitsSeriesOccurences.js +0 -51
  72. package/test/appendUnitsInLayoutData.test.js +0 -248
  73. package/test/getLayoutData.test.js +0 -311
  74. package/test/getSortedLayoutData.test.js +0 -382
  75. package/test/getUnitsSeriesOccurences.test.js +0 -133
  76. package/test/parseObservations.test.js +0 -116
  77. package/test/refineDimSeriesUnits.test.js +0 -24
  78. package/test/refineLayoutHierarchy.test.js +0 -79
@@ -1,61 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.refineLayoutHierarchy = undefined;
7
-
8
- var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
9
-
10
- var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
11
-
12
- var _ramda = require('ramda');
13
-
14
- var R = _interopRequireWildcard(_ramda);
15
-
16
- 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; } }
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- var refineParents = function refineParents(parents, indexed) {
21
- return R.pipe(R.converge(R.splitAt, [R.pipe(R.findLastIndex(R.flip(R.has)(indexed)), R.inc), R.identity]), function (_ref) {
22
- var _ref2 = (0, _slicedToArray3.default)(_ref, 2),
23
- presents = _ref2[0],
24
- absents = _ref2[1];
25
-
26
- var lastPresentParentId = R.last(presents);
27
- return [R.ifElse(R.isNil, R.always([]), R.converge(R.append, [R.identity, R.pipe(R.flip(R.prop)(indexed), R.path(['value', 'parents']))]))(lastPresentParentId), absents];
28
- })(parents);
29
- };
30
-
31
- var pushRow = function pushRow(row, last, acc) {
32
- return {
33
- refined: R.append(row, acc.refined),
34
- indexed: R.assoc(R.path(['value', 'id'], last), last, acc.indexed)
35
- };
36
- };
37
-
38
- var refineLayoutHierarchy = exports.refineLayoutHierarchy = function refineLayoutHierarchy(sectionsData, lastDimension) {
39
- var lastDimIndexedValues = R.pipe(R.propOr([], 'values'), R.indexBy(R.prop('id')))(lastDimension);
40
- return R.map(function (sectionData) {
41
- return R.pipe(R.last, R.reduce(function (acc, row) {
42
- var last = R.last(row);
43
- if (R.anyPass([R.isNil, R.isEmpty])(R.path(['value', 'parents'], last))) {
44
- return pushRow(row, last, acc);
45
- }
46
-
47
- var _refineParents = refineParents(R.path(['value', 'parents'], last), acc.indexed),
48
- _refineParents2 = (0, _slicedToArray3.default)(_refineParents, 2),
49
- presents = _refineParents2[0],
50
- absents = _refineParents2[1];
51
-
52
- var name = R.pipe(R.map(R.pipe(R.flip(R.prop)(lastDimIndexedValues), R.prop('name'))), R.append(R.path(['value', 'name'], last)), R.join(' > '))(absents);
53
- var refinedLast = R.over(R.lensProp('value'), R.pipe(R.assoc('name', name), R.assoc('parents', presents)), last);
54
- var refinedRow = R.pipe(R.dropLast(1), R.append(refinedLast))(row);
55
- return pushRow(refinedRow, refinedLast, acc);
56
- }, { refined: [], indexed: {} }), function (_ref3) {
57
- var refined = _ref3.refined;
58
- return [R.head(sectionData), refined];
59
- })(sectionData);
60
- }, sectionsData);
61
- };
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parseObservations = undefined;
7
-
8
- var _extends2 = require('babel-runtime/helpers/extends');
9
-
10
- var _extends3 = _interopRequireDefault(_extends2);
11
-
12
- var _ramda = require('ramda');
13
-
14
- var R = _interopRequireWildcard(_ramda);
15
-
16
- var _getAttributeValue = require('./getAttributeValue');
17
-
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
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- /*
23
- unitsArtefacts = { dimensions: { series: {} }, attributes: { series: {} } };
24
- */
25
- var getUnitsValues = function getUnitsValues(indexes, getDisplay) {
26
- return R.mapObjIndexed(function (codelist) {
27
- var valueIndex = R.prop(codelist.index, indexes);
28
- if (R.isNil(valueIndex) || !getDisplay(codelist)) {
29
- return null;
30
- }
31
- var value = R.path(['values', Number(valueIndex)], codelist);
32
- if (R.isNil(value) || !getDisplay((0, _extends3.default)({}, value, { parent: codelist.id }))) {
33
- return null;
34
- }
35
- return (0, _extends3.default)({}, R.pick(['id', 'name'], codelist), {
36
- value: R.when(R.complement(R.isNil), R.assoc('index', Number(valueIndex)))(value)
37
- });
38
- });
39
- };
40
- var getObservationUnits = function getObservationUnits(_ref) {
41
- var dimValuesIndexes = _ref.dimValuesIndexes,
42
- attrValuesIndexes = _ref.attrValuesIndexes,
43
- getDisplay = _ref.getDisplay;
44
- return R.converge(R.merge, [R.pipe(R.pathOr({}, ['dimensions', 'series']), getUnitsValues(dimValuesIndexes, getDisplay)), R.pipe(R.pathOr({}, ['attributes', 'series']), getUnitsValues(attrValuesIndexes, getDisplay))]);
45
- };
46
-
47
- var parseObservations = exports.parseObservations = function parseObservations(observations, dimensions, obsAttributes, formatAttributes, unitsArtefacts, getDisplay) {
48
- return R.mapObjIndexed(function (obs, key) {
49
- var dimValuesIndexes = R.split(':', key);
50
- var indexedDimValIds = R.addIndex(R.reduce)(function (acc, dimValIndex, dimIndex) {
51
- var dimension = R.nth(dimIndex, dimensions) || {};
52
- var value = R.pipe(R.propOr([], 'values'), R.find(R.propEq('__index', Number(dimValIndex))), R.when(R.isNil, R.always({})))(dimension);
53
- return R.assoc(dimension.id, value.id, acc);
54
- }, {}, dimValuesIndexes);
55
- var value = R.head(obs);
56
- var attrValuesIndexes = R.tail(obs);
57
- var units = getObservationUnits({ dimValuesIndexes: dimValuesIndexes, attrValuesIndexes: attrValuesIndexes, getDisplay: getDisplay })(unitsArtefacts);
58
- var attributes = R.mapObjIndexed(function (attribute) {
59
- return (0, _getAttributeValue.getAttributeValue)(attribute, R.nth(attribute.index, attrValuesIndexes));
60
- }, obsAttributes);
61
-
62
- var format = R.mapObjIndexed(function (attribute) {
63
- var attributeValue = (0, _getAttributeValue.getAttributeValue)(attribute, R.nth(attribute.index, attrValuesIndexes));
64
- return R.when(R.complement(R.isNil), R.path(['value', 'id']))(attributeValue);
65
- }, formatAttributes);
66
- return (0, _extends3.default)({}, format, {
67
- value: value,
68
- key: key,
69
- indexedDimValIds: indexedDimValIds,
70
- dimValuesIndexes: dimValuesIndexes,
71
- attrValuesIndexes: attrValuesIndexes,
72
- attributes: R.filter(R.complement(R.isNil), attributes),
73
- units: units
74
- });
75
- }, observations);
76
- };
@@ -1,39 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getUnitsSeriesOccurences = undefined;
7
-
8
- var _ramda = require('ramda');
9
-
10
- var R = _interopRequireWildcard(_ramda);
11
-
12
- 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; } }
13
-
14
- var getUnitsSeriesOccurences = exports.getUnitsSeriesOccurences = function getUnitsSeriesOccurences(_ref) {
15
- var attachmentSeriesIndexes = _ref.attachmentSeriesIndexes;
16
- return R.pipe(R.values, R.reduce(function (acc, observation) {
17
- var serieKey = R.pipe(R.addIndex(R.map)(function (valueIndex, dimIndex) {
18
- if (R.includes(dimIndex, attachmentSeriesIndexes)) {
19
- return valueIndex;
20
- }
21
- return 'x';
22
- }), R.join(':'))(observation.dimValuesIndexes);
23
-
24
- var serie = R.pathOr({}, ['rawUnitsSeries', serieKey], acc);
25
-
26
- var unitsOccurences = R.mapObjIndexed(R.ifElse(R.isNil, R.identity, R.path(['value', 'index'])), observation.units);
27
-
28
- var updatedSerie = serie;
29
- R.forEachObjIndexed(function (valueIndex, unitId) {
30
- updatedSerie = R.over(R.lensProp(unitId), R.ifElse(R.isNil, R.always([valueIndex]), R.append(valueIndex)))(updatedSerie);
31
- }, unitsOccurences);
32
- updatedSerie = R.over(R.lensProp('observations'), R.ifElse(R.isNil, R.always(1), R.inc))(updatedSerie);
33
-
34
- return R.evolve({
35
- rawUnitsSeries: R.assoc(serieKey, updatedSerie),
36
- obs: R.assoc(observation.key, R.assocPath(['units', 'serieKey'], serieKey, observation))
37
- })(acc);
38
- }, { rawUnitsSeries: {}, obs: {} }));
39
- };
@@ -1,133 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- const getSublayoutIndexToPositionPivots = dimensions => R.map(
4
- (dimension) => {
5
- const indexedPositions = R.reduce( // => [(entryIndex) : { ...val, __index }] => { [__index]: entryIndex }
6
- (acc, value) => ({
7
- ...acc,
8
- [R.prop('__index', value)]: R.prop('__indexPosition', value)
9
- }),
10
- {},
11
- R.prop('values', dimension)
12
- );
13
-
14
- return (splitKey) => R.pipe(
15
- R.nth(R.prop('__index', dimension)),
16
- index => R.prop(index, indexedPositions)
17
- )(splitKey);
18
- },
19
- dimensions
20
- );
21
-
22
- const coordinatesToSublayoutData = (sublayout, coordinates) => R.addIndex(R.map)(
23
- (valueIndex, dimensionIndex) => {
24
- const sublayoutDimension = R.nth(dimensionIndex, sublayout);
25
- const value = R.find(R.propEq('__indexPosition', valueIndex), R.prop('values', sublayoutDimension));
26
- return ({
27
- dimension: R.pick(['id', 'name', '__index'], sublayoutDimension),
28
- value,
29
- });
30
- },
31
- coordinates
32
- );
33
-
34
- export const getSortedLayoutData = (layout, observations) => {
35
- const headersPivots = getSublayoutIndexToPositionPivots(R.prop('header', layout));
36
- const rowsPivots = getSublayoutIndexToPositionPivots(R.prop('rows', layout));
37
- const sectionsPivots = getSublayoutIndexToPositionPivots(R.prop('sections', layout));
38
-
39
- const rowsSize = R.length(R.prop('rows', layout));
40
- const sectionsSize = R.length(R.prop('sections', layout));
41
-
42
- const sortedLayoutPositions = R.pipe(
43
- R.keys,
44
- R.map(
45
- key => {
46
- const splitKey = R.split(':', key);
47
- return R.converge((...rest) => rest, [...sectionsPivots, ...rowsPivots, ...headersPivots])(splitKey);
48
- }
49
- ),
50
- R.map(
51
- (coordinates) => {
52
- const [sections, tail] = R.splitAt(sectionsSize, coordinates);
53
- const [rows, headers] = R.splitAt(rowsSize, tail);
54
- return { headers, rows, sections };
55
- }
56
- )
57
- )(observations);
58
-
59
- const headerData = R.pipe(
60
- R.pluck('headers'),
61
- R.uniq,
62
- R.map(
63
- (coordinates) => coordinatesToSublayoutData(R.prop('header', layout), coordinates)
64
- ),
65
- (headerData) => {
66
- if (R.isEmpty(headerData)) {
67
- return headerData;
68
- }
69
- const comparators = R.pipe(
70
- R.head,
71
- R.length,
72
- (length) => R.times(R.identity, length),
73
- R.map(index => R.ascend(R.pathOr(0, [index, 'value', '__indexPosition'])))
74
- )(headerData);
75
-
76
- return R.sortWith(comparators)(headerData);
77
- }
78
- )(sortedLayoutPositions);
79
-
80
- const sectionsData = R.pipe(
81
- R.reduce((acc, layout) => {
82
- const sections = layout.sections;
83
-
84
- const index = R.findIndex(R.pathEq([0, 'sections'], sections))(acc);
85
- if (index === -1) {
86
- return R.append([layout], acc);
87
- }
88
- return R.over(R.lensIndex(index), R.append(layout))(acc);
89
- },
90
- []),
91
- R.map(
92
- (entries) => {
93
- const sectionData = coordinatesToSublayoutData(R.prop('sections', layout), R.prop('sections', R.head(entries)));
94
- const rowsData = R.map(
95
- (coordinates) => coordinatesToSublayoutData(R.prop('rows', layout), coordinates),
96
- R.uniq(R.pluck('rows', entries))
97
- );
98
- return [sectionData, rowsData];
99
- }
100
- ),
101
- sData => { //sort sections
102
- if (R.isEmpty(sData) || R.isEmpty(R.head(R.head(sData)))) {
103
- return sData;
104
- }
105
- const comparators = R.pipe(
106
- R.head,
107
- R.head,
108
- R.length,
109
- (length) => R.times(R.identity, length),
110
- R.map(index => R.ascend(R.pathOr(0, [0, index, 'value', '__indexPosition'])))
111
- )(sData);
112
-
113
- return R.sortWith(comparators)(sData);
114
- },
115
- sData => { //sort rows
116
- if (R.isEmpty(sData) || R.isEmpty(R.last(R.head(sData)))) {
117
- return sData;
118
- }
119
- const comparators = R.pipe(
120
- R.head,
121
- R.last,
122
- R.head,
123
- R.length,
124
- (length) => R.times(R.identity, length),
125
- R.map(index => R.ascend(R.pathOr(0, [index, 'value', '__indexPosition'])))
126
- )(sData);
127
-
128
- return R.map(R.over(R.lensIndex(1), R.sortWith(comparators)))(sData);
129
- }
130
- )(sortedLayoutPositions);
131
-
132
- return { headerData, sectionsData };
133
- };
@@ -1,64 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- const refineParents = (parents, indexed) => R.pipe(
4
- R.converge(
5
- R.splitAt,
6
- [
7
- R.pipe(R.findLastIndex(R.flip(R.has)(indexed)), R.inc),
8
- R.identity
9
- ]
10
- ),
11
- ([presents, absents]) => {
12
- const lastPresentParentId = R.last(presents);
13
- return [
14
- R.ifElse(
15
- R.isNil,
16
- R.always([]),
17
- R.converge(R.append, [R.identity, R.pipe(R.flip(R.prop)(indexed), R.path(['value', 'parents']))])
18
- )(lastPresentParentId),
19
- absents
20
- ];
21
- }
22
- )(parents);
23
-
24
- const pushRow = (row, last, acc) => ({
25
- refined: R.append(row, acc.refined),
26
- indexed: R.assoc(R.path(['value', 'id'], last), last, acc.indexed)
27
- });
28
-
29
- export const refineLayoutHierarchy = (sectionsData, lastDimension) => {
30
- const lastDimIndexedValues = R.pipe(
31
- R.propOr([], 'values'),
32
- R.indexBy(R.prop('id'))
33
- )(lastDimension);
34
- return R.map(
35
- (sectionData) => R.pipe(
36
- R.last,
37
- R.reduce(
38
- (acc, row) => {
39
- const last = R.last(row);
40
- if (R.anyPass([R.isNil, R.isEmpty])(R.path(['value', 'parents'], last))) {
41
- return pushRow(row, last, acc);
42
- }
43
- const [presents, absents] = refineParents(R.path(['value', 'parents'], last), acc.indexed);
44
- const name = R.pipe(
45
- R.map(
46
- R.pipe(R.flip(R.prop)(lastDimIndexedValues), R.prop('name'))),
47
- R.append(R.path(['value', 'name'], last)),
48
- R.join(' > ')
49
- )(absents);
50
- const refinedLast = R.over(
51
- R.lensProp('value'),
52
- R.pipe(R.assoc('name', name), R.assoc('parents', presents)),
53
- last
54
- );
55
- const refinedRow = R.pipe(R.dropLast(1), R.append(refinedLast))(row);
56
- return pushRow(refinedRow, refinedLast, acc);
57
- },
58
- { refined: [], indexed: {} }
59
- ),
60
- ({ refined }) => ([R.head(sectionData), refined])
61
- )(sectionData),
62
- sectionsData
63
- );
64
- };
@@ -1,81 +0,0 @@
1
- import * as R from 'ramda';
2
- import { getAttributeValue } from './getAttributeValue';
3
- /*
4
- unitsArtefacts = { dimensions: { series: {} }, attributes: { series: {} } };
5
- */
6
- const getUnitsValues = (indexes, getDisplay) => R.mapObjIndexed(
7
- (codelist) => {
8
- const valueIndex = R.prop(codelist.index, indexes);
9
- if (R.isNil(valueIndex) || !getDisplay(codelist)) {
10
- return null;
11
- }
12
- const value = R.path(['values', Number(valueIndex)], codelist);
13
- if (R.isNil(value) || !getDisplay({ ...value, parent: codelist.id })) {
14
- return null;
15
- }
16
- return ({
17
- ...R.pick(['id', 'name'], codelist),
18
- value: R.when(R.complement(R.isNil), R.assoc('index', Number(valueIndex)))(value)
19
- });
20
- }
21
- );
22
- const getObservationUnits = ({ dimValuesIndexes, attrValuesIndexes, getDisplay }) => R.converge(
23
- R.merge,
24
- [
25
- R.pipe(
26
- R.pathOr({}, ['dimensions', 'series']),
27
- getUnitsValues(dimValuesIndexes, getDisplay)
28
- ),
29
- R.pipe(
30
- R.pathOr({}, ['attributes', 'series']),
31
- getUnitsValues(attrValuesIndexes, getDisplay)
32
- ),
33
- ]
34
- );
35
-
36
- export const parseObservations = (observations, dimensions, obsAttributes, formatAttributes, unitsArtefacts, getDisplay) => R.mapObjIndexed(
37
- (obs, key) => {
38
- const dimValuesIndexes = R.split(':', key);
39
- const indexedDimValIds = R.addIndex(R.reduce)(
40
- (acc, dimValIndex, dimIndex) => {
41
- const dimension = R.nth(dimIndex, dimensions) || {};
42
- const value = R.pipe(
43
- R.propOr([], 'values'),
44
- R.find(R.propEq('__index', Number(dimValIndex))),
45
- R.when(R.isNil, R.always({}))
46
- )(dimension);
47
- return R.assoc(dimension.id, value.id, acc);
48
- },
49
- {},
50
- dimValuesIndexes
51
- );
52
- const value = R.head(obs);
53
- const attrValuesIndexes = R.tail(obs);
54
- const units = getObservationUnits({ dimValuesIndexes, attrValuesIndexes, getDisplay })(unitsArtefacts);
55
- const attributes = R.mapObjIndexed(
56
- (attribute) => {
57
- return getAttributeValue(attribute, R.nth(attribute.index, attrValuesIndexes));
58
- },
59
- obsAttributes
60
- );
61
-
62
- const format = R.mapObjIndexed(
63
- (attribute) => {
64
- const attributeValue = getAttributeValue(attribute, R.nth(attribute.index, attrValuesIndexes));
65
- return R.when(R.complement(R.isNil), R.path(['value', 'id']))(attributeValue);
66
- },
67
- formatAttributes
68
- );
69
- return ({
70
- ...format,
71
- value,
72
- key,
73
- indexedDimValIds,
74
- dimValuesIndexes,
75
- attrValuesIndexes,
76
- attributes: R.filter(R.complement(R.isNil), attributes),
77
- units
78
- });
79
- },
80
- observations
81
- );
@@ -1,51 +0,0 @@
1
- import * as R from 'ramda';
2
-
3
- export const getUnitsSeriesOccurences = ({ attachmentSeriesIndexes }) => R.pipe(
4
- R.values,
5
- R.reduce(
6
- (acc, observation) => {
7
- const serieKey = R.pipe(
8
- R.addIndex(R.map)(
9
- (valueIndex, dimIndex) => {
10
- if (R.includes(dimIndex, attachmentSeriesIndexes)) {
11
- return valueIndex;
12
- }
13
- return 'x';
14
- }
15
- ),
16
- R.join(':')
17
- )(observation.dimValuesIndexes);
18
-
19
- const serie = R.pathOr({}, ['rawUnitsSeries', serieKey], acc);
20
-
21
- const unitsOccurences = R.mapObjIndexed(
22
- R.ifElse(R.isNil, R.identity, R.path(['value', 'index'])),
23
- observation.units
24
- );
25
-
26
- let updatedSerie = serie;
27
- R.forEachObjIndexed(
28
- (valueIndex, unitId) => {
29
- updatedSerie = R.over(
30
- R.lensProp(unitId),
31
- R.ifElse(R.isNil, R.always([valueIndex]), R.append(valueIndex))
32
- )(updatedSerie)
33
- },
34
- unitsOccurences
35
- );
36
- updatedSerie = R.over(
37
- R.lensProp('observations'),
38
- R.ifElse(R.isNil, R.always(1), R.inc)
39
- )(updatedSerie);
40
-
41
- return R.evolve({
42
- rawUnitsSeries: R.assoc(serieKey, updatedSerie),
43
- obs: R.assoc(
44
- observation.key,
45
- R.assocPath(['units', 'serieKey'], serieKey, observation)
46
- )
47
- })(acc);
48
- },
49
- { rawUnitsSeries: {}, obs: {} }
50
- )
51
- );