@xube/kit-aws-data 0.0.81 → 0.0.83
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/get/get-data.js +29 -10
- package/package.json +8 -8
- package/src/get/get-data.ts +36 -19
package/dist/get/get-data.js
CHANGED
|
@@ -6,14 +6,19 @@ const kit_constants_1 = require("@xube/kit-constants");
|
|
|
6
6
|
const kit_aws_data_schema_1 = require("@xube/kit-aws-data-schema");
|
|
7
7
|
const kit_log_1 = require("@xube/kit-log");
|
|
8
8
|
const kit_request_1 = require("@xube/kit-request");
|
|
9
|
-
const fetchItemsFromDB = async (request, tableName) => {
|
|
9
|
+
const fetchItemsFromDB = async (request, tableName, log = kit_log_1.XubeLog.getInstance()) => {
|
|
10
10
|
const queryItemsPromises = [];
|
|
11
|
+
const start = new Date(request.dateRange.start).getTime() / 1000;
|
|
12
|
+
const end = new Date(request.dateRange.end).getTime() / 1000;
|
|
13
|
+
log.info(`Fetching data for date range: ${JSON.stringify(request)}`);
|
|
14
|
+
log.info(`Start: ${start}`);
|
|
15
|
+
log.info(`End: ${end}`);
|
|
11
16
|
for (const device of request.devices) {
|
|
12
17
|
for (const component of device.components) {
|
|
13
18
|
queryItemsPromises.push((0, kit_aws_1.queryItemsFromTableBetween)(tableName, {
|
|
14
19
|
PK: (0, kit_aws_data_schema_1.getDataPartitionKey)(device.id),
|
|
15
|
-
SKstart: (0, kit_aws_data_schema_1.getDataSortKey)(component, `${
|
|
16
|
-
SKend: (0, kit_aws_data_schema_1.getDataSortKey)(component, `${
|
|
20
|
+
SKstart: (0, kit_aws_data_schema_1.getDataSortKey)(component, `${start}`),
|
|
21
|
+
SKend: (0, kit_aws_data_schema_1.getDataSortKey)(component, `${end}`),
|
|
17
22
|
}));
|
|
18
23
|
}
|
|
19
24
|
}
|
|
@@ -37,14 +42,28 @@ const processResponseItems = (response, log) => {
|
|
|
37
42
|
}
|
|
38
43
|
let component = device.components.find((component) => component.id === item.component);
|
|
39
44
|
if (!component) {
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
const componentId = item.component ?? (0, kit_aws_data_schema_1.getComponentIdFromSortKey)(item.SK);
|
|
46
|
+
if (componentId) {
|
|
47
|
+
component = {
|
|
48
|
+
id: componentId,
|
|
49
|
+
data: [
|
|
50
|
+
{
|
|
51
|
+
seconds: item.s,
|
|
52
|
+
microseconds: item.us,
|
|
53
|
+
readings: item.data,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
device.components.push(component);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
component.data.push({
|
|
62
|
+
seconds: item.s,
|
|
63
|
+
microseconds: item.us,
|
|
64
|
+
readings: item.data,
|
|
65
|
+
});
|
|
42
66
|
}
|
|
43
|
-
component.data.push({
|
|
44
|
-
seconds: item.s,
|
|
45
|
-
microseconds: item.us,
|
|
46
|
-
readings: item.data,
|
|
47
|
-
});
|
|
48
67
|
}
|
|
49
68
|
return { data: getDataResponse, errorCount: 0 };
|
|
50
69
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xube/kit-aws-data",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.83",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"homepage": "https://github.com/XubeLtd/dev-kit#readme",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@types/uuid": "^9.0.5",
|
|
21
|
-
"@xube/kit-aws": "^0.0.
|
|
22
|
-
"@xube/kit-aws-data-schema": "^0.0.
|
|
23
|
-
"@xube/kit-aws-schema": "^0.0.
|
|
24
|
-
"@xube/kit-generator": "^0.0.
|
|
25
|
-
"@xube/kit-log": "^0.0.
|
|
26
|
-
"@xube/kit-schema": "^0.0.
|
|
21
|
+
"@xube/kit-aws": "^0.0.83",
|
|
22
|
+
"@xube/kit-aws-data-schema": "^0.0.83",
|
|
23
|
+
"@xube/kit-aws-schema": "^0.0.83",
|
|
24
|
+
"@xube/kit-generator": "^0.0.83",
|
|
25
|
+
"@xube/kit-log": "^0.0.83",
|
|
26
|
+
"@xube/kit-schema": "^0.0.83",
|
|
27
27
|
"uuid": "^9.0.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@xube/kit-build": "^0.0.
|
|
30
|
+
"@xube/kit-build": "^0.0.83"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/get/get-data.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { StatusCode } from "@xube/kit-constants";
|
|
|
4
4
|
import {
|
|
5
5
|
GetDataByDateRangeRequest,
|
|
6
6
|
GetDataByDateRangeResponse,
|
|
7
|
+
getComponentIdFromSortKey,
|
|
7
8
|
getDataPartitionKey,
|
|
8
9
|
getDataSortKey,
|
|
9
10
|
isReadingV1,
|
|
@@ -13,23 +14,25 @@ import { XubeResponse } from "@xube/kit-request";
|
|
|
13
14
|
|
|
14
15
|
const fetchItemsFromDB = async (
|
|
15
16
|
request: GetDataByDateRangeRequest,
|
|
16
|
-
tableName: string
|
|
17
|
+
tableName: string,
|
|
18
|
+
log: XubeLog = XubeLog.getInstance()
|
|
17
19
|
): Promise<XubeResponse<TableItem[]>[]> => {
|
|
18
20
|
const queryItemsPromises: Promise<XubeResponse<TableItem[]>>[] = [];
|
|
19
21
|
|
|
22
|
+
const start = new Date(request.dateRange.start).getTime() / 1000;
|
|
23
|
+
const end = new Date(request.dateRange.end).getTime() / 1000;
|
|
24
|
+
|
|
25
|
+
log.info(`Fetching data for date range: ${JSON.stringify(request)}`);
|
|
26
|
+
log.info(`Start: ${start}`);
|
|
27
|
+
log.info(`End: ${end}`);
|
|
28
|
+
|
|
20
29
|
for (const device of request.devices) {
|
|
21
30
|
for (const component of device.components) {
|
|
22
31
|
queryItemsPromises.push(
|
|
23
32
|
queryItemsFromTableBetween(tableName, {
|
|
24
33
|
PK: getDataPartitionKey(device.id),
|
|
25
|
-
SKstart: getDataSortKey(
|
|
26
|
-
|
|
27
|
-
`${new Date(request.dateRange.start).getTime() / 1000}`
|
|
28
|
-
),
|
|
29
|
-
SKend: getDataSortKey(
|
|
30
|
-
component,
|
|
31
|
-
`${new Date(request.dateRange.end).getTime() / 1000}`
|
|
32
|
-
),
|
|
34
|
+
SKstart: getDataSortKey(component, `${start}`),
|
|
35
|
+
SKend: getDataSortKey(component, `${end}`),
|
|
33
36
|
})
|
|
34
37
|
);
|
|
35
38
|
}
|
|
@@ -58,7 +61,9 @@ const processResponseItems = (
|
|
|
58
61
|
return { errorCount: 1 };
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
let device = getDataResponse.devices.find(
|
|
64
|
+
let device = getDataResponse.devices.find(
|
|
65
|
+
(device) => device.id === item.id
|
|
66
|
+
);
|
|
62
67
|
if (!device) {
|
|
63
68
|
device = { id: item.id, components: [] };
|
|
64
69
|
getDataResponse.devices.push(device);
|
|
@@ -68,15 +73,27 @@ const processResponseItems = (
|
|
|
68
73
|
(component) => component.id === item.component
|
|
69
74
|
);
|
|
70
75
|
if (!component) {
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
const componentId = item.component ?? getComponentIdFromSortKey(item.SK);
|
|
77
|
+
if (componentId) {
|
|
78
|
+
component = {
|
|
79
|
+
id: componentId,
|
|
80
|
+
data: [
|
|
81
|
+
{
|
|
82
|
+
seconds: item.s,
|
|
83
|
+
microseconds: item.us,
|
|
84
|
+
readings: item.data,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
device.components.push(component);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
component.data.push({
|
|
92
|
+
seconds: item.s,
|
|
93
|
+
microseconds: item.us,
|
|
94
|
+
readings: item.data,
|
|
95
|
+
});
|
|
73
96
|
}
|
|
74
|
-
|
|
75
|
-
component.data.push({
|
|
76
|
-
seconds: item.s,
|
|
77
|
-
microseconds: item.us,
|
|
78
|
-
readings: item.data,
|
|
79
|
-
});
|
|
80
97
|
}
|
|
81
98
|
|
|
82
99
|
return { data: getDataResponse, errorCount: 0 };
|
|
@@ -88,7 +105,7 @@ export const getDataForDateRange = async (
|
|
|
88
105
|
log: XubeLog = XubeLog.getInstance()
|
|
89
106
|
): Promise<XubeResponse<GetDataByDateRangeResponse>> => {
|
|
90
107
|
const queryItemsResponses = await fetchItemsFromDB(request, tableName);
|
|
91
|
-
|
|
108
|
+
|
|
92
109
|
let totalErrorCount = 0;
|
|
93
110
|
const getDataResponse: GetDataByDateRangeResponse = { devices: [] };
|
|
94
111
|
|