@golemio/pid 2.6.9-dev.854604880 → 2.6.10-dev.856817708
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/03_ropidgtfs_dump.sql +1 -1
- package/db/migrations/postgresql/20230502115509-positions-output-view.js +53 -0
- package/db/migrations/postgresql/sqls/20230502115509-positions-output-view-down.sql +7 -0
- package/db/migrations/postgresql/sqls/20230502115509-positions-output-view-up.sql +94 -0
- package/dist/integration-engine/vehicle-positions/workers/runs/data-access/CommonRunsRepository.js +2 -5
- package/dist/integration-engine/vehicle-positions/workers/runs/data-access/CommonRunsRepository.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/StopTimeDelayPredictionRepository.d.ts +1 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/StopTimeDelayPredictionRepository.js +5 -5
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/StopTimeDelayPredictionRepository.js.map +1 -1
- package/dist/output-gateway/vehicle-positions/VehiclePositionsRouter.d.ts +3 -3
- package/dist/output-gateway/vehicle-positions/VehiclePositionsRouter.js +6 -6
- package/dist/output-gateway/vehicle-positions/VehiclePositionsRouter.js.map +1 -1
- package/dist/output-gateway/vehicle-positions/data-access/ProcessedPositionRepository.d.ts +9 -0
- package/dist/output-gateway/vehicle-positions/data-access/ProcessedPositionRepository.js +21 -0
- package/dist/output-gateway/vehicle-positions/data-access/ProcessedPositionRepository.js.map +1 -0
- package/dist/output-gateway/vehicle-positions/data-access/TripRepository.d.ts +5 -63
- package/dist/output-gateway/vehicle-positions/data-access/TripRepository.js +7 -371
- package/dist/output-gateway/vehicle-positions/data-access/TripRepository.js.map +1 -1
- package/dist/output-gateway/vehicle-positions/data-access/TripWithLastPositionRepository.d.ts +51 -0
- package/dist/output-gateway/vehicle-positions/data-access/TripWithLastPositionRepository.js +240 -0
- package/dist/output-gateway/vehicle-positions/data-access/TripWithLastPositionRepository.js.map +1 -0
- package/dist/output-gateway/vehicle-positions/data-access/helpers/PositionOutputMapper.d.ts +5 -0
- package/dist/output-gateway/vehicle-positions/data-access/helpers/PositionOutputMapper.js +104 -0
- package/dist/output-gateway/vehicle-positions/data-access/helpers/PositionOutputMapper.js.map +1 -0
- package/dist/output-gateway/vehicle-positions/data-access/index.js +5 -1
- package/dist/output-gateway/vehicle-positions/data-access/index.js.map +1 -1
- package/dist/output-gateway/vehicle-positions/data-access/interfaces/{ITripRepository.d.ts → ITripWithPositionRepository.d.ts} +2 -2
- package/dist/output-gateway/vehicle-positions/data-access/interfaces/ITripWithPositionRepository.js +3 -0
- package/dist/output-gateway/vehicle-positions/data-access/interfaces/ITripWithPositionRepository.js.map +1 -0
- package/dist/output-gateway/vehicle-positions/data-access/interfaces/IVPRepositoryInstances.d.ts +4 -2
- package/dist/schema-definitions/vehicle-positions/index.d.ts +0 -8
- package/dist/schema-definitions/vehicle-positions/index.js +0 -8
- package/dist/schema-definitions/vehicle-positions/index.js.map +1 -1
- package/dist/schema-definitions/vehicle-positions/models/index.d.ts +0 -1
- package/dist/schema-definitions/vehicle-positions/models/index.js +0 -1
- package/dist/schema-definitions/vehicle-positions/models/index.js.map +1 -1
- package/dist/schema-definitions/vehicle-positions/models/views/ProcessedPositionModel.d.ts +27 -0
- package/dist/schema-definitions/vehicle-positions/models/views/ProcessedPositionModel.js +37 -0
- package/dist/schema-definitions/vehicle-positions/models/views/ProcessedPositionModel.js.map +1 -0
- package/dist/schema-definitions/vehicle-positions/models/views/StopTimeDelayPredictionModel.js.map +1 -0
- package/dist/schema-definitions/vehicle-positions/models/views/TripWithLastPositionModel.d.ts +52 -0
- package/dist/schema-definitions/vehicle-positions/models/views/TripWithLastPositionModel.js +56 -0
- package/dist/schema-definitions/vehicle-positions/models/views/TripWithLastPositionModel.js.map +1 -0
- package/dist/schema-definitions/vehicle-positions/models/views/index.d.ts +3 -0
- package/dist/schema-definitions/vehicle-positions/models/views/index.js +20 -0
- package/dist/schema-definitions/vehicle-positions/models/views/index.js.map +1 -0
- package/dist/schema-definitions/vehicle-positions/models/views/interfaces/IProcessedPositionDto.d.ts +23 -0
- package/dist/{output-gateway/vehicle-positions/data-access/interfaces/ITripRepository.js → schema-definitions/vehicle-positions/models/views/interfaces/IProcessedPositionDto.js} +1 -1
- package/dist/schema-definitions/vehicle-positions/models/views/interfaces/IProcessedPositionDto.js.map +1 -0
- package/dist/schema-definitions/vehicle-positions/models/views/interfaces/IStopTimeDelayPredictionDto.js.map +1 -0
- package/dist/schema-definitions/vehicle-positions/models/views/interfaces/ITripWithLastPositionDto.d.ts +42 -0
- package/dist/schema-definitions/vehicle-positions/models/views/interfaces/ITripWithLastPositionDto.js +3 -0
- package/dist/schema-definitions/vehicle-positions/models/views/interfaces/ITripWithLastPositionDto.js.map +1 -0
- package/docs/assets/pid_vp_view_erd.png +0 -0
- package/docs/implementation_documentation.md +11 -3
- package/docs/openapi-output.yaml +2 -2
- package/package.json +3 -3
- package/dist/output-gateway/vehicle-positions/data-access/interfaces/ITripRepository.js.map +0 -1
- package/dist/schema-definitions/vehicle-positions/models/StopTimeDelayPredictionModel.js.map +0 -1
- package/dist/schema-definitions/vehicle-positions/models/interfaces/IStopTimeDelayPredictionDto.js.map +0 -1
- /package/dist/schema-definitions/vehicle-positions/models/{StopTimeDelayPredictionModel.d.ts → views/StopTimeDelayPredictionModel.d.ts} +0 -0
- /package/dist/schema-definitions/vehicle-positions/models/{StopTimeDelayPredictionModel.js → views/StopTimeDelayPredictionModel.js} +0 -0
- /package/dist/schema-definitions/vehicle-positions/models/{interfaces → views/interfaces}/IStopTimeDelayPredictionDto.d.ts +0 -0
- /package/dist/schema-definitions/vehicle-positions/models/{interfaces → views/interfaces}/IStopTimeDelayPredictionDto.js +0 -0
|
@@ -1,387 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
35
|
-
var t = {};
|
|
36
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
37
|
-
t[p] = s[p];
|
|
38
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
39
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
40
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
41
|
-
t[p[i]] = s[p[i]];
|
|
42
|
-
}
|
|
43
|
-
return t;
|
|
44
|
-
};
|
|
45
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
-
};
|
|
48
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
3
|
exports.TripRepository = void 0;
|
|
50
|
-
const data_access_1 = require("../../shared/data-access");
|
|
51
4
|
const const_1 = require("../../../schema-definitions/const");
|
|
52
|
-
const models_1 = require("../../../schema-definitions/vehicle-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const data_access_2 = require("@golemio/core/dist/output-gateway/data-access");
|
|
56
|
-
const database_1 = require("@golemio/core/dist/output-gateway/database");
|
|
57
|
-
const Geo_1 = require("@golemio/core/dist/output-gateway/Geo");
|
|
58
|
-
const models_3 = require("@golemio/core/dist/output-gateway/models");
|
|
59
|
-
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
|
|
60
|
-
const moment_timezone_1 = __importDefault(require("@golemio/core/dist/shared/moment-timezone"));
|
|
61
|
-
const sequelize_1 = __importStar(require("@golemio/core/dist/shared/sequelize"));
|
|
62
|
-
const const_2 = require("../../../const");
|
|
63
|
-
const RouteTypeEnums_1 = require("../../../helpers/RouteTypeEnums");
|
|
64
|
-
const POSITION_LIMIT = 100;
|
|
65
|
-
class TripRepository extends models_3.SequelizeModel {
|
|
5
|
+
const models_1 = require("../../../schema-definitions/vehicle-positions/models");
|
|
6
|
+
const models_2 = require("@golemio/core/dist/output-gateway/models");
|
|
7
|
+
class TripRepository extends models_2.SequelizeModel {
|
|
66
8
|
constructor() {
|
|
67
|
-
super("VPTripsRepository",
|
|
9
|
+
super("VPTripsRepository", models_1.VPTripsModel.TABLE_NAME, models_1.VPTripsModel.attributeModel, {
|
|
68
10
|
schema: const_1.PG_SCHEMA,
|
|
69
11
|
});
|
|
70
|
-
this.Associate = (repositories) => {
|
|
71
|
-
this.sequelizeModel.hasMany(repositories.positionRepository.sequelizeModel, {
|
|
72
|
-
as: "all_positions",
|
|
73
|
-
foreignKey: "trips_id",
|
|
74
|
-
});
|
|
75
|
-
this.sequelizeModel.belongsTo(repositories.positionRepository.sequelizeModel, {
|
|
76
|
-
as: "last_position",
|
|
77
|
-
foreignKey: "last_position_id",
|
|
78
|
-
});
|
|
79
|
-
this.sequelizeModel.belongsTo(repositories.vehicleTypeRepository.sequelizeModel, {
|
|
80
|
-
as: "vehicle_type",
|
|
81
|
-
foreignKey: "vehicle_type_id",
|
|
82
|
-
});
|
|
83
|
-
this.sequelizeModel.belongsTo(repositories.vehicleDescriptorRepository.sequelizeModel, {
|
|
84
|
-
as: "vehicle_descriptor",
|
|
85
|
-
foreignKey: "vehicle_registration_number",
|
|
86
|
-
targetKey: "registration_number",
|
|
87
|
-
scope: {
|
|
88
|
-
[sequelize_1.default.Op.and]: [
|
|
89
|
-
sequelize_1.default.literal(`${models_2.VPTripsModel.TABLE_NAME}.gtfs_route_type = vehicle_descriptor.gtfs_route_type`),
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
/** Retrieves all vehicle trips
|
|
95
|
-
* @param {object} options Options object with params
|
|
96
|
-
* @param {number} [options.limit] Limit
|
|
97
|
-
* @param {number} [options.offset] Offset
|
|
98
|
-
* @param {string} [options.routeId] Filter trips by specific route id
|
|
99
|
-
* @param {string} [options.routeShortName] Filter trips by specific route short name
|
|
100
|
-
* @param {string} [options.tripId] Filter trips by specific trip id
|
|
101
|
-
* @param {boolean} [options.includeNotTracking] Should include not tracking vehicle positions (those off a trip)
|
|
102
|
-
* @param {boolean} [options.includePositions] Should include all vehicle positions
|
|
103
|
-
* @returns Array of the retrieved records
|
|
104
|
-
*/
|
|
105
|
-
this.GetAll = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
try {
|
|
107
|
-
const { limit, offset, updatedSince } = options;
|
|
108
|
-
const minUpdatedAt = (0, moment_timezone_1.default)().subtract(10, "minutes");
|
|
109
|
-
// updatedSince cannot be more than 10 minutes ago
|
|
110
|
-
const maxUpdatedAt = updatedSince && (0, moment_timezone_1.default)(updatedSince).isSameOrAfter(minUpdatedAt) ? updatedSince.toISOString() : null;
|
|
111
|
-
const include = this.ComposeIncludes(options);
|
|
112
|
-
const isMetroVisible = yield data_access_2.featureFlagService.isFeatureEnabled(data_access_1.FeatureFlagEnum.PIDShowMetroOnMap, true);
|
|
113
|
-
const rows = yield this.sequelizeModel.findAll({
|
|
114
|
-
attributes: {
|
|
115
|
-
include: ["updated_at", this.convertEpochMsColumnToISOString("start_timestamp", options.preferredTimezone)],
|
|
116
|
-
},
|
|
117
|
-
include,
|
|
118
|
-
limit: options.includePositions ? (limit && limit < POSITION_LIMIT ? limit : POSITION_LIMIT) : limit,
|
|
119
|
-
offset,
|
|
120
|
-
where: {
|
|
121
|
-
[sequelize_1.Op.and]: [
|
|
122
|
-
{
|
|
123
|
-
[sequelize_1.Op.or]: [
|
|
124
|
-
{ gtfs_trip_id: { [sequelize_1.Op.ne]: null } },
|
|
125
|
-
{
|
|
126
|
-
vehicle_registration_number: { [sequelize_1.Op.in]: const_2.ArrayNotPublicRegistrationNumbers },
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
},
|
|
130
|
-
maxUpdatedAt
|
|
131
|
-
? {
|
|
132
|
-
updated_at: {
|
|
133
|
-
[sequelize_1.Op.gt]: maxUpdatedAt,
|
|
134
|
-
},
|
|
135
|
-
}
|
|
136
|
-
: {},
|
|
137
|
-
options.cisTripNumber ? { cis_trip_number: options.cisTripNumber } : {},
|
|
138
|
-
options.routeId ? { gtfs_route_id: options.routeId } : {},
|
|
139
|
-
options.routeShortName ? { gtfs_route_short_name: options.routeShortName } : {},
|
|
140
|
-
options.tripId ? { gtfs_trip_id: options.tripId } : {},
|
|
141
|
-
isMetroVisible ? {} : { vehicle_type_id: { [sequelize_1.Op.ne]: RouteTypeEnums_1.MPVRouteTypesEnum.METRO } },
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
if (rows.length === 0) {
|
|
146
|
-
return {
|
|
147
|
-
data: (0, Geo_1.buildGeojsonFeatureCollection)([]),
|
|
148
|
-
metadata: {
|
|
149
|
-
maxUpdatedAt: maxUpdatedAt || new Date().toISOString(),
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
let returnData = [];
|
|
154
|
-
let maxUpdatedAtData = null;
|
|
155
|
-
for (const row of rows) {
|
|
156
|
-
returnData.push(this.ConvertItem(row));
|
|
157
|
-
if (row.updated_at > maxUpdatedAtData) {
|
|
158
|
-
maxUpdatedAtData = row.updated_at;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
data: (0, Geo_1.buildGeojsonFeatureCollection)(returnData),
|
|
163
|
-
metadata: {
|
|
164
|
-
maxUpdatedAt: maxUpdatedAtData || new Date().toISOString(),
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
throw new golemio_errors_1.CustomError("Database error", true, "VehiclepositionsTripsModel", 500, err);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
/** Retrieves specific vehicle trip
|
|
173
|
-
* @param {string} id Id of the trip
|
|
174
|
-
* @param {object} [options] Options object with params
|
|
175
|
-
* @param {string} [options.includeNotTracking] Returns last known trip even if it is not tracked at time
|
|
176
|
-
* @param {boolean} [options.includePositions] Should include all vehicle positions
|
|
177
|
-
* @returns Object of the retrieved record or null
|
|
178
|
-
*/
|
|
179
|
-
this.GetOneByGTFSTripId = (id, options) => __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
try {
|
|
181
|
-
const include = this.ComposeIncludes(options);
|
|
182
|
-
const data = yield this.sequelizeModel.findOne({
|
|
183
|
-
attributes: {
|
|
184
|
-
include: [this.convertEpochMsColumnToISOString("start_timestamp", options.preferredTimezone)],
|
|
185
|
-
},
|
|
186
|
-
include,
|
|
187
|
-
order: [["start_timestamp", "DESC"]],
|
|
188
|
-
where: {
|
|
189
|
-
gtfs_trip_id: id,
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
if (!data) {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
return this.ConvertItem(data);
|
|
196
|
-
}
|
|
197
|
-
catch (err) {
|
|
198
|
-
throw new golemio_errors_1.CustomError("Database error", true, "VehiclePositionsTripsModel", 500, err);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
/**
|
|
202
|
-
* Convert db result to proper output format
|
|
203
|
-
* @param {object} item Trip object
|
|
204
|
-
* @return
|
|
205
|
-
*/
|
|
206
|
-
this.ConvertItem = (item) => {
|
|
207
|
-
var _a, _b;
|
|
208
|
-
const _c = item.toJSON ? item.toJSON() : item, { last_position, vehicle_type, vehicle_descriptor, ropidgtfs_trip, all_positions = [] } = _c, trip = __rest(_c, ["last_position", "vehicle_type", "vehicle_descriptor", "ropidgtfs_trip", "all_positions"]);
|
|
209
|
-
const tripObject = Object.assign({ last_position: {
|
|
210
|
-
// TODO: status is at stop, or on route
|
|
211
|
-
// status: last_position.this_stop_id ? 'at_stop' : 'on_route/before_route/after_route',
|
|
212
|
-
bearing: last_position.bearing,
|
|
213
|
-
delay: {
|
|
214
|
-
actual: last_position.delay,
|
|
215
|
-
last_stop_arrival: last_position.delay_stop_arrival,
|
|
216
|
-
last_stop_departure: last_position.delay_stop_departure,
|
|
217
|
-
},
|
|
218
|
-
is_canceled: last_position.is_canceled,
|
|
219
|
-
last_stop: {
|
|
220
|
-
arrival_time: last_position.last_stop_arrival_time_isostring,
|
|
221
|
-
departure_time: last_position.last_stop_departure_time_isostring,
|
|
222
|
-
id: last_position.last_stop_id,
|
|
223
|
-
sequence: last_position.last_stop_sequence,
|
|
224
|
-
},
|
|
225
|
-
next_stop: {
|
|
226
|
-
arrival_time: last_position.next_stop_arrival_time_isostring,
|
|
227
|
-
departure_time: last_position.next_stop_departure_time_isostring,
|
|
228
|
-
id: last_position.next_stop_id,
|
|
229
|
-
sequence: last_position.next_stop_sequence,
|
|
230
|
-
},
|
|
231
|
-
origin_timestamp: last_position.origin_timestamp_isostring,
|
|
232
|
-
shape_dist_traveled: last_position.shape_dist_traveled,
|
|
233
|
-
speed: last_position.speed,
|
|
234
|
-
state_position: last_position.state_position || null,
|
|
235
|
-
tracking: last_position.tracking === const_2.PositionTrackingEnum.TRACKING ? true : false,
|
|
236
|
-
}, trip: {
|
|
237
|
-
agency_name: {
|
|
238
|
-
real: trip.agency_name_real,
|
|
239
|
-
scheduled: trip.agency_name_scheduled,
|
|
240
|
-
},
|
|
241
|
-
cis: {
|
|
242
|
-
line_id: trip.cis_line_id,
|
|
243
|
-
trip_number: trip.cis_trip_number,
|
|
244
|
-
},
|
|
245
|
-
gtfs: {
|
|
246
|
-
route_id: trip.gtfs_route_id,
|
|
247
|
-
route_short_name: trip.gtfs_route_short_name,
|
|
248
|
-
route_type: trip.gtfs_route_type,
|
|
249
|
-
trip_headsign: (_a = last_position.last_stop_headsign) !== null && _a !== void 0 ? _a : trip.gtfs_trip_headsign,
|
|
250
|
-
trip_id: trip.gtfs_trip_id,
|
|
251
|
-
trip_short_name: trip.gtfs_trip_short_name,
|
|
252
|
-
},
|
|
253
|
-
origin_route_name: trip.origin_route_name,
|
|
254
|
-
sequence_id: trip.run_number,
|
|
255
|
-
start_timestamp: trip.start_timestamp_isostring,
|
|
256
|
-
vehicle_registration_number: trip.vehicle_registration_number,
|
|
257
|
-
vehicle_type,
|
|
258
|
-
wheelchair_accessible: trip.wheelchair_accessible,
|
|
259
|
-
air_conditioned: (_b = vehicle_descriptor === null || vehicle_descriptor === void 0 ? void 0 : vehicle_descriptor.is_air_conditioned) !== null && _b !== void 0 ? _b : null,
|
|
260
|
-
} }, (all_positions.length && {
|
|
261
|
-
all_positions: (0, Geo_1.buildGeojsonFeatureCollection)(all_positions.map((position) => {
|
|
262
|
-
return {
|
|
263
|
-
bearing: position.bearing,
|
|
264
|
-
delay: {
|
|
265
|
-
actual: position.delay,
|
|
266
|
-
last_stop_arrival: position.delay_stop_arrival,
|
|
267
|
-
last_stop_departure: position.delay_stop_departure,
|
|
268
|
-
},
|
|
269
|
-
is_canceled: position.is_canceled,
|
|
270
|
-
last_stop: {
|
|
271
|
-
arrival_time: position.last_stop_arrival_time_isostring,
|
|
272
|
-
departure_time: position.last_stop_departure_time_isostring,
|
|
273
|
-
id: position.last_stop_id,
|
|
274
|
-
sequence: position.last_stop_sequence,
|
|
275
|
-
},
|
|
276
|
-
lat: position.lat,
|
|
277
|
-
lng: position.lng,
|
|
278
|
-
next_stop: {
|
|
279
|
-
arrival_time: position.next_stop_arrival_time_isostring,
|
|
280
|
-
departure_time: position.next_stop_departure_time_isostring,
|
|
281
|
-
id: position.next_stop_id,
|
|
282
|
-
sequence: position.next_stop_sequence,
|
|
283
|
-
},
|
|
284
|
-
origin_timestamp: position.origin_timestamp_isostring,
|
|
285
|
-
shape_dist_traveled: position.shape_dist_traveled,
|
|
286
|
-
speed: position.speed,
|
|
287
|
-
};
|
|
288
|
-
}), "lng", "lat", true),
|
|
289
|
-
}));
|
|
290
|
-
return (0, Geo_1.buildGeojsonFeatureLatLng)(tripObject, last_position.lng, last_position.lat);
|
|
291
|
-
};
|
|
292
|
-
/** Prepare orm query with selected params
|
|
293
|
-
* @param {object} options Options object with params
|
|
294
|
-
* @param {boolean} [options.includeNotTracking] Should include all vehicles, even not tracked
|
|
295
|
-
* @param {boolean} [options.includePositions] Should include all vehicle positions
|
|
296
|
-
* @param {Date | null} [options.updatedSince] Should include all newer positions than updatedSince
|
|
297
|
-
* @param {string} [options.preferredTimezone] Preferred timezone code
|
|
298
|
-
* @returns Array of inclusions
|
|
299
|
-
*/
|
|
300
|
-
this.ComposeIncludes = (options) => {
|
|
301
|
-
const possibleStatePosition = [const_2.StatePositionEnum.AT_STOP, const_2.StatePositionEnum.ON_TRACK];
|
|
302
|
-
if (options.includeNotTracking) {
|
|
303
|
-
possibleStatePosition.push(const_2.StatePositionEnum.AFTER_TRACK, const_2.StatePositionEnum.BEFORE_TRACK, const_2.StatePositionEnum.BEFORE_TRACK_DELAYED, const_2.StatePositionEnum.CANCELED, const_2.StatePositionEnum.OFF_TRACK);
|
|
304
|
-
}
|
|
305
|
-
if (options.includeNotPublic) {
|
|
306
|
-
possibleStatePosition.push(const_2.StatePositionEnum.NOT_PUBLIC);
|
|
307
|
-
}
|
|
308
|
-
const include = [
|
|
309
|
-
{
|
|
310
|
-
attributes: {
|
|
311
|
-
include: [
|
|
312
|
-
this.convertEpochMsColumnToISOString("last_stop_arrival_time", options.preferredTimezone),
|
|
313
|
-
this.convertEpochMsColumnToISOString("last_stop_departure_time", options.preferredTimezone),
|
|
314
|
-
this.convertEpochMsColumnToISOString("next_stop_arrival_time", options.preferredTimezone),
|
|
315
|
-
this.convertEpochMsColumnToISOString("next_stop_departure_time", options.preferredTimezone),
|
|
316
|
-
this.convertEpochMsColumnToISOString("origin_timestamp", options.preferredTimezone),
|
|
317
|
-
],
|
|
318
|
-
exclude: ["valid_to"],
|
|
319
|
-
},
|
|
320
|
-
as: "last_position",
|
|
321
|
-
model: database_1.sequelizeConnection.models[vehicle_positions_1.VehiclePositions.positions.pgTableName],
|
|
322
|
-
where: {
|
|
323
|
-
valid_to: {
|
|
324
|
-
[sequelize_1.Op.or]: [null, { [sequelize_1.Op.gte]: new Date().valueOf() }],
|
|
325
|
-
},
|
|
326
|
-
state_position: {
|
|
327
|
-
[sequelize_1.Op.in]: possibleStatePosition,
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
as: "vehicle_type",
|
|
333
|
-
model: database_1.sequelizeConnection.models[vehicle_positions_1.VehiclePositions.vehicleTypes.pgTableName],
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
as: "vehicle_descriptor",
|
|
337
|
-
model: database_1.sequelizeConnection.models[models_1.DescriptorModel.tableName],
|
|
338
|
-
attributes: ["is_air_conditioned"],
|
|
339
|
-
},
|
|
340
|
-
];
|
|
341
|
-
if (options.includePositions) {
|
|
342
|
-
include.push({
|
|
343
|
-
attributes: {
|
|
344
|
-
include: [
|
|
345
|
-
this.convertEpochMsColumnToISOString("last_stop_arrival_time", options.preferredTimezone),
|
|
346
|
-
this.convertEpochMsColumnToISOString("last_stop_departure_time", options.preferredTimezone),
|
|
347
|
-
this.convertEpochMsColumnToISOString("next_stop_arrival_time", options.preferredTimezone),
|
|
348
|
-
this.convertEpochMsColumnToISOString("next_stop_departure_time", options.preferredTimezone),
|
|
349
|
-
this.convertEpochMsColumnToISOString("origin_timestamp", options.preferredTimezone),
|
|
350
|
-
],
|
|
351
|
-
exclude: ["valid_to"],
|
|
352
|
-
},
|
|
353
|
-
as: "all_positions",
|
|
354
|
-
model: database_1.sequelizeConnection.models[vehicle_positions_1.VehiclePositions.positions.pgTableName],
|
|
355
|
-
where: {
|
|
356
|
-
state_position: {
|
|
357
|
-
[sequelize_1.Op.in]: possibleStatePosition,
|
|
358
|
-
},
|
|
359
|
-
},
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
return include;
|
|
363
|
-
};
|
|
364
12
|
// last_position_context and provider_source_type should never be consumed by API users
|
|
365
13
|
this.sequelizeModel.removeAttribute("last_position_context");
|
|
366
14
|
this.sequelizeModel.removeAttribute("provider_source_type");
|
|
367
15
|
}
|
|
368
|
-
|
|
16
|
+
GetAll() {
|
|
369
17
|
throw new Error("Not implemented");
|
|
370
18
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
* @param {string} preferredTimezone Preferred timezone code
|
|
374
|
-
* @returns Projection Alias with _isostring suffix
|
|
375
|
-
*/
|
|
376
|
-
convertEpochMsColumnToISOString(name, preferredTimezone) {
|
|
377
|
-
return [
|
|
378
|
-
sequelize_1.default.literal(` TO_CHAR(DATE_TRUNC('second',TO_TIMESTAMP("${name}"/1000)) AT TIME ZONE '${preferredTimezone}',` +
|
|
379
|
-
` 'YYYY-MM-DD"T"HH24:MI:SS') || replace('+'` +
|
|
380
|
-
` || to_char(DATE_TRUNC('second',TO_TIMESTAMP("${name}"/1000))` +
|
|
381
|
-
` AT TIME ZONE '${preferredTimezone}' - DATE_TRUNC('second',TO_TIMESTAMP("${name}"/1000))` +
|
|
382
|
-
` AT TIME ZONE 'UTC','HH24:MMFM'),'+-', '-')`),
|
|
383
|
-
name + `_isostring`,
|
|
384
|
-
];
|
|
19
|
+
GetOne() {
|
|
20
|
+
throw new Error("Not implemented");
|
|
385
21
|
}
|
|
386
22
|
}
|
|
387
23
|
exports.TripRepository = TripRepository;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TripRepository.js","sourceRoot":"","sources":["../../../../src/output-gateway/vehicle-positions/data-access/TripRepository.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TripRepository.js","sourceRoot":"","sources":["../../../../src/output-gateway/vehicle-positions/data-access/TripRepository.ts"],"names":[],"mappings":";;;AAAA,6DAAuC;AACvC,iFAA6D;AAC7D,qEAA0E;AAG1E,MAAa,cAAe,SAAQ,uBAAc;IAG9C;QACI,KAAK,CAAC,mBAAmB,EAAE,qBAAY,CAAC,UAAU,EAAE,qBAAY,CAAC,cAAc,EAAE;YAC7E,MAAM,EAAE,iBAAS;SACpB,CAAC,CAAC;QAEH,uFAAuF;QACvF,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC;IAChE,CAAC;IAEM,MAAM;QACT,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;IAEM,MAAM;QACT,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AApBD,wCAoBC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TripWithLastPositionModel } from "../../../schema-definitions/vehicle-positions/models/views";
|
|
2
|
+
import { SequelizeModel } from "@golemio/core/dist/output-gateway";
|
|
3
|
+
import { IGeoJSONFeature } from "@golemio/core/dist/output-gateway/Geo";
|
|
4
|
+
import { ModelStatic } from "@golemio/core/dist/shared/sequelize";
|
|
5
|
+
import { ITripGetAllOutput, ITripWithPositionRepository } from "./interfaces/ITripWithPositionRepository";
|
|
6
|
+
import { IVPRepositoryInstances } from "./interfaces/IVPRepositoryInstances";
|
|
7
|
+
export declare class TripWithLastPositionRepository extends SequelizeModel implements ITripWithPositionRepository {
|
|
8
|
+
sequelizeModel: ModelStatic<TripWithLastPositionModel>;
|
|
9
|
+
constructor();
|
|
10
|
+
Associate: (repositories: IVPRepositoryInstances) => void;
|
|
11
|
+
/** Retrieves all vehicle trips
|
|
12
|
+
* @param {object} options Options object with params
|
|
13
|
+
* @param {number} [options.limit] Limit
|
|
14
|
+
* @param {number} [options.offset] Offset
|
|
15
|
+
* @param {string} [options.routeId] Filter trips by specific route id
|
|
16
|
+
* @param {string} [options.routeShortName] Filter trips by specific route short name
|
|
17
|
+
* @param {string} [options.tripId] Filter trips by specific trip id
|
|
18
|
+
* @param {boolean} [options.includeNotTracking] Should include not tracking vehicle positions (those off a trip)
|
|
19
|
+
* @param {boolean} [options.includePositions] Should include all vehicle positions
|
|
20
|
+
* @returns Array of the retrieved records
|
|
21
|
+
*/
|
|
22
|
+
GetAll: (options: {
|
|
23
|
+
cisTripNumber?: number;
|
|
24
|
+
routeId?: string;
|
|
25
|
+
routeShortName?: string;
|
|
26
|
+
tripId?: string;
|
|
27
|
+
includeNotTracking?: boolean;
|
|
28
|
+
includePositions?: boolean;
|
|
29
|
+
includeNotPublic?: boolean;
|
|
30
|
+
limit?: number;
|
|
31
|
+
offset?: number;
|
|
32
|
+
updatedSince?: Date | null;
|
|
33
|
+
preferredTimezone: string;
|
|
34
|
+
}) => Promise<ITripGetAllOutput>;
|
|
35
|
+
GetOne(): never;
|
|
36
|
+
/** Retrieves specific vehicle trip
|
|
37
|
+
* @param {string} id Id of the trip
|
|
38
|
+
* @param {object} [options] Options object with params
|
|
39
|
+
* @param {string} [options.includeNotTracking] Returns last known trip even if it is not tracked at time
|
|
40
|
+
* @param {boolean} [options.includePositions] Should include all vehicle positions
|
|
41
|
+
* @returns Object of the retrieved record or null
|
|
42
|
+
*/
|
|
43
|
+
GetOneByGTFSTripId: (id: string, options: {
|
|
44
|
+
includeNotTracking?: boolean;
|
|
45
|
+
includePositions?: boolean;
|
|
46
|
+
includeNotPublic?: boolean;
|
|
47
|
+
preferredTimezone: string;
|
|
48
|
+
}) => Promise<IGeoJSONFeature | null>;
|
|
49
|
+
private composeIncludes;
|
|
50
|
+
private determinePossibleStatePositions;
|
|
51
|
+
}
|