@sis-cc/dotstatsuite-components 17.1.0 → 17.3.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.
- package/lib/rules/src/layout.js +9 -2
- package/lib/rules/src/v8-transformer.js +13 -4
- package/lib/rules2/src/getManyValuesDimensions.js +1 -1
- package/lib/rules2/src/getOneValueDimensions.js +1 -1
- package/lib/rules2/src/index.js +9 -0
- package/lib/rules2/src/parseAttributes.js +2 -2
- package/lib/rules2/src/parseCombinations.js +4 -4
- package/lib/rules2/src/prepareData.js +10 -6
- package/lib/rules2/src/refineDimensions.js +39 -0
- package/lib/rules2/src/refineTimePeriod.js +146 -0
- package/lib/rules2/src/table/getLayout.js +3 -0
- package/package.json +1 -1
- package/src/rules/src/layout.js +6 -3
- package/src/rules/src/v8-transformer.js +21 -15
- package/src/rules2/src/getManyValuesDimensions.js +1 -1
- package/src/rules2/src/getOneValueDimensions.js +1 -1
- package/src/rules2/src/index.js +1 -0
- package/src/rules2/src/parseAttributes.js +2 -2
- package/src/rules2/src/parseCombinations.js +4 -4
- package/src/rules2/src/prepareData.js +8 -6
- package/src/rules2/src/refineDimensions.js +19 -0
- package/src/rules2/src/refineTimePeriod.js +122 -0
- package/src/rules2/src/table/getLayout.js +3 -0
- package/test/getOneValueDimensions.test.js +14 -11
- package/test/parseAttributes.test.js +7 -7
- package/test/parseCombinations.test.js +6 -6
- package/test/refineTimePeriod.test.js +564 -0
- package/test/refinedDimensions.test.js +35 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import * as dateFns from 'date-fns';
|
|
3
|
+
import { getLocale, dateWithoutTZ } from '../../rules/src/date';
|
|
4
|
+
|
|
5
|
+
const computeDisplayFreq = (start, duration) => {
|
|
6
|
+
const startMinute = dateFns.startOfMinute(start);
|
|
7
|
+
const startHour = dateFns.startOfHour(start);
|
|
8
|
+
const startDay = dateFns.startOfDay(start);
|
|
9
|
+
if (!dateFns.isEqual(start, startMinute) || duration === 'S') {
|
|
10
|
+
return 'S';
|
|
11
|
+
}
|
|
12
|
+
else if (!dateFns.isEqual(start, startHour) || !dateFns.isEqual(start, startDay)
|
|
13
|
+
|| duration === 'H' || duration === 'm') {
|
|
14
|
+
return 'm';
|
|
15
|
+
}
|
|
16
|
+
else if (!dateFns.isFirstDayOfMonth(start) || duration === 'D') {
|
|
17
|
+
return 'D';
|
|
18
|
+
}
|
|
19
|
+
else if (dateFns.getMonth(start) !== 0 || duration === 'M') {
|
|
20
|
+
return 'M';
|
|
21
|
+
}
|
|
22
|
+
return 'Y';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getAdder = (duration) => {
|
|
26
|
+
if (duration === 'S')
|
|
27
|
+
return dateFns.addSeconds;
|
|
28
|
+
if (duration === 'm')
|
|
29
|
+
return dateFns.addMinutes;
|
|
30
|
+
if (duration === 'H')
|
|
31
|
+
return dateFns.addHours;
|
|
32
|
+
if (duration === 'D')
|
|
33
|
+
return dateFns.addDays;
|
|
34
|
+
if (duration === 'M')
|
|
35
|
+
return dateFns.addMonths;
|
|
36
|
+
return dateFns.addYears;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getFormat = (freqDisplay) => {
|
|
40
|
+
if (freqDisplay === 'Y')
|
|
41
|
+
return 'YYYY';
|
|
42
|
+
if (freqDisplay === 'D')
|
|
43
|
+
return 'YYYY-MM-DD';
|
|
44
|
+
if (freqDisplay === 'H' || freqDisplay === 'm') {
|
|
45
|
+
return 'HH:mm';
|
|
46
|
+
}
|
|
47
|
+
if (freqDisplay === 'S') {
|
|
48
|
+
return 'HH:mm:ss';
|
|
49
|
+
}
|
|
50
|
+
return 'MMM';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const getEndDate = (start, mult, duration) => {
|
|
54
|
+
const adder = getAdder(duration);
|
|
55
|
+
let endDate = adder(start, Number(mult));
|
|
56
|
+
const startTZ = start.getTimezoneOffset();
|
|
57
|
+
const endTZ = endDate.getTimezoneOffset();
|
|
58
|
+
if (startTZ !== endTZ) {
|
|
59
|
+
endDate = dateFns.addMinutes(endDate, (Math.abs(endTZ) - Math.abs(startTZ)));
|
|
60
|
+
}
|
|
61
|
+
return dateFns.subSeconds(endDate, 1);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const computeName = (start, end, freqDisplay, locale) => {
|
|
65
|
+
const opts = { locale: getLocale(locale) };
|
|
66
|
+
const isSameDay = dateFns.isSameDay(start, end);
|
|
67
|
+
const isSameYear = dateFns.isSameYear(start, end);
|
|
68
|
+
if (freqDisplay === 'H' || freqDisplay === 'm' || freqDisplay === 'S') {
|
|
69
|
+
const dayFormat = getFormat('D');
|
|
70
|
+
const timeFormat = getFormat(freqDisplay);
|
|
71
|
+
if (isSameDay)
|
|
72
|
+
return `${dateFns.format(start, dayFormat, opts)} ${dateFns.format(start, timeFormat, opts)} - ${dateFns.format(end, timeFormat, opts)}`;
|
|
73
|
+
return `${dateFns.format(start, `${dayFormat} ${timeFormat}`, opts)} - ${dateFns.format(end, `${dayFormat} ${timeFormat}`, opts)}`;
|
|
74
|
+
}
|
|
75
|
+
if (freqDisplay === 'D' || freqDisplay === 'Y') {
|
|
76
|
+
const format = getFormat(freqDisplay);
|
|
77
|
+
return `${dateFns.format(start, format, opts)} - ${dateFns.format(end, format, opts)}`;
|
|
78
|
+
}
|
|
79
|
+
const yearFormat = getFormat('Y');
|
|
80
|
+
const monthFormat = getFormat('M');
|
|
81
|
+
if (isSameYear && locale === 'fr') {
|
|
82
|
+
return `${dateFns.format(start, monthFormat, opts)} - ${dateFns.format(end, monthFormat, opts)} ${dateFns.format(start, yearFormat, opts)}`;
|
|
83
|
+
}
|
|
84
|
+
const format = locale === 'fr' ? `${monthFormat} ${yearFormat}` : `${yearFormat}-${monthFormat}`;
|
|
85
|
+
return `${dateFns.format(start, format, opts)} - ${dateFns.format(end, format, opts)}`;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const getStartDate = (start) => {
|
|
89
|
+
if (!R.includes('T', start) && !R.endsWith('Z', start)) {
|
|
90
|
+
return new Date(start);
|
|
91
|
+
}
|
|
92
|
+
const date = new Date(start);
|
|
93
|
+
return dateFns.addMinutes(date, -date.getTimezoneOffset());
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const refineTimePeriod = (timePeriod, { locale }) => {
|
|
97
|
+
const { id } = timePeriod;
|
|
98
|
+
const split = R.split('/', id);
|
|
99
|
+
if (R.length(split) !== 2) {
|
|
100
|
+
const start = getStartDate(R.prop('start', timePeriod));
|
|
101
|
+
const end = getStartDate(R.prop('end', timePeriod))
|
|
102
|
+
return ({ ...timePeriod, start: start.toISOString(), end: end.toISOString() });
|
|
103
|
+
}
|
|
104
|
+
const [start, range] = split;
|
|
105
|
+
const startDate = getStartDate(start);
|
|
106
|
+
const match = R.match(/^P(T?)(\d+)([YMDHS])$/, range);
|
|
107
|
+
if (R.isEmpty(match) || !dateFns.isValid(startDate)) {
|
|
108
|
+
return timePeriod;
|
|
109
|
+
}
|
|
110
|
+
const [timeIndicator, mult, _duration] = R.tail(match);
|
|
111
|
+
const duration = !R.isEmpty(timeIndicator) && _duration === 'M' ? 'm' : _duration;
|
|
112
|
+
const endDate = getEndDate(startDate, mult, duration);
|
|
113
|
+
const freqDisplay = computeDisplayFreq(start, duration);
|
|
114
|
+
const name = computeName(dateWithoutTZ(startDate), dateWithoutTZ(endDate), freqDisplay, locale);
|
|
115
|
+
return ({
|
|
116
|
+
...timePeriod,
|
|
117
|
+
id,
|
|
118
|
+
name,
|
|
119
|
+
start: startDate.toISOString(),
|
|
120
|
+
end: endDate.toISOString()
|
|
121
|
+
})
|
|
122
|
+
};
|
|
@@ -59,6 +59,9 @@ export const getLayout = (layoutIds, dimensions, combinations, isTimeInverted) =
|
|
|
59
59
|
if (R.has(id, conceptIds)) {
|
|
60
60
|
return acc;
|
|
61
61
|
}
|
|
62
|
+
if (!R.has(id, indexedDimensions)) {
|
|
63
|
+
return acc;
|
|
64
|
+
}
|
|
62
65
|
return R.append(R.prop(id, indexedDimensions), acc);
|
|
63
66
|
},
|
|
64
67
|
[],
|
|
@@ -13,20 +13,23 @@ describe('getOneValueDimensions tests', () => {
|
|
|
13
13
|
];
|
|
14
14
|
|
|
15
15
|
const dimensions = [
|
|
16
|
-
{ id: 'd0', values: [{ id: 'v' }] },
|
|
17
|
-
{ id: 'd1', values: [{ id: 'v' }] },
|
|
18
|
-
{ id: 'd2', display: false, values: [{ id: 'v' }] },
|
|
19
|
-
{ id: 'd3', values: [{ id: 'v', display: false }] },
|
|
20
|
-
{ id: 'd4', values: [{ id: '_T' }] },
|
|
21
|
-
{ id: 'd5', values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
16
|
+
{ id: 'd0', header: true, values: [{ id: 'v' }] },
|
|
17
|
+
{ id: 'd1', header: true, values: [{ id: 'v' }] },
|
|
18
|
+
{ id: 'd2', header: true, display: false, values: [{ id: 'v' }] },
|
|
19
|
+
{ id: 'd3', header: true, values: [{ id: 'v', display: false }] },
|
|
20
|
+
{ id: 'd4', header: true, values: [{ id: '_T' }] },
|
|
21
|
+
{ id: 'd5', header: true, values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
22
|
+
{ id: 'd6', header: false, values: [{ id: 'v0' }] },
|
|
23
|
+
{ id: 'd7', header: false, values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
22
24
|
];
|
|
23
25
|
|
|
24
26
|
expect(getOneValueDimensions(dimensions, attributes)).to.deep.equal([
|
|
25
|
-
{ id: 'd0', values: [{ id: 'v' }], attrValues: { a1: { id: 'a1', header: true, values: [{ id: 'v' }], relationship: ['d0'], value: { id: 'v' } } } },
|
|
26
|
-
{ id: 'd1', values: [{ id: 'v' }], attrValues: {} },
|
|
27
|
-
{ id: 'd2', values: [{ id: 'v' }], display: false, attrValues: {} },
|
|
28
|
-
{ id: 'd3', values: [{ id: 'v', display: false }], attrValues: {} },
|
|
29
|
-
{ id: 'd4', values: [{ id: '_T' }], attrValues: {} },
|
|
27
|
+
{ id: 'd0', header: true, values: [{ id: 'v' }], attrValues: { a1: { id: 'a1', header: true, values: [{ id: 'v' }], relationship: ['d0'], value: { id: 'v' } } } },
|
|
28
|
+
{ id: 'd1', header: true, values: [{ id: 'v' }], attrValues: {} },
|
|
29
|
+
{ id: 'd2', header: true, values: [{ id: 'v' }], display: false, attrValues: {} },
|
|
30
|
+
{ id: 'd3', header: true, values: [{ id: 'v', display: false }], attrValues: {} },
|
|
31
|
+
{ id: 'd4', header: true, values: [{ id: '_T' }], attrValues: {} },
|
|
32
|
+
{ id: 'd5', header: true, values: [{ id: 'v0' }, { id: 'v1' }], attrValues: {} },
|
|
30
33
|
])
|
|
31
34
|
});
|
|
32
35
|
});
|
|
@@ -12,19 +12,19 @@ const attributes = [
|
|
|
12
12
|
const customAttributes = {};
|
|
13
13
|
|
|
14
14
|
const dimensions = [
|
|
15
|
-
{ id: 'd1', values: [{ id: 'v0' }] },
|
|
16
|
-
{ id: 'd2', values: [{ id: 'v0' }] },
|
|
17
|
-
{ id: 'd3', values: [{ id: 'v0' }] },
|
|
18
|
-
{ id: 'd4', values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
19
|
-
{ id: 'd5', values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
20
|
-
{ id: 'd6', values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
15
|
+
{ id: 'd1', header: true, values: [{ id: 'v0' }] },
|
|
16
|
+
{ id: 'd2', header: true, values: [{ id: 'v0' }] },
|
|
17
|
+
{ id: 'd3', header: true, values: [{ id: 'v0' }] },
|
|
18
|
+
{ id: 'd4', header: false, values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
19
|
+
{ id: 'd5', header: false, values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
20
|
+
{ id: 'd6', header: false, values: [{ id: 'v0' }, { id: 'v1' }] },
|
|
21
21
|
];
|
|
22
22
|
|
|
23
23
|
describe('parseAttributes test', () => {
|
|
24
24
|
it('complete case', () => {
|
|
25
25
|
expect(parseAttributes(attributes, dimensions, customAttributes)).to.deep.equal([
|
|
26
26
|
{ id: 'a6', index: 0, relationship: [], series: true, values: [{ id: 'a6v1' }] },
|
|
27
|
-
{ id: 'a8', index: 1, relationship: ['d1'], header: true,values: [{ id: 'a8v1' }] },
|
|
27
|
+
{ id: 'a8', index: 1, relationship: ['d1'], header: true, values: [{ id: 'a8v1' }] },
|
|
28
28
|
{ id: 'a9', index: 2, relationship: ['d4'], series: true, values: [{ id: 'a9v1' }] },
|
|
29
29
|
{ id: 'a10', index: 3, relationship: ['d1', 'd2'], header: true, values: [{ id: 'a10v1' }] },
|
|
30
30
|
{ id: 'a11', index: 4, relationship: ['d4'], series: true, values: [{ id: 'a11v1' }] },
|
|
@@ -17,12 +17,12 @@ describe('parseCombinations tests', () => {
|
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
const dimensions = [
|
|
20
|
-
{ id: 'DIM1', values: [{ id: 'v1' }] },
|
|
21
|
-
{ id: 'DIM2', values: [{ id: 'v1' }] },
|
|
22
|
-
{ id: 'DIM3', values: [{ id: 'v1' }, { id: 'v2' }] },
|
|
23
|
-
{ id: 'DIM4', values: [{ id: 'v1' }, { id: 'v2' }] },
|
|
24
|
-
{ id: 'DIM5', values: [{ id: '_Z' }, { id: 'v2', display: false }] },
|
|
25
|
-
{ id: 'DIM6', values: [{ id: 'v1', display: false }, { id: 'v2', display: false }] }
|
|
20
|
+
{ id: 'DIM1', header: true, values: [{ id: 'v1' }] },
|
|
21
|
+
{ id: 'DIM2', header: true, values: [{ id: 'v1' }] },
|
|
22
|
+
{ id: 'DIM3', header: false, values: [{ id: 'v1' }, { id: 'v2' }] },
|
|
23
|
+
{ id: 'DIM4', header: false, values: [{ id: 'v1' }, { id: 'v2' }] },
|
|
24
|
+
{ id: 'DIM5', header: false, values: [{ id: '_Z' }, { id: 'v2', display: false }] },
|
|
25
|
+
{ id: 'DIM6', header: false, values: [{ id: 'v1', display: false }, { id: 'v2', display: false }] }
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
const attributes = [
|