@opentripplanner/core-utils 11.4.0 → 11.4.2-mobility-profile
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/lib/__tests__/__mocks__/bike-rental-itinerary.json +863 -0
- package/lib/__tests__/__mocks__/config.json +54 -0
- package/lib/__tests__/__mocks__/fare-products-itinerary.json +1299 -0
- package/lib/__tests__/__mocks__/routes.json +107 -0
- package/lib/__tests__/__mocks__/tnc-itinerary.json +1726 -0
- package/lib/bike-rental-itinerary.json +863 -0
- package/lib/config.json +54 -0
- package/lib/core-utils.story.d.ts +0 -1
- package/lib/core-utils.story.d.ts.map +1 -1
- package/lib/fare-products-itinerary.json +1299 -0
- package/lib/otpSchema.json +13373 -0
- package/lib/planQuery.graphql +281 -0
- package/lib/query-gen.d.ts +3 -1
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +6 -2
- package/lib/query-gen.js.map +1 -1
- package/lib/routes.json +107 -0
- package/lib/suspense.js +26 -0
- package/lib/suspense.js.map +1 -0
- package/lib/tnc-itinerary.json +1726 -0
- package/package.json +2 -2
- package/src/otpSchema.json +10 -0
- package/src/planQuery.graphql +2 -0
- package/src/query-gen.ts +7 -1
- package/esm/graphql.d.js +0 -2
- package/esm/graphql.d.js.map +0 -1
- package/esm/index.js +0 -24
- package/esm/index.js.map +0 -1
- package/esm/itinerary.js +0 -688
- package/esm/itinerary.js.map +0 -1
- package/esm/map.js +0 -53
- package/esm/map.js.map +0 -1
- package/esm/profile.js +0 -172
- package/esm/profile.js.map +0 -1
- package/esm/query-gen.js +0 -231
- package/esm/query-gen.js.map +0 -1
- package/esm/query-params.js +0 -786
- package/esm/query-params.js.map +0 -1
- package/esm/query.js +0 -538
- package/esm/query.js.map +0 -1
- package/esm/route.js +0 -460
- package/esm/route.js.map +0 -1
- package/esm/storage.js +0 -46
- package/esm/storage.js.map +0 -1
- package/esm/time.js +0 -94
- package/esm/time.js.map +0 -1
- package/esm/ui.js +0 -48
- package/esm/ui.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
package/esm/itinerary.js
DELETED
|
@@ -1,688 +0,0 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
-
|
|
5
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
|
|
7
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
|
-
|
|
9
|
-
import polyline from "@mapbox/polyline";
|
|
10
|
-
import turfAlong from "@turf/along"; // All OTP transit modes
|
|
11
|
-
|
|
12
|
-
export var transitModes = ["TRAM", "TROLLEYBUS", "BUS", "SUBWAY", "FERRY", "RAIL", "GONDOLA"];
|
|
13
|
-
/**
|
|
14
|
-
* @param {config} config OTP-RR configuration object
|
|
15
|
-
* @return {Array} List of all transit modes defined in config; otherwise default mode list
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
export function getTransitModes(config) {
|
|
19
|
-
if (!config || !config.modes || !config.modes.transitModes) return transitModes;
|
|
20
|
-
return config.modes.transitModes.map(function (tm) {
|
|
21
|
-
return typeof tm !== "string" ? tm.mode : tm;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
export function isTransit(mode) {
|
|
25
|
-
return transitModes.includes(mode) || mode === "TRANSIT";
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Returns true if the leg pickup rules enabled which require
|
|
29
|
-
* calling ahead for the service to run. "mustPhone" is the only
|
|
30
|
-
* property which encodes this info.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
export function isReservationRequired(leg) {
|
|
34
|
-
return leg.boardRule === "mustPhone" || leg.alightRule === "mustPhone";
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns true if a user must ask the driver to let the user off
|
|
38
|
-
* or if the user must flag the driver down for pickup.
|
|
39
|
-
* "coordinateWithDriver" in board/alight rule encodes this info.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
export function isCoordinationRequired(leg) {
|
|
43
|
-
return leg.boardRule === "coordinateWithDriver" || leg.alightRule === "coordinateWithDriver";
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The two rules checked by the above two functions are the only values
|
|
47
|
-
* returned by OTP when a leg is a flex leg.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
export function isFlex(leg) {
|
|
51
|
-
return isReservationRequired(leg) || isCoordinationRequired(leg);
|
|
52
|
-
}
|
|
53
|
-
export function isAdvanceBookingRequired(info) {
|
|
54
|
-
var _info$latestBookingTi;
|
|
55
|
-
|
|
56
|
-
return (info === null || info === void 0 ? void 0 : (_info$latestBookingTi = info.latestBookingTime) === null || _info$latestBookingTi === void 0 ? void 0 : _info$latestBookingTi.daysPrior) > 0;
|
|
57
|
-
}
|
|
58
|
-
export function legDropoffRequiresAdvanceBooking(leg) {
|
|
59
|
-
return isAdvanceBookingRequired(leg.dropOffBookingInfo);
|
|
60
|
-
}
|
|
61
|
-
export function isRideshareLeg(leg) {
|
|
62
|
-
var _leg$rideHailingEstim, _leg$rideHailingEstim2;
|
|
63
|
-
|
|
64
|
-
return !!((_leg$rideHailingEstim = leg.rideHailingEstimate) !== null && _leg$rideHailingEstim !== void 0 && (_leg$rideHailingEstim2 = _leg$rideHailingEstim.provider) !== null && _leg$rideHailingEstim2 !== void 0 && _leg$rideHailingEstim2.id);
|
|
65
|
-
}
|
|
66
|
-
export function isWalk(mode) {
|
|
67
|
-
if (!mode) return false;
|
|
68
|
-
return mode === "WALK";
|
|
69
|
-
}
|
|
70
|
-
export function isBicycle(mode) {
|
|
71
|
-
if (!mode) return false;
|
|
72
|
-
return mode === "BICYCLE";
|
|
73
|
-
}
|
|
74
|
-
export function isBicycleRent(mode) {
|
|
75
|
-
if (!mode) return false;
|
|
76
|
-
return mode === "BICYCLE_RENT";
|
|
77
|
-
}
|
|
78
|
-
export function isCar(mode) {
|
|
79
|
-
if (!mode) return false;
|
|
80
|
-
return mode.startsWith("CAR");
|
|
81
|
-
}
|
|
82
|
-
export function isMicromobility(mode) {
|
|
83
|
-
if (!mode) return false;
|
|
84
|
-
return mode.startsWith("MICROMOBILITY") || mode.startsWith("SCOOTER");
|
|
85
|
-
}
|
|
86
|
-
export function isAccessMode(mode) {
|
|
87
|
-
return isWalk(mode) || isBicycle(mode) || isBicycleRent(mode) || isCar(mode) || isMicromobility(mode);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* @param {string} modesStr a comma-separated list of OTP modes
|
|
91
|
-
* @return {boolean} whether any of the modes are transit modes
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
export function hasTransit(modesStr) {
|
|
95
|
-
return modesStr.split(",").some(function (mode) {
|
|
96
|
-
return isTransit(mode);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* @param {string} modesStr a comma-separated list of OTP modes
|
|
101
|
-
* @return {boolean} whether any of the modes are car-based modes
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
export function hasCar(modesStr) {
|
|
105
|
-
return modesStr.split(",").some(function (mode) {
|
|
106
|
-
return isCar(mode);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* @param {string} modesStr a comma-separated list of OTP modes
|
|
111
|
-
* @return {boolean} whether any of the modes are bicycle-based modes
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
export function hasBike(modesStr) {
|
|
115
|
-
return modesStr.split(",").some(function (mode) {
|
|
116
|
-
return isBicycle(mode) || isBicycleRent(mode);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* @param {string} modesStr a comma-separated list of OTP modes
|
|
121
|
-
* @return {boolean} whether any of the modes are micromobility-based modes
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
export function hasMicromobility(modesStr) {
|
|
125
|
-
return modesStr.split(",").some(function (mode) {
|
|
126
|
-
return isMicromobility(mode);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* @param {string} modesStr a comma-separated list of OTP modes
|
|
131
|
-
* @return {boolean} whether any of the modes is a hailing mode
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
export function hasHail(modesStr) {
|
|
135
|
-
return modesStr.split(",").some(function (mode) {
|
|
136
|
-
return mode.indexOf("_HAIL") > -1;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* @param {string} modesStr a comma-separated list of OTP modes
|
|
141
|
-
* @return {boolean} whether any of the modes is a rental mode
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
export function hasRental(modesStr) {
|
|
145
|
-
return modesStr.split(",").some(function (mode) {
|
|
146
|
-
return mode.indexOf("_RENT") > -1;
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
export function getMapColor(mode) {
|
|
150
|
-
mode = mode || this.get("mode");
|
|
151
|
-
if (mode === "WALK") return "#444";
|
|
152
|
-
if (mode === "BICYCLE") return "#0073e5";
|
|
153
|
-
if (mode === "SUBWAY") return "#e60000";
|
|
154
|
-
if (mode === "RAIL") return "#b00";
|
|
155
|
-
if (mode === "BUS") return "#080";
|
|
156
|
-
if (mode === "TROLLEYBUS") return "#080";
|
|
157
|
-
if (mode === "TRAM") return "#800";
|
|
158
|
-
if (mode === "FERRY") return "#008";
|
|
159
|
-
if (mode === "CAR") return "#444";
|
|
160
|
-
if (mode === "MICROMOBILITY" || mode === "SCOOTER") return "#f5a729";
|
|
161
|
-
return "#aaa";
|
|
162
|
-
}
|
|
163
|
-
export function toSentenceCase(str) {
|
|
164
|
-
if (str == null) {
|
|
165
|
-
return "";
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
str = String(str);
|
|
169
|
-
return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Derive the company string based on mode and network associated with leg.
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
export function getCompanyFromLeg(leg) {
|
|
176
|
-
if (!leg) return null;
|
|
177
|
-
var from = leg.from,
|
|
178
|
-
mode = leg.mode,
|
|
179
|
-
rentedBike = leg.rentedBike,
|
|
180
|
-
rentedCar = leg.rentedCar,
|
|
181
|
-
rentedVehicle = leg.rentedVehicle,
|
|
182
|
-
rideHailingEstimate = leg.rideHailingEstimate;
|
|
183
|
-
|
|
184
|
-
if (mode === "CAR" && rentedCar) {
|
|
185
|
-
return from.networks[0];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (mode === "CAR" && rideHailingEstimate) {
|
|
189
|
-
return rideHailingEstimate.provider.id;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (mode === "BICYCLE" && rentedBike && from.networks) {
|
|
193
|
-
return from.networks[0];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (from.rentalVehicle) {
|
|
197
|
-
return from.rentalVehicle.network;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle && from.networks) {
|
|
201
|
-
return from.networks[0];
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
export function getItineraryBounds(itinerary) {
|
|
207
|
-
var coords = [];
|
|
208
|
-
itinerary.legs.forEach(function (leg) {
|
|
209
|
-
var legCoords = polyline.toGeoJSON(leg.legGeometry.points).coordinates.map(function (c) {
|
|
210
|
-
return [c[1], c[0]];
|
|
211
|
-
});
|
|
212
|
-
coords = [].concat(_toConsumableArray(coords), _toConsumableArray(legCoords));
|
|
213
|
-
});
|
|
214
|
-
return coords;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Return a coords object that encloses the given leg's geometry.
|
|
218
|
-
*/
|
|
219
|
-
|
|
220
|
-
export function getLegBounds(leg) {
|
|
221
|
-
var coords = polyline.toGeoJSON(leg.legGeometry.points).coordinates.map(function (c) {
|
|
222
|
-
return [c[1], c[0]];
|
|
223
|
-
}); // in certain cases, there might be zero-length coordinates in the leg
|
|
224
|
-
// geometry. In these cases, build us an array of coordinates using the from
|
|
225
|
-
// and to data of the leg.
|
|
226
|
-
|
|
227
|
-
if (coords.length === 0) {
|
|
228
|
-
coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return coords;
|
|
232
|
-
}
|
|
233
|
-
/* Returns an interpolated lat-lon at a specified distance along a leg */
|
|
234
|
-
|
|
235
|
-
export function legLocationAtDistance(leg, distance) {
|
|
236
|
-
if (!leg.legGeometry) return null;
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
var line = polyline.toGeoJSON(leg.legGeometry.points);
|
|
240
|
-
var pt = turfAlong(line, distance, {
|
|
241
|
-
units: "meters"
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
if (pt && pt.geometry && pt.geometry.coordinates) {
|
|
245
|
-
return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];
|
|
246
|
-
}
|
|
247
|
-
} catch (e) {// FIXME handle error!
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
/* Returns an interpolated elevation at a specified distance along a leg */
|
|
253
|
-
|
|
254
|
-
export function legElevationAtDistance(points, distance) {
|
|
255
|
-
// Iterate through the combined elevation profile
|
|
256
|
-
var traversed = 0; // If first point distance is not zero, insert starting point at zero with
|
|
257
|
-
// null elevation. Encountering this value should trigger the warning below.
|
|
258
|
-
|
|
259
|
-
if (points[0][0] > 0) {
|
|
260
|
-
points.unshift([0, null]);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
for (var i = 1; i < points.length; i++) {
|
|
264
|
-
var start = points[i - 1];
|
|
265
|
-
var elevDistanceSpan = points[i][0] - start[0];
|
|
266
|
-
|
|
267
|
-
if (distance >= traversed && distance <= traversed + elevDistanceSpan) {
|
|
268
|
-
// Distance falls within this point and the previous one;
|
|
269
|
-
// compute & return interpolated elevation value
|
|
270
|
-
if (start[1] === null) {
|
|
271
|
-
console.warn("Elevation value does not exist for distance.", distance, traversed);
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
var pct = (distance - traversed) / elevDistanceSpan;
|
|
276
|
-
var elevSpan = points[i][1] - start[1];
|
|
277
|
-
return start[1] + elevSpan * pct;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
traversed += elevDistanceSpan;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
console.warn("Elevation value does not exist for distance.", distance, traversed);
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
export function mapOldElevationComponentToNew(oldElev) {
|
|
287
|
-
return {
|
|
288
|
-
distance: oldElev.first,
|
|
289
|
-
elevation: oldElev.second
|
|
290
|
-
};
|
|
291
|
-
} // Iterate through the steps, building the array of elevation points and
|
|
292
|
-
// keeping track of the minimum and maximum elevations reached
|
|
293
|
-
|
|
294
|
-
export function getElevationProfile(steps) {
|
|
295
|
-
var unitConversion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
296
|
-
var minElev = 100000;
|
|
297
|
-
var maxElev = -100000;
|
|
298
|
-
var traversed = 0;
|
|
299
|
-
var gain = 0;
|
|
300
|
-
var loss = 0;
|
|
301
|
-
var previous = null;
|
|
302
|
-
var points = [];
|
|
303
|
-
steps.forEach(function (step) {
|
|
304
|
-
var _step$elevation;
|
|
305
|
-
|
|
306
|
-
// Support for old REST response data (in step.elevation)
|
|
307
|
-
var stepElevationProfile = step.elevationProfile || Array.isArray(step.elevation) && ((_step$elevation = step.elevation) === null || _step$elevation === void 0 ? void 0 : _step$elevation.map(mapOldElevationComponentToNew));
|
|
308
|
-
|
|
309
|
-
if (!stepElevationProfile || stepElevationProfile.length === 0) {
|
|
310
|
-
traversed += step.distance;
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
for (var i = 0; i < stepElevationProfile.length; i++) {
|
|
315
|
-
var elev = stepElevationProfile[i];
|
|
316
|
-
|
|
317
|
-
if (previous) {
|
|
318
|
-
var diff = (elev.elevation - previous.elevation) * unitConversion;
|
|
319
|
-
if (diff > 0) gain += diff;else loss += diff;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (i === 0 && elev.distance !== 0) {// console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
var convertedElevation = elev.elevation * unitConversion;
|
|
326
|
-
if (convertedElevation < minElev) minElev = convertedElevation;
|
|
327
|
-
if (convertedElevation > maxElev) maxElev = convertedElevation;
|
|
328
|
-
points.push([traversed + elev.distance, elev.elevation]); // Insert "filler" point if the last point in elevation profile does not
|
|
329
|
-
// reach the full distance of the step.
|
|
330
|
-
|
|
331
|
-
if (i === stepElevationProfile.length - 1 && elev.distance !== step.distance) {// points.push([traversed + step.distance, elev.second])
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
previous = elev;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
traversed += step.distance;
|
|
338
|
-
});
|
|
339
|
-
return {
|
|
340
|
-
maxElev: maxElev,
|
|
341
|
-
minElev: minElev,
|
|
342
|
-
points: points,
|
|
343
|
-
traversed: traversed,
|
|
344
|
-
gain: gain,
|
|
345
|
-
loss: loss
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Uses canvas.measureText to compute and return the width of the given text of given font in pixels.
|
|
350
|
-
*
|
|
351
|
-
* @param {string} text The text to be rendered.
|
|
352
|
-
* @param {string} font The css font descriptor that text is to be rendered with (e.g. "bold 14px verdana").
|
|
353
|
-
*
|
|
354
|
-
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
|
|
355
|
-
*/
|
|
356
|
-
|
|
357
|
-
export function getTextWidth(text) {
|
|
358
|
-
var font = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "22px Arial";
|
|
359
|
-
// reuse canvas object for better performance
|
|
360
|
-
var canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
|
361
|
-
var context = canvas.getContext("2d");
|
|
362
|
-
context.font = font;
|
|
363
|
-
var metrics = context.measureText(text);
|
|
364
|
-
return metrics.width;
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Get the configured company object for the given network string if the company
|
|
368
|
-
* has been defined in the provided companies array config.
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
export function getCompanyForNetwork(networkString) {
|
|
372
|
-
var companies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
373
|
-
var company = companies.find(function (co) {
|
|
374
|
-
return co.id === networkString;
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
if (!company) {
|
|
378
|
-
console.warn("No company found in config.yml that matches rented vehicle network: ".concat(networkString), companies);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
return company;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Get a string label to display from a list of vehicle rental networks.
|
|
385
|
-
*
|
|
386
|
-
* @param {Array<string>} networks A list of network ids.
|
|
387
|
-
* @param {Array<object>} [companies=[]] An optional list of the companies config.
|
|
388
|
-
* @return {string} A label for use in presentation on a website.
|
|
389
|
-
*/
|
|
390
|
-
|
|
391
|
-
export function getCompaniesLabelFromNetworks(networks) {
|
|
392
|
-
var companies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
393
|
-
return (Array.isArray(networks) ? networks : [networks]).map(function (network) {
|
|
394
|
-
return getCompanyForNetwork(network, companies);
|
|
395
|
-
}).filter(function (co) {
|
|
396
|
-
return !!co;
|
|
397
|
-
}).map(function (co) {
|
|
398
|
-
return co.label;
|
|
399
|
-
}).join("/");
|
|
400
|
-
}
|
|
401
|
-
export function getTNCLocation(leg, type) {
|
|
402
|
-
var location = leg[type];
|
|
403
|
-
return "".concat(location.lat.toFixed(5), ",").concat(location.lon.toFixed(5));
|
|
404
|
-
}
|
|
405
|
-
export function calculatePhysicalActivity(itinerary) {
|
|
406
|
-
var walkDuration = 0;
|
|
407
|
-
var bikeDuration = 0;
|
|
408
|
-
itinerary.legs.forEach(function (leg) {
|
|
409
|
-
if (leg.mode.startsWith("WALK")) walkDuration += leg.duration;
|
|
410
|
-
if (leg.mode.startsWith("BICYCLE")) bikeDuration += leg.duration;
|
|
411
|
-
});
|
|
412
|
-
var caloriesBurned = walkDuration / 3600 * 280 + bikeDuration / 3600 * 290;
|
|
413
|
-
return {
|
|
414
|
-
bikeDuration: bikeDuration,
|
|
415
|
-
caloriesBurned: caloriesBurned,
|
|
416
|
-
walkDuration: walkDuration
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* For an itinerary, calculates the TNC fares and returns an object with
|
|
421
|
-
* these values and currency info.
|
|
422
|
-
* It is assumed that the same currency is used for all TNC legs.
|
|
423
|
-
*/
|
|
424
|
-
|
|
425
|
-
export function calculateTncFares(itinerary) {
|
|
426
|
-
return itinerary.legs.filter(function (leg) {
|
|
427
|
-
return leg.mode === "CAR" && leg.rideHailingEstimate;
|
|
428
|
-
}).reduce(function (_ref, _ref2) {
|
|
429
|
-
var maxTNCFare = _ref.maxTNCFare,
|
|
430
|
-
minTNCFare = _ref.minTNCFare;
|
|
431
|
-
var rideHailingEstimate = _ref2.rideHailingEstimate;
|
|
432
|
-
var minPrice = rideHailingEstimate.minPrice,
|
|
433
|
-
maxPrice = rideHailingEstimate.maxPrice;
|
|
434
|
-
return {
|
|
435
|
-
// Assumes a single currency for entire itinerary.
|
|
436
|
-
currencyCode: minPrice.currency.code,
|
|
437
|
-
maxTNCFare: maxTNCFare + maxPrice.amount,
|
|
438
|
-
minTNCFare: minTNCFare + minPrice.amount
|
|
439
|
-
};
|
|
440
|
-
}, {
|
|
441
|
-
currencyCode: null,
|
|
442
|
-
maxTNCFare: 0,
|
|
443
|
-
minTNCFare: 0
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Sources:
|
|
448
|
-
* - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf
|
|
449
|
-
* - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey
|
|
450
|
-
* - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx
|
|
451
|
-
* Other values extrapolated.
|
|
452
|
-
*/
|
|
453
|
-
|
|
454
|
-
var CARBON_INTENSITY_DEFAULTS = {
|
|
455
|
-
walk: 0.026,
|
|
456
|
-
bicycle: 0.017,
|
|
457
|
-
car: 0.162,
|
|
458
|
-
tram: 0.066,
|
|
459
|
-
trolleybus: 0.066,
|
|
460
|
-
subway: 0.066,
|
|
461
|
-
rail: 0.066,
|
|
462
|
-
bus: 0.09,
|
|
463
|
-
ferry: 0.082,
|
|
464
|
-
cable_car: 0.021,
|
|
465
|
-
gondola: 0.021,
|
|
466
|
-
funicular: 0.066,
|
|
467
|
-
transit: 0.066,
|
|
468
|
-
leg_switch: 0,
|
|
469
|
-
airplane: 0.382,
|
|
470
|
-
micromobility: 0.095
|
|
471
|
-
};
|
|
472
|
-
/**
|
|
473
|
-
* @param {itinerary} itinerary OTP trip itinierary, only legs is required.
|
|
474
|
-
* @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
|
|
475
|
-
* @param {units} units units to be used in return value
|
|
476
|
-
* @return Amount of carbon in chosen unit
|
|
477
|
-
*/
|
|
478
|
-
|
|
479
|
-
export function calculateEmissions( // This type makes all the properties from Itinerary optional except legs.
|
|
480
|
-
itinerary) {
|
|
481
|
-
var _itinerary$legs;
|
|
482
|
-
|
|
483
|
-
var carbonIntensity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
484
|
-
var units = arguments.length > 2 ? arguments[2] : undefined;
|
|
485
|
-
|
|
486
|
-
// Apply defaults for any values that we don't have.
|
|
487
|
-
var carbonIntensityWithDefaults = _objectSpread(_objectSpread({}, CARBON_INTENSITY_DEFAULTS), carbonIntensity); // Distance is in meters, totalCarbon is in grams
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
var totalCarbon = (itinerary === null || itinerary === void 0 ? void 0 : (_itinerary$legs = itinerary.legs) === null || _itinerary$legs === void 0 ? void 0 : _itinerary$legs.reduce(function (total, leg) {
|
|
491
|
-
return (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] || 0) + total;
|
|
492
|
-
}, 0)) || 0;
|
|
493
|
-
|
|
494
|
-
switch (units) {
|
|
495
|
-
case "ounce":
|
|
496
|
-
return totalCarbon / 28.35;
|
|
497
|
-
|
|
498
|
-
case "kilogram":
|
|
499
|
-
return totalCarbon / 1000;
|
|
500
|
-
|
|
501
|
-
case "pound":
|
|
502
|
-
return totalCarbon / 454;
|
|
503
|
-
|
|
504
|
-
case "gram":
|
|
505
|
-
default:
|
|
506
|
-
return totalCarbon;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Returns the user-facing stop id to display for a stop or place, using the following priority:
|
|
511
|
-
* 1. stop code,
|
|
512
|
-
* 2. stop id without the agency id portion, if stop id contains an agency portion,
|
|
513
|
-
* 3. stop id, whether null or not (this is the fallback case).
|
|
514
|
-
*/
|
|
515
|
-
|
|
516
|
-
export function getDisplayedStopId(placeOrStop) {
|
|
517
|
-
var _stopId;
|
|
518
|
-
|
|
519
|
-
var stopId;
|
|
520
|
-
var stopCode;
|
|
521
|
-
|
|
522
|
-
if ("stopId" in placeOrStop) {
|
|
523
|
-
stopCode = placeOrStop.stopCode;
|
|
524
|
-
stopId = placeOrStop.stopId;
|
|
525
|
-
} else if ("id" in placeOrStop) {
|
|
526
|
-
stopCode = placeOrStop.code;
|
|
527
|
-
stopId = placeOrStop.id;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return stopCode || ((_stopId = stopId) === null || _stopId === void 0 ? void 0 : _stopId.split(":")[1]) || stopId;
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
|
|
534
|
-
* @param leg Leg with fare products (must have used getLegsWithFares)
|
|
535
|
-
* @param category Rider category
|
|
536
|
-
* @param container Fare container (cash, electronic)
|
|
537
|
-
* @returns Object containing price as well as the transfer discount amount, if a transfer was used.
|
|
538
|
-
*/
|
|
539
|
-
|
|
540
|
-
export function getLegCost(leg, mediumId, riderCategoryId) {
|
|
541
|
-
if (!leg.fareProducts) return {
|
|
542
|
-
price: undefined
|
|
543
|
-
};
|
|
544
|
-
var relevantFareProducts = leg.fareProducts.filter(function (_ref3) {
|
|
545
|
-
var product = _ref3.product;
|
|
546
|
-
// riderCategory and medium can be specifically defined as null to handle
|
|
547
|
-
// generic GTFS based fares from OTP when there is no fare model
|
|
548
|
-
return (product.riderCategory === null ? null : product.riderCategory.id) === riderCategoryId && (product.medium === null ? null : product.medium.id) === mediumId;
|
|
549
|
-
}); // Custom fare models return "rideCost", generic GTFS fares return "regular"
|
|
550
|
-
|
|
551
|
-
var totalCostProduct = relevantFareProducts.find(function (fp) {
|
|
552
|
-
return fp.product.name === "rideCost" || fp.product.name === "regular";
|
|
553
|
-
});
|
|
554
|
-
var transferFareProduct = relevantFareProducts.find(function (fp) {
|
|
555
|
-
return fp.product.name === "transfer";
|
|
556
|
-
});
|
|
557
|
-
return {
|
|
558
|
-
price: totalCostProduct === null || totalCostProduct === void 0 ? void 0 : totalCostProduct.product.price,
|
|
559
|
-
transferAmount: transferFareProduct === null || transferFareProduct === void 0 ? void 0 : transferFareProduct.product.price,
|
|
560
|
-
productUseId: totalCostProduct === null || totalCostProduct === void 0 ? void 0 : totalCostProduct.id
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Returns the total itinerary cost for a given set of legs.
|
|
565
|
-
* @param legs Itinerary legs with fare products (must have used getLegsWithFares)
|
|
566
|
-
* @param category Rider category (youth, regular, senior)
|
|
567
|
-
* @param container Fare container (cash, electronic)
|
|
568
|
-
* @returns Money object for the total itinerary cost.
|
|
569
|
-
*/
|
|
570
|
-
|
|
571
|
-
export function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
572
|
-
var legCosts = legs // Only legs with fares (no walking legs)
|
|
573
|
-
.filter(function (leg) {
|
|
574
|
-
var _leg$fareProducts;
|
|
575
|
-
|
|
576
|
-
return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) > 0;
|
|
577
|
-
}) // Get the leg cost object of each leg
|
|
578
|
-
.map(function (leg) {
|
|
579
|
-
return getLegCost(leg, mediumId, riderCategoryId);
|
|
580
|
-
}).filter(function (cost) {
|
|
581
|
-
return cost.price !== undefined;
|
|
582
|
-
}) // Filter out duplicate use IDs
|
|
583
|
-
// One fare product can be used on multiple legs,
|
|
584
|
-
// and we don't want to count it more than once.
|
|
585
|
-
.reduce(function (prev, cur) {
|
|
586
|
-
if (!prev.some(function (p) {
|
|
587
|
-
return p.productUseId === cur.productUseId;
|
|
588
|
-
})) {
|
|
589
|
-
prev.push({
|
|
590
|
-
productUseId: cur.productUseId,
|
|
591
|
-
price: cur.price
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
return prev;
|
|
596
|
-
}, []).map(function (productUse) {
|
|
597
|
-
return productUse.price;
|
|
598
|
-
});
|
|
599
|
-
if (legCosts.length === 0) return undefined; // Calculate the total
|
|
600
|
-
|
|
601
|
-
return legCosts.reduce(function (prev, cur) {
|
|
602
|
-
var _prev$currency;
|
|
603
|
-
|
|
604
|
-
return {
|
|
605
|
-
amount: prev.amount + (cur === null || cur === void 0 ? void 0 : cur.amount) || 0,
|
|
606
|
-
currency: (_prev$currency = prev.currency) !== null && _prev$currency !== void 0 ? _prev$currency : cur === null || cur === void 0 ? void 0 : cur.currency
|
|
607
|
-
};
|
|
608
|
-
}, {
|
|
609
|
-
amount: 0,
|
|
610
|
-
currency: null
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
var pickupDropoffTypeToOtp1 = function pickupDropoffTypeToOtp1(otp2Type) {
|
|
615
|
-
switch (otp2Type) {
|
|
616
|
-
case "COORDINATE_WITH_DRIVER":
|
|
617
|
-
return "coordinateWithDriver";
|
|
618
|
-
|
|
619
|
-
case "CALL_AGENCY":
|
|
620
|
-
return "mustPhone";
|
|
621
|
-
|
|
622
|
-
case "SCHEDULED":
|
|
623
|
-
return "scheduled";
|
|
624
|
-
|
|
625
|
-
case "NONE":
|
|
626
|
-
return "none";
|
|
627
|
-
|
|
628
|
-
default:
|
|
629
|
-
return null;
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
export var convertGraphQLResponseToLegacy = function convertGraphQLResponseToLegacy(leg) {
|
|
634
|
-
var _leg$agency, _leg$agency2, _leg$agency3, _leg$agency4, _leg$from$stop, _leg$from$stop2, _leg$route, _leg$route2, _leg$route3, _leg$route4, _leg$route5, _leg$route6, _leg$to$stop, _leg$to$stop2, _leg$trip, _leg$trip2;
|
|
635
|
-
|
|
636
|
-
return _objectSpread(_objectSpread({}, leg), {}, {
|
|
637
|
-
agencyBrandingUrl: (_leg$agency = leg.agency) === null || _leg$agency === void 0 ? void 0 : _leg$agency.url,
|
|
638
|
-
agencyId: (_leg$agency2 = leg.agency) === null || _leg$agency2 === void 0 ? void 0 : _leg$agency2.id,
|
|
639
|
-
agencyName: (_leg$agency3 = leg.agency) === null || _leg$agency3 === void 0 ? void 0 : _leg$agency3.name,
|
|
640
|
-
agencyUrl: (_leg$agency4 = leg.agency) === null || _leg$agency4 === void 0 ? void 0 : _leg$agency4.url,
|
|
641
|
-
alightRule: pickupDropoffTypeToOtp1(leg.dropoffType),
|
|
642
|
-
boardRule: pickupDropoffTypeToOtp1(leg.pickupType),
|
|
643
|
-
dropOffBookingInfo: {
|
|
644
|
-
latestBookingTime: leg.dropOffBookingInfo
|
|
645
|
-
},
|
|
646
|
-
from: _objectSpread(_objectSpread({}, leg.from), {}, {
|
|
647
|
-
stopCode: (_leg$from$stop = leg.from.stop) === null || _leg$from$stop === void 0 ? void 0 : _leg$from$stop.code,
|
|
648
|
-
stopId: (_leg$from$stop2 = leg.from.stop) === null || _leg$from$stop2 === void 0 ? void 0 : _leg$from$stop2.gtfsId
|
|
649
|
-
}),
|
|
650
|
-
route: (_leg$route = leg.route) === null || _leg$route === void 0 ? void 0 : _leg$route.shortName,
|
|
651
|
-
routeColor: (_leg$route2 = leg.route) === null || _leg$route2 === void 0 ? void 0 : _leg$route2.color,
|
|
652
|
-
routeId: (_leg$route3 = leg.route) === null || _leg$route3 === void 0 ? void 0 : _leg$route3.gtfsId,
|
|
653
|
-
routeLongName: (_leg$route4 = leg.route) === null || _leg$route4 === void 0 ? void 0 : _leg$route4.longName,
|
|
654
|
-
routeShortName: (_leg$route5 = leg.route) === null || _leg$route5 === void 0 ? void 0 : _leg$route5.shortName,
|
|
655
|
-
routeTextColor: (_leg$route6 = leg.route) === null || _leg$route6 === void 0 ? void 0 : _leg$route6.textColor,
|
|
656
|
-
to: _objectSpread(_objectSpread({}, leg.to), {}, {
|
|
657
|
-
stopCode: (_leg$to$stop = leg.to.stop) === null || _leg$to$stop === void 0 ? void 0 : _leg$to$stop.code,
|
|
658
|
-
stopId: (_leg$to$stop2 = leg.to.stop) === null || _leg$to$stop2 === void 0 ? void 0 : _leg$to$stop2.gtfsId
|
|
659
|
-
}),
|
|
660
|
-
tripHeadsign: (_leg$trip = leg.trip) === null || _leg$trip === void 0 ? void 0 : _leg$trip.tripHeadsign,
|
|
661
|
-
tripId: (_leg$trip2 = leg.trip) === null || _leg$trip2 === void 0 ? void 0 : _leg$trip2.gtfsId
|
|
662
|
-
});
|
|
663
|
-
};
|
|
664
|
-
/** Extracts the route number for a leg returned from OTP1 or OTP2. */
|
|
665
|
-
|
|
666
|
-
export var getLegRouteShortName = function getLegRouteShortName(leg) {
|
|
667
|
-
var route = leg.route,
|
|
668
|
-
routeShortName = leg.routeShortName; // typeof route === "object" denotes newer OTP2 responses. routeShortName and route as string is OTP1.
|
|
669
|
-
|
|
670
|
-
return _typeof(route) === "object" ? route === null || route === void 0 ? void 0 : route.shortName : routeShortName || route;
|
|
671
|
-
};
|
|
672
|
-
/** Extract the route long name for a leg returned from OTP1 or OTP2. */
|
|
673
|
-
|
|
674
|
-
export var getLegRouteLongName = function getLegRouteLongName(leg) {
|
|
675
|
-
var route = leg.route,
|
|
676
|
-
routeLongName = leg.routeLongName; // typeof route === "object" denotes newer OTP2 responses. routeLongName is OTP1.
|
|
677
|
-
|
|
678
|
-
return _typeof(route) === "object" ? route === null || route === void 0 ? void 0 : route.longName : routeLongName;
|
|
679
|
-
};
|
|
680
|
-
/**
|
|
681
|
-
* Returns the route short name, or the route long name if no short name is provided.
|
|
682
|
-
* This is happens with Seattle area streetcars and ferries.
|
|
683
|
-
*/
|
|
684
|
-
|
|
685
|
-
export var getLegRouteName = function getLegRouteName(leg) {
|
|
686
|
-
return getLegRouteShortName(leg) || getLegRouteLongName(leg);
|
|
687
|
-
};
|
|
688
|
-
//# sourceMappingURL=itinerary.js.map
|