@gisce/ooui 0.6.15 → 0.7.2
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/dist/Graph/processor/graphProcessor.js +12 -1
- package/dist/Graph/processor/graphProcessor.js.map +1 -1
- package/dist/Graph/processor/timerangeHelper.d.ts +33 -0
- package/dist/Graph/processor/timerangeHelper.js +228 -0
- package/dist/Graph/processor/timerangeHelper.js.map +1 -0
- package/dist/Tags.d.ts +32 -0
- package/dist/Tags.js +93 -0
- package/dist/Tags.js.map +1 -0
- package/dist/WidgetFactory.js +5 -0
- package/dist/WidgetFactory.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/Graph/processor/graphProcessor.ts +14 -1
- package/src/Graph/processor/timerangeHelper.ts +290 -0
- package/src/Tags.ts +74 -0
- package/src/WidgetFactory.ts +5 -0
- package/src/index.ts +2 -0
- package/src/spec/Tags.spec.ts +25 -0
- package/src/spec/WidgetFactory.spec.ts +9 -0
- package/src/spec/domainParser.spec.ts +0 -12
- package/src/spec/graphProcessor.spec.ts +24 -0
- package/src/spec/timerangeHelper.spec.ts +603 -0
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
import {
|
|
2
|
+
checkDatesConsecutive,
|
|
3
|
+
adjustXValuesForTimeRage,
|
|
4
|
+
combineValuesForTimerange,
|
|
5
|
+
fillGapsInTimerangeData,
|
|
6
|
+
getMissingConsecutiveDates,
|
|
7
|
+
} from "../Graph/processor/timerangeHelper";
|
|
8
|
+
|
|
9
|
+
describe("a timerangeHelper", () => {
|
|
10
|
+
describe("in checkDatesConsecutive function", () => {
|
|
11
|
+
describe("with day units", () => {
|
|
12
|
+
it("should return true with only one date", () => {
|
|
13
|
+
const consecutive = checkDatesConsecutive(["2020-01-01"], "days");
|
|
14
|
+
expect(consecutive).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
it("should return false with two non consecutive dates", () => {
|
|
17
|
+
const consecutive = checkDatesConsecutive(
|
|
18
|
+
["2020-01-01", "2020-01-05"],
|
|
19
|
+
"days"
|
|
20
|
+
);
|
|
21
|
+
expect(consecutive).toBeFalsy();
|
|
22
|
+
});
|
|
23
|
+
it("should return true with two consecutive dates", () => {
|
|
24
|
+
const consecutive = checkDatesConsecutive(
|
|
25
|
+
["2020-01-01", "2020-01-02"],
|
|
26
|
+
"days"
|
|
27
|
+
);
|
|
28
|
+
expect(consecutive).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
it("should return false with three non consecutive dates", () => {
|
|
31
|
+
const consecutive = checkDatesConsecutive(
|
|
32
|
+
["2020-01-01", "2020-01-02", "2020-07-02"],
|
|
33
|
+
"days"
|
|
34
|
+
);
|
|
35
|
+
expect(consecutive).toBeFalsy();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe("with hour units", () => {
|
|
39
|
+
it("should return true with only one date", () => {
|
|
40
|
+
const consecutive = checkDatesConsecutive(
|
|
41
|
+
["2020-01-01 18:00"],
|
|
42
|
+
"hours"
|
|
43
|
+
);
|
|
44
|
+
expect(consecutive).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
it("should return false with two non consecutive dates", () => {
|
|
47
|
+
const consecutive = checkDatesConsecutive(
|
|
48
|
+
["2020-01-01 18:00", "2020-01-05 05:00"],
|
|
49
|
+
"hours"
|
|
50
|
+
);
|
|
51
|
+
expect(consecutive).toBeFalsy();
|
|
52
|
+
});
|
|
53
|
+
it("should return true with two consecutive dates", () => {
|
|
54
|
+
const consecutive = checkDatesConsecutive(
|
|
55
|
+
["2020-01-01 18:00", "2020-01-01 19:00"],
|
|
56
|
+
"hours"
|
|
57
|
+
);
|
|
58
|
+
expect(consecutive).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
it("should return false with three non consecutive dates", () => {
|
|
61
|
+
const consecutive = checkDatesConsecutive(
|
|
62
|
+
["2020-01-01 01:00", "2020-01-01 04:00", "2020-01-02 01:00"],
|
|
63
|
+
"hours"
|
|
64
|
+
);
|
|
65
|
+
expect(consecutive).toBeFalsy();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("with week units", () => {
|
|
69
|
+
it("should return true with only one date", () => {
|
|
70
|
+
const consecutive = checkDatesConsecutive(["2020-01"], "weeks");
|
|
71
|
+
expect(consecutive).toBeTruthy();
|
|
72
|
+
});
|
|
73
|
+
it("should return false with two non consecutive dates", () => {
|
|
74
|
+
const consecutive = checkDatesConsecutive(
|
|
75
|
+
["2020-01", "2020-03"],
|
|
76
|
+
"weeks"
|
|
77
|
+
);
|
|
78
|
+
expect(consecutive).toBeFalsy();
|
|
79
|
+
});
|
|
80
|
+
it("should return true with two consecutive dates", () => {
|
|
81
|
+
const consecutive = checkDatesConsecutive(
|
|
82
|
+
["2020-24", "2020-25"],
|
|
83
|
+
"weeks"
|
|
84
|
+
);
|
|
85
|
+
expect(consecutive).toBeTruthy();
|
|
86
|
+
});
|
|
87
|
+
it("should return false with three non consecutive dates", () => {
|
|
88
|
+
const consecutive = checkDatesConsecutive(
|
|
89
|
+
["2020-01", "2020-02", "2020-04"],
|
|
90
|
+
"weeks"
|
|
91
|
+
);
|
|
92
|
+
expect(consecutive).toBeFalsy();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe("in adjustXValuesForTimeRage function", () => {
|
|
97
|
+
it("should transform x values for same hour grouping", () => {
|
|
98
|
+
const values = [
|
|
99
|
+
{
|
|
100
|
+
x: "2022-06-01 15:03:11",
|
|
101
|
+
value: 1,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
x: "2022-06-02 15:03:11",
|
|
105
|
+
value: 2,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
x: "2022-06-03 15:03:11",
|
|
109
|
+
value: 3,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
x: "2022-06-03 15:13:11",
|
|
113
|
+
value: 4,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
x: "2022-06-03 16:13:11",
|
|
117
|
+
value: 5,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
x: "2022-06-03 16:53:11",
|
|
121
|
+
value: 6,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
x: "2022-06-03 16:59:11",
|
|
125
|
+
value: 7,
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
const adjustedValues = adjustXValuesForTimeRage({
|
|
129
|
+
values,
|
|
130
|
+
timerange: "hour",
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(adjustedValues.length).toBe(7);
|
|
134
|
+
expect(adjustedValues[0].x).toBe("2022-06-01 15:00");
|
|
135
|
+
expect(adjustedValues[0].value).toBe(1);
|
|
136
|
+
expect(adjustedValues[1].x).toBe("2022-06-02 15:00");
|
|
137
|
+
expect(adjustedValues[1].value).toBe(2);
|
|
138
|
+
expect(adjustedValues[2].x).toBe("2022-06-03 15:00");
|
|
139
|
+
expect(adjustedValues[2].value).toBe(3);
|
|
140
|
+
expect(adjustedValues[3].x).toBe("2022-06-03 15:00");
|
|
141
|
+
expect(adjustedValues[3].value).toBe(4);
|
|
142
|
+
expect(adjustedValues[4].x).toBe("2022-06-03 16:00");
|
|
143
|
+
expect(adjustedValues[4].value).toBe(5);
|
|
144
|
+
expect(adjustedValues[5].x).toBe("2022-06-03 16:00");
|
|
145
|
+
expect(adjustedValues[5].value).toBe(6);
|
|
146
|
+
expect(adjustedValues[6].x).toBe("2022-06-03 16:00");
|
|
147
|
+
expect(adjustedValues[6].value).toBe(7);
|
|
148
|
+
});
|
|
149
|
+
it("should transform x values for same day grouping", () => {
|
|
150
|
+
const values = [
|
|
151
|
+
{
|
|
152
|
+
x: "2022-06-01 15:03:11",
|
|
153
|
+
value: 1,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
x: "2022-06-02 15:03:11",
|
|
157
|
+
value: 2,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
x: "2022-06-03 15:03:11",
|
|
161
|
+
value: 3,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
x: "2022-06-03 15:13:11",
|
|
165
|
+
value: 4,
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
x: "2022-06-04 16:13:11",
|
|
169
|
+
value: 5,
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
x: "2022-06-04 16:53:11",
|
|
173
|
+
value: 6,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
x: "2022-06-05 16:59:11",
|
|
177
|
+
value: 7,
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
const adjustedValues = adjustXValuesForTimeRage({
|
|
181
|
+
values,
|
|
182
|
+
timerange: "day",
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
expect(adjustedValues.length).toBe(7);
|
|
186
|
+
expect(adjustedValues[0].x).toBe("2022-06-01");
|
|
187
|
+
expect(adjustedValues[0].value).toBe(1);
|
|
188
|
+
expect(adjustedValues[1].x).toBe("2022-06-02");
|
|
189
|
+
expect(adjustedValues[1].value).toBe(2);
|
|
190
|
+
expect(adjustedValues[2].x).toBe("2022-06-03");
|
|
191
|
+
expect(adjustedValues[2].value).toBe(3);
|
|
192
|
+
expect(adjustedValues[3].x).toBe("2022-06-03");
|
|
193
|
+
expect(adjustedValues[3].value).toBe(4);
|
|
194
|
+
expect(adjustedValues[4].x).toBe("2022-06-04");
|
|
195
|
+
expect(adjustedValues[4].value).toBe(5);
|
|
196
|
+
expect(adjustedValues[5].x).toBe("2022-06-04");
|
|
197
|
+
expect(adjustedValues[5].value).toBe(6);
|
|
198
|
+
expect(adjustedValues[6].x).toBe("2022-06-05");
|
|
199
|
+
expect(adjustedValues[6].value).toBe(7);
|
|
200
|
+
});
|
|
201
|
+
it("should transform x values for same week grouping", () => {
|
|
202
|
+
const values = [
|
|
203
|
+
{
|
|
204
|
+
x: "2022-06-01 15:03:11",
|
|
205
|
+
value: 1,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
x: "2022-06-02 15:03:11",
|
|
209
|
+
value: 2,
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
x: "2022-06-03 15:03:11",
|
|
213
|
+
value: 3,
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
x: "2022-06-03 15:13:11",
|
|
217
|
+
value: 4,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
x: "2022-06-04 16:13:11",
|
|
221
|
+
value: 5,
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
x: "2022-06-04 16:53:11",
|
|
225
|
+
value: 6,
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
x: "2022-06-05 16:59:11",
|
|
229
|
+
value: 7,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
x: "2022-06-15 16:59:11",
|
|
233
|
+
value: 8,
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
x: "2022-06-25 16:59:11",
|
|
237
|
+
value: 9,
|
|
238
|
+
},
|
|
239
|
+
];
|
|
240
|
+
const adjustedValues = adjustXValuesForTimeRage({
|
|
241
|
+
values,
|
|
242
|
+
timerange: "week",
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
expect(adjustedValues.length).toBe(9);
|
|
246
|
+
expect(adjustedValues[0].x).toBe("2022-22");
|
|
247
|
+
expect(adjustedValues[0].value).toBe(1);
|
|
248
|
+
expect(adjustedValues[1].x).toBe("2022-22");
|
|
249
|
+
expect(adjustedValues[1].value).toBe(2);
|
|
250
|
+
expect(adjustedValues[2].x).toBe("2022-22");
|
|
251
|
+
expect(adjustedValues[2].value).toBe(3);
|
|
252
|
+
expect(adjustedValues[3].x).toBe("2022-22");
|
|
253
|
+
expect(adjustedValues[3].value).toBe(4);
|
|
254
|
+
expect(adjustedValues[4].x).toBe("2022-22");
|
|
255
|
+
expect(adjustedValues[4].value).toBe(5);
|
|
256
|
+
expect(adjustedValues[5].x).toBe("2022-22");
|
|
257
|
+
expect(adjustedValues[5].value).toBe(6);
|
|
258
|
+
expect(adjustedValues[6].x).toBe("2022-22");
|
|
259
|
+
expect(adjustedValues[6].value).toBe(7);
|
|
260
|
+
expect(adjustedValues[7].x).toBe("2022-24");
|
|
261
|
+
expect(adjustedValues[7].value).toBe(8);
|
|
262
|
+
expect(adjustedValues[8].x).toBe("2022-25");
|
|
263
|
+
expect(adjustedValues[8].value).toBe(9);
|
|
264
|
+
});
|
|
265
|
+
it("should transform x values for same month grouping", () => {
|
|
266
|
+
const values = [
|
|
267
|
+
{
|
|
268
|
+
x: "2022-06-01 15:03:11",
|
|
269
|
+
value: 1,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
x: "2022-06-02 15:03:11",
|
|
273
|
+
value: 2,
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
x: "2022-04-03 15:03:11",
|
|
277
|
+
value: 3,
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
x: "2022-04-03 15:13:11",
|
|
281
|
+
value: 4,
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
x: "2022-05-04 16:13:11",
|
|
285
|
+
value: 5,
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
x: "2022-01-04 16:53:11",
|
|
289
|
+
value: 6,
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
x: "2022-02-05 16:59:11",
|
|
293
|
+
value: 7,
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
x: "2022-02-15 16:59:11",
|
|
297
|
+
value: 8,
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
x: "2021-03-25 16:59:11",
|
|
301
|
+
value: 9,
|
|
302
|
+
},
|
|
303
|
+
];
|
|
304
|
+
const adjustedValues = adjustXValuesForTimeRage({
|
|
305
|
+
values,
|
|
306
|
+
timerange: "month",
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
expect(adjustedValues.length).toBe(9);
|
|
310
|
+
expect(adjustedValues[0].x).toBe("2022-06");
|
|
311
|
+
expect(adjustedValues[0].value).toBe(1);
|
|
312
|
+
expect(adjustedValues[1].x).toBe("2022-06");
|
|
313
|
+
expect(adjustedValues[1].value).toBe(2);
|
|
314
|
+
expect(adjustedValues[2].x).toBe("2022-04");
|
|
315
|
+
expect(adjustedValues[2].value).toBe(3);
|
|
316
|
+
expect(adjustedValues[3].x).toBe("2022-04");
|
|
317
|
+
expect(adjustedValues[3].value).toBe(4);
|
|
318
|
+
expect(adjustedValues[4].x).toBe("2022-05");
|
|
319
|
+
expect(adjustedValues[4].value).toBe(5);
|
|
320
|
+
expect(adjustedValues[5].x).toBe("2022-01");
|
|
321
|
+
expect(adjustedValues[5].value).toBe(6);
|
|
322
|
+
expect(adjustedValues[6].x).toBe("2022-02");
|
|
323
|
+
expect(adjustedValues[6].value).toBe(7);
|
|
324
|
+
expect(adjustedValues[7].x).toBe("2022-02");
|
|
325
|
+
expect(adjustedValues[7].value).toBe(8);
|
|
326
|
+
expect(adjustedValues[8].x).toBe("2021-03");
|
|
327
|
+
expect(adjustedValues[8].value).toBe(9);
|
|
328
|
+
});
|
|
329
|
+
it("should transform x values for same year grouping", () => {
|
|
330
|
+
const values = [
|
|
331
|
+
{
|
|
332
|
+
x: "2022-06-01 15:03:11",
|
|
333
|
+
value: 1,
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
x: "2022-06-02 15:03:11",
|
|
337
|
+
value: 2,
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
x: "2023-04-03 15:03:11",
|
|
341
|
+
value: 3,
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
x: "2023-04-03 15:13:11",
|
|
345
|
+
value: 4,
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
x: "2020-05-04 16:13:11",
|
|
349
|
+
value: 5,
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
x: "2020-01-04 16:53:11",
|
|
353
|
+
value: 6,
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
x: "2019-02-05 16:59:11",
|
|
357
|
+
value: 7,
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
x: "2018-02-15 16:59:11",
|
|
361
|
+
value: 8,
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
x: "2018-03-25 16:59:11",
|
|
365
|
+
value: 9,
|
|
366
|
+
},
|
|
367
|
+
];
|
|
368
|
+
const adjustedValues = adjustXValuesForTimeRage({
|
|
369
|
+
values,
|
|
370
|
+
timerange: "year",
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
expect(adjustedValues.length).toBe(9);
|
|
374
|
+
expect(adjustedValues[0].x).toBe("2022");
|
|
375
|
+
expect(adjustedValues[0].value).toBe(1);
|
|
376
|
+
expect(adjustedValues[1].x).toBe("2022");
|
|
377
|
+
expect(adjustedValues[1].value).toBe(2);
|
|
378
|
+
expect(adjustedValues[2].x).toBe("2023");
|
|
379
|
+
expect(adjustedValues[2].value).toBe(3);
|
|
380
|
+
expect(adjustedValues[3].x).toBe("2023");
|
|
381
|
+
expect(adjustedValues[3].value).toBe(4);
|
|
382
|
+
expect(adjustedValues[4].x).toBe("2020");
|
|
383
|
+
expect(adjustedValues[4].value).toBe(5);
|
|
384
|
+
expect(adjustedValues[5].x).toBe("2020");
|
|
385
|
+
expect(adjustedValues[5].value).toBe(6);
|
|
386
|
+
expect(adjustedValues[6].x).toBe("2019");
|
|
387
|
+
expect(adjustedValues[6].value).toBe(7);
|
|
388
|
+
expect(adjustedValues[7].x).toBe("2018");
|
|
389
|
+
expect(adjustedValues[7].value).toBe(8);
|
|
390
|
+
expect(adjustedValues[8].x).toBe("2018");
|
|
391
|
+
expect(adjustedValues[8].value).toBe(9);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
describe("in combineValuesForTimerange function", () => {
|
|
395
|
+
it("should combine values for same hour grouping", () => {
|
|
396
|
+
const values = [
|
|
397
|
+
{
|
|
398
|
+
x: "2022-06-01 15:03:11",
|
|
399
|
+
value: 1,
|
|
400
|
+
operator: "+",
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
x: "2022-06-01 15:03:11",
|
|
404
|
+
value: 2,
|
|
405
|
+
operator: "+",
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
x: "2022-06-02 16:03:11",
|
|
409
|
+
value: 3,
|
|
410
|
+
operator: "+",
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
x: "2022-06-02 16:53:11",
|
|
414
|
+
value: 4,
|
|
415
|
+
operator: "+",
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
x: "2022-06-03 18:03:11",
|
|
419
|
+
value: 5,
|
|
420
|
+
operator: "+",
|
|
421
|
+
},
|
|
422
|
+
];
|
|
423
|
+
const combinedValues = combineValuesForTimerange({
|
|
424
|
+
values,
|
|
425
|
+
timerange: "hour",
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
expect(combinedValues.length).toBe(3);
|
|
429
|
+
expect(combinedValues[0].x).toBe("2022-06-01 15:00");
|
|
430
|
+
expect(combinedValues[0].value).toBe(3);
|
|
431
|
+
expect(combinedValues[1].x).toBe("2022-06-02 16:00");
|
|
432
|
+
expect(combinedValues[1].value).toBe(7);
|
|
433
|
+
expect(combinedValues[2].x).toBe("2022-06-03 18:00");
|
|
434
|
+
expect(combinedValues[2].value).toBe(5);
|
|
435
|
+
});
|
|
436
|
+
it("should combine values for same day grouping with type and stacked", () => {
|
|
437
|
+
const values = [
|
|
438
|
+
{
|
|
439
|
+
x: "2022-06-01 15:03:11",
|
|
440
|
+
value: 1,
|
|
441
|
+
operator: "+",
|
|
442
|
+
type: "Data alta",
|
|
443
|
+
stacked: "sortida",
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
x: "2022-06-01 15:03:11",
|
|
447
|
+
value: 2,
|
|
448
|
+
operator: "+",
|
|
449
|
+
type: "Data alta",
|
|
450
|
+
stacked: "sortida",
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
x: "2022-06-02 16:03:11",
|
|
454
|
+
value: 3,
|
|
455
|
+
operator: "+",
|
|
456
|
+
type: "Data baixa",
|
|
457
|
+
stacked: "entrada",
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
x: "2022-06-02 16:53:11",
|
|
461
|
+
value: 4,
|
|
462
|
+
operator: "+",
|
|
463
|
+
type: "Data alta",
|
|
464
|
+
stacked: "sortida",
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
x: "2022-06-03 18:03:11",
|
|
468
|
+
value: 5,
|
|
469
|
+
operator: "+",
|
|
470
|
+
type: "Data alta",
|
|
471
|
+
stacked: "sortida",
|
|
472
|
+
},
|
|
473
|
+
];
|
|
474
|
+
const combinedValues = combineValuesForTimerange({
|
|
475
|
+
values,
|
|
476
|
+
timerange: "day",
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
expect(combinedValues.length).toBe(4);
|
|
480
|
+
expect(combinedValues[0].x).toBe("2022-06-01");
|
|
481
|
+
expect(combinedValues[0].value).toBe(3);
|
|
482
|
+
expect(combinedValues[0].type).toBe("Data alta");
|
|
483
|
+
expect(combinedValues[0].stacked).toBe("sortida");
|
|
484
|
+
|
|
485
|
+
expect(combinedValues[1].x).toBe("2022-06-02");
|
|
486
|
+
expect(combinedValues[1].value).toBe(3);
|
|
487
|
+
expect(combinedValues[1].type).toBe("Data baixa");
|
|
488
|
+
expect(combinedValues[1].stacked).toBe("entrada");
|
|
489
|
+
|
|
490
|
+
expect(combinedValues[2].x).toBe("2022-06-02");
|
|
491
|
+
expect(combinedValues[2].value).toBe(4);
|
|
492
|
+
expect(combinedValues[2].type).toBe("Data alta");
|
|
493
|
+
expect(combinedValues[2].stacked).toBe("sortida");
|
|
494
|
+
|
|
495
|
+
expect(combinedValues[3].x).toBe("2022-06-03");
|
|
496
|
+
expect(combinedValues[3].value).toBe(5);
|
|
497
|
+
expect(combinedValues[3].type).toBe("Data alta");
|
|
498
|
+
expect(combinedValues[3].stacked).toBe("sortida");
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
describe("in getMissingConsecutiveDates function", () => {
|
|
502
|
+
it("should return missing consecutive dates by hour", () => {
|
|
503
|
+
const dates = ["2021-01-01 15:00", "2021-01-01 18:00"];
|
|
504
|
+
const missingDates = getMissingConsecutiveDates({
|
|
505
|
+
dates,
|
|
506
|
+
timerange: "hour",
|
|
507
|
+
});
|
|
508
|
+
expect(missingDates.length).toBe(2);
|
|
509
|
+
expect(missingDates[0]).toBe("2021-01-01 16:00");
|
|
510
|
+
expect(missingDates[1]).toBe("2021-01-01 17:00");
|
|
511
|
+
});
|
|
512
|
+
it("should return missing consecutive dates by hour in two different days", () => {
|
|
513
|
+
const dates = ["2021-01-01 23:00", "2021-01-02 05:00"];
|
|
514
|
+
const missingDates = getMissingConsecutiveDates({
|
|
515
|
+
dates,
|
|
516
|
+
timerange: "hour",
|
|
517
|
+
});
|
|
518
|
+
expect(missingDates.length).toBe(5);
|
|
519
|
+
expect(missingDates[0]).toBe("2021-01-02 00:00");
|
|
520
|
+
expect(missingDates[1]).toBe("2021-01-02 01:00");
|
|
521
|
+
expect(missingDates[2]).toBe("2021-01-02 02:00");
|
|
522
|
+
expect(missingDates[3]).toBe("2021-01-02 03:00");
|
|
523
|
+
expect(missingDates[4]).toBe("2021-01-02 04:00");
|
|
524
|
+
});
|
|
525
|
+
it("should return missing consecutive dates by day", () => {
|
|
526
|
+
const dates = ["2021-01-01", "2021-01-15"];
|
|
527
|
+
const missingDates = getMissingConsecutiveDates({
|
|
528
|
+
dates,
|
|
529
|
+
timerange: "day",
|
|
530
|
+
});
|
|
531
|
+
expect(missingDates.length).toBe(13);
|
|
532
|
+
expect(missingDates[0]).toBe("2021-01-02");
|
|
533
|
+
expect(missingDates[12]).toBe("2021-01-14");
|
|
534
|
+
});
|
|
535
|
+
it("should return missing consecutive dates by day different month", () => {
|
|
536
|
+
const dates = ["2021-01-31", "2021-02-02"];
|
|
537
|
+
const missingDates = getMissingConsecutiveDates({
|
|
538
|
+
dates,
|
|
539
|
+
timerange: "day",
|
|
540
|
+
});
|
|
541
|
+
expect(missingDates.length).toBe(1);
|
|
542
|
+
expect(missingDates[0]).toBe("2021-02-01");
|
|
543
|
+
});
|
|
544
|
+
it("should return missing consecutive dates by day different year", () => {
|
|
545
|
+
const dates = ["2021-12-31", "2022-01-02"];
|
|
546
|
+
const missingDates = getMissingConsecutiveDates({
|
|
547
|
+
dates,
|
|
548
|
+
timerange: "day",
|
|
549
|
+
});
|
|
550
|
+
expect(missingDates.length).toBe(1);
|
|
551
|
+
expect(missingDates[0]).toBe("2022-01-01");
|
|
552
|
+
});
|
|
553
|
+
it("should return missing consecutive dates by week", () => {
|
|
554
|
+
const dates = ["2021-50", "2021-52"];
|
|
555
|
+
const missingDates = getMissingConsecutiveDates({
|
|
556
|
+
dates,
|
|
557
|
+
timerange: "week",
|
|
558
|
+
});
|
|
559
|
+
expect(missingDates.length).toBe(1);
|
|
560
|
+
expect(missingDates[0]).toBe("2021-51");
|
|
561
|
+
});
|
|
562
|
+
it("should return missing consecutive dates by week between years", () => {
|
|
563
|
+
const dates = ["2021-52", "2022-02"];
|
|
564
|
+
const missingDates = getMissingConsecutiveDates({
|
|
565
|
+
dates,
|
|
566
|
+
timerange: "week",
|
|
567
|
+
});
|
|
568
|
+
expect(missingDates.length).toBe(1);
|
|
569
|
+
expect(missingDates[0]).toBe("2022-01");
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
describe("in fillGapsInTimerangeData function", () => {
|
|
573
|
+
it("should fill gaps in data for hour grouping", () => {
|
|
574
|
+
const values = [
|
|
575
|
+
{
|
|
576
|
+
x: "2022-06-01 15:00",
|
|
577
|
+
value: 1,
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
x: "2022-06-01 20:00",
|
|
581
|
+
value: 2,
|
|
582
|
+
},
|
|
583
|
+
];
|
|
584
|
+
const filledValues = fillGapsInTimerangeData({
|
|
585
|
+
values,
|
|
586
|
+
timerange: "hour",
|
|
587
|
+
});
|
|
588
|
+
expect(filledValues.length).toBe(6);
|
|
589
|
+
expect(filledValues[0].x).toBe("2022-06-01 15:00");
|
|
590
|
+
expect(filledValues[0].value).toBe(1);
|
|
591
|
+
expect(filledValues[1].x).toBe("2022-06-01 16:00");
|
|
592
|
+
expect(filledValues[1].value).toBe(0);
|
|
593
|
+
expect(filledValues[2].x).toBe("2022-06-01 17:00");
|
|
594
|
+
expect(filledValues[2].value).toBe(0);
|
|
595
|
+
expect(filledValues[3].x).toBe("2022-06-01 18:00");
|
|
596
|
+
expect(filledValues[3].value).toBe(0);
|
|
597
|
+
expect(filledValues[4].x).toBe("2022-06-01 19:00");
|
|
598
|
+
expect(filledValues[4].value).toBe(0);
|
|
599
|
+
expect(filledValues[5].x).toBe("2022-06-01 20:00");
|
|
600
|
+
expect(filledValues[5].value).toBe(2);
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
});
|