@opentripplanner/core-utils 14.2.4 → 14.3.1
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/esm/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/esm/itinerary.js +20 -25
- package/esm/itinerary.js.map +1 -1
- package/esm/otpSchema.json +17765 -14884
- package/esm/planQuery.graphql +1 -3
- package/esm/query-gen.js +1 -1
- package/esm/query-gen.js.map +1 -1
- package/esm/three-transfer-itinerary.json +2195 -0
- package/lib/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/lib/index.js +13 -42
- package/lib/index.js.map +1 -1
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +75 -134
- package/lib/itinerary.js.map +1 -1
- package/lib/map.js +11 -25
- package/lib/map.js.map +1 -1
- package/lib/otpSchema.json +17765 -14884
- package/lib/planQuery.graphql +1 -3
- package/lib/query-gen.js +12 -21
- package/lib/query-gen.js.map +1 -1
- package/lib/route.d.ts.map +1 -1
- package/lib/route.js +26 -44
- package/lib/route.js.map +1 -1
- package/lib/storage.js +4 -11
- package/lib/storage.js.map +1 -1
- package/lib/suspense.d.ts.map +1 -1
- package/lib/suspense.js +3 -28
- package/lib/suspense.js.map +1 -1
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +20 -33
- package/lib/time.js.map +1 -1
- package/lib/ui.js +2 -7
- package/lib/ui.js.map +1 -1
- package/package.json +2 -2
- package/src/__snapshots__/core-utils.story.tsx.snap +1 -1
- package/src/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/src/__tests__/itinerary.ts +9 -0
- package/src/itinerary.ts +21 -21
- package/src/otpSchema.json +17765 -14884
- package/src/planQuery.graphql +1 -3
- package/tsconfig.tsbuildinfo +1 -1
package/lib/itinerary.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getLegRouteLongName = exports.getLegRouteShortName = exports.convertGraphQLResponseToLegacy = exports.getItineraryCost = exports.getLegCost = exports.zeroDollars = exports.descope = exports.getDisplayedStopId = exports.calculateEmissions = exports.calculateTncFares = exports.calculatePhysicalActivity = exports.getTNCLocation = exports.getCompaniesLabelFromNetworks = exports.getCompanyForNetwork = exports.getTextWidth = exports.getElevationProfile = exports.mapOldElevationComponentToNew = exports.legElevationAtDistance = exports.legLocationAtDistance = exports.getLegBounds = exports.getItineraryBounds = exports.getCompanyFromLeg = exports.toSentenceCase = exports.getMapColor = exports.hasRental = exports.hasHail = exports.hasMicromobility = exports.hasBike = exports.hasCar = exports.hasTransit = exports.isAccessMode = exports.isMicromobility = exports.isCar = exports.isBicycleRent = exports.isBicycle = exports.isWalk = exports.isRideshareLeg = exports.isFlex = exports.legDropoffRequiresAdvanceBooking = exports.isAdvanceBookingRequired = exports.legContainsGeometry = exports.startsWithGeometry = exports.endsWithGeometry = exports.containsGeometry = exports.isCoordinationRequired = exports.isReservationRequired = exports.isTransit = exports.isTransitLeg = exports.getTransitModes = exports.transitModes = void 0;
|
|
7
|
-
exports.getLegRouteName = void 0;
|
|
8
|
-
const polyline_1 = __importDefault(require("@mapbox/polyline"));
|
|
9
|
-
const along_1 = __importDefault(require("@turf/along"));
|
|
1
|
+
import polyline from "@mapbox/polyline";
|
|
2
|
+
import turfAlong from "@turf/along";
|
|
10
3
|
// All OTP transit modes
|
|
11
|
-
|
|
4
|
+
export const transitModes = [
|
|
12
5
|
"TRAM",
|
|
13
6
|
"TROLLEYBUS",
|
|
14
7
|
"BUS",
|
|
@@ -21,171 +14,146 @@ exports.transitModes = [
|
|
|
21
14
|
* @param {config} config OTP-RR configuration object
|
|
22
15
|
* @return {Array} List of all transit modes defined in config; otherwise default mode list
|
|
23
16
|
*/
|
|
24
|
-
function getTransitModes(config) {
|
|
17
|
+
export function getTransitModes(config) {
|
|
25
18
|
if (!config || !config.modes || !config.modes.transitModes)
|
|
26
|
-
return
|
|
19
|
+
return transitModes;
|
|
27
20
|
return config.modes.transitModes.map(tm => typeof tm !== "string" ? tm.mode : tm);
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
function isTransitLeg(leg) {
|
|
22
|
+
export function isTransitLeg(leg) {
|
|
31
23
|
return leg.transitLeg;
|
|
32
24
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return exports.transitModes.includes(mode) || mode === "TRANSIT";
|
|
25
|
+
export function isTransit(mode) {
|
|
26
|
+
return transitModes.includes(mode) || mode === "TRANSIT";
|
|
36
27
|
}
|
|
37
|
-
exports.isTransit = isTransit;
|
|
38
28
|
/**
|
|
39
29
|
* Returns true if the leg pickup rules enabled which require
|
|
40
30
|
* calling ahead for the service to run. "mustPhone" is the only
|
|
41
31
|
* property which encodes this info.
|
|
42
32
|
*/
|
|
43
|
-
function isReservationRequired(leg) {
|
|
33
|
+
export function isReservationRequired(leg) {
|
|
44
34
|
return (leg === null || leg === void 0 ? void 0 : leg.boardRule) === "mustPhone" || (leg === null || leg === void 0 ? void 0 : leg.alightRule) === "mustPhone";
|
|
45
35
|
}
|
|
46
|
-
exports.isReservationRequired = isReservationRequired;
|
|
47
36
|
/**
|
|
48
37
|
* Returns true if a user must ask the driver to let the user off
|
|
49
38
|
* or if the user must flag the driver down for pickup.
|
|
50
39
|
* "coordinateWithDriver" in board/alight rule encodes this info.
|
|
51
40
|
*/
|
|
52
|
-
function isCoordinationRequired(leg) {
|
|
41
|
+
export function isCoordinationRequired(leg) {
|
|
53
42
|
return ((leg === null || leg === void 0 ? void 0 : leg.boardRule) === "coordinateWithDriver" ||
|
|
54
43
|
(leg === null || leg === void 0 ? void 0 : leg.alightRule) === "coordinateWithDriver");
|
|
55
44
|
}
|
|
56
|
-
|
|
57
|
-
function containsGeometry(place) {
|
|
45
|
+
export function containsGeometry(place) {
|
|
58
46
|
var _a, _b;
|
|
59
47
|
return (((_a = place === null || place === void 0 ? void 0 : place.stop) === null || _a === void 0 ? void 0 : _a.geometries) !== null && ((_b = place === null || place === void 0 ? void 0 : place.stop) === null || _b === void 0 ? void 0 : _b.geometries) !== undefined);
|
|
60
48
|
}
|
|
61
|
-
|
|
62
|
-
function endsWithGeometry(leg) {
|
|
49
|
+
export function endsWithGeometry(leg) {
|
|
63
50
|
return containsGeometry(leg === null || leg === void 0 ? void 0 : leg.to);
|
|
64
51
|
}
|
|
65
|
-
|
|
66
|
-
function startsWithGeometry(leg) {
|
|
52
|
+
export function startsWithGeometry(leg) {
|
|
67
53
|
return containsGeometry(leg === null || leg === void 0 ? void 0 : leg.from);
|
|
68
54
|
}
|
|
69
|
-
|
|
70
|
-
function legContainsGeometry(leg) {
|
|
55
|
+
export function legContainsGeometry(leg) {
|
|
71
56
|
return endsWithGeometry(leg) || startsWithGeometry(leg);
|
|
72
57
|
}
|
|
73
|
-
|
|
74
|
-
function isAdvanceBookingRequired(info) {
|
|
58
|
+
export function isAdvanceBookingRequired(info) {
|
|
75
59
|
var _a;
|
|
76
60
|
return ((_a = info === null || info === void 0 ? void 0 : info.latestBookingTime) === null || _a === void 0 ? void 0 : _a.daysPrior) > 0;
|
|
77
61
|
}
|
|
78
|
-
|
|
79
|
-
function legDropoffRequiresAdvanceBooking(leg) {
|
|
62
|
+
export function legDropoffRequiresAdvanceBooking(leg) {
|
|
80
63
|
return isAdvanceBookingRequired(leg === null || leg === void 0 ? void 0 : leg.dropOffBookingInfo);
|
|
81
64
|
}
|
|
82
|
-
exports.legDropoffRequiresAdvanceBooking = legDropoffRequiresAdvanceBooking;
|
|
83
65
|
/**
|
|
84
66
|
* The two rules checked by the above two functions are the only values
|
|
85
67
|
* returned by OTP when a leg is a flex leg.
|
|
86
68
|
*/
|
|
87
|
-
function isFlex(leg) {
|
|
69
|
+
export function isFlex(leg) {
|
|
88
70
|
var _a;
|
|
89
71
|
return (((_a = leg === null || leg === void 0 ? void 0 : leg.stopCalls) === null || _a === void 0 ? void 0 : _a.some(call => { var _a;
|
|
90
72
|
// Flex calls are "Location" or "LocationGroup"
|
|
91
73
|
// eslint-disable-next-line no-underscore-dangle
|
|
92
74
|
return (_a = call === null || call === void 0 ? void 0 : call.stopLocation) === null || _a === void 0 ? void 0 : _a.__typename.startsWith("Location"); })) || false);
|
|
93
75
|
}
|
|
94
|
-
|
|
95
|
-
function isRideshareLeg(leg) {
|
|
76
|
+
export function isRideshareLeg(leg) {
|
|
96
77
|
var _a, _b;
|
|
97
78
|
return !!((_b = (_a = leg.rideHailingEstimate) === null || _a === void 0 ? void 0 : _a.provider) === null || _b === void 0 ? void 0 : _b.id);
|
|
98
79
|
}
|
|
99
|
-
|
|
100
|
-
function isWalk(mode) {
|
|
80
|
+
export function isWalk(mode) {
|
|
101
81
|
if (!mode)
|
|
102
82
|
return false;
|
|
103
83
|
return mode === "WALK";
|
|
104
84
|
}
|
|
105
|
-
|
|
106
|
-
function isBicycle(mode) {
|
|
85
|
+
export function isBicycle(mode) {
|
|
107
86
|
if (!mode)
|
|
108
87
|
return false;
|
|
109
88
|
return mode === "BICYCLE";
|
|
110
89
|
}
|
|
111
|
-
|
|
112
|
-
function isBicycleRent(mode) {
|
|
90
|
+
export function isBicycleRent(mode) {
|
|
113
91
|
if (!mode)
|
|
114
92
|
return false;
|
|
115
93
|
return mode === "BICYCLE_RENT";
|
|
116
94
|
}
|
|
117
|
-
|
|
118
|
-
function isCar(mode) {
|
|
95
|
+
export function isCar(mode) {
|
|
119
96
|
if (!mode)
|
|
120
97
|
return false;
|
|
121
98
|
return mode.startsWith("CAR");
|
|
122
99
|
}
|
|
123
|
-
|
|
124
|
-
function isMicromobility(mode) {
|
|
100
|
+
export function isMicromobility(mode) {
|
|
125
101
|
if (!mode)
|
|
126
102
|
return false;
|
|
127
103
|
return mode.startsWith("MICROMOBILITY") || mode.startsWith("SCOOTER");
|
|
128
104
|
}
|
|
129
|
-
|
|
130
|
-
function isAccessMode(mode) {
|
|
105
|
+
export function isAccessMode(mode) {
|
|
131
106
|
return (isWalk(mode) ||
|
|
132
107
|
isBicycle(mode) ||
|
|
133
108
|
isBicycleRent(mode) ||
|
|
134
109
|
isCar(mode) ||
|
|
135
110
|
isMicromobility(mode));
|
|
136
111
|
}
|
|
137
|
-
exports.isAccessMode = isAccessMode;
|
|
138
112
|
/**
|
|
139
113
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
140
114
|
* @return {boolean} whether any of the modes are transit modes
|
|
141
115
|
*/
|
|
142
|
-
function hasTransit(modesStr) {
|
|
116
|
+
export function hasTransit(modesStr) {
|
|
143
117
|
return modesStr.split(",").some(mode => isTransit(mode));
|
|
144
118
|
}
|
|
145
|
-
exports.hasTransit = hasTransit;
|
|
146
119
|
/**
|
|
147
120
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
148
121
|
* @return {boolean} whether any of the modes are car-based modes
|
|
149
122
|
*/
|
|
150
|
-
function hasCar(modesStr) {
|
|
123
|
+
export function hasCar(modesStr) {
|
|
151
124
|
return modesStr.split(",").some(mode => isCar(mode));
|
|
152
125
|
}
|
|
153
|
-
exports.hasCar = hasCar;
|
|
154
126
|
/**
|
|
155
127
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
156
128
|
* @return {boolean} whether any of the modes are bicycle-based modes
|
|
157
129
|
*/
|
|
158
|
-
function hasBike(modesStr) {
|
|
130
|
+
export function hasBike(modesStr) {
|
|
159
131
|
return modesStr
|
|
160
132
|
.split(",")
|
|
161
133
|
.some(mode => isBicycle(mode) || isBicycleRent(mode));
|
|
162
134
|
}
|
|
163
|
-
exports.hasBike = hasBike;
|
|
164
135
|
/**
|
|
165
136
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
166
137
|
* @return {boolean} whether any of the modes are micromobility-based modes
|
|
167
138
|
*/
|
|
168
|
-
function hasMicromobility(modesStr) {
|
|
139
|
+
export function hasMicromobility(modesStr) {
|
|
169
140
|
return modesStr.split(",").some(mode => isMicromobility(mode));
|
|
170
141
|
}
|
|
171
|
-
exports.hasMicromobility = hasMicromobility;
|
|
172
142
|
/**
|
|
173
143
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
174
144
|
* @return {boolean} whether any of the modes is a hailing mode
|
|
175
145
|
*/
|
|
176
|
-
function hasHail(modesStr) {
|
|
146
|
+
export function hasHail(modesStr) {
|
|
177
147
|
return modesStr.split(",").some(mode => mode.indexOf("_HAIL") > -1);
|
|
178
148
|
}
|
|
179
|
-
exports.hasHail = hasHail;
|
|
180
149
|
/**
|
|
181
150
|
* @param {string} modesStr a comma-separated list of OTP modes
|
|
182
151
|
* @return {boolean} whether any of the modes is a rental mode
|
|
183
152
|
*/
|
|
184
|
-
function hasRental(modesStr) {
|
|
153
|
+
export function hasRental(modesStr) {
|
|
185
154
|
return modesStr.split(",").some(mode => mode.indexOf("_RENT") > -1);
|
|
186
155
|
}
|
|
187
|
-
|
|
188
|
-
function getMapColor(mode) {
|
|
156
|
+
export function getMapColor(mode) {
|
|
189
157
|
mode = mode || this.get("mode");
|
|
190
158
|
if (mode === "WALK")
|
|
191
159
|
return "#444";
|
|
@@ -209,19 +177,17 @@ function getMapColor(mode) {
|
|
|
209
177
|
return "#f5a729";
|
|
210
178
|
return "#aaa";
|
|
211
179
|
}
|
|
212
|
-
|
|
213
|
-
function toSentenceCase(str) {
|
|
180
|
+
export function toSentenceCase(str) {
|
|
214
181
|
if (str == null) {
|
|
215
182
|
return "";
|
|
216
183
|
}
|
|
217
184
|
str = String(str);
|
|
218
185
|
return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
|
|
219
186
|
}
|
|
220
|
-
exports.toSentenceCase = toSentenceCase;
|
|
221
187
|
/**
|
|
222
188
|
* Derive the company string based on mode and network associated with leg.
|
|
223
189
|
*/
|
|
224
|
-
function getCompanyFromLeg(leg) {
|
|
190
|
+
export function getCompanyFromLeg(leg) {
|
|
225
191
|
var _a;
|
|
226
192
|
if (!leg)
|
|
227
193
|
return null;
|
|
@@ -248,23 +214,21 @@ function getCompanyFromLeg(leg) {
|
|
|
248
214
|
}
|
|
249
215
|
return null;
|
|
250
216
|
}
|
|
251
|
-
|
|
252
|
-
function getItineraryBounds(itinerary) {
|
|
217
|
+
export function getItineraryBounds(itinerary) {
|
|
253
218
|
let coords = [];
|
|
254
219
|
itinerary.legs.forEach(leg => {
|
|
255
|
-
const legCoords =
|
|
220
|
+
const legCoords = polyline
|
|
256
221
|
.toGeoJSON(leg.legGeometry.points)
|
|
257
222
|
.coordinates.map((c) => [c[1], c[0]]);
|
|
258
223
|
coords = [...coords, ...legCoords];
|
|
259
224
|
});
|
|
260
225
|
return coords;
|
|
261
226
|
}
|
|
262
|
-
exports.getItineraryBounds = getItineraryBounds;
|
|
263
227
|
/**
|
|
264
228
|
* Return a coords object that encloses the given leg's geometry.
|
|
265
229
|
*/
|
|
266
|
-
function getLegBounds(leg) {
|
|
267
|
-
const coords =
|
|
230
|
+
export function getLegBounds(leg) {
|
|
231
|
+
const coords = polyline
|
|
268
232
|
.toGeoJSON(leg.legGeometry.points)
|
|
269
233
|
.coordinates.map(c => [c[1], c[0]]);
|
|
270
234
|
// in certain cases, there might be zero-length coordinates in the leg
|
|
@@ -275,14 +239,13 @@ function getLegBounds(leg) {
|
|
|
275
239
|
}
|
|
276
240
|
return coords;
|
|
277
241
|
}
|
|
278
|
-
exports.getLegBounds = getLegBounds;
|
|
279
242
|
/* Returns an interpolated lat-lon at a specified distance along a leg */
|
|
280
|
-
function legLocationAtDistance(leg, distance) {
|
|
243
|
+
export function legLocationAtDistance(leg, distance) {
|
|
281
244
|
if (!leg.legGeometry)
|
|
282
245
|
return null;
|
|
283
246
|
try {
|
|
284
|
-
const line =
|
|
285
|
-
const pt = (
|
|
247
|
+
const line = polyline.toGeoJSON(leg.legGeometry.points);
|
|
248
|
+
const pt = turfAlong(line, distance, { units: "meters" });
|
|
286
249
|
if (pt && pt.geometry && pt.geometry.coordinates) {
|
|
287
250
|
return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];
|
|
288
251
|
}
|
|
@@ -292,9 +255,8 @@ function legLocationAtDistance(leg, distance) {
|
|
|
292
255
|
}
|
|
293
256
|
return null;
|
|
294
257
|
}
|
|
295
|
-
exports.legLocationAtDistance = legLocationAtDistance;
|
|
296
258
|
/* Returns an interpolated elevation at a specified distance along a leg */
|
|
297
|
-
function legElevationAtDistance(points, distance) {
|
|
259
|
+
export function legElevationAtDistance(points, distance) {
|
|
298
260
|
// Iterate through the combined elevation profile
|
|
299
261
|
let traversed = 0;
|
|
300
262
|
// If first point distance is not zero, insert starting point at zero with
|
|
@@ -321,17 +283,15 @@ function legElevationAtDistance(points, distance) {
|
|
|
321
283
|
console.warn("Elevation value does not exist for distance.", distance, traversed);
|
|
322
284
|
return null;
|
|
323
285
|
}
|
|
324
|
-
|
|
325
|
-
function mapOldElevationComponentToNew(oldElev) {
|
|
286
|
+
export function mapOldElevationComponentToNew(oldElev) {
|
|
326
287
|
return {
|
|
327
288
|
distance: oldElev.first,
|
|
328
289
|
elevation: oldElev.second
|
|
329
290
|
};
|
|
330
291
|
}
|
|
331
|
-
exports.mapOldElevationComponentToNew = mapOldElevationComponentToNew;
|
|
332
292
|
// Iterate through the steps, building the array of elevation points and
|
|
333
293
|
// keeping track of the minimum and maximum elevations reached
|
|
334
|
-
function getElevationProfile(steps, unitConversion = 1) {
|
|
294
|
+
export function getElevationProfile(steps, unitConversion = 1) {
|
|
335
295
|
let minElev = 100000;
|
|
336
296
|
let maxElev = -100000;
|
|
337
297
|
let traversed = 0;
|
|
@@ -379,7 +339,6 @@ function getElevationProfile(steps, unitConversion = 1) {
|
|
|
379
339
|
});
|
|
380
340
|
return { maxElev, minElev, points, traversed, gain, loss };
|
|
381
341
|
}
|
|
382
|
-
exports.getElevationProfile = getElevationProfile;
|
|
383
342
|
/**
|
|
384
343
|
* Uses canvas.measureText to compute and return the width of the given text of given font in pixels.
|
|
385
344
|
*
|
|
@@ -388,7 +347,7 @@ exports.getElevationProfile = getElevationProfile;
|
|
|
388
347
|
*
|
|
389
348
|
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
|
|
390
349
|
*/
|
|
391
|
-
function getTextWidth(text, font = "22px Arial") {
|
|
350
|
+
export function getTextWidth(text, font = "22px Arial") {
|
|
392
351
|
// reuse canvas object for better performance
|
|
393
352
|
const canvas = getTextWidth.canvas ||
|
|
394
353
|
(getTextWidth.canvas = document.createElement("canvas"));
|
|
@@ -397,19 +356,17 @@ function getTextWidth(text, font = "22px Arial") {
|
|
|
397
356
|
const metrics = context.measureText(text);
|
|
398
357
|
return metrics.width;
|
|
399
358
|
}
|
|
400
|
-
exports.getTextWidth = getTextWidth;
|
|
401
359
|
/**
|
|
402
360
|
* Get the configured company object for the given network string if the company
|
|
403
361
|
* has been defined in the provided companies array config.
|
|
404
362
|
*/
|
|
405
|
-
function getCompanyForNetwork(networkString, companies = []) {
|
|
363
|
+
export function getCompanyForNetwork(networkString, companies = []) {
|
|
406
364
|
const company = companies.find(co => co.id === networkString);
|
|
407
365
|
if (!company) {
|
|
408
366
|
console.warn(`No company found in config.yml that matches rented vehicle network: ${networkString}`, companies);
|
|
409
367
|
}
|
|
410
368
|
return company;
|
|
411
369
|
}
|
|
412
|
-
exports.getCompanyForNetwork = getCompanyForNetwork;
|
|
413
370
|
/**
|
|
414
371
|
* Get a string label to display from a list of vehicle rental networks. Returns
|
|
415
372
|
* empty string if no networks provided.
|
|
@@ -418,7 +375,7 @@ exports.getCompanyForNetwork = getCompanyForNetwork;
|
|
|
418
375
|
* @param {Array<object>} [companies=[]] An optional list of the companies config.
|
|
419
376
|
* @return {string} A label for use in presentation on a website.
|
|
420
377
|
*/
|
|
421
|
-
function getCompaniesLabelFromNetworks(networks, companies = []) {
|
|
378
|
+
export function getCompaniesLabelFromNetworks(networks, companies = []) {
|
|
422
379
|
if (!networks)
|
|
423
380
|
return "";
|
|
424
381
|
return (Array.isArray(networks) ? networks : [networks])
|
|
@@ -427,13 +384,11 @@ function getCompaniesLabelFromNetworks(networks, companies = []) {
|
|
|
427
384
|
.map(co => co.label)
|
|
428
385
|
.join("/");
|
|
429
386
|
}
|
|
430
|
-
|
|
431
|
-
function getTNCLocation(leg, type) {
|
|
387
|
+
export function getTNCLocation(leg, type) {
|
|
432
388
|
const location = leg[type];
|
|
433
389
|
return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;
|
|
434
390
|
}
|
|
435
|
-
|
|
436
|
-
function calculatePhysicalActivity(itinerary) {
|
|
391
|
+
export function calculatePhysicalActivity(itinerary) {
|
|
437
392
|
let walkDuration = 0;
|
|
438
393
|
let bikeDuration = 0;
|
|
439
394
|
itinerary.legs.forEach(leg => {
|
|
@@ -449,13 +404,12 @@ function calculatePhysicalActivity(itinerary) {
|
|
|
449
404
|
walkDuration
|
|
450
405
|
};
|
|
451
406
|
}
|
|
452
|
-
exports.calculatePhysicalActivity = calculatePhysicalActivity;
|
|
453
407
|
/**
|
|
454
408
|
* For an itinerary, calculates the TNC fares and returns an object with
|
|
455
409
|
* these values and currency info.
|
|
456
410
|
* It is assumed that the same currency is used for all TNC legs.
|
|
457
411
|
*/
|
|
458
|
-
function calculateTncFares(itinerary) {
|
|
412
|
+
export function calculateTncFares(itinerary) {
|
|
459
413
|
return itinerary.legs
|
|
460
414
|
.filter(leg => leg.mode === "CAR" && leg.rideHailingEstimate)
|
|
461
415
|
.reduce(({ maxTNCFare, minTNCFare }, { rideHailingEstimate }) => {
|
|
@@ -472,7 +426,6 @@ function calculateTncFares(itinerary) {
|
|
|
472
426
|
minTNCFare: 0
|
|
473
427
|
});
|
|
474
428
|
}
|
|
475
|
-
exports.calculateTncFares = calculateTncFares;
|
|
476
429
|
/**
|
|
477
430
|
* Sources:
|
|
478
431
|
* - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf
|
|
@@ -504,7 +457,7 @@ const CARBON_INTENSITY_DEFAULTS = {
|
|
|
504
457
|
* @param {units} units units to be used in return value
|
|
505
458
|
* @return Amount of carbon in chosen unit
|
|
506
459
|
*/
|
|
507
|
-
function calculateEmissions(
|
|
460
|
+
export function calculateEmissions(
|
|
508
461
|
// This type makes all the properties from Itinerary optional except legs.
|
|
509
462
|
itinerary, carbonIntensity = {}, units) {
|
|
510
463
|
var _a;
|
|
@@ -530,14 +483,13 @@ itinerary, carbonIntensity = {}, units) {
|
|
|
530
483
|
return totalCarbon;
|
|
531
484
|
}
|
|
532
485
|
}
|
|
533
|
-
exports.calculateEmissions = calculateEmissions;
|
|
534
486
|
/**
|
|
535
487
|
* Returns the user-facing stop id to display for a stop or place, using the following priority:
|
|
536
488
|
* 1. stop code,
|
|
537
489
|
* 2. stop id without the agency id portion, if stop id contains an agency portion,
|
|
538
490
|
* 3. stop id, whether null or not (this is the fallback case).
|
|
539
491
|
*/
|
|
540
|
-
function getDisplayedStopId(placeOrStop) {
|
|
492
|
+
export function getDisplayedStopId(placeOrStop) {
|
|
541
493
|
let stopId;
|
|
542
494
|
let stopCode;
|
|
543
495
|
if ("stopId" in placeOrStop) {
|
|
@@ -548,19 +500,16 @@ function getDisplayedStopId(placeOrStop) {
|
|
|
548
500
|
}
|
|
549
501
|
return stopCode || (stopId === null || stopId === void 0 ? void 0 : stopId.split(":")[1]) || stopId;
|
|
550
502
|
}
|
|
551
|
-
exports.getDisplayedStopId = getDisplayedStopId;
|
|
552
503
|
/**
|
|
553
504
|
* Removes the first part of the OTP standard scope (":"), if it is present
|
|
554
505
|
* @param item String that is potentially scoped with `:` character
|
|
555
506
|
* @returns descoped string
|
|
556
507
|
*/
|
|
557
|
-
const descope = (item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.split(":")) === null || _a === void 0 ? void 0 : _a[1]; };
|
|
558
|
-
|
|
559
|
-
const zeroDollars = (currency) => ({
|
|
508
|
+
export const descope = (item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.split(":")) === null || _a === void 0 ? void 0 : _a[1]; };
|
|
509
|
+
export const zeroDollars = (currency) => ({
|
|
560
510
|
amount: 0,
|
|
561
511
|
currency
|
|
562
512
|
});
|
|
563
|
-
exports.zeroDollars = zeroDollars;
|
|
564
513
|
/**
|
|
565
514
|
* Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
|
|
566
515
|
* @param leg Leg with Fares v2 information
|
|
@@ -572,7 +521,7 @@ exports.zeroDollars = zeroDollars;
|
|
|
572
521
|
* all the information needed, but the other fields are kept to
|
|
573
522
|
* make the transition to Fares V2 less jarring.
|
|
574
523
|
*/
|
|
575
|
-
function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
524
|
+
export function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
576
525
|
if (!leg.fareProducts)
|
|
577
526
|
return { price: undefined };
|
|
578
527
|
const relevantFareProducts = leg.fareProducts
|
|
@@ -581,10 +530,10 @@ function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
|
581
530
|
// generic GTFS based fares from OTP when there is no fare model
|
|
582
531
|
var _a, _b, _c, _d;
|
|
583
532
|
// Remove (optional) agency scoping
|
|
584
|
-
const productRiderCategoryId =
|
|
533
|
+
const productRiderCategoryId = descope((_a = product === null || product === void 0 ? void 0 : product.riderCategory) === null || _a === void 0 ? void 0 : _a.id) ||
|
|
585
534
|
((_b = product === null || product === void 0 ? void 0 : product.riderCategory) === null || _b === void 0 ? void 0 : _b.id) ||
|
|
586
535
|
null;
|
|
587
|
-
const productMediaId =
|
|
536
|
+
const productMediaId = descope((_c = product === null || product === void 0 ? void 0 : product.medium) === null || _c === void 0 ? void 0 : _c.id) || ((_d = product === null || product === void 0 ? void 0 : product.medium) === null || _d === void 0 ? void 0 : _d.id) || null;
|
|
588
537
|
return (productRiderCategoryId === riderCategoryId &&
|
|
589
538
|
productMediaId === mediumId &&
|
|
590
539
|
(
|
|
@@ -599,7 +548,7 @@ function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
|
599
548
|
id: fare.id,
|
|
600
549
|
product: {
|
|
601
550
|
...fare.product,
|
|
602
|
-
legPrice: alreadySeen ?
|
|
551
|
+
legPrice: alreadySeen ? zeroDollars(currency) : fare.product.price
|
|
603
552
|
}
|
|
604
553
|
};
|
|
605
554
|
})
|
|
@@ -618,7 +567,6 @@ function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
|
618
567
|
productUseId: cheapestRelevantFareProduct === null || cheapestRelevantFareProduct === void 0 ? void 0 : cheapestRelevantFareProduct.id
|
|
619
568
|
};
|
|
620
569
|
}
|
|
621
|
-
exports.getLegCost = getLegCost;
|
|
622
570
|
/**
|
|
623
571
|
* Returns the total itinerary cost for a given set of legs.
|
|
624
572
|
* @param legs Itinerary legs with fare products (must have used getLegsWithFares)
|
|
@@ -627,7 +575,7 @@ exports.getLegCost = getLegCost;
|
|
|
627
575
|
* @param seenFareIds List of fare product IDs that have already been seen on prev legs.
|
|
628
576
|
* @returns Money object for the total itinerary cost.
|
|
629
577
|
*/
|
|
630
|
-
function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
578
|
+
export function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
631
579
|
var _a;
|
|
632
580
|
// TODO: Better input type handling
|
|
633
581
|
if (Array.isArray(mediumId) || Array.isArray(riderCategoryId)) {
|
|
@@ -649,26 +597,24 @@ function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
|
649
597
|
return undefined;
|
|
650
598
|
return total;
|
|
651
599
|
}
|
|
652
|
-
const
|
|
600
|
+
const legCosts = legs
|
|
653
601
|
// Only legs with fares (no walking legs)
|
|
654
602
|
.filter(leg => { var _a; return ((_a = leg.fareProducts) === null || _a === void 0 ? void 0 : _a.length) > 0; })
|
|
655
603
|
// Get the leg cost object of each leg
|
|
656
|
-
.
|
|
657
|
-
|
|
658
|
-
arr.splice(0, index).flatMap(l => l === null || l === void 0 ? void 0 : l.fareProducts.map(fp => fp === null || fp === void 0 ? void 0 : fp.id))))
|
|
659
|
-
.filter(cost => { var _a; return ((_a = cost.appliedFareProduct) === null || _a === void 0 ? void 0 : _a.legPrice) !== undefined; })
|
|
660
|
-
// Filter out duplicate use IDs
|
|
604
|
+
.reduce((acc, leg) => {
|
|
605
|
+
// getLegCost handles filtering out duplicate use IDs
|
|
661
606
|
// One fare product can be used on multiple legs,
|
|
662
607
|
// and we don't want to count it more than once.
|
|
663
608
|
// Use an object keyed by productUseId to deduplicate, then extract prices
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
609
|
+
const { appliedFareProduct, productUseId } = getLegCost(leg, mediumId, riderCategoryId, acc.seenIds);
|
|
610
|
+
if (!appliedFareProduct)
|
|
611
|
+
return acc;
|
|
612
|
+
return {
|
|
613
|
+
legCosts: [...acc.legCosts, appliedFareProduct],
|
|
614
|
+
seenIds: [...acc.seenIds, productUseId]
|
|
615
|
+
};
|
|
616
|
+
}, { seenIds: [], legCosts: [] })
|
|
617
|
+
.legCosts.map(lc => lc.legPrice);
|
|
672
618
|
if (legCosts.length === 0)
|
|
673
619
|
return undefined;
|
|
674
620
|
// Calculate the total
|
|
@@ -680,7 +626,6 @@ function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
|
680
626
|
});
|
|
681
627
|
}, { amount: 0, currency: null });
|
|
682
628
|
}
|
|
683
|
-
exports.getItineraryCost = getItineraryCost;
|
|
684
629
|
const pickupDropoffTypeToOtp1 = otp2Type => {
|
|
685
630
|
switch (otp2Type) {
|
|
686
631
|
case "COORDINATE_WITH_DRIVER":
|
|
@@ -695,7 +640,7 @@ const pickupDropoffTypeToOtp1 = otp2Type => {
|
|
|
695
640
|
return null;
|
|
696
641
|
}
|
|
697
642
|
};
|
|
698
|
-
const convertGraphQLResponseToLegacy = (leg) => {
|
|
643
|
+
export const convertGraphQLResponseToLegacy = (leg) => {
|
|
699
644
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
700
645
|
return ({
|
|
701
646
|
...leg,
|
|
@@ -732,29 +677,25 @@ const convertGraphQLResponseToLegacy = (leg) => {
|
|
|
732
677
|
tripId: (_r = leg.trip) === null || _r === void 0 ? void 0 : _r.gtfsId
|
|
733
678
|
});
|
|
734
679
|
};
|
|
735
|
-
exports.convertGraphQLResponseToLegacy = convertGraphQLResponseToLegacy;
|
|
736
680
|
/** Extracts the route number for a leg returned from OTP1 or OTP2. */
|
|
737
|
-
const getLegRouteShortName = (leg) => {
|
|
681
|
+
export const getLegRouteShortName = (leg) => {
|
|
738
682
|
const { route, routeShortName } = leg;
|
|
739
683
|
// typeof route === "object" denotes newer OTP2 responses. routeShortName and route as string is OTP1.
|
|
740
684
|
return typeof route === "object"
|
|
741
685
|
? route === null || route === void 0 ? void 0 : route.shortName
|
|
742
686
|
: routeShortName || route;
|
|
743
687
|
};
|
|
744
|
-
exports.getLegRouteShortName = getLegRouteShortName;
|
|
745
688
|
/** Extract the route long name for a leg returned from OTP1 or OTP2. */
|
|
746
|
-
const getLegRouteLongName = (leg) => {
|
|
689
|
+
export const getLegRouteLongName = (leg) => {
|
|
747
690
|
const { route, routeLongName } = leg;
|
|
748
691
|
// typeof route === "object" denotes newer OTP2 responses. routeLongName is OTP1.
|
|
749
692
|
return typeof route === "object" ? route === null || route === void 0 ? void 0 : route.longName : routeLongName;
|
|
750
693
|
};
|
|
751
|
-
exports.getLegRouteLongName = getLegRouteLongName;
|
|
752
694
|
/**
|
|
753
695
|
* Returns the route short name, or the route long name if no short name is provided.
|
|
754
696
|
* This is happens with Seattle area streetcars and ferries.
|
|
755
697
|
*/
|
|
756
|
-
const getLegRouteName = (leg) => {
|
|
757
|
-
return
|
|
698
|
+
export const getLegRouteName = (leg) => {
|
|
699
|
+
return getLegRouteShortName(leg) || getLegRouteLongName(leg);
|
|
758
700
|
};
|
|
759
|
-
exports.getLegRouteName = getLegRouteName;
|
|
760
701
|
//# sourceMappingURL=itinerary.js.map
|