@tmlmobilidade/databases 20260528.1652.52 → 20260528.1745.17
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.
|
@@ -52,8 +52,8 @@ declare class SimplifiedVehicleEventsNewClass extends ClickHouseInterfaceTemplat
|
|
|
52
52
|
* @param secondsAgo - The number of seconds in the past to consider for retrieving recent positions. Defaults to 90 seconds.
|
|
53
53
|
* @returns A promise resolving to an array of SimplifiedVehicleEvent objects, each representing the latest event for a vehicle within the specified period.
|
|
54
54
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
55
|
+
* When the latest event has no bearing, the immediately previous event's bearing is used if that
|
|
56
|
+
* event is at most 5 minutes older; otherwise bearing stays null.
|
|
57
57
|
*/
|
|
58
58
|
getPositions(secondsAgo?: number): Promise<SimplifiedVehicleEvent[]>;
|
|
59
59
|
/**
|
|
@@ -62,13 +62,29 @@ class SimplifiedVehicleEventsNewClass extends ClickHouseInterfaceTemplate {
|
|
|
62
62
|
* @param secondsAgo - The number of seconds in the past to consider for retrieving recent positions. Defaults to 90 seconds.
|
|
63
63
|
* @returns A promise resolving to an array of SimplifiedVehicleEvent objects, each representing the latest event for a vehicle within the specified period.
|
|
64
64
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
65
|
+
* When the latest event has no bearing, the immediately previous event's bearing is used if that
|
|
66
|
+
* event is at most 5 minutes older; otherwise bearing stays null.
|
|
67
67
|
*/
|
|
68
68
|
async getPositions(secondsAgo = 90) {
|
|
69
|
+
const bearingInferenceLookbackSeconds = 300;
|
|
70
|
+
const bearingInferenceMaxGapMs = bearingInferenceLookbackSeconds * 1000;
|
|
69
71
|
const query = `
|
|
70
72
|
SELECT *
|
|
71
|
-
FROM
|
|
73
|
+
FROM (
|
|
74
|
+
SELECT
|
|
75
|
+
* REPLACE(
|
|
76
|
+
if(
|
|
77
|
+
bearing IS NULL
|
|
78
|
+
AND lagInFrame(created_at) OVER w IS NOT NULL
|
|
79
|
+
AND (created_at - lagInFrame(created_at) OVER w) <= ${bearingInferenceMaxGapMs},
|
|
80
|
+
lagInFrame(bearing) OVER w,
|
|
81
|
+
bearing
|
|
82
|
+
) AS bearing
|
|
83
|
+
)
|
|
84
|
+
FROM "${this.databaseName}"."${this.tableName}"
|
|
85
|
+
WHERE created_at > toUnixTimestamp64Milli(now64(3) - INTERVAL ${secondsAgo + bearingInferenceLookbackSeconds} SECOND)
|
|
86
|
+
WINDOW w AS (PARTITION BY vehicle_id, agency_id ORDER BY created_at)
|
|
87
|
+
)
|
|
72
88
|
WHERE created_at > toUnixTimestamp64Milli(now64(3) - INTERVAL ${secondsAgo} SECOND)
|
|
73
89
|
ORDER BY created_at DESC
|
|
74
90
|
LIMIT 1 BY vehicle_id, agency_id
|