@xube/kit-aws-hooks 0.0.57 → 0.0.59
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/transform.js +6 -4
- package/package.json +8 -8
- package/src/transform.test.ts +17 -13
- package/src/transform.ts +10 -4
package/dist/transform.js
CHANGED
|
@@ -13,12 +13,14 @@ const getTimeSeriesDataFromData = (items, log = kit_log_1.XubeLog.getInstance())
|
|
|
13
13
|
const previousMicroSecondsSinceEpochById = {};
|
|
14
14
|
log.info(`Staging data for send based on ${items.length} items.`);
|
|
15
15
|
log.info(JSON.stringify(items, null, 2));
|
|
16
|
-
|
|
16
|
+
const itemsOrderedByMicrosecondsSinceEpoch = items.sort((a, b) => microsecondsSinceEpoch(a.s, a.us ?? 0) -
|
|
17
|
+
microsecondsSinceEpoch(b.s, b.us ?? 0));
|
|
18
|
+
for (const item of itemsOrderedByMicrosecondsSinceEpoch) {
|
|
17
19
|
if (!(0, kit_data_schema_1.isReadingV1)(item)) {
|
|
18
20
|
console.log(`${item.type} is not a currently supported type.`);
|
|
19
21
|
continue;
|
|
20
22
|
}
|
|
21
|
-
const microsSinceEpoch = microsecondsSinceEpoch(item.s, item
|
|
23
|
+
const microsSinceEpoch = microsecondsSinceEpoch(item.s, item.us ?? 0);
|
|
22
24
|
if (!timeSeriesEntriesById[item.id]) {
|
|
23
25
|
timeSeriesEntriesById[item.id] = {
|
|
24
26
|
v: "1",
|
|
@@ -36,7 +38,7 @@ const getTimeSeriesDataFromData = (items, log = kit_log_1.XubeLog.getInstance())
|
|
|
36
38
|
}
|
|
37
39
|
else {
|
|
38
40
|
const timeSeriesEntry = timeSeriesEntriesById[item.id];
|
|
39
|
-
const timeDifference = Math.
|
|
41
|
+
const timeDifference = Math.round((microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id]) /
|
|
40
42
|
getDivisorByTimeUnit(timeSeriesEntry.dtt));
|
|
41
43
|
timeSeriesEntry.data.push(item.data);
|
|
42
44
|
if (timeSeriesEntry.dt === 0) {
|
|
@@ -86,7 +88,7 @@ function microsecondsSinceEpoch(s, us) {
|
|
|
86
88
|
return s * 1000000 + us;
|
|
87
89
|
}
|
|
88
90
|
function isoDateTimeWithMicroseconds(microsecondsSinceEpoch) {
|
|
89
|
-
const milliseconds = Math.
|
|
91
|
+
const milliseconds = Math.round(microsecondsSinceEpoch / 1000);
|
|
90
92
|
const microseconds = microsecondsSinceEpoch % 1000;
|
|
91
93
|
const date = new Date(milliseconds);
|
|
92
94
|
const year = date.getUTCFullYear();
|
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.59",
|
|
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.59"
|
|
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.59",
|
|
24
|
+
"@xube/kit-aws-schema": "^0.0.59",
|
|
25
|
+
"@xube/kit-data-schema": "^0.0.59",
|
|
26
|
+
"@xube/kit-log": "^0.0.59",
|
|
27
|
+
"@xube/kit-request": "^0.0.59",
|
|
28
|
+
"@xube/kit-schema": "^0.0.59",
|
|
29
29
|
"zod": "^3.22.4"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/transform.test.ts
CHANGED
|
@@ -10,8 +10,8 @@ describe("getTimeSeriesDataFromData", () => {
|
|
|
10
10
|
PK: "",
|
|
11
11
|
SK: "",
|
|
12
12
|
data: "S,+000.30,+001.74,M,00,33",
|
|
13
|
-
s:
|
|
14
|
-
us:
|
|
13
|
+
s: 1697578841,
|
|
14
|
+
us: 213581,
|
|
15
15
|
type: DATA_TYPE,
|
|
16
16
|
id: "12345678",
|
|
17
17
|
},
|
|
@@ -19,8 +19,8 @@ describe("getTimeSeriesDataFromData", () => {
|
|
|
19
19
|
PK: "",
|
|
20
20
|
SK: "",
|
|
21
21
|
data: "S,+000.35,+001.84,M,00,39",
|
|
22
|
-
s:
|
|
23
|
-
us:
|
|
22
|
+
s: 1697578841,
|
|
23
|
+
us: 413572,
|
|
24
24
|
type: DATA_TYPE,
|
|
25
25
|
id: "12345678",
|
|
26
26
|
},
|
|
@@ -28,8 +28,8 @@ describe("getTimeSeriesDataFromData", () => {
|
|
|
28
28
|
PK: "",
|
|
29
29
|
SK: "",
|
|
30
30
|
data: "S,+000.26,+002.00,M,00,34",
|
|
31
|
-
s:
|
|
32
|
-
us:
|
|
31
|
+
s: 1697578841,
|
|
32
|
+
us: 612976,
|
|
33
33
|
type: DATA_TYPE,
|
|
34
34
|
id: "12345678",
|
|
35
35
|
},
|
|
@@ -37,8 +37,8 @@ describe("getTimeSeriesDataFromData", () => {
|
|
|
37
37
|
PK: "",
|
|
38
38
|
SK: "",
|
|
39
39
|
data: "S,+000.34,+001.88,M,00,34",
|
|
40
|
-
s:
|
|
41
|
-
us:
|
|
40
|
+
s: 1697578841,
|
|
41
|
+
us: 813754,
|
|
42
42
|
type: DATA_TYPE,
|
|
43
43
|
id: "12345678",
|
|
44
44
|
},
|
|
@@ -46,8 +46,8 @@ describe("getTimeSeriesDataFromData", () => {
|
|
|
46
46
|
PK: "",
|
|
47
47
|
SK: "",
|
|
48
48
|
data: "S,+000.35,+001.82,M,00,3F",
|
|
49
|
-
s:
|
|
50
|
-
us:
|
|
49
|
+
s: 1697578842,
|
|
50
|
+
us: 13019,
|
|
51
51
|
type: DATA_TYPE,
|
|
52
52
|
id: "12345678",
|
|
53
53
|
},
|
|
@@ -63,18 +63,22 @@ describe("getTimeSeriesDataFromData", () => {
|
|
|
63
63
|
trigger: DATA_TYPE,
|
|
64
64
|
source: "device",
|
|
65
65
|
},
|
|
66
|
-
t0: "2023-10-
|
|
66
|
+
t0: "2023-10-17T21:40:41.214581Z",
|
|
67
67
|
dtt: "ms",
|
|
68
68
|
dt: 200,
|
|
69
69
|
dataT: [
|
|
70
70
|
{
|
|
71
|
-
dt:
|
|
71
|
+
dt: 199,
|
|
72
72
|
i: 2,
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
|
-
dt:
|
|
75
|
+
dt: 201,
|
|
76
76
|
i: 3,
|
|
77
77
|
},
|
|
78
|
+
{
|
|
79
|
+
dt: 199,
|
|
80
|
+
i: 4,
|
|
81
|
+
},
|
|
78
82
|
],
|
|
79
83
|
data: [
|
|
80
84
|
"S,+000.30,+001.74,M,00,33",
|
package/src/transform.ts
CHANGED
|
@@ -18,13 +18,19 @@ export const getTimeSeriesDataFromData = (
|
|
|
18
18
|
log.info(`Staging data for send based on ${items.length} items.`);
|
|
19
19
|
log.info(JSON.stringify(items, null, 2));
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const itemsOrderedByMicrosecondsSinceEpoch = items.sort(
|
|
22
|
+
(a, b) =>
|
|
23
|
+
microsecondsSinceEpoch(a.s, a.us ?? 0) -
|
|
24
|
+
microsecondsSinceEpoch(b.s, b.us ?? 0)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
for (const item of itemsOrderedByMicrosecondsSinceEpoch) {
|
|
22
28
|
if (!isReadingV1(item)) {
|
|
23
29
|
console.log(`${item.type} is not a currently supported type.`);
|
|
24
30
|
continue;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
const microsSinceEpoch = microsecondsSinceEpoch(item.s, item
|
|
33
|
+
const microsSinceEpoch = microsecondsSinceEpoch(item.s, item.us ?? 0);
|
|
28
34
|
|
|
29
35
|
if (!timeSeriesEntriesById[item.id]) {
|
|
30
36
|
timeSeriesEntriesById[item.id] = {
|
|
@@ -43,7 +49,7 @@ export const getTimeSeriesDataFromData = (
|
|
|
43
49
|
} else {
|
|
44
50
|
const timeSeriesEntry = timeSeriesEntriesById[item.id];
|
|
45
51
|
|
|
46
|
-
const timeDifference = Math.
|
|
52
|
+
const timeDifference = Math.round(
|
|
47
53
|
(microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id]) /
|
|
48
54
|
getDivisorByTimeUnit(timeSeriesEntry.dtt)
|
|
49
55
|
);
|
|
@@ -99,7 +105,7 @@ function microsecondsSinceEpoch(s: number, us: number): number {
|
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
function isoDateTimeWithMicroseconds(microsecondsSinceEpoch: number): string {
|
|
102
|
-
const milliseconds = Math.
|
|
108
|
+
const milliseconds = Math.round(microsecondsSinceEpoch / 1000);
|
|
103
109
|
const microseconds = microsecondsSinceEpoch % 1000;
|
|
104
110
|
|
|
105
111
|
const date = new Date(milliseconds);
|