@golemio/pid 2.1.13 → 2.1.14-dev.511689839
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/{__truncate_tables.sql → 00_truncate_tables.sql} +0 -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} +27 -27
- 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/{tmp_example.sql → 07_tmp_example.sql} +0 -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/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 +34 -0
- package/dist/integration-engine/ropid-gtfs/RopidGTFSStopTimesModel.js.map +1 -1
- package/dist/integration-engine/ropid-gtfs/RopidGTFSTripsModel.js +2 -1
- package/dist/integration-engine/ropid-gtfs/RopidGTFSTripsModel.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/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 +30 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsUtils.js +58 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsUtils.js.map +1 -0
- package/dist/integration-engine/vehicle-positions/VehiclePositionsWorker.d.ts +43 -90
- package/dist/integration-engine/vehicle-positions/VehiclePositionsWorker.js +366 -231
- 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} +5 -7
- package/dist/integration-engine/vehicle-positions/{VehiclePositionsTripsModel.js → models/VehiclePositionsTripsModel.js} +54 -31
- 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 +83 -82
- 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,30 @@
|
|
|
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;
|
|
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 - New trip
|
|
18
|
+
* @param {IPositionTransformationResult} position - Current position
|
|
19
|
+
*/
|
|
20
|
+
static determineNewPositionTracking: (tripStopSchedule: TripStopsSchedule | undefined, trip: IUpdateDelayRunTripsData | IUpdateDelayTripsIdsData, position: IPositionTransformationResult) => IPositionTrackingStatements;
|
|
21
|
+
/**
|
|
22
|
+
* Determine tracking status
|
|
23
|
+
*
|
|
24
|
+
* @param {IUpdateDelayRunTripsData | IUpdateDelayTripsIdsData} gtfsTripId - new trip id
|
|
25
|
+
* @param {TripStopsSchedule | undefined} tripStopSchedule - Cached trip stops for given block id (see Redis)
|
|
26
|
+
* @param {IPositionTransformationResult} position - Current position
|
|
27
|
+
*/
|
|
28
|
+
static determineTrackingStatus: (gtfsTripId: string, tripStopSchedule: TripStopsSchedule | undefined, position: IPositionTransformationResult) => PositionTrackingEnum;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var _a;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.VehiclePositionsUtils = void 0;
|
|
8
|
+
const moment_timezone_1 = __importDefault(require("@golemio/core/dist/shared/moment-timezone"));
|
|
9
|
+
const const_1 = require("../../const");
|
|
10
|
+
const models_1 = require("./models");
|
|
11
|
+
class VehiclePositionsUtils {
|
|
12
|
+
}
|
|
13
|
+
exports.VehiclePositionsUtils = VehiclePositionsUtils;
|
|
14
|
+
_a = VehiclePositionsUtils;
|
|
15
|
+
VehiclePositionsUtils.TRIP_STOPS_CACHE_TTL = 14400; // 4 hours
|
|
16
|
+
VehiclePositionsUtils.RUN_TRIPS_CACHE_TTL = 21600; // 6 hours
|
|
17
|
+
VehiclePositionsUtils.DELAY_COMPUTATION_CACHE_TTL = 7200; // 2 hours
|
|
18
|
+
/**
|
|
19
|
+
* Determine whether to create new position and its tracking status (trains only for now)
|
|
20
|
+
*
|
|
21
|
+
* @param {TripStopsSchedule | undefined} tripStopSchedule - Cached trip stops for given block id (see Redis)
|
|
22
|
+
* @param {IUpdateDelayRunTripsData | IUpdateDelayTripsIdsData} trip - New trip
|
|
23
|
+
* @param {IPositionTransformationResult} position - Current position
|
|
24
|
+
*/
|
|
25
|
+
VehiclePositionsUtils.determineNewPositionTracking = (tripStopSchedule, trip, position) => {
|
|
26
|
+
let statements = {
|
|
27
|
+
shouldCreateNewPosition: false,
|
|
28
|
+
trackingStatus: position.tracking,
|
|
29
|
+
};
|
|
30
|
+
if (!trip.gtfs_block_id || !trip.gtfs_trip_id || trip.gtfs_route_type != models_1.GTFSRouteTypeEnum.TRAIN) {
|
|
31
|
+
return statements;
|
|
32
|
+
}
|
|
33
|
+
// positions should have min_stop_time > current - 30 minutes AND max_stop_time < current + 30 minutes
|
|
34
|
+
const shouldCreateNewPosition = (0, moment_timezone_1.default)(Number(trip.start_timestamp)).isAfter((0, moment_timezone_1.default)().subtract(30, "minutes")) &&
|
|
35
|
+
!!trip.end_timestamp &&
|
|
36
|
+
(0, moment_timezone_1.default)(Number(trip.end_timestamp)).isBefore((0, moment_timezone_1.default)().add(30, "minutes"));
|
|
37
|
+
statements.shouldCreateNewPosition = shouldCreateNewPosition;
|
|
38
|
+
statements.trackingStatus = _a.determineTrackingStatus(trip.gtfs_trip_id, tripStopSchedule, position);
|
|
39
|
+
return statements;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Determine tracking status
|
|
43
|
+
*
|
|
44
|
+
* @param {IUpdateDelayRunTripsData | IUpdateDelayTripsIdsData} gtfsTripId - new trip id
|
|
45
|
+
* @param {TripStopsSchedule | undefined} tripStopSchedule - Cached trip stops for given block id (see Redis)
|
|
46
|
+
* @param {IPositionTransformationResult} position - Current position
|
|
47
|
+
*/
|
|
48
|
+
VehiclePositionsUtils.determineTrackingStatus = (gtfsTripId, tripStopSchedule, position) => {
|
|
49
|
+
var _b;
|
|
50
|
+
const { trip_stops: tripStops } = (_b = tripStopSchedule === null || tripStopSchedule === void 0 ? void 0 : tripStopSchedule[gtfsTripId]) !== null && _b !== void 0 ? _b : {};
|
|
51
|
+
if (!tripStops) {
|
|
52
|
+
return position.tracking;
|
|
53
|
+
}
|
|
54
|
+
const cisLastStopIndex = tripStops.findIndex((stop) => stop.cis === position.cis_last_stop_id);
|
|
55
|
+
const shouldBeTracking = cisLastStopIndex > -1;
|
|
56
|
+
return shouldBeTracking ? const_1.PositionTrackingEnum.TRACKING : const_1.PositionTrackingEnum.NOT_TRACKING;
|
|
57
|
+
};
|
|
58
|
+
//# 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,sDA0DC;;AAzDiB,0CAAoB,GAAG,KAAM,CAAA,CAAC,UAAU;AACxC,yCAAmB,GAAG,KAAM,CAAA,CAAC,UAAU;AACvC,iDAA2B,GAAG,IAAK,CAAA,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,QAAQ,CAAC,QAAS;KACrC,CAAC;IAEF,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,eAAe,IAAI,0BAAiB,CAAC,KAAK,EAAE;QAC9F,OAAO,UAAU,CAAC;KACrB;IAED,sGAAsG;IACtG,MAAM,uBAAuB,GACzB,IAAA,yBAAM,EAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,IAAA,yBAAM,GAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QAC9E,CAAC,CAAC,IAAI,CAAC,aAAa;QACpB,IAAA,yBAAM,EAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAA,yBAAM,GAAE,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAE7E,UAAU,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;IAC7D,UAAU,CAAC,cAAc,GAAG,EAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,YAAY,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAC;IACxG,OAAO,UAAU,CAAC;AACtB,CAAE,CAAA;AAEF;;;;;;GAMG;AACW,6CAAuB,GAAG,CACpC,UAAkB,EAClB,gBAA+C,EAC/C,QAAuC,EACnB,EAAE;;IACtB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAG,UAAU,CAAC,mCAAI,EAAE,CAAC;IACvE,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO,QAAQ,CAAC,QAAS,CAAC;KAC7B;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;IAC/C,OAAO,gBAAgB,CAAC,CAAC,CAAC,4BAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,4BAAoB,CAAC,YAAY,CAAC;AAChG,CAAE,CAAA"}
|
|
@@ -1,86 +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
|
-
interface IComputationTrip {
|
|
46
|
-
trip_id: string;
|
|
47
|
-
stop_times: IStopTime[];
|
|
48
|
-
shapes_anchor_points: IShapeAnchorPoint[];
|
|
49
|
-
}
|
|
50
|
-
interface ITripPositionsWithOrWithoutGTFS {
|
|
51
|
-
gtfsData: IComputationTrip | null;
|
|
52
|
-
id: string;
|
|
53
|
-
gtfs_trip_id: string;
|
|
54
|
-
gtfs_route_type: GTFSRouteTypeEnum;
|
|
55
|
-
start_timestamp: string;
|
|
56
|
-
agency_name_scheduled: string;
|
|
57
|
-
start_cis_stop_id: number;
|
|
58
|
-
positions: ITripPositionAttributes[];
|
|
59
|
-
}
|
|
60
|
-
export interface ITripPositionsWithGTFS extends ITripPositionsWithOrWithoutGTFS {
|
|
61
|
-
gtfsData: IComputationTrip;
|
|
62
|
-
}
|
|
63
|
-
export interface ICurrentPositionProperties {
|
|
64
|
-
id: string;
|
|
65
|
-
origin_time: string;
|
|
66
|
-
origin_timestamp: number;
|
|
67
|
-
tcp_event: string | null;
|
|
68
|
-
}
|
|
69
|
-
export interface ILastPositionProperties {
|
|
70
|
-
time_delay: number;
|
|
71
|
-
atStopStreak: IComputedPositionAtStopStreak;
|
|
72
|
-
}
|
|
73
|
-
export interface IPropagateDelay {
|
|
74
|
-
nextGtfsTrips: string[];
|
|
75
|
-
currentOriginTimestamp: number;
|
|
76
|
-
currentGtfsTripId: string;
|
|
77
|
-
currentRegistrationNumber: number;
|
|
78
|
-
currentDelay: number;
|
|
79
|
-
currentStartTime: string;
|
|
80
|
-
currentEndTime: string;
|
|
81
|
-
}
|
|
3
|
+
import { IVehiclePositionsRunCommon } from "./transformations";
|
|
4
|
+
import type { IPropagateDelay } from "./VehiclePositionsInterfaces";
|
|
82
5
|
export declare class VehiclePositionsWorker extends BaseWorker {
|
|
83
6
|
private modelGTFSTrips;
|
|
7
|
+
private modelGTFSStopTimes;
|
|
84
8
|
private modelPositions;
|
|
85
9
|
private modelRuns;
|
|
86
10
|
private modelStops;
|
|
@@ -90,26 +14,36 @@ export declare class VehiclePositionsWorker extends BaseWorker {
|
|
|
90
14
|
private delayComputationTripsModel;
|
|
91
15
|
private runTripsModel;
|
|
92
16
|
private gtfsRtModel;
|
|
17
|
+
private tripStopsModel;
|
|
93
18
|
private upsertTripsFQ;
|
|
94
19
|
private readonly queuePrefix;
|
|
95
|
-
private modelGTFSStopTimes;
|
|
96
20
|
constructor();
|
|
97
|
-
saveDataToDB: (msg:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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>;
|
|
101
31
|
private isUpdateDelayRunTripsIdsData;
|
|
102
32
|
private mapDelayedPositionsToRunTrips;
|
|
103
33
|
propagateDelayForGtfsTrip: (data: IPropagateDelay) => Promise<void>;
|
|
104
|
-
propagateDelay: (msg:
|
|
105
|
-
|
|
34
|
+
propagateDelay: (msg: {
|
|
35
|
+
content: Buffer;
|
|
36
|
+
}) => Promise<void>;
|
|
37
|
+
updateDelay: (msg: {
|
|
38
|
+
content: Buffer;
|
|
39
|
+
}) => Promise<void>;
|
|
106
40
|
/**
|
|
107
41
|
* Queue listener method - triggers processing of TCP input gateway runs data
|
|
108
42
|
*
|
|
109
43
|
* @param {object} msg - xml->json parsed run message
|
|
110
44
|
* @returns {void}
|
|
111
45
|
*/
|
|
112
|
-
saveRunsToDB: (msg: any) => Promise<void>;
|
|
46
|
+
saveRunsToDB: (msg: Record<string, any>) => Promise<void>;
|
|
113
47
|
/**
|
|
114
48
|
* Process not public trips from runs data
|
|
115
49
|
*
|
|
@@ -123,7 +57,9 @@ export declare class VehiclePositionsWorker extends BaseWorker {
|
|
|
123
57
|
* @param {object} msg
|
|
124
58
|
* @returns {void}
|
|
125
59
|
*/
|
|
126
|
-
updateRunsGTFSTripId: (msg:
|
|
60
|
+
updateRunsGTFSTripId: (msg: {
|
|
61
|
+
content: Buffer;
|
|
62
|
+
}) => Promise<void>;
|
|
127
63
|
/**
|
|
128
64
|
* Queue listener method - delete old data
|
|
129
65
|
*/
|
|
@@ -135,7 +71,14 @@ export declare class VehiclePositionsWorker extends BaseWorker {
|
|
|
135
71
|
*
|
|
136
72
|
* @returns {string[]} array of tripIds
|
|
137
73
|
*/
|
|
138
|
-
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;
|
|
139
82
|
/**
|
|
140
83
|
* Takes all newly computed positions and saves it, then save the last ones to the trips
|
|
141
84
|
*
|
|
@@ -248,8 +191,18 @@ export declare class VehiclePositionsWorker extends BaseWorker {
|
|
|
248
191
|
*
|
|
249
192
|
* @param {string} shapeId - GTFS shape id
|
|
250
193
|
* @param {ITransformedTripShape[]} shapes - GTFS shape points
|
|
194
|
+
* @param {IStopTime[]} stops
|
|
251
195
|
* @returns {IShapeGeometryAnchorPoint[]} - Result array of geometry points along trip track shape
|
|
252
196
|
*/
|
|
253
197
|
private getShapesGeometryAnchorPoints;
|
|
198
|
+
/**
|
|
199
|
+
* Generates new shape points from segment of trip shape along original one
|
|
200
|
+
* - preserving start and end shape points belonging to stops
|
|
201
|
+
* - creates new set of shape points between stops to get same point distance along original shape
|
|
202
|
+
*
|
|
203
|
+
* @param {ISegmentShape[]} segmentsArr - Original shape points segment between two stops
|
|
204
|
+
* @param {number} distance - Minimal distance for two consequent shape points
|
|
205
|
+
* @returns {ISegmentShape[]} - Result array of new shape points
|
|
206
|
+
*/
|
|
207
|
+
private divideSegmentLine;
|
|
254
208
|
}
|
|
255
|
-
export {};
|