@xube/kit-aws-hooks 0.0.49 → 0.0.50
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/generate.js +0 -1
- package/dist/transform.js +12 -4
- package/package.json +8 -8
- package/src/generate.ts +0 -1
- package/src/transform.test.ts +89 -0
- package/src/transform.ts +12 -6
package/dist/generate.js
CHANGED
package/dist/transform.js
CHANGED
|
@@ -33,17 +33,25 @@ const getTimeSeriesDataFromData = (items) => {
|
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
const timeSeriesEntry = timeSeriesEntriesById[item.id];
|
|
36
|
-
timeSeriesEntry.data.push(item.data);
|
|
37
36
|
const timeDifference = Math.floor((microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id]) /
|
|
38
37
|
getDivisorByTimeUnit(timeSeriesEntry.dtt));
|
|
39
|
-
|
|
38
|
+
timeSeriesEntry.data.push(item.data);
|
|
39
|
+
if (timeSeriesEntry.dt === 0) {
|
|
40
|
+
timeSeriesEntry.dt = timeDifference;
|
|
41
|
+
}
|
|
42
|
+
else if (timeDifference !== timeSeriesEntry.dt) {
|
|
40
43
|
if (!timeSeriesEntry.dataT) {
|
|
41
|
-
timeSeriesEntry.dataT = [
|
|
44
|
+
timeSeriesEntry.dataT = [
|
|
45
|
+
{
|
|
46
|
+
i: timeSeriesEntry.data.length - 1,
|
|
47
|
+
dt: timeDifference,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
42
50
|
}
|
|
43
51
|
else {
|
|
44
52
|
timeSeriesEntry.dataT.push({
|
|
45
53
|
i: timeSeriesEntry.data.length - 1,
|
|
46
|
-
dt:
|
|
54
|
+
dt: timeDifference,
|
|
47
55
|
});
|
|
48
56
|
}
|
|
49
57
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xube/kit-aws-hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/XubeLtd/dev-kit#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@xube/kit-build": "^0.0.
|
|
20
|
+
"@xube/kit-build": "^0.0.50"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@xube/kit-aws": "^0.0.
|
|
24
|
-
"@xube/kit-aws-schema": "^0.0.
|
|
25
|
-
"@xube/kit-data-schema": "^0.0.
|
|
26
|
-
"@xube/kit-log": "^0.0.
|
|
27
|
-
"@xube/kit-request": "^0.0.
|
|
28
|
-
"@xube/kit-schema": "^0.0.
|
|
23
|
+
"@xube/kit-aws": "^0.0.50",
|
|
24
|
+
"@xube/kit-aws-schema": "^0.0.50",
|
|
25
|
+
"@xube/kit-data-schema": "^0.0.50",
|
|
26
|
+
"@xube/kit-log": "^0.0.50",
|
|
27
|
+
"@xube/kit-request": "^0.0.50",
|
|
28
|
+
"@xube/kit-schema": "^0.0.50",
|
|
29
29
|
"zod": "^3.22.4"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/generate.ts
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { DATA_TYPE, ReadingV1 } from "@xube/kit-data-schema";
|
|
2
|
+
import { getTimeSeriesDataFromData, stageDataForSend } from "./transform";
|
|
3
|
+
import { TableItem } from "@xube/kit-aws-schema";
|
|
4
|
+
import { TimeSeries } from "@xube/kit-schema";
|
|
5
|
+
|
|
6
|
+
describe("getTimeSeriesDataFromData", () => {
|
|
7
|
+
it("should return an array of objects with the time series shape", () => {
|
|
8
|
+
const items: (ReadingV1 & TableItem)[] = [
|
|
9
|
+
{
|
|
10
|
+
PK: "",
|
|
11
|
+
SK: "",
|
|
12
|
+
data: "S,+000.30,+001.74,M,00,33",
|
|
13
|
+
s: 1697556567,
|
|
14
|
+
us: 136366,
|
|
15
|
+
type: DATA_TYPE,
|
|
16
|
+
id: "12345678",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
PK: "",
|
|
20
|
+
SK: "",
|
|
21
|
+
data: "S,+000.35,+001.84,M,00,39",
|
|
22
|
+
s: 1697556567,
|
|
23
|
+
us: 336628,
|
|
24
|
+
type: DATA_TYPE,
|
|
25
|
+
id: "12345678",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
PK: "",
|
|
29
|
+
SK: "",
|
|
30
|
+
data: "S,+000.26,+002.00,M,00,34",
|
|
31
|
+
s: 1697556567,
|
|
32
|
+
us: 539512,
|
|
33
|
+
type: DATA_TYPE,
|
|
34
|
+
id: "12345678",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
PK: "",
|
|
38
|
+
SK: "",
|
|
39
|
+
data: "S,+000.34,+001.88,M,00,34",
|
|
40
|
+
s: 1697556567,
|
|
41
|
+
us: 736473,
|
|
42
|
+
type: DATA_TYPE,
|
|
43
|
+
id: "12345678",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
PK: "",
|
|
47
|
+
SK: "",
|
|
48
|
+
data: "S,+000.35,+001.82,M,00,3F",
|
|
49
|
+
s: 1697556567,
|
|
50
|
+
us: 937183,
|
|
51
|
+
type: DATA_TYPE,
|
|
52
|
+
id: "12345678",
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const timeSeries: TimeSeries = getTimeSeriesDataFromData(items);
|
|
57
|
+
|
|
58
|
+
expect(timeSeries).toEqual([
|
|
59
|
+
{
|
|
60
|
+
v: "1",
|
|
61
|
+
m: {
|
|
62
|
+
id: "12345678",
|
|
63
|
+
trigger: DATA_TYPE,
|
|
64
|
+
source: "device",
|
|
65
|
+
},
|
|
66
|
+
t0: "2023-10-17T15:29:27.136366Z",
|
|
67
|
+
dtt: "ms",
|
|
68
|
+
dt: 200,
|
|
69
|
+
dataT: [
|
|
70
|
+
{
|
|
71
|
+
dt: 202,
|
|
72
|
+
i: 2,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
dt: 196,
|
|
76
|
+
i: 3,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
data: [
|
|
80
|
+
"S,+000.30,+001.74,M,00,33",
|
|
81
|
+
"S,+000.35,+001.84,M,00,39",
|
|
82
|
+
"S,+000.26,+002.00,M,00,34",
|
|
83
|
+
"S,+000.34,+001.88,M,00,34",
|
|
84
|
+
"S,+000.35,+001.82,M,00,3F",
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
});
|
package/src/transform.ts
CHANGED
|
@@ -36,21 +36,27 @@ export const getTimeSeriesDataFromData = (items: TableItem[]): TimeSeries => {
|
|
|
36
36
|
} else {
|
|
37
37
|
const timeSeriesEntry = timeSeriesEntriesById[item.id];
|
|
38
38
|
|
|
39
|
-
timeSeriesEntry.data.push(item.data);
|
|
40
|
-
|
|
41
39
|
const timeDifference = Math.floor(
|
|
42
40
|
(microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id]) /
|
|
43
41
|
getDivisorByTimeUnit(timeSeriesEntry.dtt)
|
|
44
42
|
);
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
timeSeriesEntry.data.push(item.data);
|
|
45
|
+
|
|
46
|
+
if (timeSeriesEntry.dt === 0) {
|
|
47
|
+
timeSeriesEntry.dt = timeDifference;
|
|
48
|
+
} else if (timeDifference !== timeSeriesEntry.dt) {
|
|
47
49
|
if (!timeSeriesEntry.dataT) {
|
|
48
|
-
timeSeriesEntry.dataT = [
|
|
50
|
+
timeSeriesEntry.dataT = [
|
|
51
|
+
{
|
|
52
|
+
i: timeSeriesEntry.data.length - 1,
|
|
53
|
+
dt: timeDifference,
|
|
54
|
+
},
|
|
55
|
+
];
|
|
49
56
|
} else {
|
|
50
57
|
timeSeriesEntry.dataT.push({
|
|
51
58
|
i: timeSeriesEntry.data.length - 1,
|
|
52
|
-
dt:
|
|
53
|
-
microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id],
|
|
59
|
+
dt: timeDifference,
|
|
54
60
|
});
|
|
55
61
|
}
|
|
56
62
|
}
|