@opentripplanner/core-utils 9.0.0-alpha.3 → 9.0.0-alpha.31
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/itinerary.js +131 -29
- package/esm/itinerary.js.map +1 -1
- package/esm/query-gen.js +134 -61
- package/esm/query-gen.js.map +1 -1
- package/lib/core-utils.story.d.ts +22 -0
- package/lib/core-utils.story.d.ts.map +1 -0
- package/lib/core-utils.story.js +69 -0
- package/lib/core-utils.story.js.map +1 -0
- package/lib/itinerary.d.ts +29 -16
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +134 -33
- package/lib/itinerary.js.map +1 -1
- package/lib/query-gen.d.ts +49 -5
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +111 -45
- package/lib/query-gen.js.map +1 -1
- package/package.json +5 -6
- package/src/__tests__/__mocks__/fare-products-itinerary.json +1283 -0
- package/src/__tests__/__mocks__/tnc-itinerary.json +34 -18
- package/src/__tests__/itinerary.js +55 -28
- package/src/__tests__/{query-params.js → query-params.ts} +95 -10
- package/src/core-utils.story.tsx +1 -1
- package/src/itinerary.ts +144 -40
- package/src/otpSchema.json +12940 -0
- package/src/planQuery.graphql +222 -106
- package/src/query-gen.ts +169 -71
- package/tsconfig.json +3 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/esm/state.js +0 -2
- package/esm/state.js.map +0 -1
- package/lib/state.d.ts +0 -1
- package/lib/state.d.ts.map +0 -1
- package/lib/state.js +0 -2
- package/lib/state.js.map +0 -1
- package/src/state.ts +0 -0
- /package/src/__tests__/__snapshots__/{query-params.js.snap → query-params.ts.snap} +0 -0
package/esm/itinerary.js
CHANGED
|
@@ -56,6 +56,12 @@ export function isAdvanceBookingRequired(info) {
|
|
|
56
56
|
}
|
|
57
57
|
export function legDropoffRequiresAdvanceBooking(leg) {
|
|
58
58
|
return isAdvanceBookingRequired(leg.dropOffBookingInfo);
|
|
59
|
+
} // alpha-only comment
|
|
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);
|
|
59
65
|
}
|
|
60
66
|
export function isWalk(mode) {
|
|
61
67
|
if (!mode) return false;
|
|
@@ -172,20 +178,24 @@ export function getCompanyFromLeg(leg) {
|
|
|
172
178
|
rentedBike = leg.rentedBike,
|
|
173
179
|
rentedCar = leg.rentedCar,
|
|
174
180
|
rentedVehicle = leg.rentedVehicle,
|
|
175
|
-
|
|
181
|
+
rideHailingEstimate = leg.rideHailingEstimate;
|
|
176
182
|
|
|
177
183
|
if (mode === "CAR" && rentedCar) {
|
|
178
184
|
return from.networks[0];
|
|
179
185
|
}
|
|
180
186
|
|
|
181
|
-
if (mode === "CAR" &&
|
|
182
|
-
return
|
|
187
|
+
if (mode === "CAR" && rideHailingEstimate) {
|
|
188
|
+
return rideHailingEstimate.provider.id;
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
if (mode === "BICYCLE" && rentedBike && from.networks) {
|
|
186
192
|
return from.networks[0];
|
|
187
193
|
}
|
|
188
194
|
|
|
195
|
+
if (from.rentalVehicle) {
|
|
196
|
+
return from.rentalVehicle.network;
|
|
197
|
+
}
|
|
198
|
+
|
|
189
199
|
if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle && from.networks) {
|
|
190
200
|
return from.networks[0];
|
|
191
201
|
}
|
|
@@ -368,7 +378,9 @@ export function getCompanyForNetwork(networkString) {
|
|
|
368
378
|
|
|
369
379
|
export function getCompaniesLabelFromNetworks(networks) {
|
|
370
380
|
var companies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
371
|
-
|
|
381
|
+
var networksArray = networks;
|
|
382
|
+
if (typeof networks === "string") networksArray = [networks];
|
|
383
|
+
return networksArray.map(function (network) {
|
|
372
384
|
return getCompanyForNetwork(network, companies);
|
|
373
385
|
}).filter(function (co) {
|
|
374
386
|
return !!co;
|
|
@@ -402,19 +414,18 @@ export function calculatePhysicalActivity(itinerary) {
|
|
|
402
414
|
|
|
403
415
|
export function calculateTncFares(itinerary) {
|
|
404
416
|
return itinerary.legs.filter(function (leg) {
|
|
405
|
-
return leg.mode === "CAR" && leg.
|
|
417
|
+
return leg.mode === "CAR" && leg.rideHailingEstimate;
|
|
406
418
|
}).reduce(function (_ref, _ref2) {
|
|
407
419
|
var maxTNCFare = _ref.maxTNCFare,
|
|
408
420
|
minTNCFare = _ref.minTNCFare;
|
|
409
|
-
var
|
|
410
|
-
var
|
|
411
|
-
|
|
412
|
-
minCost = tncData.minCost;
|
|
421
|
+
var rideHailingEstimate = _ref2.rideHailingEstimate;
|
|
422
|
+
var minPrice = rideHailingEstimate.minPrice,
|
|
423
|
+
maxPrice = rideHailingEstimate.maxPrice;
|
|
413
424
|
return {
|
|
414
425
|
// Assumes a single currency for entire itinerary.
|
|
415
|
-
currencyCode: currency,
|
|
416
|
-
maxTNCFare: maxTNCFare +
|
|
417
|
-
minTNCFare: minTNCFare +
|
|
426
|
+
currencyCode: minPrice.currency.code,
|
|
427
|
+
maxTNCFare: maxTNCFare + maxPrice.amount,
|
|
428
|
+
minTNCFare: minTNCFare + minPrice.amount
|
|
418
429
|
};
|
|
419
430
|
}, {
|
|
420
431
|
currencyCode: null,
|
|
@@ -422,20 +433,6 @@ export function calculateTncFares(itinerary) {
|
|
|
422
433
|
minTNCFare: 0
|
|
423
434
|
});
|
|
424
435
|
}
|
|
425
|
-
/**
|
|
426
|
-
* For a given fare component (either total fare or component parts), returns
|
|
427
|
-
* an object with the fare value (in cents).
|
|
428
|
-
*/
|
|
429
|
-
|
|
430
|
-
export function getTransitFare(fareComponent) {
|
|
431
|
-
return fareComponent ? {
|
|
432
|
-
currencyCode: fareComponent.currency.currencyCode,
|
|
433
|
-
transitFare: fareComponent.cents
|
|
434
|
-
} : {
|
|
435
|
-
currencyCode: "USD",
|
|
436
|
-
transitFare: 0
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
436
|
/**
|
|
440
437
|
* Sources:
|
|
441
438
|
* - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf
|
|
@@ -462,13 +459,14 @@ var CARBON_INTENSITY_DEFAULTS = {
|
|
|
462
459
|
micromobility: 0.095
|
|
463
460
|
};
|
|
464
461
|
/**
|
|
465
|
-
* @param
|
|
466
|
-
* @param
|
|
462
|
+
* @param {itinerary} itinerary OTP trip itinierary, only legs is required.
|
|
463
|
+
* @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
|
|
467
464
|
* @param {units} units units to be used in return value
|
|
468
465
|
* @return Amount of carbon in chosen unit
|
|
469
466
|
*/
|
|
470
467
|
|
|
471
|
-
export function calculateEmissions(
|
|
468
|
+
export function calculateEmissions( // This type makes all the properties from Itinerary optional except legs.
|
|
469
|
+
itinerary) {
|
|
472
470
|
var _itinerary$legs;
|
|
473
471
|
|
|
474
472
|
var carbonIntensity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -520,4 +518,108 @@ export function getDisplayedStopId(placeOrStop) {
|
|
|
520
518
|
|
|
521
519
|
return stopCode || ((_stopId = stopId) === null || _stopId === void 0 ? void 0 : _stopId.split(":")[1]) || stopId;
|
|
522
520
|
}
|
|
521
|
+
/**
|
|
522
|
+
* Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
|
|
523
|
+
* @param leg Leg with fare products (must have used getLegsWithFares)
|
|
524
|
+
* @param category Rider category
|
|
525
|
+
* @param container Fare container (cash, electronic)
|
|
526
|
+
* @returns Object containing price as well as the transfer discount amount, if a transfer was used.
|
|
527
|
+
*/
|
|
528
|
+
|
|
529
|
+
export function getLegCost(leg, mediumId, riderCategoryId) {
|
|
530
|
+
var _relevantFareProducts, _relevantFareProducts2;
|
|
531
|
+
|
|
532
|
+
if (!leg.fareProducts) return {
|
|
533
|
+
price: undefined
|
|
534
|
+
};
|
|
535
|
+
var relevantFareProducts = leg.fareProducts.filter(function (_ref3) {
|
|
536
|
+
var product = _ref3.product;
|
|
537
|
+
return product.riderCategory.id === riderCategoryId && product.medium.id === mediumId;
|
|
538
|
+
});
|
|
539
|
+
var totalCost = (_relevantFareProducts = relevantFareProducts.find(function (fp) {
|
|
540
|
+
return fp.product.name === "rideCost";
|
|
541
|
+
})) === null || _relevantFareProducts === void 0 ? void 0 : (_relevantFareProducts2 = _relevantFareProducts.product) === null || _relevantFareProducts2 === void 0 ? void 0 : _relevantFareProducts2.price;
|
|
542
|
+
var transferFareProduct = relevantFareProducts.find(function (fp) {
|
|
543
|
+
return fp.product.name === "transfer";
|
|
544
|
+
});
|
|
545
|
+
return {
|
|
546
|
+
price: totalCost,
|
|
547
|
+
transferAmount: transferFareProduct === null || transferFareProduct === void 0 ? void 0 : transferFareProduct.product.price
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Returns the total itinerary cost for a given set of legs.
|
|
552
|
+
* @param legs Itinerary legs with fare products (must have used getLegsWithFares)
|
|
553
|
+
* @param category Rider category (youth, regular, senior)
|
|
554
|
+
* @param container Fare container (cash, electronic)
|
|
555
|
+
* @returns Money object for the total itinerary cost.
|
|
556
|
+
*/
|
|
557
|
+
|
|
558
|
+
export function getItineraryCost(legs, category, container) {
|
|
559
|
+
return legs.filter(function (leg) {
|
|
560
|
+
return !!leg.fareProducts;
|
|
561
|
+
}).map(function (leg) {
|
|
562
|
+
return getLegCost(leg, category, container).price;
|
|
563
|
+
}).reduce(function (prev, cur) {
|
|
564
|
+
var _prev$currency;
|
|
565
|
+
|
|
566
|
+
return {
|
|
567
|
+
amount: prev.amount + (cur === null || cur === void 0 ? void 0 : cur.amount) || 0,
|
|
568
|
+
currency: (_prev$currency = prev.currency) !== null && _prev$currency !== void 0 ? _prev$currency : cur === null || cur === void 0 ? void 0 : cur.currency
|
|
569
|
+
};
|
|
570
|
+
}, {
|
|
571
|
+
amount: 0,
|
|
572
|
+
currency: null
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
var pickupDropoffTypeToOtp1 = function pickupDropoffTypeToOtp1(otp2Type) {
|
|
577
|
+
switch (otp2Type) {
|
|
578
|
+
case "COORDINATE_WITH_DRIVER":
|
|
579
|
+
return "coordinateWithDriver";
|
|
580
|
+
|
|
581
|
+
case "CALL_AGENCY":
|
|
582
|
+
return "mustPhone";
|
|
583
|
+
|
|
584
|
+
case "SCHEDULED":
|
|
585
|
+
return "scheduled";
|
|
586
|
+
|
|
587
|
+
case "NONE":
|
|
588
|
+
return "none";
|
|
589
|
+
|
|
590
|
+
default:
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
export var convertGraphQLResponseToLegacy = function convertGraphQLResponseToLegacy(leg) {
|
|
596
|
+
var _leg$agency, _leg$agency2, _leg$agency3, _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;
|
|
597
|
+
|
|
598
|
+
return _objectSpread(_objectSpread({}, leg), {}, {
|
|
599
|
+
agencyBrandingUrl: (_leg$agency = leg.agency) === null || _leg$agency === void 0 ? void 0 : _leg$agency.url,
|
|
600
|
+
agencyName: (_leg$agency2 = leg.agency) === null || _leg$agency2 === void 0 ? void 0 : _leg$agency2.name,
|
|
601
|
+
agencyUrl: (_leg$agency3 = leg.agency) === null || _leg$agency3 === void 0 ? void 0 : _leg$agency3.url,
|
|
602
|
+
alightRule: pickupDropoffTypeToOtp1(leg.dropoffType),
|
|
603
|
+
boardRule: pickupDropoffTypeToOtp1(leg.pickupType),
|
|
604
|
+
dropOffBookingInfo: {
|
|
605
|
+
latestBookingTime: leg.dropOffBookingInfo
|
|
606
|
+
},
|
|
607
|
+
from: _objectSpread(_objectSpread({}, leg.from), {}, {
|
|
608
|
+
stopCode: (_leg$from$stop = leg.from.stop) === null || _leg$from$stop === void 0 ? void 0 : _leg$from$stop.code,
|
|
609
|
+
stopId: (_leg$from$stop2 = leg.from.stop) === null || _leg$from$stop2 === void 0 ? void 0 : _leg$from$stop2.gtfsId
|
|
610
|
+
}),
|
|
611
|
+
route: (_leg$route = leg.route) === null || _leg$route === void 0 ? void 0 : _leg$route.shortName,
|
|
612
|
+
routeColor: (_leg$route2 = leg.route) === null || _leg$route2 === void 0 ? void 0 : _leg$route2.color,
|
|
613
|
+
routeId: (_leg$route3 = leg.route) === null || _leg$route3 === void 0 ? void 0 : _leg$route3.id,
|
|
614
|
+
routeLongName: (_leg$route4 = leg.route) === null || _leg$route4 === void 0 ? void 0 : _leg$route4.longName,
|
|
615
|
+
routeShortName: (_leg$route5 = leg.route) === null || _leg$route5 === void 0 ? void 0 : _leg$route5.shortName,
|
|
616
|
+
routeTextColor: (_leg$route6 = leg.route) === null || _leg$route6 === void 0 ? void 0 : _leg$route6.textColor,
|
|
617
|
+
to: _objectSpread(_objectSpread({}, leg.to), {}, {
|
|
618
|
+
stopCode: (_leg$to$stop = leg.to.stop) === null || _leg$to$stop === void 0 ? void 0 : _leg$to$stop.code,
|
|
619
|
+
stopId: (_leg$to$stop2 = leg.to.stop) === null || _leg$to$stop2 === void 0 ? void 0 : _leg$to$stop2.gtfsId
|
|
620
|
+
}),
|
|
621
|
+
tripHeadsign: (_leg$trip = leg.trip) === null || _leg$trip === void 0 ? void 0 : _leg$trip.tripHeadsign,
|
|
622
|
+
tripId: (_leg$trip2 = leg.trip) === null || _leg$trip2 === void 0 ? void 0 : _leg$trip2.gtfsId
|
|
623
|
+
});
|
|
624
|
+
};
|
|
523
625
|
//# sourceMappingURL=itinerary.js.map
|
package/esm/itinerary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/itinerary.ts"],"names":["polyline","turfAlong","transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","alightRule","isCoordinationRequired","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","hailedCar","reduce","maxTNCFare","minTNCFare","currency","maxCost","minCost","currencyCode","getTransitFare","fareComponent","transitFare","cents","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","carbonIntensityWithDefaults","totalCarbon","total","getDisplayedStopId","placeOrStop","stopId","stopCode","code"],"mappings":";;;;;;;AAAA,OAAOA,QAAP,MAAqB,kBAArB;AAeA,OAAOC,SAAP,MAAsB,aAAtB,C,CAEA;;AACA,OAAO,IAAMC,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EA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AP;AATJ;AAWD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,kBAAT,CAA4BC,WAA5B,EAA+D;AAAA;;AACpE,MAAIC,MAAJ;AACA,MAAIC,QAAJ;;AACA,MAAI,YAAYF,WAAhB,EAA6B;AACxBE,IAAAA,QADwB,GACHF,WADG,CACxBE,QADwB;AACdD,IAAAA,MADc,GACHD,WADG,CACdC,MADc;AAE5B,GAFD,MAEO,IAAI,QAAQD,WAAZ,EAAyB;AACrBE,IAAAA,QADqB,GACIF,WADJ,CAC3BG,IAD2B;AACPF,IAAAA,MADO,GACID,WADJ,CACXlD,EADW;AAE/B;;AACD,SAAOoD,QAAQ,gBAAID,MAAJ,4CAAI,QAAQ7I,KAAR,CAAc,GAAd,EAAmB,CAAnB,CAAJ,CAAR,IAAqC6I,MAA5C;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Money,\n Place,\n Step,\n Stop,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\" || leg.alightRule === \"mustPhone\";\n}\n/**\n * Returns true if a user must ask the driver to let the user off\n * or if the user must flag the driver down for pickup.\n * \"coordinateWithDriver\" in board/alight rule encodes this info.\n */\nexport function isCoordinationRequired(leg: Leg): boolean {\n return (\n leg.boardRule === \"coordinateWithDriver\" ||\n leg.alightRule === \"coordinateWithDriver\"\n );\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isCoordinationRequired(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[][] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string[],\n companies: Company[] = []\n): string {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: Itinerary\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(itinerary: Itinerary): TncFare {\n return itinerary.legs\n .filter(leg => leg.mode === \"CAR\" && leg.hailedCar && leg.tncData)\n .reduce(\n ({ maxTNCFare, minTNCFare }, { tncData }) => {\n const { currency, maxCost, minCost } = tncData;\n return {\n // Assumes a single currency for entire itinerary.\n currencyCode: currency,\n maxTNCFare: maxTNCFare + maxCost,\n minTNCFare: minTNCFare + minCost\n };\n },\n {\n currencyCode: null,\n maxTNCFare: 0,\n minTNCFare: 0\n }\n );\n}\n\n/**\n * For a given fare component (either total fare or component parts), returns\n * an object with the fare value (in cents).\n */\nexport function getTransitFare(\n fareComponent: Money\n): {\n currencyCode: string;\n transitFare: number;\n} {\n return fareComponent\n ? {\n currencyCode: fareComponent.currency.currencyCode,\n transitFare: fareComponent.cents\n }\n : {\n currencyCode: \"USD\",\n transitFare: 0\n };\n}\n\n/**\n * Sources:\n * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf\n * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey\n * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx\n * Other values extrapolated.\n */\nconst CARBON_INTENSITY_DEFAULTS = {\n walk: 0.026,\n bicycle: 0.017,\n car: 0.162,\n tram: 0.066,\n subway: 0.066,\n rail: 0.066,\n bus: 0.09,\n ferry: 0.082,\n cable_car: 0.021,\n gondola: 0.021,\n funicular: 0.066,\n transit: 0.066,\n leg_switch: 0,\n airplane: 0.382,\n micromobility: 0.095\n};\n\n/**\n * @param {itinerary} itinerary OTP trip itinierary\n * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter\n * @param {units} units units to be used in return value\n * @return Amount of carbon in chosen unit\n */\nexport function calculateEmissions(\n itinerary: Itinerary,\n carbonIntensity: Record<string, number> = {},\n units?: string\n): number {\n // Apply defaults for any values that we don't have.\n const carbonIntensityWithDefaults = {\n ...CARBON_INTENSITY_DEFAULTS,\n ...carbonIntensity\n };\n\n // Distance is in meters, totalCarbon is in grams\n const totalCarbon =\n itinerary?.legs?.reduce((total, leg) => {\n return (\n (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||\n 0) + total\n );\n }, 0) || 0;\n\n switch (units) {\n case \"ounce\":\n return totalCarbon / 28.35;\n case \"kilogram\":\n return totalCarbon / 1000;\n case \"pound\":\n return totalCarbon / 454;\n case \"gram\":\n default:\n return totalCarbon;\n }\n}\n\n/**\n * Returns the user-facing stop id to display for a stop or place, using the following priority:\n * 1. stop code,\n * 2. stop id without the agency id portion, if stop id contains an agency portion,\n * 3. stop id, whether null or not (this is the fallback case).\n */\nexport function getDisplayedStopId(placeOrStop: Place | Stop): string {\n let stopId;\n let stopCode;\n if (\"stopId\" in placeOrStop) {\n ({ stopCode, stopId } = placeOrStop);\n } else if (\"id\" in placeOrStop) {\n ({ code: stopCode, id: stopId } = placeOrStop);\n }\n return stopCode || stopId?.split(\":\")[1] || stopId;\n}\n"],"file":"itinerary.js"}
|
|
1
|
+
{"version":3,"sources":["../src/itinerary.ts"],"names":["polyline","turfAlong","transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","alightRule","isCoordinationRequired","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isRideshareLeg","rideHailingEstimate","provider","id","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","networks","rentalVehicle","network","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","company","find","co","getCompaniesLabelFromNetworks","networksArray","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","reduce","maxTNCFare","minTNCFare","minPrice","maxPrice","currencyCode","currency","code","amount","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","carbonIntensityWithDefaults","totalCarbon","total","getDisplayedStopId","placeOrStop","stopId","stopCode","getLegCost","mediumId","riderCategoryId","fareProducts","price","undefined","relevantFareProducts","product","riderCategory","medium","totalCost","fp","name","transferFareProduct","transferAmount","getItineraryCost","category","container","prev","cur","pickupDropoffTypeToOtp1","otp2Type","convertGraphQLResponseToLegacy","agencyBrandingUrl","agency","url","agencyName","agencyUrl","dropoffType","pickupType","stop","gtfsId","route","shortName","routeColor","color","routeId","routeLongName","longName","routeShortName","routeTextColor","textColor","tripHeadsign","trip","tripId"],"mappings":";;;;;;;AAAA,OAAOA,QAAP,MAAqB,kBAArB;AAgBA,OAAOC,SAAP,MAAsB,aAAtB,C,CAEA;;AACA,OAAO,IAAMC,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MAL0B,EAM1B,SAN0B,CAArB;AASP;AACA;AACA;AACA;;AAEA,OAAO,SAASC,eAAT,CAAyBC,MAAzB,EAAmD;AACxD,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACC,KAAnB,IAA4B,CAACD,MAAM,CAACC,KAAP,CAAaH,YAA9C,EACE,OAAOA,YAAP;AAEF,SAAOE,MAAM,CAACC,KAAP,CAAaH,YAAb,CAA0BI,GAA1B,CAA8B,UAAAC,EAAE;AAAA,WACrC,OAAOA,EAAP,KAAc,QAAd,GAAyBA,EAAE,CAACC,IAA5B,GAAmCD,EADE;AAAA,GAAhC,CAAP;AAGD;AA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WAAUZ;AA3B0B;AAAA,CAAvC","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n ItineraryOnlyLegsRequired,\n LatLngArray,\n Leg,\n MassUnitOption,\n Money,\n Place,\n Step,\n Stop,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\" || leg.alightRule === \"mustPhone\";\n}\n/**\n * Returns true if a user must ask the driver to let the user off\n * or if the user must flag the driver down for pickup.\n * \"coordinateWithDriver\" in board/alight rule encodes this info.\n */\nexport function isCoordinationRequired(leg: Leg): boolean {\n return (\n leg.boardRule === \"coordinateWithDriver\" ||\n leg.alightRule === \"coordinateWithDriver\"\n );\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isCoordinationRequired(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\n// alpha-only comment\nexport function isRideshareLeg(leg: Leg): boolean {\n return !!leg.rideHailingEstimate?.provider?.id;\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const {\n from,\n mode,\n rentedBike,\n rentedCar,\n rentedVehicle,\n rideHailingEstimate\n } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && rideHailingEstimate) {\n return rideHailingEstimate.provider.id;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (from.rentalVehicle) {\n return from.rentalVehicle.network;\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(\n itinerary: ItineraryOnlyLegsRequired\n): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[][] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string | string[],\n companies: Company[] = []\n): string {\n let networksArray = networks;\n if (typeof networks === \"string\") networksArray = [networks];\n\n return (networksArray as string[])\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: ItineraryOnlyLegsRequired\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(\n itinerary: ItineraryOnlyLegsRequired\n): TncFare {\n return itinerary.legs\n .filter(leg => leg.mode === \"CAR\" && leg.rideHailingEstimate)\n .reduce(\n ({ maxTNCFare, minTNCFare }, { rideHailingEstimate }) => {\n const { minPrice, maxPrice } = rideHailingEstimate;\n return {\n // Assumes a single currency for entire itinerary.\n currencyCode: minPrice.currency.code,\n maxTNCFare: maxTNCFare + maxPrice.amount,\n minTNCFare: minTNCFare + minPrice.amount\n };\n },\n {\n currencyCode: null,\n maxTNCFare: 0,\n minTNCFare: 0\n }\n );\n}\n\n/**\n * Sources:\n * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf\n * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey\n * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx\n * Other values extrapolated.\n */\nconst CARBON_INTENSITY_DEFAULTS = {\n walk: 0.026,\n bicycle: 0.017,\n car: 0.162,\n tram: 0.066,\n subway: 0.066,\n rail: 0.066,\n bus: 0.09,\n ferry: 0.082,\n cable_car: 0.021,\n gondola: 0.021,\n funicular: 0.066,\n transit: 0.066,\n leg_switch: 0,\n airplane: 0.382,\n micromobility: 0.095\n};\n\n/**\n * @param {itinerary} itinerary OTP trip itinierary, only legs is required.\n * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter\n * @param {units} units units to be used in return value\n * @return Amount of carbon in chosen unit\n */\nexport function calculateEmissions(\n // This type makes all the properties from Itinerary optional except legs.\n itinerary: ItineraryOnlyLegsRequired,\n carbonIntensity: Record<string, number> = {},\n units?: MassUnitOption\n): number {\n // Apply defaults for any values that we don't have.\n const carbonIntensityWithDefaults = {\n ...CARBON_INTENSITY_DEFAULTS,\n ...carbonIntensity\n };\n\n // Distance is in meters, totalCarbon is in grams\n const totalCarbon =\n itinerary?.legs?.reduce((total, leg) => {\n return (\n (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||\n 0) + total\n );\n }, 0) || 0;\n\n switch (units) {\n case \"ounce\":\n return totalCarbon / 28.35;\n case \"kilogram\":\n return totalCarbon / 1000;\n case \"pound\":\n return totalCarbon / 454;\n case \"gram\":\n default:\n return totalCarbon;\n }\n}\n\n/**\n * Returns the user-facing stop id to display for a stop or place, using the following priority:\n * 1. stop code,\n * 2. stop id without the agency id portion, if stop id contains an agency portion,\n * 3. stop id, whether null or not (this is the fallback case).\n */\nexport function getDisplayedStopId(placeOrStop: Place | Stop): string {\n let stopId;\n let stopCode;\n if (\"stopId\" in placeOrStop) {\n ({ stopCode, stopId } = placeOrStop);\n } else if (\"id\" in placeOrStop) {\n ({ code: stopCode, id: stopId } = placeOrStop);\n }\n return stopCode || stopId?.split(\":\")[1] || stopId;\n}\n\n/**\n * Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.\n * @param leg Leg with fare products (must have used getLegsWithFares)\n * @param category Rider category\n * @param container Fare container (cash, electronic)\n * @returns Object containing price as well as the transfer discount amount, if a transfer was used.\n */\nexport function getLegCost(\n leg: Leg,\n mediumId: string,\n riderCategoryId: string\n): { price: Money; transferAmount?: Money | undefined } {\n if (!leg.fareProducts) return { price: undefined };\n const relevantFareProducts = leg.fareProducts.filter(({ product }) => {\n return (\n product.riderCategory.id === riderCategoryId &&\n product.medium.id === mediumId\n );\n });\n const totalCost = relevantFareProducts.find(\n fp => fp.product.name === \"rideCost\"\n )?.product?.price;\n const transferFareProduct = relevantFareProducts.find(\n fp => fp.product.name === \"transfer\"\n );\n\n return {\n price: totalCost,\n transferAmount: transferFareProduct?.product.price\n };\n}\n\n/**\n * Returns the total itinerary cost for a given set of legs.\n * @param legs Itinerary legs with fare products (must have used getLegsWithFares)\n * @param category Rider category (youth, regular, senior)\n * @param container Fare container (cash, electronic)\n * @returns Money object for the total itinerary cost.\n */\nexport function getItineraryCost(\n legs: Leg[],\n category: string,\n container: string\n): Money {\n return legs\n .filter(leg => !!leg.fareProducts)\n .map(leg => getLegCost(leg, category, container).price)\n .reduce<Money>(\n (prev, cur) => ({\n amount: prev.amount + cur?.amount || 0,\n currency: prev.currency ?? cur?.currency\n }),\n { amount: 0, currency: null }\n );\n}\n\nconst pickupDropoffTypeToOtp1 = otp2Type => {\n switch (otp2Type) {\n case \"COORDINATE_WITH_DRIVER\":\n return \"coordinateWithDriver\";\n case \"CALL_AGENCY\":\n return \"mustPhone\";\n case \"SCHEDULED\":\n return \"scheduled\";\n case \"NONE\":\n return \"none\";\n default:\n return null;\n }\n};\n\nexport const convertGraphQLResponseToLegacy = (leg: any): any => ({\n ...leg,\n agencyBrandingUrl: leg.agency?.url,\n agencyName: leg.agency?.name,\n agencyUrl: leg.agency?.url,\n alightRule: pickupDropoffTypeToOtp1(leg.dropoffType),\n boardRule: pickupDropoffTypeToOtp1(leg.pickupType),\n dropOffBookingInfo: {\n latestBookingTime: leg.dropOffBookingInfo\n },\n from: {\n ...leg.from,\n stopCode: leg.from.stop?.code,\n stopId: leg.from.stop?.gtfsId\n },\n route: leg.route?.shortName,\n routeColor: leg.route?.color,\n routeId: leg.route?.id,\n routeLongName: leg.route?.longName,\n routeShortName: leg.route?.shortName,\n routeTextColor: leg.route?.textColor,\n to: {\n ...leg.to,\n stopCode: leg.to.stop?.code,\n stopId: leg.to.stop?.gtfsId\n },\n tripHeadsign: leg.trip?.tripHeadsign,\n tripId: leg.trip?.gtfsId\n});\n"],"file":"itinerary.js"}
|