@golemio/pid 3.5.2-dev.1636139600 → 3.5.2-rc.1637873076
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/integration-engine/ropid-gtfs/data-access/cache/RunTripsRedisRepository.js +1 -2
- package/dist/integration-engine/ropid-gtfs/data-access/cache/RunTripsRedisRepository.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/TripsRepository.js +5 -6
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/TripsRepository.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/helpers/RawQueryProvider.d.ts +1 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/helpers/RawQueryProvider.js +165 -101
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/helpers/RawQueryProvider.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/tasks/PropagateTrainDelayTask.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/transformations/MpvMessageTransformation.js +7 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/transformations/MpvMessageTransformation.js.map +1 -1
- package/dist/output-gateway/pid/controllers/v2/V2DepartureBoardsController.js +1 -1
- package/dist/output-gateway/pid/index.d.ts +5 -4
- package/dist/output-gateway/pid/index.js +0 -1
- package/dist/output-gateway/pid/index.js.map +1 -1
- package/dist/output-gateway/pid/ioc/Di.js +0 -4
- package/dist/output-gateway/pid/ioc/Di.js.map +1 -1
- package/dist/output-gateway/pid/ioc/OgPidToken.d.ts +0 -2
- package/dist/output-gateway/pid/ioc/OgPidToken.js +0 -2
- package/dist/output-gateway/pid/ioc/OgPidToken.js.map +1 -1
- package/dist/output-gateway/pid/models/PIDDepartureBoardsModel.d.ts +28 -14
- package/dist/output-gateway/pid/models/PIDDepartureBoardsModel.js +72 -192
- package/dist/output-gateway/pid/models/PIDDepartureBoardsModel.js.map +1 -1
- package/dist/output-gateway/pid/models/helpers/PIDDepartureModel.js +15 -26
- package/dist/output-gateway/pid/models/helpers/PIDDepartureModel.js.map +1 -1
- package/dist/output-gateway/pid/models/helpers/SkipHelper.d.ts +0 -11
- package/dist/output-gateway/pid/models/helpers/SkipHelper.js +0 -91
- package/dist/output-gateway/pid/models/helpers/SkipHelper.js.map +1 -1
- package/dist/output-gateway/pid/models/helpers/interfaces/IPIDDepartureQueryOptions.d.ts +0 -3
- package/dist/output-gateway/pid/service/facade/TransferFacade.js +0 -2
- package/dist/output-gateway/pid/service/facade/TransferFacade.js.map +1 -1
- package/dist/output-gateway/public/data-access/redis/PublicVehiclePositionsRepository.d.ts +2 -4
- package/dist/output-gateway/public/data-access/redis/PublicVehiclePositionsRepository.js +68 -90
- package/dist/output-gateway/public/data-access/redis/PublicVehiclePositionsRepository.js.map +1 -1
- package/dist/output-gateway/public/domain/repository/IVehiclePositionsRepository.d.ts +1 -2
- package/dist/output-gateway/shared/constants/validations.js +1 -1
- package/dist/output-gateway/shared/constants/validations.js.map +1 -1
- package/dist/schema-definitions/ropid-gtfs/redis/const.d.ts +0 -1
- package/dist/schema-definitions/ropid-gtfs/redis/const.js +1 -2
- package/dist/schema-definitions/ropid-gtfs/redis/const.js.map +1 -1
- package/docs/openapi-output.yaml +2 -10
- package/package.json +2 -2
- package/db/migrations/postgresql/20250103092631-skip-missing.js +0 -53
- package/db/migrations/postgresql/20250109122504-braking-down-mapping-queries.js +0 -53
- package/db/migrations/postgresql/sqls/20250103092631-skip-missing-down.sql +0 -184
- package/db/migrations/postgresql/sqls/20250103092631-skip-missing-up.sql +0 -195
- package/db/migrations/postgresql/sqls/20250109122504-braking-down-mapping-queries-down.sql +0 -12
- package/db/migrations/postgresql/sqls/20250109122504-braking-down-mapping-queries-up.sql +0 -139
- package/dist/output-gateway/pid/domain/DepartureInterfaces.d.ts +0 -7
- package/dist/output-gateway/pid/domain/DepartureInterfaces.js +0 -3
- package/dist/output-gateway/pid/domain/DepartureInterfaces.js.map +0 -1
- package/dist/output-gateway/pid/models/helpers/const.d.ts +0 -4
- package/dist/output-gateway/pid/models/helpers/const.js +0 -8
- package/dist/output-gateway/pid/models/helpers/const.js.map +0 -1
- package/dist/output-gateway/pid/models/interfaces/IGetDeparturesOptions.d.ts +0 -21
- package/dist/output-gateway/pid/models/interfaces/IGetDeparturesOptions.js +0 -3
- package/dist/output-gateway/pid/models/interfaces/IGetDeparturesOptions.js.map +0 -1
- package/dist/output-gateway/ropid-gtfs/data-access/redis/RunTripsRedisRepository.d.ts +0 -10
- package/dist/output-gateway/ropid-gtfs/data-access/redis/RunTripsRedisRepository.js +0 -65
- package/dist/output-gateway/ropid-gtfs/data-access/redis/RunTripsRedisRepository.js.map +0 -1
- package/dist/output-gateway/ropid-gtfs/domain/repository/IRunTripsRedisRepository.d.ts +0 -4
- package/dist/output-gateway/ropid-gtfs/domain/repository/IRunTripsRedisRepository.js +0 -3
- package/dist/output-gateway/ropid-gtfs/domain/repository/IRunTripsRedisRepository.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Di.js","sourceRoot":"","sources":["../../../../src/output-gateway/pid/ioc/Di.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Di.js","sourceRoot":"","sources":["../../../../src/output-gateway/pid/ioc/Di.ts"],"names":[],"mappings":";;;AAAA,gGAA2F;AAC3F,+DAA+E;AAE/E,mFAAgF;AAChF,6FAA0F;AAC1F,gDAAsD;AACtD,gFAA6E;AAC7E,4GAAyG;AACzG,qEAAkE;AAClE,6DAA0D;AAC1D,qEAAkE;AAClE,sHAAmH;AACnH,oHAAiH;AACjH,oHAAiH;AACjH,gHAA6G;AAC7G,6CAA0C;AAE1C,MAAM,cAAc,GAAwB,4BAAsB,CAAC,oBAAoB,EAAE,CAAC;AA4B/D,wCAAc;AA1BzC,sBAAsB;AACtB,cAAc,CAAC,iBAAiB,CAAC,uBAAU,CAAC,sB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opsRepository: symbol;
|
|
4
4
|
JISInfotextRepository: symbol;
|
|
5
5
|
DeparturesRepository: symbol;
|
|
6
|
-
RunTripsRedisRepository: symbol;
|
|
7
|
-
PublicVehiclePositionsRepository: symbol;
|
|
8
6
|
JISInfotextDepartureTransformation: symbol;
|
|
9
7
|
JISInfotextTransferTransformation: symbol;
|
|
10
8
|
JISInfotextOverviewTransformation: symbol;
|
|
@@ -7,8 +7,6 @@ exports.OgPidToken = {
|
|
|
7
7
|
JISInfotextRopidGTFSStopsRepository: Symbol(),
|
|
8
8
|
JISInfotextRepository: Symbol(),
|
|
9
9
|
DeparturesRepository: Symbol(),
|
|
10
|
-
RunTripsRedisRepository: Symbol(),
|
|
11
|
-
PublicVehiclePositionsRepository: Symbol(),
|
|
12
10
|
//#endregion
|
|
13
11
|
//#region Transformations
|
|
14
12
|
JISInfotextDepartureTransformation: Symbol(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OgPidToken.js","sourceRoot":"","sources":["../../../../src/output-gateway/pid/ioc/OgPidToken.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACtB,sBAAsB;IACtB,sBAAsB,EAAE,MAAM,EAAE;IAChC,mCAAmC,EAAE,MAAM,EAAE;IAC7C,qBAAqB,EAAE,MAAM,EAAE;IAC/B,oBAAoB,EAAE,MAAM,EAAE;IAC9B,
|
|
1
|
+
{"version":3,"file":"OgPidToken.js","sourceRoot":"","sources":["../../../../src/output-gateway/pid/ioc/OgPidToken.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACtB,sBAAsB;IACtB,sBAAsB,EAAE,MAAM,EAAE;IAChC,mCAAmC,EAAE,MAAM,EAAE;IAC7C,qBAAqB,EAAE,MAAM,EAAE;IAC/B,oBAAoB,EAAE,MAAM,EAAE;IAC9B,YAAY;IAEZ,yBAAyB;IACzB,kCAAkC,EAAE,MAAM,EAAE;IAC5C,iCAAiC,EAAE,MAAM,EAAE;IAC3C,iCAAiC,EAAE,MAAM,EAAE;IAC3C,+BAA+B,EAAE,MAAM,EAAE;IACzC,YAAY;IAEZ,gBAAgB;IAChB,UAAU,EAAE,MAAM,EAAE;IACpB,cAAc,EAAE,MAAM,EAAE;IACxB,cAAc,EAAE,MAAM,EAAE;IACxB,YAAY;IAEZ,qBAAqB;IACrB,0BAA0B,EAAE,MAAM,EAAE;IACpC,qBAAqB,EAAE,MAAM,EAAE;IAC/B,YAAY;CACf,CAAC"}
|
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Moment } from "@golemio/core/dist/shared/moment-timezone";
|
|
2
|
+
import { DepartureFilter, DepartureMode, DepartureOrder, DepartureSkip } from "..";
|
|
3
3
|
declare class PIDDepartureBoardsModel {
|
|
4
|
-
private
|
|
5
|
-
private
|
|
6
|
-
private
|
|
7
|
-
private readonly runTripsRedisRepository;
|
|
8
|
-
private readonly positionsRedisRepository;
|
|
4
|
+
private stopsMaxCount;
|
|
5
|
+
private ropidDeparturesDirectionsModel;
|
|
6
|
+
private departuresRepository;
|
|
9
7
|
private readonly infotextRepository;
|
|
10
8
|
private readonly infotextTransformation;
|
|
11
9
|
constructor();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
/** Retrieves all gtfs stop times for specific stop, optionaly enhanced with realtime delays
|
|
11
|
+
* @param {string} id Id of the stop
|
|
12
|
+
* @returns Object of the retrieved record or null
|
|
13
|
+
*/
|
|
14
|
+
GetAll: (options: {
|
|
15
|
+
aswIds?: string[];
|
|
16
|
+
cisIds?: string[];
|
|
17
|
+
gtfsIds?: string[];
|
|
18
|
+
names?: string[];
|
|
19
|
+
total: number;
|
|
20
|
+
limit: number;
|
|
21
|
+
offset: number;
|
|
22
|
+
mode: DepartureMode;
|
|
23
|
+
minutesBefore: number;
|
|
24
|
+
minutesAfter: number;
|
|
25
|
+
timeFrom?: Moment;
|
|
26
|
+
order: DepartureOrder;
|
|
27
|
+
filter: DepartureFilter;
|
|
28
|
+
skip: DepartureSkip[];
|
|
29
|
+
includeMetroTrains?: boolean;
|
|
30
|
+
airCondition?: boolean;
|
|
31
|
+
timezone: string;
|
|
32
|
+
}) => Promise<any>;
|
|
19
33
|
}
|
|
20
34
|
export { PIDDepartureBoardsModel };
|
|
@@ -12,223 +12,103 @@ const trace_provider_1 = require("@golemio/core/dist/monitoring/opentelemetry/tr
|
|
|
12
12
|
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
|
|
13
13
|
const moment_timezone_1 = __importDefault(require("@golemio/core/dist/shared/moment-timezone"));
|
|
14
14
|
const _1 = require(".");
|
|
15
|
-
const __1 = require("..");
|
|
16
15
|
const Di_1 = require("../ioc/Di");
|
|
17
16
|
const OgPidToken_1 = require("../ioc/OgPidToken");
|
|
18
17
|
const PIDDepartureModel_1 = __importDefault(require("./helpers/PIDDepartureModel"));
|
|
19
|
-
const STOPS_MAX_COUNT = 100;
|
|
20
|
-
// TODO refactor - split into facade and multiple service/strategy classes
|
|
21
|
-
// Check V3TransferBoardsController and TransferFacade for inspiration
|
|
22
18
|
class PIDDepartureBoardsModel {
|
|
23
19
|
constructor() {
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//#region Data retrieval from DB (GTFS stops, infotexts, directions, departures)
|
|
35
|
-
const { stopsToInclude, stopIds } = await this.retrieveAndReturnStops(options);
|
|
36
|
-
const [infotextsToInclude, directions, departures] = await Promise.all([
|
|
37
|
-
this.retrieveAndReturnInfotexts(stopIds, currentMoment, options),
|
|
38
|
-
this.retrieveAndReturnDirections(stopIds),
|
|
39
|
-
this.retrieveAndReturnDepartures(stopIds, currentMoment, options),
|
|
40
|
-
]);
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region Data retrieval from Redis (run schedule, untracked trips)
|
|
43
|
-
let runScheduleMap = new Map();
|
|
44
|
-
let untrackedTrips = new Set();
|
|
45
|
-
const isMissingRequested = options.skip.includes(__1.DepartureSkip.MISSING) && !options.skip.includes(__1.DepartureSkip.UNTRACKED);
|
|
46
|
-
// Note: The run schedule and untracked trips are populated only if the skip[]=missing (without untracked) is present
|
|
47
|
-
// Check the PIDDeparturesModel.skip function. In other cases they are not needed
|
|
48
|
-
if (isMissingRequested) {
|
|
49
|
-
const runTuples = new Set();
|
|
50
|
-
for (const departure of departures) {
|
|
51
|
-
runTuples.add(`${departure.origin_route_name}_${departure.run_number}`);
|
|
52
|
-
}
|
|
53
|
-
const { runSchedule, runTripIds } = await this.retrieveAndReturnRunTrips(runTuples);
|
|
54
|
-
runScheduleMap = runSchedule;
|
|
55
|
-
untrackedTrips = await this.retrieveAndReturnUntrackedTrips(runTripIds);
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region Processing and returning departures
|
|
59
|
-
const spanProcessing = (0, trace_provider_1.createChildSpan)("V2PIDRouter.Processing");
|
|
60
|
-
try {
|
|
61
|
-
const departuresToInclude = new PIDDepartureModel_1.default(departures, {
|
|
62
|
-
limit: options.limit,
|
|
63
|
-
offset: options.offset,
|
|
64
|
-
total: options.total,
|
|
65
|
-
mode: options.mode,
|
|
66
|
-
order: options.order,
|
|
67
|
-
filter: options.filter,
|
|
68
|
-
skip: options.skip,
|
|
69
|
-
departuresDirections: directions,
|
|
70
|
-
timezone: options.timezone,
|
|
71
|
-
tripNumber: null,
|
|
72
|
-
runScheduleMap,
|
|
73
|
-
untrackedTrips,
|
|
74
|
-
}).toArray();
|
|
75
|
-
spanProcessing?.end();
|
|
76
|
-
return {
|
|
77
|
-
departures: departuresToInclude,
|
|
78
|
-
infotexts: infotextsToInclude,
|
|
79
|
-
stops: stopsToInclude,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
spanProcessing?.recordException(error);
|
|
84
|
-
if (error instanceof golemio_errors_1.AbstractGolemioError) {
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
throw new golemio_errors_1.GeneralError("Error while processing departures", this.constructor.name, error, 500);
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
|
-
}
|
|
91
|
-
async retrieveAndReturnStops(options) {
|
|
92
|
-
const spanStops = (0, trace_provider_1.createChildSpan)("V2PIDRouter.DB.stops");
|
|
93
|
-
spanStops?.setAttributes({ ...options, timeFrom: options.timeFrom?.toString() });
|
|
94
|
-
try {
|
|
20
|
+
this.stopsMaxCount = 100;
|
|
21
|
+
/** Retrieves all gtfs stop times for specific stop, optionaly enhanced with realtime delays
|
|
22
|
+
* @param {string} id Id of the stop
|
|
23
|
+
* @returns Object of the retrieved record or null
|
|
24
|
+
*/
|
|
25
|
+
this.GetAll = async (options) => {
|
|
26
|
+
const currentMoment = (0, moment_timezone_1.default)();
|
|
27
|
+
const minutesOffset = options.timeFrom ? options.timeFrom.diff(currentMoment, "minutes") : 0;
|
|
28
|
+
const spanStops = (0, trace_provider_1.createChildSpan)("V2PIDRouter.DB.stops");
|
|
29
|
+
spanStops?.setAttributes({ ...options, timeFrom: options.timeFrom?.toString() });
|
|
95
30
|
const stopsToInclude = await models_1.models.GTFSStopModel.GetAll({
|
|
96
31
|
includeMetroTrains: options.includeMetroTrains,
|
|
97
32
|
appendAswId: true,
|
|
98
33
|
aswIds: options.aswIds,
|
|
99
34
|
cisIds: options.cisIds,
|
|
100
35
|
gtfsIds: options.gtfsIds,
|
|
101
|
-
limit:
|
|
36
|
+
limit: this.stopsMaxCount + 1,
|
|
102
37
|
locationType: StopEnums_1.GtfsStopLocationType.StopOrPlatform,
|
|
103
38
|
names: options.names,
|
|
104
39
|
returnRaw: true,
|
|
105
40
|
});
|
|
106
41
|
if (stopsToInclude.length === 0) {
|
|
107
|
-
throw new golemio_errors_1.GeneralError("No stops found.",
|
|
42
|
+
throw new golemio_errors_1.GeneralError("No stops found.", "DepartureBoardsRouter", undefined, 404);
|
|
108
43
|
}
|
|
109
|
-
|
|
110
|
-
throw new golemio_errors_1.GeneralError(`Too many stops, try lower number or split requests. The maximum is ${
|
|
44
|
+
if (stopsToInclude.length > this.stopsMaxCount) {
|
|
45
|
+
throw new golemio_errors_1.GeneralError(`Too many stops, try lower number or split requests. The maximum is ${this.stopsMaxCount} stops.`, "DepartureBoardsRouter", undefined, 413);
|
|
111
46
|
}
|
|
112
|
-
const
|
|
47
|
+
const stopsIds = stopsToInclude.map((e) => e.stop_id);
|
|
113
48
|
spanStops?.end();
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
49
|
+
const spanInfotexts = (0, trace_provider_1.createChildSpan)("V2PIDRouter.DB.infotexts");
|
|
50
|
+
let infotextsToInclude;
|
|
51
|
+
try {
|
|
52
|
+
const infotexts = await this.infotextRepository.findAllForDepartureBoard(stopsIds, (options.timeFrom ?? currentMoment).toDate());
|
|
53
|
+
infotextsToInclude = this.infotextTransformation.transformArray(infotexts.map((infotext) => ({
|
|
54
|
+
data: infotext,
|
|
55
|
+
timeZone: options.timezone,
|
|
56
|
+
})));
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (err instanceof golemio_errors_1.AbstractGolemioError) {
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
throw new golemio_errors_1.GeneralError("Database error", "DepartureBoardsModel", err, 500);
|
|
120
63
|
}
|
|
121
|
-
throw new golemio_errors_1.GeneralError("Error while getting stops", this.constructor.name, error, 500);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async retrieveAndReturnInfotexts(stopIds, currentMoment, options) {
|
|
125
|
-
const spanInfotexts = (0, trace_provider_1.createChildSpan)("V2PIDRouter.DB.infotexts");
|
|
126
|
-
try {
|
|
127
|
-
const infotexts = await this.infotextRepository.findAllForDepartureBoard(stopIds, (options.timeFrom ?? currentMoment).toDate());
|
|
128
|
-
const infotextsToInclude = this.infotextTransformation.transformArray(infotexts.map((infotext) => ({
|
|
129
|
-
data: infotext,
|
|
130
|
-
timeZone: options.timezone,
|
|
131
|
-
})));
|
|
132
64
|
spanInfotexts?.end();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (error instanceof golemio_errors_1.AbstractGolemioError) {
|
|
138
|
-
throw error;
|
|
65
|
+
const spanDirections = (0, trace_provider_1.createChildSpan)("V2PIDRouter.DB.directions");
|
|
66
|
+
let departuresDirections;
|
|
67
|
+
try {
|
|
68
|
+
departuresDirections = await this.ropidDeparturesDirectionsModel.GetAll(stopsIds);
|
|
139
69
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
async retrieveAndReturnDirections(stopIds) {
|
|
144
|
-
const spanDirections = (0, trace_provider_1.createChildSpan)("V2PIDRouter.DB.directions");
|
|
145
|
-
try {
|
|
146
|
-
const departuresDirections = await this.ropidDeparturesDirectionsModel.GetAll(stopIds);
|
|
147
|
-
spanDirections?.end();
|
|
148
|
-
return departuresDirections;
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
spanDirections?.recordException(error);
|
|
152
|
-
if (error instanceof golemio_errors_1.AbstractGolemioError) {
|
|
153
|
-
throw error;
|
|
70
|
+
catch (err) {
|
|
71
|
+
throw new golemio_errors_1.GeneralError("Database error", "DepartureBoardsModel", err, 500);
|
|
154
72
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
73
|
+
spanDirections?.end();
|
|
74
|
+
try {
|
|
75
|
+
const results = await this.departuresRepository.GetAll({
|
|
76
|
+
currentMoment,
|
|
77
|
+
minutesAfter: options.minutesAfter,
|
|
78
|
+
minutesBefore: options.minutesBefore,
|
|
79
|
+
minutesOffset,
|
|
80
|
+
stopsIds,
|
|
81
|
+
mode: options.mode,
|
|
82
|
+
isAirCondition: !!options.airCondition,
|
|
83
|
+
});
|
|
84
|
+
const spanDepartures = (0, trace_provider_1.createChildSpan)("V2PIDRouter.DB.departures");
|
|
85
|
+
const res = {
|
|
86
|
+
departures: new PIDDepartureModel_1.default(results, {
|
|
87
|
+
limit: options.limit,
|
|
88
|
+
offset: options.offset,
|
|
89
|
+
total: options.total,
|
|
90
|
+
mode: options.mode,
|
|
91
|
+
order: options.order,
|
|
92
|
+
filter: options.filter,
|
|
93
|
+
skip: options.skip,
|
|
94
|
+
departuresDirections,
|
|
95
|
+
timezone: options.timezone,
|
|
96
|
+
tripNumber: null, // not used in this context
|
|
97
|
+
}).toArray(),
|
|
98
|
+
infotexts: infotextsToInclude,
|
|
99
|
+
stops: stopsToInclude,
|
|
100
|
+
};
|
|
101
|
+
spanDepartures?.end();
|
|
102
|
+
return res;
|
|
179
103
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
async retrieveAndReturnRunTrips(runTuples) {
|
|
184
|
-
const runScheduleMap = new Map();
|
|
185
|
-
const tripIds = new Set();
|
|
186
|
-
const spanRunTrips = (0, trace_provider_1.createChildSpan)("V2PIDRouter.Redis.runTrips");
|
|
187
|
-
try {
|
|
188
|
-
const runTuplesArray = Array.from(runTuples);
|
|
189
|
-
const runSchedule = await this.runTripsRedisRepository.getMultipleSchedule(runTuplesArray);
|
|
190
|
-
for (let i = 0; i < runSchedule.length; i++) {
|
|
191
|
-
const runTrip = runSchedule[i];
|
|
192
|
-
if (runTrip) {
|
|
193
|
-
const tuple = runTuplesArray[i];
|
|
194
|
-
runScheduleMap.set(tuple, runTrip.schedule);
|
|
195
|
-
for (const trip of runTrip.schedule) {
|
|
196
|
-
tripIds.add(trip.trip_id);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
throw new golemio_errors_1.GeneralError("Database error", "DepartureBoardsModel", err, 500);
|
|
199
106
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// eslint-disable-next-line max-len
|
|
206
|
-
"Cannot retrieve run schedule. The API consumer will receive departures with missing vehicles even if they requested to skip them.");
|
|
207
|
-
}
|
|
208
|
-
finally {
|
|
209
|
-
return {
|
|
210
|
-
runSchedule: runScheduleMap,
|
|
211
|
-
runTripIds: tripIds,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
async retrieveAndReturnUntrackedTrips(tripIds) {
|
|
216
|
-
let untrackedTrips = new Set();
|
|
217
|
-
const spanUntrackedTrips = (0, trace_provider_1.createChildSpan)("V2PIDRouter.Redis.untrackedTrips");
|
|
218
|
-
try {
|
|
219
|
-
const tripIdsArray = Array.from(tripIds);
|
|
220
|
-
untrackedTrips = await this.positionsRedisRepository.getTripsWithUntrackedVehicles(tripIdsArray);
|
|
221
|
-
spanUntrackedTrips?.end();
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
spanUntrackedTrips?.recordException(error);
|
|
225
|
-
this.log.error(error,
|
|
226
|
-
// eslint-disable-next-line max-len
|
|
227
|
-
"Cannot retrieve untracked trips. The API consumer will receive departures with missing vehicles even if they requested to skip them.");
|
|
228
|
-
}
|
|
229
|
-
finally {
|
|
230
|
-
return untrackedTrips;
|
|
231
|
-
}
|
|
107
|
+
};
|
|
108
|
+
this.ropidDeparturesDirectionsModel = new _1.RopidDeparturesDirectionsModel();
|
|
109
|
+
this.departuresRepository = new data_access_1.DeparturesRepository(Di_1.OgPidContainer.resolve(CoreToken_1.CoreToken.PostgresConnector), Di_1.OgPidContainer.resolve(CoreToken_1.CoreToken.SimpleConfig));
|
|
110
|
+
this.infotextRepository = Di_1.OgPidContainer.resolve(OgPidToken_1.OgPidToken.JISInfotextRepository);
|
|
111
|
+
this.infotextTransformation = Di_1.OgPidContainer.resolve(OgPidToken_1.OgPidToken.JISInfotextDepartureTransformation);
|
|
232
112
|
}
|
|
233
113
|
}
|
|
234
114
|
exports.PIDDepartureBoardsModel = PIDDepartureBoardsModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PIDDepartureBoardsModel.js","sourceRoot":"","sources":["../../../../src/output-gateway/pid/models/PIDDepartureBoardsModel.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA0D;AAC1D,gDAA2D;
|
|
1
|
+
{"version":3,"file":"PIDDepartureBoardsModel.js","sourceRoot":"","sources":["../../../../src/output-gateway/pid/models/PIDDepartureBoardsModel.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA0D;AAC1D,gDAA2D;AAC3D,oDAA+C;AAI/C,wEAAqE;AACrE,+FAA6F;AAC7F,6EAA8F;AAC9F,gGAA2E;AAE3E,wBAAmD;AAInD,kCAA2C;AAC3C,kDAA+C;AAE/C,oFAA6D;AAE7D,MAAM,uBAAuB;IAOzB;QANQ,kBAAa,GAAG,GAAG,CAAC;QAkB5B;;;WAGG;QACI,WAAM,GAAG,KAAK,EAAE,OAkBtB,EAAgB,EAAE;YACf,MAAM,aAAa,GAAG,IAAA,yBAAM,GAAE,CAAC;YAC/B,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAE7F,MAAM,SAAS,GAAG,IAAA,gCAAe,EAAC,sBAAsB,CAAC,CAAC;YAC1D,SAAS,EAAE,aAAa,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,E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AAO,CAAC,MAAM;wBACtB,KAAK,EAAE,OAAO,CAAC,KAAK;wBACpB,IAAI,EAAE,OAAO,CAAC,IAAI;wBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;wBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;wBACtB,IAAI,EAAE,OAAO,CAAC,IAAI;wBAClB,oBAAoB;wBACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;wBAC1B,UAAU,EAAE,IAAI,EAAE,2BAA2B;qBAChD,CAAC,CAAC,OAAO,EAAE;oBACZ,SAAS,EAAE,kBAAkB;oBAC7B,KAAK,EAAE,cAAc;iBACxB,CAAC;gBACF,cAAc,EAAE,GAAG,EAAE,CAAC;gBACtB,OAAO,GAAG,CAAC;aACd;YAAC,OAAO,GAAG,EAAE;gBACV,MAAM,IAAI,6BAAY,CAAC,gBAAgB,EAAE,sBAAsB,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;aAC9E;QACL,CAAC,CAAC;QAlIE,IAAI,CAAC,8BAA8B,GAAG,IAAI,iCAA8B,EAAE,CAAC;QAC3E,IAAI,CAAC,oBAAoB,GAAG,IAAI,kCAAoB,CAChD,mBAAc,CAAC,OAAO,CAAqB,qBAAS,CAAC,iBAAiB,CAAC,EACvE,mBAAc,CAAC,OAAO,CAAgB,qBAAS,CAAC,YAAY,CAAC,CAChE,CAAC;QACF,IAAI,CAAC,kBAAkB,GAAG,mBAAc,CAAC,OAAO,CAAwB,uBAAU,CAAC,qBAAqB,CAAC,CAAC;QAC1G,IAAI,CAAC,sBAAsB,GAAG,mBAAc,CAAC,OAAO,CAChD,uBAAU,CAAC,kCAAkC,CAChD,CAAC;IACN,CAAC;CA0HJ;AAEQ,0DAAuB"}
|
|
@@ -43,34 +43,23 @@ class PIDDeparturesModel {
|
|
|
43
43
|
*/
|
|
44
44
|
this.skip = () => {
|
|
45
45
|
this.departures = this.departures.filter((departure) => {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
let isAtStop = false;
|
|
47
|
+
let isPassStop = false;
|
|
48
|
+
let isCurrentTrip = false;
|
|
49
|
+
if ("arrival_datetime" in departure) {
|
|
50
|
+
isAtStop = departure.stop_sequence === departure["trip.last_position.this_stop_sequence"];
|
|
51
|
+
isPassStop =
|
|
52
|
+
!!departure["trip.last_position.last_stop_sequence"] &&
|
|
53
|
+
departure.stop_sequence <= departure["trip.last_position.last_stop_sequence"];
|
|
48
54
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let isSkipAtStop = false;
|
|
53
|
-
for (const skip of this.options.skip) {
|
|
54
|
-
if (skip === pid_1.DepartureSkip.UNTRACKED) {
|
|
55
|
-
isSkipUntracked = true;
|
|
56
|
-
}
|
|
57
|
-
else if (skip === pid_1.DepartureSkip.MISSING) {
|
|
58
|
-
isSkipMissing = true;
|
|
59
|
-
}
|
|
60
|
-
else if (skip === pid_1.DepartureSkip.CANCELED) {
|
|
61
|
-
isSkipCanceled = true;
|
|
62
|
-
}
|
|
63
|
-
else if (skip === pid_1.DepartureSkip.AT_STOP) {
|
|
64
|
-
isSkipAtStop = true;
|
|
65
|
-
}
|
|
55
|
+
else if (this.options.tripNumber) {
|
|
56
|
+
// Skip transfers of current trip (in the vehicle in which the transfer board is located)
|
|
57
|
+
isCurrentTrip = SkipHelper_1.SkipHelper.isMatchingTripNumber(departure, this.options.tripNumber);
|
|
66
58
|
}
|
|
67
|
-
return !(
|
|
68
|
-
(
|
|
69
|
-
(
|
|
70
|
-
|
|
71
|
-
SkipHelper_1.SkipHelper.isVehicleMissing(departure, this.options.runScheduleMap, this.options.untrackedTrips)) ||
|
|
72
|
-
(isSkipCanceled && SkipHelper_1.SkipHelper.isTripCanceled(departure)) ||
|
|
73
|
-
(isSkipAtStop && SkipHelper_1.SkipHelper.isVehicleAtStop(departure)));
|
|
59
|
+
return !(isCurrentTrip ||
|
|
60
|
+
(this.options.skip.includes(pid_1.DepartureSkip.UNTRACKED) && !departure.is_delay_available) ||
|
|
61
|
+
(this.options.skip.includes(pid_1.DepartureSkip.CANCELED) && departure.is_canceled) ||
|
|
62
|
+
(this.options.skip.includes(pid_1.DepartureSkip.AT_STOP) && (isAtStop || isPassStop)));
|
|
74
63
|
});
|
|
75
64
|
};
|
|
76
65
|
/** Sorts by proper datetime by given options
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PIDDepartureModel.js","sourceRoot":"","sources":["../../../../../src/output-gateway/pid/models/helpers/PIDDepartureModel.ts"],"names":[],"mappings":";;;;;AAAA,+BAQiB;AACjB,8FAAwE;AACxE,iDAAoE;AACpE,6CAA0C;AAG1C,MAAqB,kBAAkB;IAcnC,YAAY,UAA4B,EAAE,OAAkC;QAKrE,YAAO,GAAG,GAAoB,EAAE;YACnC,IAAI,CAAC,eAAe,EAAE,CAAC;YAEvB,OAAO,8BAAoB,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9F,CAAC,CAAC;QASM,oBAAe,GAAG,CAAC,uBAAuB,GAAG,IAAI,EAAE,EAAE;YACzD,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,IAAI,CAAC,IAAI,EAAE,CAAC;YAEZ,IAAI,uBAAuB,EAAE;gBACzB,IAAI,CAAC,aAAa,EAAE,CAAC;aACxB;QACL,CAAC,CAAC;QAEF;WACG;QACK,mBAAc,GAAG,GAAS,EAAE;YAChC,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAEhD,IAAI,2BAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACpD,wEAAwE;gBACxE,IAAI,CAAC,UAAU,GAAG,eAAe,CAAC,IAAI;qBACjC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO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qB,EAAE,2BAAY,CAAC,8BAA8B;IAClE,yBAAyB,EAAE,2BAAY,CAAC,8BAA8B;IACtE,IAAI,EAAE,SAAS;CAClB,AARgC,CAQ/B;kBAZe,kBAAkB"}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import type { DepartureUnion } from "../..";
|
|
2
|
-
import type { IScheduleDto } from "../../../../schema-definitions/vehicle-positions/redis/interfaces/IGtfsRunTripCacheDto";
|
|
3
2
|
export declare class SkipHelper {
|
|
4
3
|
/**
|
|
5
4
|
* Used exclusively in transfer boards to skip transfers for the current trip
|
|
6
5
|
* (i.e., transfers within the vehicle where the transfer board is located)
|
|
7
6
|
*/
|
|
8
7
|
static isMatchingTripNumber(departure: DepartureUnion, tripNumber: string): boolean;
|
|
9
|
-
static hasNoDelayInfo(departure: DepartureUnion): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Used exclusively in departure boards when skip[]=missing is requested (without untracked)
|
|
12
|
-
*/
|
|
13
|
-
static isVehicleMissing(departure: DepartureUnion, runScheduleMap: Map<string, IScheduleDto[]> | null, untrackedTrips: Set<string> | null, nowDate?: Date): boolean;
|
|
14
|
-
static isTripCanceled(departure: DepartureUnion): boolean;
|
|
15
|
-
static isVehicleAtStop(departure: DepartureUnion): boolean;
|
|
16
|
-
private static isOutsideStartThreshold;
|
|
17
|
-
private static hasAlreadyDeparted;
|
|
18
|
-
private static hasLargeTimegapBetweenTrips;
|
|
19
8
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SkipHelper = void 0;
|
|
4
|
-
const RouteTypeEnums_1 = require("../../../../helpers/RouteTypeEnums");
|
|
5
|
-
const const_1 = require("./const");
|
|
6
4
|
/** Extracts the last numeric sequence from strings like:
|
|
7
5
|
* Os 1111 -> 1111
|
|
8
6
|
* Os 1111 B -> 1111
|
|
@@ -22,95 +20,6 @@ class SkipHelper {
|
|
|
22
20
|
const lastNumber = tripShortName.match(TRIP_NUMBER_REGEX)?.[1];
|
|
23
21
|
return !!lastNumber && lastNumber === tripNumber;
|
|
24
22
|
}
|
|
25
|
-
static hasNoDelayInfo(departure) {
|
|
26
|
-
return !departure.is_delay_available;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Used exclusively in departure boards when skip[]=missing is requested (without untracked)
|
|
30
|
-
*/
|
|
31
|
-
static isVehicleMissing(departure, runScheduleMap, untrackedTrips, nowDate = new Date()) {
|
|
32
|
-
// Not missing if essential trip data is missing or if delay information is available
|
|
33
|
-
if (!("trip.start_timestamp" in departure) ||
|
|
34
|
-
departure["trip.start_timestamp"] === null ||
|
|
35
|
-
departure.run_number === null ||
|
|
36
|
-
departure.origin_route_name === null ||
|
|
37
|
-
departure.is_delay_available) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
const startTimestamp = new Date(departure["trip.start_timestamp"]);
|
|
41
|
-
const minutesToStart = (startTimestamp.getTime() - nowDate.getTime()) / 60000;
|
|
42
|
-
/// Not missing if departure is too far in the future (threshold varies for metro)
|
|
43
|
-
if (this.isOutsideStartThreshold(minutesToStart, departure.route_type)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
// Missing if the trip should have already started
|
|
47
|
-
else if (this.hasAlreadyDeparted(minutesToStart)) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
// Cannot determine missing status without run schedule information
|
|
51
|
-
const runId = `${departure.origin_route_name}_${departure.run_number}`;
|
|
52
|
-
const runSchedule = runScheduleMap?.get(runId);
|
|
53
|
-
if (!runSchedule) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
// Not missing if this is the first trip in the run or if trip isn't found
|
|
57
|
-
const runTripIndex = runSchedule.findIndex((trip) => trip.trip_id === departure.trip_id);
|
|
58
|
-
if (runTripIndex === -1 || runTripIndex === 0) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
// Not missing if there's a significant gap after the previous trip
|
|
62
|
-
const previousRunTripEnd = new Date(runSchedule[runTripIndex - 1].end_timestamp);
|
|
63
|
-
if (this.hasLargeTimegapBetweenTrips(previousRunTripEnd, startTimestamp)) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
// Not missing if the previous trip has delay information available
|
|
67
|
-
const isPreviousUntracked = untrackedTrips?.has(runSchedule[runTripIndex - 1].trip_id);
|
|
68
|
-
if (!isPreviousUntracked) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
const previousStartTimestamp = new Date(runSchedule[runTripIndex - 1].start_timestamp);
|
|
72
|
-
const previousMinutesToStart = (previousStartTimestamp.getTime() - nowDate.getTime()) / 60000;
|
|
73
|
-
// Missing if previous trip should have already started
|
|
74
|
-
if (this.hasAlreadyDeparted(previousMinutesToStart)) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
// Check position of previous trip in the run
|
|
78
|
-
const previousRunTripIndex = runTripIndex - 1;
|
|
79
|
-
if (previousRunTripIndex === -1 || previousRunTripIndex === 0) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
// Check for gaps before the previous trip
|
|
83
|
-
const previousPreviousRunTripEnd = new Date(runSchedule[previousRunTripIndex - 1].end_timestamp);
|
|
84
|
-
if (this.hasLargeTimegapBetweenTrips(previousPreviousRunTripEnd, previousStartTimestamp)) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
// If we reach here, the previous untracked trip is likely missing,
|
|
88
|
-
// which implies the current trip is also missing
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
static isTripCanceled(departure) {
|
|
92
|
-
return !!departure.is_canceled;
|
|
93
|
-
}
|
|
94
|
-
static isVehicleAtStop(departure) {
|
|
95
|
-
if (!("arrival_datetime" in departure)) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
const isAtStop = departure.stop_sequence === departure["trip.last_position.this_stop_sequence"];
|
|
99
|
-
const isPassStop = !!departure["trip.last_position.last_stop_sequence"] &&
|
|
100
|
-
departure.stop_sequence <= departure["trip.last_position.last_stop_sequence"];
|
|
101
|
-
return isAtStop || isPassStop;
|
|
102
|
-
}
|
|
103
|
-
static isOutsideStartThreshold(minutesToStart, routeType) {
|
|
104
|
-
const isMetro = routeType === RouteTypeEnums_1.GTFSRouteTypeEnum.METRO;
|
|
105
|
-
return isMetro ? minutesToStart >= const_1.START_SOON_METRO_MINUTES_THRESHOLD : minutesToStart >= const_1.START_SOON_MINUTES_THRESHOLD;
|
|
106
|
-
}
|
|
107
|
-
static hasAlreadyDeparted(minutesToStart) {
|
|
108
|
-
return minutesToStart < const_1.DEPARTURED_MINUTES_THRESHOLD;
|
|
109
|
-
}
|
|
110
|
-
static hasLargeTimegapBetweenTrips(endTimestamp, startTimestamp) {
|
|
111
|
-
const minutesAfterPrevious = (startTimestamp.getTime() - endTimestamp.getTime()) / 60000;
|
|
112
|
-
return minutesAfterPrevious >= const_1.TRIP_GAP_MINUTES_THRESHOLD;
|
|
113
|
-
}
|
|
114
23
|
}
|
|
115
24
|
exports.SkipHelper = SkipHelper;
|
|
116
25
|
//# sourceMappingURL=SkipHelper.js.map
|