@sis-cc/dotstatsuite-components 13.5.6 → 14.1.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 (52) hide show
  1. package/lib/rules/src/preparators/enhanceObservations.js +0 -7
  2. package/lib/rules/src/table/factories/getCells.js +1 -1
  3. package/lib/rules/src/table/factories/getCuratedCells.js +2 -3
  4. package/lib/rules/src/table/factories/getTableData.js +6 -11
  5. package/lib/rules/src/table/preparators/prepareData.js +30 -5
  6. package/lib/rules/src/table/units/getUnitsSeries.js +15 -4
  7. package/lib/rules/src/v8-transformer.js +10 -25
  8. package/lib/rules2/src/duplicateObservations.js +51 -0
  9. package/lib/rules2/src/getDimensionValuesIndexes.js +19 -0
  10. package/lib/rules2/src/getDimensionsSimpleHierarchies.js +42 -0
  11. package/lib/rules2/src/getHCodelistsRefsInData.js +46 -0
  12. package/lib/rules2/src/hierarchiseDimension.js +47 -0
  13. package/lib/rules2/src/index.js +24 -0
  14. package/lib/rules2/src/invertTime.js +33 -0
  15. package/lib/rules2/src/parseHierarchicalCodelist.js +22 -0
  16. package/package.json +2 -2
  17. package/src/rules/src/preparators/enhanceObservations.js +0 -6
  18. package/src/rules/src/table/factories/getCells.js +2 -1
  19. package/src/rules/src/table/factories/getCuratedCells.js +3 -4
  20. package/src/rules/src/table/factories/getTableData.js +3 -22
  21. package/src/rules/src/table/preparators/prepareData.js +20 -3
  22. package/src/rules/src/table/units/getUnitsSeries.js +18 -6
  23. package/src/rules/src/v8-transformer.js +11 -30
  24. package/src/rules2/src/duplicateObservations.js +45 -0
  25. package/src/rules2/src/getDimensionValuesIndexes.js +13 -0
  26. package/src/rules2/src/getDimensionsSimpleHierarchies.js +34 -0
  27. package/src/rules2/src/getHCodelistsRefsInData.js +23 -0
  28. package/src/rules2/src/hierarchiseDimension.js +38 -0
  29. package/src/rules2/src/index.js +2 -0
  30. package/src/rules2/src/invertTime.js +22 -0
  31. package/src/rules2/src/parseHierarchicalCodelist.js +14 -0
  32. package/test/duplicateObservations.test.js +108 -0
  33. package/test/enhanceObservations.test.js +13 -48
  34. package/test/getCells.test.js +4 -11
  35. package/test/getDimensionValuesIndexes.test.js +33 -0
  36. package/test/getHCodelistsRefs.test.js +20 -0
  37. package/test/getUnitsSeries.test.js +112 -47
  38. package/test/hierarchiseDimension.test.js +87 -0
  39. package/test/invertTime.test.js +77 -0
  40. package/test/mocks/h-codelist.json +2095 -0
  41. package/test/mocks/table-invert-time--data.json +80211 -0
  42. package/test/mocks/table-invert-time--inverted.json +80076 -0
  43. package/test/mocks/table-prep-multi-duplicate--duplicated.json +26938 -0
  44. package/test/mocks/table-prep-multi-duplicate--indexes.json +1417 -0
  45. package/test/mocks/table-prep-multi-duplicate--observations.json +20330 -0
  46. package/test/mocks/table-prep-simple-duplicate--duplicated.json +77502 -0
  47. package/test/mocks/table-prep-simple-duplicate--indexes.json +274 -0
  48. package/test/mocks/table-prep-simple-duplicate--observations.json +60002 -0
  49. package/test/parseHierarchicalCodelist.test.js +76 -0
  50. package/test/table-invert-time-perf.test.js +11 -0
  51. package/test/table-prep-duplicate-perf.test.js +21 -0
  52. package/test/table-prep-perf.test.js +5 -2
@@ -13,6 +13,7 @@ describe('getCells tests', () => {
13
13
  expect(getCells({
14
14
  observations: {
15
15
  a: {
16
+ key: 'a',
16
17
  value: 33,
17
18
  formattedValue: '33',
18
19
  attributes: {
@@ -26,6 +27,7 @@ describe('getCells tests', () => {
26
27
  }, 'label', customAttributes,
27
28
  { unitsDefinitionCodes: [], unitsSeries: {}, unitsDisplay: 'cells', unitDimension: {} }, [])).to.deep.equal({
28
29
  a: {
30
+ key: 'a',
29
31
  value: '33',
30
32
  intValue: 33,
31
33
  flags: [
@@ -42,6 +44,7 @@ describe('getCells tests', () => {
42
44
  expect(getCells({
43
45
  observations: {
44
46
  a: {
47
+ key: 'a',
45
48
  value: 33,
46
49
  formattedValue: '33',
47
50
  attributes: {
@@ -54,6 +57,7 @@ describe('getCells tests', () => {
54
57
  }
55
58
  }, 'both', customAttributes, {}, [])).to.deep.equal({
56
59
  a: {
60
+ key: 'a',
57
61
  value: '33',
58
62
  intValue: 33,
59
63
  flags: [
@@ -66,15 +70,4 @@ describe('getCells tests', () => {
66
70
  }
67
71
  })
68
72
  });
69
- /*it('string observation type display test', () => {
70
- expect(getCells({
71
- observations: {
72
- a: { value: '16.35', units: {}, decimals: '2', prefscale: '1', indexedDimValIds: {} },
73
- b: { value: '155062.56', units: {}, decimals: '3', indexedDimValIds: {} },
74
- }
75
- }, 'label', customAttributes, {}, OBS_TYPE_NUMERICAL_STRING)).to.deep.equal({
76
- a: { value: '16.35', intValue: '16.35', flags: [], indexedDimValIds: {} },
77
- b: { value: '155062.56', intValue: '155062.56', flags: [], indexedDimValIds: {} },
78
- })
79
- });*/
80
73
  });
@@ -0,0 +1,33 @@
1
+ import { expect } from 'chai';
2
+ import { getDimensionValuesIndexes } from '../src/rules2/src/getDimensionValuesIndexes';
3
+
4
+ describe('getDimensionValuesIndexes test', () => {
5
+ it('basic test', () => {
6
+ const values = [
7
+ { id: 'OECD', parent: undefined, parents: [], __index: 2 },
8
+ { id: 'GER', parent: 'OECD', parents: ['OECD'], __index: 1 },
9
+ { id: 'FRA', parent: 'OECD', parents: ['OECD'], __index: 0 },
10
+ { id: 'USA', parent: 'OECD', parents: ['OECD'], __index: 3 },
11
+ { id: 'A', parent: undefined, parents: [], __index: 4 },
12
+ { id: 'USA', parent: 'A', parents: ['A'], __index: 3 },
13
+ { id: 'MEX', parent: 'A', parents: ['A'], __index: 7 },
14
+ { id: 'EA', parent: undefined, parents: [], __index: 5 },
15
+ { id: 'FRA', parent: 'EA', parents: ['EA'], __index: 0 },
16
+ { id: 'GER', parent: 'EA', parents: ['EA'], __index: 1 },
17
+ { id: 'CHI', parent: undefined, parents: [], __index: 6 }
18
+ ];
19
+
20
+ const indexes = {
21
+ '0': [2, 8],
22
+ '1': [1, 9],
23
+ '2': [0],
24
+ '3': [3, 5],
25
+ '4': [4],
26
+ '5': [7],
27
+ '6': [10],
28
+ '7': [6]
29
+ };
30
+
31
+ expect(getDimensionValuesIndexes(values)).to.deep.equal(indexes);
32
+ });
33
+ });
@@ -0,0 +1,20 @@
1
+ import { expect } from 'chai';
2
+ import { getHCodelistsRefs } from '../src/rules2/src';
3
+
4
+ describe('getHCodelistsRefs tests', () => {
5
+ it('basic case', () => {
6
+ const annotations = [
7
+ { type: 'test' },
8
+ { type: 'HIER_CONTEXT', text: 'C1:A:HCL1(1.0).HIER1' },
9
+ { type: 'HIER_CONTEXT', text: 'C2:A:HCL2(1.0).HIER1' },
10
+ { type: 'HIER_CONTEXT', text: 'C1:A:HCL1(1.0).HIER2' },
11
+ ];
12
+
13
+ const expected = {
14
+ C1: { agencyId: 'A', codelistId: 'C1', code: 'HCL1', hierarchy: 'HIER2', version: '1.0' },
15
+ C2: { agencyId: 'A', codelistId: 'C2', code: 'HCL2', hierarchy: 'HIER1', version: '1.0' },
16
+ }
17
+
18
+ expect(getHCodelistsRefs(annotations)).to.deep.equal(expected);
19
+ });
20
+ });
@@ -1,55 +1,55 @@
1
1
  import { expect } from 'chai';
2
2
  import { getUnitsSeries } from '../src/rules/src/table/units/getUnitsSeries';
3
3
 
4
- const observations = {
5
- 0: {
6
- key: '0:0:0:0',
7
- units: {
8
- serieKey: '0:0:x:x',
9
- A: { value: { index: 0 } },
10
- B: { value: { index: 0 } },
11
- C: { value: { index: 0 } }
12
- }
13
- },
14
- 1: {
15
- key: '0:0:1:0',
16
- units: {
17
- serieKey: '0:0:x:x',
18
- A: { value: { index: 0 } },
19
- B: { value: { index: 0 } },
20
- C: { value: { index: 1 } }
21
- }
22
- },
23
- 2: {
24
- key: '1:0:0:0',
25
- units: {
26
- serieKey: '1:0:x:x',
27
- A: { value: { index: 1 } },
28
- B: { value: { index: 1 } },
29
- C: { value: { index: 0 } }
30
- }
31
- },
32
- 3: {
33
- key: '1:0:1:0',
34
- units: {
35
- serieKey: '1:0:x:x',
36
- A: { value: { index: 1 } },
37
- B: { value: { index: 1 } },
38
- C: { value: { index: 0 } }
39
- }
40
- },
41
- 4: {
42
- key: '2:0:0:0',
43
- units: {
44
- serieKey: '2:0:x:x',
45
- A: { value: { index: 2 } },
46
- B: { value: { index: 0 } },
47
- C: { value: { index: 0 } }
48
- }
49
- }
50
- };
51
4
 
52
5
  describe('getUnitsSeries tests', () => {
6
+ const observations = {
7
+ 0: {
8
+ key: '0:0:0:0',
9
+ units: {
10
+ serieKey: '0:0:x:x',
11
+ A: { value: { index: 0 } },
12
+ B: { value: { index: 0 } },
13
+ C: { value: { index: 0 } }
14
+ }
15
+ },
16
+ 1: {
17
+ key: '0:0:1:0',
18
+ units: {
19
+ serieKey: '0:0:x:x',
20
+ A: { value: { index: 0 } },
21
+ B: { value: { index: 0 } },
22
+ C: { value: { index: 1 } }
23
+ }
24
+ },
25
+ 2: {
26
+ key: '1:0:0:0',
27
+ units: {
28
+ serieKey: '1:0:x:x',
29
+ A: { value: { index: 1 } },
30
+ B: { value: { index: 1 } },
31
+ C: { value: { index: 0 } }
32
+ }
33
+ },
34
+ 3: {
35
+ key: '1:0:1:0',
36
+ units: {
37
+ serieKey: '1:0:x:x',
38
+ A: { value: { index: 1 } },
39
+ B: { value: { index: 1 } },
40
+ C: { value: { index: 0 } }
41
+ }
42
+ },
43
+ 4: {
44
+ key: '2:0:0:0',
45
+ units: {
46
+ serieKey: '2:0:x:x',
47
+ A: { value: { index: 2 } },
48
+ B: { value: { index: 0 } },
49
+ C: { value: { index: 0 } }
50
+ }
51
+ }
52
+ };
53
53
  it('blank test', () => {
54
54
  expect(getUnitsSeries({})).to.deep.equal({});
55
55
  });
@@ -62,3 +62,68 @@ describe('getUnitsSeries tests', () => {
62
62
  });
63
63
  });
64
64
  });
65
+
66
+ describe('getUnitsSeries tests keys difference', () => {
67
+ const observations = {
68
+ "0:0:0:0:0:0": {
69
+ "key": "0:0:0:0:0:0",
70
+ "units": {
71
+ "UNIT_MEASURE": { "value": { "index": 0 }},
72
+ "UNIT_MULT": { "value": { "index": 0 }},
73
+ "serieKey": "x:x:x:x:0:x"
74
+ },
75
+ },
76
+ "0:0:0:0:0:1": {
77
+ "key": "0:0:0:0:0:1",
78
+ "units": {
79
+ "UNIT_MEASURE": { "value": { "index": 0 }},
80
+ "UNIT_MULT": { "value": { "index": 0 }},
81
+ "serieKey": "x:x:x:x:0:x"
82
+ },
83
+ },
84
+ "0:0:0:1:0:0": {
85
+ "key": "0:0:0:1:0:0",
86
+ "units": {
87
+ "UNIT_MEASURE": { "value": { "index": 0 }},
88
+ "serieKey": "x:x:x:x:0:x"
89
+ },
90
+ },
91
+ "0:0:0:1:0:1": {
92
+ "key": "0:0:0:1:0:1",
93
+ "units": {
94
+ "UNIT_MEASURE": { "value": { "index": 0 }},
95
+ "serieKey": "x:x:x:x:0:x"
96
+ },
97
+ },
98
+ "0:0:0:2:1:0": {
99
+ "key": "0:0:0:2:1:0",
100
+ "units": {
101
+ "UNIT_MEASURE": { "value": { "index": 1 }},
102
+ "UNIT_MULT": { "value": { "index": 0 }},
103
+ "serieKey": "x:x:x:x:1:x"
104
+ },
105
+ },
106
+ "0:0:0:2:1:1": {
107
+ "key": "0:0:0:2:1:1",
108
+ "units": {
109
+ "UNIT_MEASURE": { "value": { "index": 1 }},
110
+ "UNIT_MULT": { "value": { "index": 0 }},
111
+ "serieKey": "x:x:x:x:1:x"
112
+ },
113
+ }
114
+ };
115
+ const expected = {
116
+ "x:x:x:x:0:x": {
117
+ "UNIT_MEASURE": { "value": { "index": 0 }},
118
+ "serieKey": "x:x:x:x:0:x"
119
+ },
120
+ "x:x:x:x:1:x": {
121
+ "UNIT_MEASURE": { "value": { "index": 1 }},
122
+ "UNIT_MULT": { "value": { "index": 0 }},
123
+ "serieKey": "x:x:x:x:1:x"
124
+ }
125
+ };
126
+ it('basic test', () => {
127
+ expect(getUnitsSeries(observations)).to.deep.equal(expected);
128
+ });
129
+ });
@@ -0,0 +1,87 @@
1
+ import { expect } from 'chai';
2
+ import { hierarchiseDimension } from '../src/rules2/src/hierarchiseDimension';
3
+
4
+ describe('hierarchiseDimension tests', () => {
5
+ it('basic test', () => {
6
+ const dimension = {
7
+ id: 'test',
8
+ values: [
9
+ { id: 'FRA' },
10
+ { id: 'GER' },
11
+ { id: 'OECD' },
12
+ { id: 'USA' },
13
+ { id: 'A' },
14
+ { id: 'EA' },
15
+ { id: 'CHI' },
16
+ { id: 'MEX' },
17
+ ]
18
+ };
19
+
20
+ const hierarchy = {
21
+ OECD: ['GER', 'FRA', 'USA'],
22
+ A: ['USA', 'MEX'],
23
+ EA: ['FRA', 'GER']
24
+ };
25
+
26
+ const hierarchised = {
27
+ id: 'test',
28
+ values: [
29
+ { id: 'OECD', parent: undefined, parents: [] },
30
+ { id: 'GER', parent: 'OECD', parents: ['OECD'] },
31
+ { id: 'FRA', parent: 'OECD', parents: ['OECD'] },
32
+ { id: 'USA', parent: 'OECD', parents: ['OECD'] },
33
+ { id: 'A', parent: undefined, parents: [] },
34
+ { id: 'USA', parent: 'A', parents: ['A'] },
35
+ { id: 'MEX', parent: 'A', parents: ['A'] },
36
+ { id: 'EA', parent: undefined, parents: [] },
37
+ { id: 'FRA', parent: 'EA', parents: ['EA'] },
38
+ { id: 'GER', parent: 'EA', parents: ['EA'] },
39
+ { id: 'CHI', parent: undefined, parents: [] },
40
+ ]
41
+ }
42
+
43
+ expect(hierarchiseDimension(dimension, hierarchy)).to.deep.equal(hierarchised);
44
+ });
45
+ it('missing ids defined in the hierarchy', () => {
46
+ const hierarchy = {
47
+ W: ['EA', 'A'],
48
+ A: ['NA', 'SA'],
49
+ NA: ['USA', 'CAN'],
50
+ SA: ['BRA'],
51
+ EA: ['FRA', 'GER'],
52
+ FRA: ['IDF', 'BRE', 'ALS']
53
+ };
54
+
55
+ const dimension = {
56
+ id: 'test',
57
+ values: [
58
+ { id: 'IDF' },
59
+ { id: 'CAN' },
60
+ { id: 'USA' },
61
+ { id: 'AFK' },
62
+ { id: 'GER' },
63
+ { id: 'FRA' },
64
+ { id: 'EA' },
65
+ { id: 'A' },
66
+ { id: 'W' },
67
+ ]
68
+ };
69
+
70
+ const hierarchised = {
71
+ id: 'test',
72
+ values: [
73
+ { id: 'CAN', parent: undefined, parents: [] },
74
+ { id: 'USA', parent: undefined, parents: [] },
75
+ { id: 'AFK', parent: undefined, parents: [] },
76
+ { id: 'W', parent: undefined, parents: [] },
77
+ { id: 'EA', parent: 'W', parents: ['W'] },
78
+ { id: 'FRA', parent: 'EA', parents: ['W', 'EA'] },
79
+ { id: 'IDF', parent: 'FRA', parents: ['W', 'EA', 'FRA'] },
80
+ { id: 'GER', parent: 'EA', parents: ['W', 'EA'] },
81
+ { id: 'A', parent: 'W', parents: ['W'] },
82
+ ]
83
+ };
84
+
85
+ expect(hierarchiseDimension(dimension, hierarchy)).to.deep.equal(hierarchised);
86
+ });
87
+ });
@@ -0,0 +1,77 @@
1
+ import { expect } from 'chai';
2
+ import { invertTime } from '../src/rules2/src/invertTime';
3
+
4
+ describe('invertTime tests', () => {
5
+ it('complete test', () => {
6
+ const dimensions = {
7
+ many: {
8
+ TIME_PERIOD: {
9
+ id: 'TIME_PERIOD',
10
+ __index: 1,
11
+ role: 'TIME_PERIOD',
12
+ values: [
13
+ { id: 2000 },
14
+ { id: 2001 },
15
+ { id: 2002 },
16
+ { id: 2003 },
17
+ { id: 2004 },
18
+ { id: 2005 },
19
+ { id: 2006 },
20
+ { id: 2007 },
21
+ { id: 2008 },
22
+ { id: 2009 },
23
+ ]
24
+ }
25
+ }
26
+ };
27
+
28
+ const observations = {
29
+ '0:0': { orderedDimIndexes: [0, 0] },
30
+ '0:1': { orderedDimIndexes: [0, 1] },
31
+ '0:2': { orderedDimIndexes: [0, 2] },
32
+ '0:3': { orderedDimIndexes: [0, 3] },
33
+ '0:4': { orderedDimIndexes: [0, 4] },
34
+ '0:5': { orderedDimIndexes: [0, 5] },
35
+ '0:6': { orderedDimIndexes: [0, 6] },
36
+ '0:7': { orderedDimIndexes: [0, 7] },
37
+ '0:8': { orderedDimIndexes: [0, 8] },
38
+ '0:9': { orderedDimIndexes: [0, 9] },
39
+ };
40
+
41
+ const expected = {
42
+ dimensions: {
43
+ TIME_PERIOD: {
44
+ id: 'TIME_PERIOD',
45
+ role: 'TIME_PERIOD',
46
+ __index: 1,
47
+ values: [
48
+ { id: 2009 },
49
+ { id: 2008 },
50
+ { id: 2007 },
51
+ { id: 2006 },
52
+ { id: 2005 },
53
+ { id: 2004 },
54
+ { id: 2003 },
55
+ { id: 2002 },
56
+ { id: 2001 },
57
+ { id: 2000 },
58
+ ]
59
+ }
60
+ },
61
+ observations: {
62
+ '0:0': { orderedDimIndexes: [0, 9] },
63
+ '0:1': { orderedDimIndexes: [0, 8] },
64
+ '0:2': { orderedDimIndexes: [0, 7] },
65
+ '0:3': { orderedDimIndexes: [0, 6] },
66
+ '0:4': { orderedDimIndexes: [0, 5] },
67
+ '0:5': { orderedDimIndexes: [0, 4] },
68
+ '0:6': { orderedDimIndexes: [0, 3] },
69
+ '0:7': { orderedDimIndexes: [0, 2] },
70
+ '0:8': { orderedDimIndexes: [0, 1] },
71
+ '0:9': { orderedDimIndexes: [0, 0] },
72
+ }
73
+ };
74
+
75
+ expect(invertTime({ dimensions, observations }, true)).to.deep.equal(expected);
76
+ });
77
+ });