@opentripplanner/core-utils 9.0.0-alpha.8 → 9.0.0

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 CHANGED
@@ -57,6 +57,11 @@ export function isAdvanceBookingRequired(info) {
57
57
  export function legDropoffRequiresAdvanceBooking(leg) {
58
58
  return isAdvanceBookingRequired(leg.dropOffBookingInfo);
59
59
  }
60
+ export function isRideshareLeg(leg) {
61
+ var _leg$rideHailingEstim, _leg$rideHailingEstim2;
62
+
63
+ return !!((_leg$rideHailingEstim = leg.rideHailingEstimate) !== null && _leg$rideHailingEstim !== void 0 && (_leg$rideHailingEstim2 = _leg$rideHailingEstim.provider) !== null && _leg$rideHailingEstim2 !== void 0 && _leg$rideHailingEstim2.id);
64
+ }
60
65
  export function isWalk(mode) {
61
66
  if (!mode) return false;
62
67
  return mode === "WALK";
@@ -172,20 +177,24 @@ export function getCompanyFromLeg(leg) {
172
177
  rentedBike = leg.rentedBike,
173
178
  rentedCar = leg.rentedCar,
174
179
  rentedVehicle = leg.rentedVehicle,
175
- tncData = leg.tncData;
180
+ rideHailingEstimate = leg.rideHailingEstimate;
176
181
 
177
182
  if (mode === "CAR" && rentedCar) {
178
183
  return from.networks[0];
179
184
  }
180
185
 
181
- if (mode === "CAR" && tncData) {
182
- return tncData.company;
186
+ if (mode === "CAR" && rideHailingEstimate) {
187
+ return rideHailingEstimate.provider.id;
183
188
  }
184
189
 
185
190
  if (mode === "BICYCLE" && rentedBike && from.networks) {
186
191
  return from.networks[0];
187
192
  }
188
193
 
194
+ if (from.rentalVehicle) {
195
+ return from.rentalVehicle.network;
196
+ }
197
+
189
198
  if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle && from.networks) {
190
199
  return from.networks[0];
191
200
  }
@@ -402,19 +411,18 @@ export function calculatePhysicalActivity(itinerary) {
402
411
 
403
412
  export function calculateTncFares(itinerary) {
404
413
  return itinerary.legs.filter(function (leg) {
405
- return leg.mode === "CAR" && leg.hailedCar && leg.tncData;
414
+ return leg.mode === "CAR" && leg.rideHailingEstimate;
406
415
  }).reduce(function (_ref, _ref2) {
407
416
  var maxTNCFare = _ref.maxTNCFare,
408
417
  minTNCFare = _ref.minTNCFare;
409
- var tncData = _ref2.tncData;
410
- var currency = tncData.currency,
411
- maxCost = tncData.maxCost,
412
- minCost = tncData.minCost;
418
+ var rideHailingEstimate = _ref2.rideHailingEstimate;
419
+ var minPrice = rideHailingEstimate.minPrice,
420
+ maxPrice = rideHailingEstimate.maxPrice;
413
421
  return {
414
422
  // Assumes a single currency for entire itinerary.
415
- currencyCode: currency,
416
- maxTNCFare: maxTNCFare + maxCost,
417
- minTNCFare: minTNCFare + minCost
423
+ currencyCode: minPrice.currency.code,
424
+ maxTNCFare: maxTNCFare + maxPrice.amount,
425
+ minTNCFare: minTNCFare + minPrice.amount
418
426
  };
419
427
  }, {
420
428
  currencyCode: null,
@@ -422,20 +430,6 @@ export function calculateTncFares(itinerary) {
422
430
  minTNCFare: 0
423
431
  });
424
432
  }
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
433
  /**
440
434
  * Sources:
441
435
  * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf
@@ -521,27 +515,6 @@ export function getDisplayedStopId(placeOrStop) {
521
515
 
522
516
  return stopCode || ((_stopId = stopId) === null || _stopId === void 0 ? void 0 : _stopId.split(":")[1]) || stopId;
523
517
  }
524
- /**
525
- * Adds the fare product info to each leg in an itinerary, from the itinerary's fare property
526
- * @param itinerary Itinerary with legProducts in fare object
527
- * @returns Itinerary with legs that have fare products attached to them
528
- */
529
-
530
- export function getLegsWithFares(itinerary) {
531
- return itinerary.legs.map(function (leg, i) {
532
- var _itinerary$fare, _itinerary$fare$legPr;
533
-
534
- return _objectSpread(_objectSpread({}, leg), {}, {
535
- fareProducts: (_itinerary$fare = itinerary.fare) === null || _itinerary$fare === void 0 ? void 0 : (_itinerary$fare$legPr = _itinerary$fare.legProducts) === null || _itinerary$fare$legPr === void 0 ? void 0 : _itinerary$fare$legPr.filter(function (lp) {
536
- var _lp$legIndices;
537
-
538
- return lp === null || lp === void 0 ? void 0 : (_lp$legIndices = lp.legIndices) === null || _lp$legIndices === void 0 ? void 0 : _lp$legIndices.includes(i);
539
- }).flatMap(function (lp) {
540
- return lp.products;
541
- })
542
- });
543
- });
544
- }
545
518
  /**
546
519
  * Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
547
520
  * @param leg Leg with fare products (must have used getLegsWithFares)
@@ -550,24 +523,25 @@ export function getLegsWithFares(itinerary) {
550
523
  * @returns Object containing price as well as the transfer discount amount, if a transfer was used.
551
524
  */
552
525
 
553
- export function getLegCost(leg, category, container) {
554
- var _relevantFareProducts, _transferFareProduct$;
526
+ export function getLegCost(leg, mediumId, riderCategoryId) {
527
+ var _relevantFareProducts, _relevantFareProducts2;
555
528
 
556
529
  if (!leg.fareProducts) return {
557
530
  price: undefined
558
531
  };
559
- var relevantFareProducts = leg.fareProducts.filter(function (fp) {
560
- return fp.category.name === category && fp.container.name === container;
532
+ var relevantFareProducts = leg.fareProducts.filter(function (_ref3) {
533
+ var product = _ref3.product;
534
+ return product.riderCategory.id === riderCategoryId && product.medium.id === mediumId;
561
535
  });
562
536
  var totalCost = (_relevantFareProducts = relevantFareProducts.find(function (fp) {
563
- return fp.name === "rideCost";
564
- })) === null || _relevantFareProducts === void 0 ? void 0 : _relevantFareProducts.amount;
537
+ return fp.product.name === "rideCost";
538
+ })) === null || _relevantFareProducts === void 0 ? void 0 : (_relevantFareProducts2 = _relevantFareProducts.product) === null || _relevantFareProducts2 === void 0 ? void 0 : _relevantFareProducts2.price;
565
539
  var transferFareProduct = relevantFareProducts.find(function (fp) {
566
- return fp.name === "transfer";
540
+ return fp.product.name === "transfer";
567
541
  });
568
542
  return {
569
543
  price: totalCost,
570
- transferAmount: transferFareProduct === null || transferFareProduct === void 0 ? void 0 : (_transferFareProduct$ = transferFareProduct.amount) === null || _transferFareProduct$ === void 0 ? void 0 : _transferFareProduct$.cents
544
+ transferAmount: transferFareProduct === null || transferFareProduct === void 0 ? void 0 : transferFareProduct.product.price
571
545
  };
572
546
  }
573
547
  /**
@@ -578,21 +552,77 @@ export function getLegCost(leg, category, container) {
578
552
  * @returns Money object for the total itinerary cost.
579
553
  */
580
554
 
581
- export function getItineraryCost(legs, category, container) {
582
- return legs.filter(function (leg) {
583
- return !!leg.fareProducts;
555
+ export function getItineraryCost(legs, mediumId, riderCategoryId) {
556
+ var legCosts = legs.filter(function (leg) {
557
+ var _leg$fareProducts;
558
+
559
+ return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) > 0;
584
560
  }).map(function (leg) {
585
- return getLegCost(leg, category, container).price;
586
- }).reduce(function (prev, cur) {
561
+ return getLegCost(leg, mediumId, riderCategoryId).price;
562
+ }).filter(function (cost) {
563
+ return cost !== undefined;
564
+ });
565
+ if (legCosts.length === 0) return undefined;
566
+ return legCosts.reduce(function (prev, cur) {
587
567
  var _prev$currency;
588
568
 
589
569
  return {
590
- cents: prev.cents + (cur === null || cur === void 0 ? void 0 : cur.cents) || 0,
570
+ amount: prev.amount + (cur === null || cur === void 0 ? void 0 : cur.amount) || 0,
591
571
  currency: (_prev$currency = prev.currency) !== null && _prev$currency !== void 0 ? _prev$currency : cur === null || cur === void 0 ? void 0 : cur.currency
592
572
  };
593
573
  }, {
594
- cents: 0,
574
+ amount: 0,
595
575
  currency: null
596
576
  });
597
577
  }
578
+
579
+ var pickupDropoffTypeToOtp1 = function pickupDropoffTypeToOtp1(otp2Type) {
580
+ switch (otp2Type) {
581
+ case "COORDINATE_WITH_DRIVER":
582
+ return "coordinateWithDriver";
583
+
584
+ case "CALL_AGENCY":
585
+ return "mustPhone";
586
+
587
+ case "SCHEDULED":
588
+ return "scheduled";
589
+
590
+ case "NONE":
591
+ return "none";
592
+
593
+ default:
594
+ return null;
595
+ }
596
+ };
597
+
598
+ export var convertGraphQLResponseToLegacy = function convertGraphQLResponseToLegacy(leg) {
599
+ 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;
600
+
601
+ return _objectSpread(_objectSpread({}, leg), {}, {
602
+ agencyBrandingUrl: (_leg$agency = leg.agency) === null || _leg$agency === void 0 ? void 0 : _leg$agency.url,
603
+ agencyName: (_leg$agency2 = leg.agency) === null || _leg$agency2 === void 0 ? void 0 : _leg$agency2.name,
604
+ agencyUrl: (_leg$agency3 = leg.agency) === null || _leg$agency3 === void 0 ? void 0 : _leg$agency3.url,
605
+ alightRule: pickupDropoffTypeToOtp1(leg.dropoffType),
606
+ boardRule: pickupDropoffTypeToOtp1(leg.pickupType),
607
+ dropOffBookingInfo: {
608
+ latestBookingTime: leg.dropOffBookingInfo
609
+ },
610
+ from: _objectSpread(_objectSpread({}, leg.from), {}, {
611
+ stopCode: (_leg$from$stop = leg.from.stop) === null || _leg$from$stop === void 0 ? void 0 : _leg$from$stop.code,
612
+ stopId: (_leg$from$stop2 = leg.from.stop) === null || _leg$from$stop2 === void 0 ? void 0 : _leg$from$stop2.gtfsId
613
+ }),
614
+ route: (_leg$route = leg.route) === null || _leg$route === void 0 ? void 0 : _leg$route.shortName,
615
+ routeColor: (_leg$route2 = leg.route) === null || _leg$route2 === void 0 ? void 0 : _leg$route2.color,
616
+ routeId: (_leg$route3 = leg.route) === null || _leg$route3 === void 0 ? void 0 : _leg$route3.id,
617
+ routeLongName: (_leg$route4 = leg.route) === null || _leg$route4 === void 0 ? void 0 : _leg$route4.longName,
618
+ routeShortName: (_leg$route5 = leg.route) === null || _leg$route5 === void 0 ? void 0 : _leg$route5.shortName,
619
+ routeTextColor: (_leg$route6 = leg.route) === null || _leg$route6 === void 0 ? void 0 : _leg$route6.textColor,
620
+ to: _objectSpread(_objectSpread({}, leg.to), {}, {
621
+ stopCode: (_leg$to$stop = leg.to.stop) === null || _leg$to$stop === void 0 ? void 0 : _leg$to$stop.code,
622
+ stopId: (_leg$to$stop2 = leg.to.stop) === null || _leg$to$stop2 === void 0 ? void 0 : _leg$to$stop2.gtfsId
623
+ }),
624
+ tripHeadsign: (_leg$trip = leg.trip) === null || _leg$trip === void 0 ? void 0 : _leg$trip.tripHeadsign,
625
+ tripId: (_leg$trip2 = leg.trip) === null || _leg$trip2 === void 0 ? void 0 : _leg$trip2.gtfsId
626
+ });
627
+ };
598
628
  //# sourceMappingURL=itinerary.js.map
@@ -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","getLegsWithFares","fareProducts","fare","legProducts","lp","legIndices","flatMap","products","getLegCost","category","container","price","undefined","relevantFareProducts","fp","name","totalCost","amount","transferFareProduct","transferAmount","getItineraryCost","prev","cur"],"mappings":";;;;;;;AAAA,OAAOA,QAAP,MAAqB,kBAArB;AAiBA,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;AAED,OAAO,SAASE,SAAT,CAAmBD,IAAnB,EAA0C;AAC/C,SAAON,YAAY,CAACQ,QAAb,CAAsBF,IAAtB,KAA+BA,IAAI,KAAK,SAA/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J,IAAAA,KAAK,EAAEK,SADF;AAELG,IAAAA,cAAc,EAAED,mBAAF,aAAEA,mBAAF,gDAAEA,mBAAmB,CAAED,MAAvB,0DAAE,sBAA6B5C;AAFxC,GAAP;AAID;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS+C,gBAAT,CACLxI,IADK,EAEL6H,QAFK,EAGLC,SAHK,EAIE;AACP,SAAO9H,IAAI,CACRiE,MADI,CACG,UAAAjH,GAAG;AAAA,WAAI,CAAC,CAACA,GAAG,CAACqK,YAAV;AAAA,GADN,EAEJ3K,GAFI,CAEA,UAAAM,GAAG;AAAA,WAAI4K,UAAU,CAAC5K,GAAD,EAAM6K,QAAN,EAAgBC,SAAhB,CAAV,CAAqCC,KAAzC;AAAA,GAFH,EAGJhD,MAHI,CAIH,UAAC0D,IAAD,EAAOC,GAAP;AAAA;;AAAA,WAAgB;AACdjD,MAAAA,KAAK,EAAEgD,IAAI,CAAChD,KAAL,IAAaiD,GAAb,aAAaA,GAAb,uBAAaA,GAAG,CAAEjD,KAAlB,KAA2B,CADpB;AAEdP,MAAAA,QAAQ,oBAAEuD,IAAI,CAACvD,QAAP,2DAAmBwD,GAAnB,aAAmBA,GAAnB,uBAAmBA,GAAG,CAAExD;AAFlB,KAAhB;AAAA,GAJG,EAQH;AAAEO,IAAAA,KAAK,EAAE,CAAT;AAAYP,IAAAA,QAAQ,EAAE;AAAtB,GARG,CAAP;AAUD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\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\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(\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[],\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: 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.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, 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 * Adds the fare product info to each leg in an itinerary, from the itinerary's fare property\n * @param itinerary Itinerary with legProducts in fare object\n * @returns Itinerary with legs that have fare products attached to them\n */\nexport function getLegsWithFares(itinerary: Itinerary): Leg[] {\n return itinerary.legs.map((leg, i) => ({\n ...leg,\n fareProducts: itinerary.fare?.legProducts\n ?.filter(lp => lp?.legIndices?.includes(i))\n .flatMap(lp => lp.products)\n }));\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 category: string,\n container: string\n): { price?: Money; transferAmount?: number } {\n if (!leg.fareProducts) return { price: undefined };\n\n const relevantFareProducts = leg.fareProducts.filter(\n fp => fp.category.name === category && fp.container.name === container\n );\n const totalCost = relevantFareProducts.find(fp => fp.name === \"rideCost\")\n ?.amount;\n const transferFareProduct = relevantFareProducts.find(\n fp => fp.name === \"transfer\"\n );\n\n return {\n price: totalCost,\n transferAmount: transferFareProduct?.amount?.cents\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 cents: prev.cents + cur?.cents || 0,\n currency: prev.currency ?? cur?.currency\n }),\n { cents: 0, currency: null }\n );\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","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","legCosts","cost","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,OA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B;AAoB5CO,IAAAA,cAAc,iBAAE3M,GAAG,CAACmM,KAAN,gDAAE,YAAWS,SApBiB;AAqB5C3I,IAAAA,EAAE,kCACGjE,GAAG,CAACiE,EADP;AAEAiG,MAAAA,QAAQ,kBAAElK,GAAG,CAACiE,EAAJ,CAAOgI,IAAT,iDAAE,aAAazD,IAFvB;AAGAyB,MAAAA,MAAM,mBAAEjK,GAAG,CAACiE,EAAJ,CAAOgI,IAAT,kDAAE,cAAaC;AAHrB,MArB0C;AA0B5CW,IAAAA,YAAY,eAAE7M,GAAG,CAAC8M,IAAN,8CAAE,UAAUD,YA1BoB;AA2B5CE,IAAAA,MAAM,gBAAE/M,GAAG,CAAC8M,IAAN,+CAAE,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\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[],\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: 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 mediumId: string,\n riderCategoryId: string\n): Money | undefined {\n const legCosts = legs\n .filter(leg => leg.fareProducts?.length > 0)\n .map(leg => getLegCost(leg, mediumId, riderCategoryId).price)\n .filter(cost => cost !== undefined);\n if (legCosts.length === 0) return undefined;\n return legCosts.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"}