@golemio/pid 2.1.13-dev.501881019 → 2.1.13-dev.506830926
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/db/example/00_truncate_tables.sql +1 -0
- package/db/example/{departure_directions.sql → 01_departure_directions.sql} +0 -0
- package/db/example/{pid_line_example_115.sql → 02_pid_line_example_115.sql} +0 -0
- package/db/example/{ropid_gtfs_dump.sql → 03_ropidgtfs_dump.sql} +0 -0
- package/db/example/{ropidvymi_example.sql → 04_ropidvymi_example.sql} +0 -0
- package/db/example/{vehicle_positions_dump.sql → 05_vehicle_positions_dump.sql} +0 -0
- package/db/example/06_ropidgtfs_train_trips_stop_times.sql +83 -0
- package/db/example/{zzz_precomputed_tables.sql → 99_precomputed_tables.sql} +0 -0
- package/db/example/{trip_updates.pb → pb/trip_updates.pb} +0 -0
- package/db/example/{vehicle_positions.pb → pb/vehicle_positions.pb} +0 -0
- package/db/example/tmp_example.sql +7 -0
- package/dist/const.d.ts +4 -0
- package/dist/const.js +6 -1
- package/dist/const.js.map +1 -1
- package/dist/integration-engine/ropid-gtfs/RopidGTFSScheduledTripsModel.d.ts +1 -1
- package/dist/integration-engine/ropid-gtfs/RopidGTFSStopTimesModel.d.ts +11 -0
- package/dist/integration-engine/ropid-gtfs/RopidGTFSStopTimesModel.js +32 -0
- package/dist/integration-engine/ropid-gtfs/RopidGTFSStopTimesModel.js.map +1 -1
- package/dist/integration-engine/ropid-gtfs/RopidGTFSWorker.js +2 -2
- package/dist/integration-engine/ropid-gtfs/RopidGTFSWorker.js.map +1 -1
- package/dist/integration-engine/shared/RopidMetadataModel.js +13 -31
- package/dist/integration-engine/shared/RopidMetadataModel.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/VehiclePositionsInterfaces.d.ts +152 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsInterfaces.js +3 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsInterfaces.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsUtils.d.ts +22 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsUtils.js +53 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsUtils.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsWorker.d.ts +32 -93
- package/dist/integration-engine/vehicle-positions/VehiclePositionsWorker.js +179 -111
- package/dist/integration-engine/vehicle-positions/VehiclePositionsWorker.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/index.d.ts +2 -5
- package/dist/integration-engine/vehicle-positions/index.js +2 -5
- package/dist/integration-engine/vehicle-positions/index.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsPositionsModel.d.ts → models/VehiclePositionsPositionsModel.d.ts} +3 -3
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsPositionsModel.js → models/VehiclePositionsPositionsModel.js} +3 -3
- package/dist/integration-engine/vehicle-positions/models/VehiclePositionsPositionsModel.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsRunsMessagesModel.d.ts → models/VehiclePositionsRunsMessagesModel.d.ts} +0 -0
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsRunsMessagesModel.js → models/VehiclePositionsRunsMessagesModel.js} +5 -5
- package/dist/integration-engine/vehicle-positions/models/VehiclePositionsRunsMessagesModel.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsRunsModel.d.ts → models/VehiclePositionsRunsModel.d.ts} +2 -2
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsRunsModel.js → models/VehiclePositionsRunsModel.js} +2 -2
- package/dist/integration-engine/vehicle-positions/models/VehiclePositionsRunsModel.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsStopsModel.d.ts → models/VehiclePositionsStopsModel.d.ts} +0 -0
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsStopsModel.js → models/VehiclePositionsStopsModel.js} +1 -1
- package/dist/integration-engine/vehicle-positions/models/VehiclePositionsStopsModel.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsTripsModel.d.ts → models/VehiclePositionsTripsModel.d.ts} +6 -3
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsTripsModel.js → models/VehiclePositionsTripsModel.js} +47 -32
- package/dist/integration-engine/vehicle-positions/models/VehiclePositionsTripsModel.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/models/index.d.ts +5 -0
- package/dist/integration-engine/vehicle-positions/models/index.js +18 -0
- package/dist/integration-engine/vehicle-positions/models/index.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsRunsTransformation.d.ts → transformations/VehiclePositionsRunsTransformation.d.ts} +1 -1
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsRunsTransformation.js → transformations/VehiclePositionsRunsTransformation.js} +1 -1
- package/dist/integration-engine/vehicle-positions/transformations/VehiclePositionsRunsTransformation.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/transformations/VehiclePositionsTransformation.d.ts +108 -0
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsTransformation.js → transformations/VehiclePositionsTransformation.js} +42 -45
- package/dist/integration-engine/vehicle-positions/transformations/VehiclePositionsTransformation.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/transformations/index.d.ts +2 -0
- package/dist/integration-engine/vehicle-positions/transformations/index.js +15 -0
- package/dist/integration-engine/vehicle-positions/transformations/index.js.map +1 -0
- package/dist/output-gateway/vehicle-positions/models/VehiclePositionsTripsModel.js +1 -1
- package/dist/output-gateway/vehicle-positions/models/VehiclePositionsTripsModel.js.map +1 -1
- package/dist/schema-definitions/vehicle-positions/index.d.ts +9 -2
- package/dist/schema-definitions/vehicle-positions/index.js +18 -2
- package/dist/schema-definitions/vehicle-positions/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/integration-engine/vehicle-positions/VehiclePositionsPositionsModel.js.map +0 -1
- package/dist/integration-engine/vehicle-positions/VehiclePositionsRunsMessagesModel.js.map +0 -1
- package/dist/integration-engine/vehicle-positions/VehiclePositionsRunsModel.js.map +0 -1
- package/dist/integration-engine/vehicle-positions/VehiclePositionsRunsTransformation.js.map +0 -1
- package/dist/integration-engine/vehicle-positions/VehiclePositionsStopsModel.js.map +0 -1
- package/dist/integration-engine/vehicle-positions/VehiclePositionsTransformation.d.ts +0 -49
- package/dist/integration-engine/vehicle-positions/VehiclePositionsTransformation.js.map +0 -1
- package/dist/integration-engine/vehicle-positions/VehiclePositionsTripsModel.js.map +0 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Feature, Point } from "@turf/turf";
|
|
2
|
+
import { ITripStopsResult } from "../ropid-gtfs/RopidGTFSStopTimesModel";
|
|
3
|
+
import { IShape, IStopTime } from "../ropid-gtfs/RopidGTFSTripsModel";
|
|
4
|
+
import { StatePositionEnum } from "../../const";
|
|
5
|
+
import { ITripPositionAttributes } from "./models/VehiclePositionsPositionsModel";
|
|
6
|
+
import { GTFSRouteTypeEnum } from "./models/VehiclePositionsTripsModel";
|
|
7
|
+
export interface IComputedPositionAtStopStreak {
|
|
8
|
+
firstPositionTimestamp: number | null;
|
|
9
|
+
firstPositionDelay: number | null;
|
|
10
|
+
stop_sequence: number | null;
|
|
11
|
+
}
|
|
12
|
+
export interface IPositionsContext {
|
|
13
|
+
lastPositionId: string | null;
|
|
14
|
+
lastPositionOriginTimestamp: number | null;
|
|
15
|
+
lastPositionTracking: Feature<Point, ITripPositionAttributes> | null;
|
|
16
|
+
lastPositionCanceled: boolean | null;
|
|
17
|
+
lastPositionLastStop: {
|
|
18
|
+
id: string | null;
|
|
19
|
+
sequence: number | null;
|
|
20
|
+
arrival_time: number | null;
|
|
21
|
+
departure_time: number | null;
|
|
22
|
+
};
|
|
23
|
+
lastPositionDelay: number | null;
|
|
24
|
+
atStopStreak: IComputedPositionAtStopStreak;
|
|
25
|
+
lastPositionBeforeTrackDelayed: {
|
|
26
|
+
delay: number;
|
|
27
|
+
origin_timestamp: number;
|
|
28
|
+
} | null;
|
|
29
|
+
isLastPositionAfterTrack: boolean;
|
|
30
|
+
tripId: string;
|
|
31
|
+
}
|
|
32
|
+
export interface IPosition {
|
|
33
|
+
bearing: number | null;
|
|
34
|
+
state_process: string;
|
|
35
|
+
state_position: StatePositionEnum;
|
|
36
|
+
origin_timestamp: number;
|
|
37
|
+
id: string;
|
|
38
|
+
is_canceled: boolean;
|
|
39
|
+
lat: number;
|
|
40
|
+
lng: number;
|
|
41
|
+
tracking: number;
|
|
42
|
+
delay: number | null;
|
|
43
|
+
origin_time: string | null;
|
|
44
|
+
gtfsData?: IComputationTrip;
|
|
45
|
+
}
|
|
46
|
+
export interface IPositionToUpdate {
|
|
47
|
+
bearing?: number;
|
|
48
|
+
state_process: string;
|
|
49
|
+
state_position: StatePositionEnum;
|
|
50
|
+
origin_timestamp?: string;
|
|
51
|
+
id: string;
|
|
52
|
+
is_canceled?: boolean;
|
|
53
|
+
lat?: string;
|
|
54
|
+
lng?: string;
|
|
55
|
+
tracking?: number;
|
|
56
|
+
delay?: number | null;
|
|
57
|
+
origin_time?: string;
|
|
58
|
+
gtfsData?: IComputationTrip;
|
|
59
|
+
shape_dist_traveled?: number;
|
|
60
|
+
last_stop_arrival_time?: number;
|
|
61
|
+
last_stop_departure_time?: number;
|
|
62
|
+
last_stop_id?: string;
|
|
63
|
+
last_stop_sequence?: number;
|
|
64
|
+
last_stop_headsign?: string | null;
|
|
65
|
+
last_stop_name?: string;
|
|
66
|
+
next_stop_arrival_time?: number;
|
|
67
|
+
next_stop_departure_time?: number;
|
|
68
|
+
next_stop_id?: string;
|
|
69
|
+
next_stop_sequence?: number;
|
|
70
|
+
next_stop_name?: string;
|
|
71
|
+
this_stop_id?: string;
|
|
72
|
+
this_stop_sequence?: number;
|
|
73
|
+
this_stop_name?: string;
|
|
74
|
+
tcp_event?: string | null;
|
|
75
|
+
}
|
|
76
|
+
export interface IProcessedPositions {
|
|
77
|
+
context: IPositionsContext;
|
|
78
|
+
positions: IPositionToUpdate[];
|
|
79
|
+
}
|
|
80
|
+
export interface IUpdatePositionsIteratorOptions {
|
|
81
|
+
tripPositions: ITripPositionsWithGTFS;
|
|
82
|
+
startTimestamp: number;
|
|
83
|
+
startDayTimestamp: number;
|
|
84
|
+
context: IPositionsContext;
|
|
85
|
+
computedPositions: IPositionToUpdate[];
|
|
86
|
+
}
|
|
87
|
+
export interface IShapeGeometryAnchorPoint {
|
|
88
|
+
index: number;
|
|
89
|
+
coordinates: [number, number];
|
|
90
|
+
last_stop_sequence: number;
|
|
91
|
+
next_stop_sequence: number;
|
|
92
|
+
shape_dist_traveled: number;
|
|
93
|
+
this_stop_sequence: number | null;
|
|
94
|
+
}
|
|
95
|
+
export interface IShapeAnchorPoint {
|
|
96
|
+
index: number;
|
|
97
|
+
at_stop: boolean;
|
|
98
|
+
bearing: number;
|
|
99
|
+
coordinates: [number, number];
|
|
100
|
+
distance_from_last_stop: number;
|
|
101
|
+
last_stop_sequence: number;
|
|
102
|
+
next_stop_sequence: number;
|
|
103
|
+
shape_dist_traveled: number;
|
|
104
|
+
this_stop_sequence: number | null;
|
|
105
|
+
time_scheduled_seconds: number;
|
|
106
|
+
}
|
|
107
|
+
export interface ISegmentShape extends IShape {
|
|
108
|
+
shape_at_stop: boolean;
|
|
109
|
+
}
|
|
110
|
+
export interface IComputationTrip {
|
|
111
|
+
trip_id: string;
|
|
112
|
+
stop_times: IStopTime[];
|
|
113
|
+
shapes_anchor_points: IShapeAnchorPoint[];
|
|
114
|
+
}
|
|
115
|
+
export interface ITripPositionsWithOrWithoutGTFS {
|
|
116
|
+
gtfsData: IComputationTrip | null;
|
|
117
|
+
id: string;
|
|
118
|
+
gtfs_trip_id: string;
|
|
119
|
+
gtfs_route_type: GTFSRouteTypeEnum;
|
|
120
|
+
start_timestamp: string;
|
|
121
|
+
agency_name_scheduled: string;
|
|
122
|
+
start_cis_stop_id: number;
|
|
123
|
+
positions: ITripPositionAttributes[];
|
|
124
|
+
}
|
|
125
|
+
export interface ITripPositionsWithGTFS extends ITripPositionsWithOrWithoutGTFS {
|
|
126
|
+
gtfsData: IComputationTrip;
|
|
127
|
+
}
|
|
128
|
+
export interface ICurrentPositionProperties {
|
|
129
|
+
id: string;
|
|
130
|
+
origin_time: string;
|
|
131
|
+
origin_timestamp: number;
|
|
132
|
+
tcp_event: string | null;
|
|
133
|
+
}
|
|
134
|
+
export interface ILastPositionProperties {
|
|
135
|
+
time_delay: number;
|
|
136
|
+
atStopStreak: IComputedPositionAtStopStreak;
|
|
137
|
+
}
|
|
138
|
+
export interface IPropagateDelay {
|
|
139
|
+
nextGtfsTrips: string[];
|
|
140
|
+
currentOriginTimestamp: number;
|
|
141
|
+
currentGtfsTripId: string;
|
|
142
|
+
currentRegistrationNumber: number;
|
|
143
|
+
currentDelay: number;
|
|
144
|
+
currentStartTime: string;
|
|
145
|
+
currentEndTime: string;
|
|
146
|
+
}
|
|
147
|
+
export interface IVehiclePositionsSchedule {
|
|
148
|
+
route_id: string;
|
|
149
|
+
run_number: string;
|
|
150
|
+
msg_last_timestamp: string;
|
|
151
|
+
}
|
|
152
|
+
export declare type TripStopsSchedule = Record<string, Omit<ITripStopsResult, "trip_id">>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VehiclePositionsInterfaces.js","sourceRoot":"","sources":["../../../src/integration-engine/vehicle-positions/VehiclePositionsInterfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PositionTrackingEnum } from "../../const";
|
|
2
|
+
import { IUpdateDelayRunTripsData, IUpdateDelayTripsIdsData } from "./models";
|
|
3
|
+
import { IPositionTransformationResult } from "./transformations";
|
|
4
|
+
import { TripStopsSchedule } from "./VehiclePositionsInterfaces";
|
|
5
|
+
interface IPositionTrackingStatements {
|
|
6
|
+
shouldCreateNewPosition: boolean;
|
|
7
|
+
trackingStatus: PositionTrackingEnum | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare class VehiclePositionsUtils {
|
|
10
|
+
static TRIP_STOPS_CACHE_TTL: number;
|
|
11
|
+
static RUN_TRIPS_CACHE_TTL: number;
|
|
12
|
+
static DELAY_COMPUTATION_CACHE_TTL: number;
|
|
13
|
+
/**
|
|
14
|
+
* Determine whether to create new position and its tracking status (trains only for now)
|
|
15
|
+
*
|
|
16
|
+
* @param {TripStopsSchedule | undefined} tripStopSchedule - Cached trip stops for given block id (see Redis)
|
|
17
|
+
* @param {IUpdateDelayRunTripsData | IUpdateDelayTripsIdsData} trip - Current trip
|
|
18
|
+
* @param {IPositionTransformationResult} position - Base position
|
|
19
|
+
*/
|
|
20
|
+
static determineNewPositionTracking: (tripStopSchedule: TripStopsSchedule | undefined, trip: IUpdateDelayRunTripsData | IUpdateDelayTripsIdsData, position: IPositionTransformationResult) => IPositionTrackingStatements;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VehiclePositionsUtils = void 0;
|
|
7
|
+
const moment_timezone_1 = __importDefault(require("@golemio/core/dist/shared/moment-timezone"));
|
|
8
|
+
const const_1 = require("../../const");
|
|
9
|
+
const models_1 = require("./models");
|
|
10
|
+
class VehiclePositionsUtils {
|
|
11
|
+
}
|
|
12
|
+
exports.VehiclePositionsUtils = VehiclePositionsUtils;
|
|
13
|
+
VehiclePositionsUtils.TRIP_STOPS_CACHE_TTL = 14400; // 4 hours
|
|
14
|
+
VehiclePositionsUtils.RUN_TRIPS_CACHE_TTL = 21600; // 6 hours
|
|
15
|
+
VehiclePositionsUtils.DELAY_COMPUTATION_CACHE_TTL = 7200; // 2 hours
|
|
16
|
+
/**
|
|
17
|
+
* Determine whether to create new position and its tracking status (trains only for now)
|
|
18
|
+
*
|
|
19
|
+
* @param {TripStopsSchedule | undefined} tripStopSchedule - Cached trip stops for given block id (see Redis)
|
|
20
|
+
* @param {IUpdateDelayRunTripsData | IUpdateDelayTripsIdsData} trip - Current trip
|
|
21
|
+
* @param {IPositionTransformationResult} position - Base position
|
|
22
|
+
*/
|
|
23
|
+
VehiclePositionsUtils.determineNewPositionTracking = (tripStopSchedule, trip, position) => {
|
|
24
|
+
var _a;
|
|
25
|
+
let statements = {
|
|
26
|
+
shouldCreateNewPosition: false,
|
|
27
|
+
trackingStatus: undefined,
|
|
28
|
+
};
|
|
29
|
+
if (!trip.gtfs_block_id || !trip.gtfs_trip_id) {
|
|
30
|
+
return statements;
|
|
31
|
+
}
|
|
32
|
+
if (trip.gtfs_route_type !== models_1.GTFSRouteTypeEnum.TRAIN) {
|
|
33
|
+
statements.shouldCreateNewPosition = true;
|
|
34
|
+
return statements;
|
|
35
|
+
}
|
|
36
|
+
const { trip_stops: tripStops } = (_a = tripStopSchedule === null || tripStopSchedule === void 0 ? void 0 : tripStopSchedule[trip.gtfs_trip_id]) !== null && _a !== void 0 ? _a : {};
|
|
37
|
+
if (!tripStops) {
|
|
38
|
+
return statements;
|
|
39
|
+
}
|
|
40
|
+
const cisLastStopIndex = tripStops.findIndex((stop) => stop.cis === position.cis_last_stop_id);
|
|
41
|
+
const shouldBeTracking = cisLastStopIndex > -1;
|
|
42
|
+
// positions should have min_stop_time > current - 30 minutes AND max_stop_time < current + 30 minutes
|
|
43
|
+
const shouldInsertNewPosition = (0, moment_timezone_1.default)(trip.start_timestamp).isAfter((0, moment_timezone_1.default)().subtract(30, "minutes")) &&
|
|
44
|
+
trip.end_timestamp &&
|
|
45
|
+
(0, moment_timezone_1.default)(trip.end_timestamp).isBefore((0, moment_timezone_1.default)().add(30, "minutes"));
|
|
46
|
+
if (!shouldBeTracking && !shouldInsertNewPosition) {
|
|
47
|
+
return statements;
|
|
48
|
+
}
|
|
49
|
+
statements.shouldCreateNewPosition = true;
|
|
50
|
+
statements.trackingStatus = shouldBeTracking ? const_1.PositionTrackingEnum.TRACKING : const_1.PositionTrackingEnum.NOT_TRACKING;
|
|
51
|
+
return statements;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=VehiclePositionsUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VehiclePositionsUtils.js","sourceRoot":"","sources":["../../../src/integration-engine/vehicle-positions/VehiclePositionsUtils.ts"],"names":[],"mappings":";;;;;;AAAA,gGAA+D;AAC/D,uCAAiD;AACjD,qCAAiG;AASjG,MAAa,qBAAqB;;AAAlC,sDAqDC;AApDiB,0CAAoB,GAAG,KAAK,CAAC,CAAC,UAAU;AACxC,yCAAmB,GAAG,KAAK,CAAC,CAAC,UAAU;AACvC,iDAA2B,GAAG,IAAI,CAAC,CAAC,UAAU;AAE5D;;;;;;GAMG;AACW,kDAA4B,GAAG,CACzC,gBAA+C,EAC/C,IAAyD,EACzD,QAAuC,EACZ,EAAE;;IAC7B,IAAI,UAAU,GAAgC;QAC1C,uBAAuB,EAAE,KAAK;QAC9B,cAAc,EAAE,SAAS;KAC5B,CAAC;IAEF,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;QAC3C,OAAO,UAAU,CAAC;KACrB;IAED,IAAI,IAAI,CAAC,eAAe,KAAK,0BAAiB,CAAC,KAAK,EAAE;QAClD,UAAU,CAAC,uBAAuB,GAAG,IAAI,CAAC;QAC1C,OAAO,UAAU,CAAC;KACrB;IAED,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAG,IAAI,CAAC,YAAY,CAAC,mCAAI,EAAE,CAAC;IAC9E,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO,UAAU,CAAC;KACrB;IAED,MAAM,gBAAgB,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC/F,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,CAAC,CAAC,CAAC;IAE/C,sGAAsG;IACtG,MAAM,uBAAuB,GACzB,IAAA,yBAAM,EAAC,IAAI,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,IAAA,yBAAM,GAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QACtE,IAAI,CAAC,aAAa;QAClB,IAAA,yBAAM,EAAC,IAAI,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,IAAA,yBAAM,GAAE,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAErE,IAAI,CAAC,gBAAgB,IAAI,CAAC,uBAAuB,EAAE;QAC/C,OAAO,UAAU,CAAC;KACrB;IAED,UAAU,CAAC,uBAAuB,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,4BAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,4BAAoB,CAAC,YAAY,CAAC;IACjH,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC"}
|
|
@@ -1,89 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BaseWorker } from "@golemio/core/dist/integration-engine/workers";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { IVehiclePositionsRunCommon } from "./VehiclePositionsRunsTransformation";
|
|
6
|
-
import { Feature, Point } from "@turf/turf";
|
|
7
|
-
import { ITripPositionAttributes } from "./VehiclePositionsPositionsModel";
|
|
8
|
-
interface IComputedPositionAtStopStreak {
|
|
9
|
-
firstPositionTimestamp: number | null;
|
|
10
|
-
firstPositionDelay: number | null;
|
|
11
|
-
stop_sequence: number | null;
|
|
12
|
-
}
|
|
13
|
-
export interface IPositionsContext {
|
|
14
|
-
lastPositionId: string | null;
|
|
15
|
-
lastPositionOriginTimestamp: number | null;
|
|
16
|
-
lastPositionTracking: Feature<Point, ITripPositionAttributes> | null;
|
|
17
|
-
lastPositionCanceled: boolean | null;
|
|
18
|
-
lastPositionLastStop: {
|
|
19
|
-
id: string | null;
|
|
20
|
-
sequence: number | null;
|
|
21
|
-
arrival_time: number | null;
|
|
22
|
-
departure_time: number | null;
|
|
23
|
-
};
|
|
24
|
-
lastPositionDelay: number | null;
|
|
25
|
-
atStopStreak: IComputedPositionAtStopStreak;
|
|
26
|
-
lastPositionBeforeTrackDelayed: {
|
|
27
|
-
delay: number;
|
|
28
|
-
origin_timestamp: number;
|
|
29
|
-
} | null;
|
|
30
|
-
isLastPositionAfterTrack: boolean;
|
|
31
|
-
tripId: string;
|
|
32
|
-
}
|
|
33
|
-
export interface IShapeAnchorPoint {
|
|
34
|
-
index: number;
|
|
35
|
-
at_stop: boolean;
|
|
36
|
-
bearing: number;
|
|
37
|
-
coordinates: [number, number];
|
|
38
|
-
distance_from_last_stop: number;
|
|
39
|
-
last_stop_sequence: number;
|
|
40
|
-
next_stop_sequence: number;
|
|
41
|
-
shape_dist_traveled: number;
|
|
42
|
-
this_stop_sequence: number | null;
|
|
43
|
-
time_scheduled_seconds: number;
|
|
44
|
-
}
|
|
45
|
-
export interface ISegmentShape extends IShape {
|
|
46
|
-
shape_at_stop: boolean;
|
|
47
|
-
}
|
|
48
|
-
interface IComputationTrip {
|
|
49
|
-
trip_id: string;
|
|
50
|
-
stop_times: IStopTime[];
|
|
51
|
-
shapes_anchor_points: IShapeAnchorPoint[];
|
|
52
|
-
}
|
|
53
|
-
interface ITripPositionsWithOrWithoutGTFS {
|
|
54
|
-
gtfsData: IComputationTrip | null;
|
|
55
|
-
id: string;
|
|
56
|
-
gtfs_trip_id: string;
|
|
57
|
-
gtfs_route_type: GTFSRouteTypeEnum;
|
|
58
|
-
start_timestamp: string;
|
|
59
|
-
agency_name_scheduled: string;
|
|
60
|
-
start_cis_stop_id: number;
|
|
61
|
-
positions: ITripPositionAttributes[];
|
|
62
|
-
}
|
|
63
|
-
export interface ITripPositionsWithGTFS extends ITripPositionsWithOrWithoutGTFS {
|
|
64
|
-
gtfsData: IComputationTrip;
|
|
65
|
-
}
|
|
66
|
-
export interface ICurrentPositionProperties {
|
|
67
|
-
id: string;
|
|
68
|
-
origin_time: string;
|
|
69
|
-
origin_timestamp: number;
|
|
70
|
-
tcp_event: string | null;
|
|
71
|
-
}
|
|
72
|
-
export interface ILastPositionProperties {
|
|
73
|
-
time_delay: number;
|
|
74
|
-
atStopStreak: IComputedPositionAtStopStreak;
|
|
75
|
-
}
|
|
76
|
-
export interface IPropagateDelay {
|
|
77
|
-
nextGtfsTrips: string[];
|
|
78
|
-
currentOriginTimestamp: number;
|
|
79
|
-
currentGtfsTripId: string;
|
|
80
|
-
currentRegistrationNumber: number;
|
|
81
|
-
currentDelay: number;
|
|
82
|
-
currentStartTime: string;
|
|
83
|
-
currentEndTime: string;
|
|
84
|
-
}
|
|
3
|
+
import { IVehiclePositionsRunCommon } from "./transformations";
|
|
4
|
+
import type { IPropagateDelay } from "./VehiclePositionsInterfaces";
|
|
85
5
|
export declare class VehiclePositionsWorker extends BaseWorker {
|
|
86
6
|
private modelGTFSTrips;
|
|
7
|
+
private modelGTFSStopTimes;
|
|
87
8
|
private modelPositions;
|
|
88
9
|
private modelRuns;
|
|
89
10
|
private modelStops;
|
|
@@ -93,26 +14,36 @@ export declare class VehiclePositionsWorker extends BaseWorker {
|
|
|
93
14
|
private delayComputationTripsModel;
|
|
94
15
|
private runTripsModel;
|
|
95
16
|
private gtfsRtModel;
|
|
17
|
+
private tripStopsModel;
|
|
96
18
|
private upsertTripsFQ;
|
|
97
19
|
private readonly queuePrefix;
|
|
98
|
-
private modelGTFSStopTimes;
|
|
99
20
|
constructor();
|
|
100
|
-
saveDataToDB: (msg:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
21
|
+
saveDataToDB: (msg: {
|
|
22
|
+
content: Buffer;
|
|
23
|
+
}) => Promise<void>;
|
|
24
|
+
saveStopsToDB: (msg: {
|
|
25
|
+
content: Buffer;
|
|
26
|
+
}) => Promise<void>;
|
|
27
|
+
updateGTFSTripId: (msg: {
|
|
28
|
+
content: Buffer;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
generateGtfsRt: () => Promise<void>;
|
|
104
31
|
private isUpdateDelayRunTripsIdsData;
|
|
105
32
|
private mapDelayedPositionsToRunTrips;
|
|
106
33
|
propagateDelayForGtfsTrip: (data: IPropagateDelay) => Promise<void>;
|
|
107
|
-
propagateDelay: (msg:
|
|
108
|
-
|
|
34
|
+
propagateDelay: (msg: {
|
|
35
|
+
content: Buffer;
|
|
36
|
+
}) => Promise<void>;
|
|
37
|
+
updateDelay: (msg: {
|
|
38
|
+
content: Buffer;
|
|
39
|
+
}) => Promise<void>;
|
|
109
40
|
/**
|
|
110
41
|
* Queue listener method - triggers processing of TCP input gateway runs data
|
|
111
42
|
*
|
|
112
43
|
* @param {object} msg - xml->json parsed run message
|
|
113
44
|
* @returns {void}
|
|
114
45
|
*/
|
|
115
|
-
saveRunsToDB: (msg: any) => Promise<void>;
|
|
46
|
+
saveRunsToDB: (msg: Record<string, any>) => Promise<void>;
|
|
116
47
|
/**
|
|
117
48
|
* Process not public trips from runs data
|
|
118
49
|
*
|
|
@@ -126,7 +57,9 @@ export declare class VehiclePositionsWorker extends BaseWorker {
|
|
|
126
57
|
* @param {object} msg
|
|
127
58
|
* @returns {void}
|
|
128
59
|
*/
|
|
129
|
-
updateRunsGTFSTripId: (msg:
|
|
60
|
+
updateRunsGTFSTripId: (msg: {
|
|
61
|
+
content: Buffer;
|
|
62
|
+
}) => Promise<void>;
|
|
130
63
|
/**
|
|
131
64
|
* Queue listener method - delete old data
|
|
132
65
|
*/
|
|
@@ -138,7 +71,14 @@ export declare class VehiclePositionsWorker extends BaseWorker {
|
|
|
138
71
|
*
|
|
139
72
|
* @returns {string[]} array of tripIds
|
|
140
73
|
*/
|
|
141
|
-
private
|
|
74
|
+
private setAndReturnScheduledTrips;
|
|
75
|
+
/**
|
|
76
|
+
* Get trip stops schedule by block id
|
|
77
|
+
*
|
|
78
|
+
* @param {string} blockId - Target gtfs block id
|
|
79
|
+
* @param {string} tripIds - List of inserted gtfs trip ids
|
|
80
|
+
*/
|
|
81
|
+
private setAndReturnTripStopsSchedule;
|
|
142
82
|
/**
|
|
143
83
|
* Takes all newly computed positions and saves it, then save the last ones to the trips
|
|
144
84
|
*
|
|
@@ -266,4 +206,3 @@ export declare class VehiclePositionsWorker extends BaseWorker {
|
|
|
266
206
|
*/
|
|
267
207
|
private divideSegmentLine;
|
|
268
208
|
}
|
|
269
|
-
export {};
|