@opentripplanner/core-utils 5.0.3-alpha.1 → 6.1.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/itinerary.ts"],"names":["transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","isContinuousDropoff","alightRule","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","polyline","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","maxTNCFare","minTNCFare","tncCurrencyCode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAWA;;AAEA;;AAwBA;AACO,MAAMA,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MA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AASmB,UAAT,CAAoB,MAApB,CAAJ,EAAiC2G,YAAY,IAAI1H,GAAG,CAAC4H,QAApB;AACjC,QAAI5H,GAAG,CAACJ,IAAJ,CAASmB,UAAT,CAAoB,SAApB,CAAJ,EAAoC4G,YAAY,IAAI3H,GAAG,CAAC4H,QAApB;AACrC,GAHD;AAIA,QAAMC,cAAc,GACjBH,YAAY,GAAG,IAAhB,GAAwB,GAAxB,GAA+BC,YAAY,GAAG,IAAhB,GAAwB,GADxD;AAEA,SAAO;AACLA,IAAAA,YADK;AAELE,IAAAA,cAFK;AAGLH,IAAAA;AAHK,GAAP;AAKD;;AAEM,SAASI,iBAAT,CAA2BhF,SAA3B,EAAsC;AAC3C;AACA;AACA,QAAM;AAAEiF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,MAA8C,gCAClDnF,SADkD,EAElD,IAFkD,CAApD;AAIA,SAAO;AAAEiF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,GAAP;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Step\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\nimport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n} from \"./deprecated\";\n\nexport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n};\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 of boardRule which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\";\n}\n/**\n * Returns true if the leg has continuous dropoff enabled which requires\n * asking the driver to let the user off. \"coordinateWithDriver\" is the only\n * property of alightRule which encodes this info.\n */\nexport function isContinuousDropoff(leg: Leg): boolean {\n return leg.alightRule === \"coordinateWithDriver\";\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) || isContinuousDropoff(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\nexport function calculateTncFares(itinerary) {\n // TODO: don't rely on deprecated methods!\n // At the moment this is safe as none of these exported variables contain strings\n const { maxTNCFare, minTNCFare, tncCurrencyCode } = calculateFares(\n itinerary,\n true\n );\n return { maxTNCFare, minTNCFare, tncCurrencyCode };\n}\n"],"file":"itinerary.js"}
1
+ {"version":3,"sources":["../src/itinerary.ts"],"names":["transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","isContinuousDropoff","alightRule","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","polyline","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","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","carbonIntensityWithDefaults","totalCarbon","reduce","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AAa,EAAE;AAfiB,CAAlC;AAkBA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,kBAAT,CACLhG,SADK,EAELiG,eAAuC,GAAG,EAFrC,EAGL5E,KAHK,EAIG;AAAA;;AACR;AACA,QAAM6E,2BAA2B,GAAG,EAClC,GAAGlB,yBAD+B;AAElC,OAAGiB;AAF+B,GAApC,CAFQ,CAOR;;AACA,QAAME,WAAW,GACf,CAAAnG,SAAS,SAAT,IAAAA,SAAS,WAAT,+BAAAA,SAAS,CAAEE,IAAX,oEAAiBkG,MAAjB,CAAwB,CAACC,KAAD,EAAQnJ,GAAR,KAAgB;AACtC,WACE,CAACA,GAAG,CAACgE,QAAJ,GAAegF,2BAA2B,CAAChJ,GAAG,CAACJ,IAAJ,CAASwC,WAAT,EAAD,CAA1C,IACC,CADF,IACO+G,KAFT;AAID,GALD,EAKG,CALH,MAKS,CANX;;AAQA,UAAQhF,KAAR;AACE,SAAK,OAAL;AACE,aAAO8E,WAAW,GAAG,KAArB;;AACF,SAAK,UAAL;AACE,aAAOA,WAAW,GAAG,IAArB;;AACF,SAAK,OAAL;AACE,aAAOA,WAAW,GAAG,GAArB;;AACF,SAAK,MAAL;AACA;AACE,aAAOA,WAAP;AATJ;AAWD;;AAEM,SAASG,iBAAT,CAA2BtG,SAA3B,EAAsC;AAC3C;AACA;AACA,QAAM;AAAEuG,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,MAA8C,gCAClDzG,SADkD,EAElD,IAFkD,CAApD;AAIA,SAAO;AAAEuG,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,GAAP;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Step\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\nimport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n} from \"./deprecated\";\n\nexport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n};\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 of boardRule which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\";\n}\n/**\n * Returns true if the leg has continuous dropoff enabled which requires\n * asking the driver to let the user off. \"coordinateWithDriver\" is the only\n * property of alightRule which encodes this info.\n */\nexport function isContinuousDropoff(leg: Leg): boolean {\n return leg.alightRule === \"coordinateWithDriver\";\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) || isContinuousDropoff(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 * 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\nexport function calculateTncFares(itinerary) {\n // TODO: don't rely on deprecated methods!\n // At the moment this is safe as none of these exported variables contain strings\n const { maxTNCFare, minTNCFare, tncCurrencyCode } = calculateFares(\n itinerary,\n true\n );\n return { maxTNCFare, minTNCFare, tncCurrencyCode };\n}\n"],"file":"itinerary.js"}
package/lib/map.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Company, Itinerary, LatLngArray, Leg, Location, TransitiveData, UserPosition } from "@opentripplanner/types";
1
+ import { LatLngArray, Location, UserPosition } from "@opentripplanner/types";
2
2
  import { coordsToString, getDetailText, latlngToString } from "./deprecated";
3
3
  export { coordsToString, getDetailText, latlngToString };
4
4
  export declare function currentPositionToLocation(currentPosition: UserPosition): Location;
@@ -9,15 +9,6 @@ export declare function constructLocation(latlng: {
9
9
  }): Location;
10
10
  export declare function formatStoredPlaceName(location: Location, withDetails?: boolean): string;
11
11
  export declare function matchLatLon(location1: Location, location2: Location): boolean;
12
- /**
13
- * Converts an OTP itinerary object to a transtive.js itinerary object.
14
- * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.
15
- * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.
16
- * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)
17
- * and returns a string representing the route label to display for that leg.
18
- * @returns An itinerary in the transitive.js format.
19
- */
20
- export declare function itineraryToTransitive(itin: Itinerary, companies: Company[], getRouteLabel: (leg: Leg) => string, disableFlexArc: boolean): TransitiveData;
21
12
  declare type TransitivePlaceRaw = {
22
13
  place_id: string;
23
14
  };
package/lib/map.d.ts.map CHANGED
@@ -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C,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAOvD"}
package/lib/map.js CHANGED
@@ -8,7 +8,6 @@ exports.stringToCoords = stringToCoords;
8
8
  exports.constructLocation = constructLocation;
9
9
  exports.formatStoredPlaceName = formatStoredPlaceName;
10
10
  exports.matchLatLon = matchLatLon;
11
- exports.itineraryToTransitive = itineraryToTransitive;
12
11
  exports.isBikeshareStation = isBikeshareStation;
13
12
  exports.isEScooterStation = isEScooterStation;
14
13
  exports.isCarWalkTransition = isCarWalkTransition;
@@ -81,224 +80,6 @@ function matchLatLon(location1, location2) {
81
80
  if (!location1 || !location2) return location1 === location2;
82
81
  return location1.lat === location2.lat && location1.lon === location2.lon;
83
82
  }
84
- /**
85
- * Converts an OTP itinerary object to a transtive.js itinerary object.
86
- * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.
87
- * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.
88
- * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)
89
- * and returns a string representing the route label to display for that leg.
90
- * @returns An itinerary in the transitive.js format.
91
- */
92
-
93
-
94
- function itineraryToTransitive(itin, companies, getRouteLabel, disableFlexArc) {
95
- const tdata = {
96
- journeys: [],
97
- streetEdges: [],
98
- places: [],
99
- patterns: [],
100
- routes: [],
101
- stops: []
102
- };
103
- const routes = {};
104
- const stops = {};
105
- let streetEdgeId = 0;
106
- let patternId = 0;
107
- const journey = {
108
- journey_id: "itin",
109
- // This string is not shown in the UI
110
- journey_name: "Iterarary-derived Journey",
111
- segments: []
112
- }; // add 'from' and 'to' places to the tdata places array
113
-
114
- tdata.places.push({
115
- place_id: "from",
116
- place_lat: itin.legs[0].from.lat,
117
- place_lon: itin.legs[0].from.lon
118
- });
119
- tdata.places.push({
120
- place_id: "to",
121
- place_lat: itin.legs[itin.legs.length - 1].to.lat,
122
- place_lon: itin.legs[itin.legs.length - 1].to.lon
123
- });
124
- itin.legs.forEach((leg, idx) => {
125
- if ((0, _itinerary.isAccessMode)(leg.mode)) {
126
- let fromPlaceId;
127
-
128
- if (leg.from.bikeShareId) {
129
- fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;
130
-
131
- if ( // OTP2 Scooter case
132
- leg.mode === "SCOOTER") {
133
- fromPlaceId = `escooter_rent_station_${leg.from.bikeShareId}`;
134
- }
135
- } else if (leg.from.vertexType === "VEHICLERENTAL") {
136
- // OTP1 Scooter case
137
- fromPlaceId = `escooter_rent_station_${leg.from.name}`;
138
- } else if (leg.mode === "CAR" && idx > 0 && itin.legs[idx - 1].mode === "WALK") {
139
- // create a special place ID for car legs preceded by walking legs
140
- fromPlaceId = `itin_car_${streetEdgeId}_from`;
141
- } else if (!fromPlaceId) {
142
- fromPlaceId = `itin_street_${streetEdgeId}_from`;
143
- }
144
-
145
- let toPlaceId;
146
-
147
- if (leg.to.bikeShareId) {
148
- var _itin$legs;
149
-
150
- toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`; // OTP2 scooter case
151
- // Need to check next leg since this is a "to" place "
152
-
153
- if (leg.mode === "SCOOTER" || ((_itin$legs = itin.legs) === null || _itin$legs === void 0 ? void 0 : _itin$legs[idx + 1].mode) === "SCOOTER") {
154
- toPlaceId = `escooter_rent_station_${leg.to.bikeShareId}`;
155
- }
156
- } else if (leg.to.vertexType === "VEHICLERENTAL") {
157
- toPlaceId = `escooter_rent_station_${leg.to.name}`;
158
- } else if (leg.mode === "CAR" && idx < itin.legs.length - 1 && itin.legs[idx + 1].mode === "WALK") {
159
- // create a special place ID for car legs followed by walking legs
160
- toPlaceId = `itin_car_${streetEdgeId}_to`;
161
- } else if (!toPlaceId) {
162
- toPlaceId = `itin_street_${streetEdgeId}_to`;
163
- }
164
-
165
- const segment = {
166
- arc: false,
167
- type: leg.mode,
168
- streetEdges: [streetEdgeId],
169
- from: {
170
- type: "PLACE",
171
- place_id: fromPlaceId
172
- },
173
- to: {
174
- type: "PLACE",
175
- place_id: toPlaceId
176
- }
177
- }; // For TNC segments, draw using an arc
178
-
179
- if (leg.mode === "CAR" && leg.hailedCar) segment.arc = true;
180
- journey.segments.push(segment);
181
- tdata.streetEdges.push({
182
- edge_id: streetEdgeId,
183
- geometry: leg.legGeometry
184
- });
185
- tdata.places.push({
186
- place_id: fromPlaceId,
187
- // Do not label the from place in addition to the to place. Otherwise,
188
- // in some cases (bike rental station) the label for a single place will
189
- // appear twice on the rendered transitive view.
190
- // See https://github.com/conveyal/trimet-mod-otp/issues/152
191
- // place_name: leg.from.name,
192
- place_lat: leg.from.lat,
193
- place_lon: leg.from.lon
194
- });
195
- tdata.places.push({
196
- place_id: toPlaceId,
197
- // This string is not shown in the UI
198
- place_name: (0, _itinerary.getPlaceName)(leg.to, companies),
199
- place_lat: leg.to.lat,
200
- place_lon: leg.to.lon
201
- });
202
- streetEdgeId++;
203
- }
204
-
205
- if ((0, _itinerary.isTransit)(leg.mode)) {
206
- var _leg$legGeometry;
207
-
208
- // Flex routes sometimes have the same from and to IDs, but
209
- // these stops still need to be rendered separately!
210
- if (leg.from.stopId === leg.to.stopId) {
211
- leg.to.stopId = `${leg.to.stopId}_flexed_to`;
212
- } // determine if we have valid inter-stop geometry
213
-
214
-
215
- const hasInterStopGeometry = !!leg.interStopGeometry;
216
- const hasLegGeometry = !!((_leg$legGeometry = leg.legGeometry) !== null && _leg$legGeometry !== void 0 && _leg$legGeometry.points);
217
- const hasIntermediateStopGeometry = hasInterStopGeometry && leg.intermediateStops && leg.interStopGeometry.length === leg.intermediateStops.length + 1; // create leg-specific pattern
218
-
219
- const ptnId = `ptn_${patternId}`;
220
- const pattern = {
221
- pattern_id: ptnId,
222
- // This string is not shown in the UI
223
- pattern_name: `Pattern ${patternId}`,
224
- route_id: leg.routeId,
225
- stops: []
226
- }; // add 'from' stop to stops dictionary and pattern object
227
-
228
- stops[leg.from.stopId] = {
229
- stop_id: leg.from.stopId,
230
- stop_name: leg.from.name,
231
- stop_lat: leg.from.lat,
232
- stop_lon: leg.from.lon
233
- };
234
- pattern.stops.push({
235
- stop_id: leg.from.stopId
236
- }); // add intermediate stops to stops dictionary and pattern object
237
- // If there is no intermediateStopGeometry, do not add the intermediate stops
238
- // as it will be straight lines instead of the nice legGeometry (but only if
239
- // the legGeometry exists).
240
-
241
- if (leg.intermediateStops && (hasIntermediateStopGeometry || !hasLegGeometry)) {
242
- leg.intermediateStops.forEach((stop, i) => {
243
- stops[stop.stopId] = {
244
- stop_id: stop.stopId,
245
- stop_name: stop.name,
246
- stop_lat: stop.lat,
247
- stop_lon: stop.lon
248
- };
249
- pattern.stops.push({
250
- stop_id: stop.stopId,
251
- geometry: hasIntermediateStopGeometry && leg.interStopGeometry[i].points
252
- });
253
- });
254
- } // add 'to' stop to stops dictionary and pattern object
255
-
256
-
257
- stops[leg.to.stopId] = {
258
- stop_id: leg.to.stopId,
259
- stop_name: leg.to.name,
260
- stop_lat: leg.to.lat,
261
- stop_lon: leg.to.lon
262
- };
263
- pattern.stops.push({
264
- stop_id: leg.to.stopId,
265
- geometry: // Some legs don't have intermediateStopGeometry, but do have valid legGeometry
266
- (hasInterStopGeometry || hasLegGeometry) && (hasIntermediateStopGeometry ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points : leg.legGeometry.points)
267
- }); // add route to the route dictionary
268
- // with a custom route label if specified.
269
-
270
- const routeLabel = typeof getRouteLabel === "function" ? getRouteLabel(leg) : leg.routeShortName;
271
- routes[leg.routeId] = {
272
- agency_id: leg.agencyId,
273
- route_id: leg.routeId,
274
- route_short_name: routeLabel || "",
275
- route_long_name: leg.routeLongName || "",
276
- route_type: leg.routeType,
277
- route_color: leg.routeColor
278
- }; // add the pattern to the tdata patterns array
279
-
280
- tdata.patterns.push(pattern); // add the pattern reference to the journey object
281
-
282
- journey.segments.push({
283
- arc: typeof disableFlexArc === "undefined" ? (0, _itinerary.isFlex)(leg) : !disableFlexArc,
284
- type: "TRANSIT",
285
- patterns: [{
286
- pattern_id: ptnId,
287
- from_stop_index: 0,
288
- to_stop_index: hasIntermediateStopGeometry ? leg.intermediateStops.length + 2 - 1 : 1
289
- }]
290
- });
291
- patternId++;
292
- }
293
- }); // add the routes and stops to the tdata arrays
294
-
295
- tdata.routes.push(...Object.values(routes));
296
- tdata.stops.push(...Object.values(stops)); // add the journey to the tdata journeys array
297
-
298
- tdata.journeys.push(journey); // console.log('derived tdata', tdata);
299
-
300
- return tdata;
301
- }
302
83
 
303
84
  function isBikeshareStation(place) {
304
85
  return place.place_id.lastIndexOf("bicycle_rent_station") !== -1;
package/lib/map.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/map.ts"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","stringToCoords","str","split","map","c","constructLocation","latlng","lng","formatStoredPlaceName","location","withDetails","displayName","type","name","detailText","matchLatLon","location1","location2","itineraryToTransitive","itin","companies","getRouteLabel","disableFlexArc","tdata","journeys","streetEdges","places","patterns","routes","stops","streetEdgeId","patternId","journey","journey_id","journey_name","segments","push","place_id","place_lat","legs","from","place_lon","length","to","forEach","leg","idx","mode","fromPlaceId","bikeShareId","vertexType","toPlaceId","segment","arc","hailedCar","edge_id","geometry","legGeometry","place_name","stopId","hasInterStopGeometry","interStopGeometry","hasLegGeometry","points","hasIntermediateStopGeometry","intermediateStops","ptnId","pattern","pattern_id","pattern_name","route_id","routeId","stop_id","stop_name","stop_lat","stop_lon","stop","i","routeLabel","routeShortName","agency_id","agencyId","route_short_name","route_long_name","routeLongName","route_type","routeType","route_color","routeColor","from_stop_index","to_stop_index","Object","values","isBikeshareStation","place","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;AAQA;;AASO,SAASA,yBAAT,CACLC,eADK,EAEK;AACV,MAAIA,eAA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,KAAP;AACD;;AAKM,SAASsE,kBAAT,CAA4BC,KAA5B,EAAgE;AACrE,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,sBAA3B,MAAuD,CAAC,CAA/D;AACD;;AAEM,SAASC,iBAAT,CAA2BF,KAA3B,EAA+D;AACpE,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,uBAA3B,MAAwD,CAAC,CAAhE;AACD;;AAEM,SAASE,mBAAT,CAA6BH,KAA7B,EAAiE;AACtE,SAAOA,KAAK,CAACzD,QAAN,CAAe0D,WAAf,CAA2B,WAA3B,MAA4C,CAAC,CAApD;AACD;;AAEM,SAASG,UAAT,CAAoBvG,GAApB,EAA0C;AAC/C,SAAOwG,MAAM,CAACC,QAAP,CAAgBzG,GAAhB,KAAwBA,GAAG,IAAI,CAAC,EAAhC,IAAsCA,GAAG,IAAI,EAApD;AACD;;AAEM,SAAS0G,UAAT,CAAoB9F,GAApB,EAA0C;AAC/C,SAAO4F,MAAM,CAACC,QAAP,CAAgB7F,GAAhB,KAAwBA,GAAG,IAAI,CAAC,GAAhC,IAAuCA,GAAG,IAAI,GAArD;AACD;;AAEM,SAAS+F,aAAT,CAAuBC,GAAvB,EAAkD;AACvD,SACEC,KAAK,CAACC,OAAN,CAAcF,GAAd,KACAA,GAAG,CAAC7D,MAAJ,KAAe,CADf,IAEAwD,UAAU,CAACK,GAAG,CAAC,CAAD,CAAJ,CAFV,IAGAF,UAAU,CAACE,GAAG,CAAC,CAAD,CAAJ,CAJZ;AAMD","sourcesContent":["import {\n Company,\n Itinerary,\n LatLngArray,\n Leg,\n Location,\n TransitiveData,\n UserPosition\n} from \"@opentripplanner/types\";\nimport {\n getPlaceName,\n isAccessMode,\n isFlex,\n isTransit,\n toSentenceCase\n} from \"./itinerary\";\n\nimport {\n coordsToString,\n getDetailText,\n latlngToString,\n logDeprecationWarning\n} from \"./deprecated\";\n\nexport { coordsToString, getDetailText, latlngToString };\n\nexport function currentPositionToLocation(\n currentPosition: UserPosition\n): Location {\n if (currentPosition.error || !currentPosition.coords) {\n console.warn(\n \"Cannot construct location from current position due to geolocation error or missing coordinates.\"\n );\n return null;\n }\n return {\n lat: currentPosition.coords.latitude,\n lon: currentPosition.coords.longitude,\n category: \"CURRENT_LOCATION\"\n };\n}\n\nexport function stringToCoords(str: string): number[] {\n return (str && str.split(\",\").map(c => +c)) || [];\n}\n\nexport function constructLocation(latlng: {\n lat: number;\n lng: number;\n}): Location {\n return {\n lat: latlng.lat,\n lon: latlng.lng\n };\n}\n\nexport function formatStoredPlaceName(\n location: Location,\n withDetails = true\n): string {\n if (withDetails) {\n logDeprecationWarning(\"the formatStoredPlaceName withDetails parameter\");\n }\n\n let displayName =\n location.type === \"home\" || location.type === \"work\"\n ? toSentenceCase(location.type)\n : location.name;\n if (withDetails) {\n const detailText = getDetailText(location);\n if (detailText) displayName += ` (${detailText})`;\n }\n return displayName;\n}\n\nexport function matchLatLon(location1: Location, location2: Location): boolean {\n if (!location1 || !location2) return location1 === location2;\n return location1.lat === location2.lat && location1.lon === location2.lon;\n}\n\n/**\n * Converts an OTP itinerary object to a transtive.js itinerary object.\n * @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.\n * @param {*} companies Optional list of companies, used for labeling vehicle rental locations.\n * @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)\n * and returns a string representing the route label to display for that leg.\n * @returns An itinerary in the transitive.js format.\n */\nexport function itineraryToTransitive(\n itin: Itinerary,\n companies: Company[],\n getRouteLabel: (leg: Leg) => string,\n disableFlexArc: boolean\n): TransitiveData {\n const tdata = {\n journeys: [],\n streetEdges: [],\n places: [],\n patterns: [],\n routes: [],\n stops: []\n };\n const routes = {};\n const stops = {};\n let streetEdgeId = 0;\n let patternId = 0;\n\n const journey = {\n journey_id: \"itin\",\n // This string is not shown in the UI\n journey_name: \"Iterarary-derived Journey\",\n segments: []\n };\n\n // add 'from' and 'to' places to the tdata places array\n tdata.places.push({\n place_id: \"from\",\n place_lat: itin.legs[0].from.lat,\n place_lon: itin.legs[0].from.lon\n });\n tdata.places.push({\n place_id: \"to\",\n place_lat: itin.legs[itin.legs.length - 1].to.lat,\n place_lon: itin.legs[itin.legs.length - 1].to.lon\n });\n\n itin.legs.forEach((leg, idx) => {\n if (isAccessMode(leg.mode)) {\n let fromPlaceId: string;\n if (leg.from.bikeShareId) {\n fromPlaceId = `bicycle_rent_station_${leg.from.bikeShareId}`;\n if (\n // OTP2 Scooter case\n leg.mode === \"SCOOTER\"\n ) {\n fromPlaceId = `escooter_rent_station_${leg.from.bikeShareId}`;\n }\n } else if (leg.from.vertexType === \"VEHICLERENTAL\") {\n // OTP1 Scooter case\n fromPlaceId = `escooter_rent_station_${leg.from.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx > 0 &&\n itin.legs[idx - 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs preceded by walking legs\n fromPlaceId = `itin_car_${streetEdgeId}_from`;\n } else if (!fromPlaceId) {\n fromPlaceId = `itin_street_${streetEdgeId}_from`;\n }\n\n let toPlaceId;\n if (leg.to.bikeShareId) {\n toPlaceId = `bicycle_rent_station_${leg.to.bikeShareId}`;\n // OTP2 scooter case\n // Need to check next leg since this is a \"to\" place \"\n if (leg.mode === \"SCOOTER\" || itin.legs?.[idx + 1].mode === \"SCOOTER\") {\n toPlaceId = `escooter_rent_station_${leg.to.bikeShareId}`;\n }\n } else if (leg.to.vertexType === \"VEHICLERENTAL\") {\n toPlaceId = `escooter_rent_station_${leg.to.name}`;\n } else if (\n leg.mode === \"CAR\" &&\n idx < itin.legs.length - 1 &&\n itin.legs[idx + 1].mode === \"WALK\"\n ) {\n // create a special place ID for car legs followed by walking legs\n toPlaceId = `itin_car_${streetEdgeId}_to`;\n } else if (!toPlaceId) {\n toPlaceId = `itin_street_${streetEdgeId}_to`;\n }\n\n const segment = {\n arc: false,\n type: leg.mode,\n streetEdges: [streetEdgeId],\n from: { type: \"PLACE\", place_id: fromPlaceId },\n to: { type: \"PLACE\", place_id: toPlaceId }\n };\n // For TNC segments, draw using an arc\n if (leg.mode === \"CAR\" && leg.hailedCar) segment.arc = true;\n journey.segments.push(segment);\n\n tdata.streetEdges.push({\n edge_id: streetEdgeId,\n geometry: leg.legGeometry\n });\n tdata.places.push({\n place_id: fromPlaceId,\n // Do not label the from place in addition to the to place. Otherwise,\n // in some cases (bike rental station) the label for a single place will\n // appear twice on the rendered transitive view.\n // See https://github.com/conveyal/trimet-mod-otp/issues/152\n // place_name: leg.from.name,\n place_lat: leg.from.lat,\n place_lon: leg.from.lon\n });\n tdata.places.push({\n place_id: toPlaceId,\n // This string is not shown in the UI\n place_name: getPlaceName(leg.to, companies),\n place_lat: leg.to.lat,\n place_lon: leg.to.lon\n });\n streetEdgeId++;\n }\n\n if (isTransit(leg.mode)) {\n // Flex routes sometimes have the same from and to IDs, but\n // these stops still need to be rendered separately!\n if (leg.from.stopId === leg.to.stopId) {\n leg.to.stopId = `${leg.to.stopId}_flexed_to`;\n }\n // determine if we have valid inter-stop geometry\n const hasInterStopGeometry = !!leg.interStopGeometry;\n const hasLegGeometry = !!leg.legGeometry?.points;\n const hasIntermediateStopGeometry =\n hasInterStopGeometry &&\n leg.intermediateStops &&\n leg.interStopGeometry.length === leg.intermediateStops.length + 1;\n\n // create leg-specific pattern\n const ptnId = `ptn_${patternId}`;\n const pattern = {\n pattern_id: ptnId,\n // This string is not shown in the UI\n pattern_name: `Pattern ${patternId}`,\n route_id: leg.routeId,\n stops: []\n };\n\n // add 'from' stop to stops dictionary and pattern object\n stops[leg.from.stopId] = {\n stop_id: leg.from.stopId,\n stop_name: leg.from.name,\n stop_lat: leg.from.lat,\n stop_lon: leg.from.lon\n };\n pattern.stops.push({ stop_id: leg.from.stopId });\n\n // add intermediate stops to stops dictionary and pattern object\n // If there is no intermediateStopGeometry, do not add the intermediate stops\n // as it will be straight lines instead of the nice legGeometry (but only if\n // the legGeometry exists).\n if (\n leg.intermediateStops &&\n (hasIntermediateStopGeometry || !hasLegGeometry)\n ) {\n leg.intermediateStops.forEach((stop, i) => {\n stops[stop.stopId] = {\n stop_id: stop.stopId,\n stop_name: stop.name,\n stop_lat: stop.lat,\n stop_lon: stop.lon\n };\n pattern.stops.push({\n stop_id: stop.stopId,\n geometry:\n hasIntermediateStopGeometry && leg.interStopGeometry[i].points\n });\n });\n }\n\n // add 'to' stop to stops dictionary and pattern object\n stops[leg.to.stopId] = {\n stop_id: leg.to.stopId,\n stop_name: leg.to.name,\n stop_lat: leg.to.lat,\n stop_lon: leg.to.lon\n };\n pattern.stops.push({\n stop_id: leg.to.stopId,\n geometry:\n // Some legs don't have intermediateStopGeometry, but do have valid legGeometry\n (hasInterStopGeometry || hasLegGeometry) &&\n (hasIntermediateStopGeometry\n ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points\n : leg.legGeometry.points)\n });\n\n // add route to the route dictionary\n // with a custom route label if specified.\n const routeLabel =\n typeof getRouteLabel === \"function\"\n ? getRouteLabel(leg)\n : leg.routeShortName;\n routes[leg.routeId] = {\n agency_id: leg.agencyId,\n route_id: leg.routeId,\n route_short_name: routeLabel || \"\",\n route_long_name: leg.routeLongName || \"\",\n route_type: leg.routeType,\n route_color: leg.routeColor\n };\n\n // add the pattern to the tdata patterns array\n tdata.patterns.push(pattern);\n\n // add the pattern reference to the journey object\n journey.segments.push({\n arc:\n typeof disableFlexArc === \"undefined\" ? isFlex(leg) : !disableFlexArc,\n type: \"TRANSIT\",\n patterns: [\n {\n pattern_id: ptnId,\n from_stop_index: 0,\n to_stop_index: hasIntermediateStopGeometry\n ? leg.intermediateStops.length + 2 - 1\n : 1\n }\n ]\n });\n\n patternId++;\n }\n });\n\n // add the routes and stops to the tdata arrays\n tdata.routes.push(...Object.values(routes));\n tdata.stops.push(...Object.values(stops));\n\n // add the journey to the tdata journeys array\n tdata.journeys.push(journey);\n\n // console.log('derived tdata', tdata);\n return tdata;\n}\n\ntype TransitivePlaceRaw = {\n place_id: string;\n};\nexport function isBikeshareStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"bicycle_rent_station\") !== -1;\n}\n\nexport function isEScooterStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"escooter_rent_station\") !== -1;\n}\n\nexport function isCarWalkTransition(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"itin_car_\") !== -1;\n}\n\nexport function isValidLat(lat: number): boolean {\n return Number.isFinite(lat) && lat >= -90 && lat <= 90;\n}\n\nexport function isValidLng(lng: number): boolean {\n return Number.isFinite(lng) && lng >= -180 && lng <= 180;\n}\n\nexport function isValidLatLng(arr: LatLngArray): boolean {\n return (\n Array.isArray(arr) &&\n arr.length === 2 &&\n isValidLat(arr[0]) &&\n isValidLng(arr[1])\n );\n}\n"],"file":"map.js"}
1
+ {"version":3,"sources":["../src/map.ts"],"names":["currentPositionToLocation","currentPosition","error","coords","console","warn","lat","latitude","lon","longitude","category","stringToCoords","str","split","map","c","constructLocation","latlng","lng","formatStoredPlaceName","location","withDetails","displayName","type","name","detailText","matchLatLon","location1","location2","isBikeshareStation","place","place_id","lastIndexOf","isEScooterStation","isCarWalkTransition","isValidLat","Number","isFinite","isValidLng","isValidLatLng","arr","Array","isArray","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAEA;;AASO,SAASA,yBAAT,CACLC,eADK,EAEK;AACV,MAAIA,eAAe,CAACC,KAAhB,IAAyB,CAACD,eAAe,CAACE,MAA9C,EAAsD;AACpDC,IAAAA,OAAO,CAACC,IAAR,CACE,kGADF;AAGA,WAAO,IAAP;AACD;;AACD,SAAO;AACLC,IAAAA,GAAG,EAAEL,eAAe,CAACE,MAAhB,CAAuBI,QADvB;AAELC,IAAAA,GAAG,EAAEP,eAAe,CAACE,MAAhB,CAAuBM,SAFvB;AAGLC,IAAAA,QAAQ,EAAE;AAHL,GAAP;AAKD;;AAEM,SAASC,cAAT,CAA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,uBAA3B,MAAwD,CAAC,CAAhE;AACD;;AAEM,SAASE,mBAAT,CAA6BJ,KAA7B,EAAiE;AACtE,SAAOA,KAAK,CAACC,QAAN,CAAeC,WAAf,CAA2B,WAA3B,MAA4C,CAAC,CAApD;AACD;;AAEM,SAASG,UAAT,CAAoB7B,GAApB,EAA0C;AAC/C,SAAO8B,MAAM,CAACC,QAAP,CAAgB/B,GAAhB,KAAwBA,GAAG,IAAI,CAAC,EAAhC,IAAsCA,GAAG,IAAI,EAApD;AACD;;AAEM,SAASgC,UAAT,CAAoBpB,GAApB,EAA0C;AAC/C,SAAOkB,MAAM,CAACC,QAAP,CAAgBnB,GAAhB,KAAwBA,GAAG,IAAI,CAAC,GAAhC,IAAuCA,GAAG,IAAI,GAArD;AACD;;AAEM,SAASqB,aAAT,CAAuBC,GAAvB,EAAkD;AACvD,SACEC,KAAK,CAACC,OAAN,CAAcF,GAAd,KACAA,GAAG,CAACG,MAAJ,KAAe,CADf,IAEAR,UAAU,CAACK,GAAG,CAAC,CAAD,CAAJ,CAFV,IAGAF,UAAU,CAACE,GAAG,CAAC,CAAD,CAAJ,CAJZ;AAMD","sourcesContent":["import { LatLngArray, Location, UserPosition } from \"@opentripplanner/types\";\nimport { toSentenceCase } from \"./itinerary\";\n\nimport {\n coordsToString,\n getDetailText,\n latlngToString,\n logDeprecationWarning\n} from \"./deprecated\";\n\nexport { coordsToString, getDetailText, latlngToString };\n\nexport function currentPositionToLocation(\n currentPosition: UserPosition\n): Location {\n if (currentPosition.error || !currentPosition.coords) {\n console.warn(\n \"Cannot construct location from current position due to geolocation error or missing coordinates.\"\n );\n return null;\n }\n return {\n lat: currentPosition.coords.latitude,\n lon: currentPosition.coords.longitude,\n category: \"CURRENT_LOCATION\"\n };\n}\n\nexport function stringToCoords(str: string): number[] {\n return (str && str.split(\",\").map(c => +c)) || [];\n}\n\nexport function constructLocation(latlng: {\n lat: number;\n lng: number;\n}): Location {\n return {\n lat: latlng.lat,\n lon: latlng.lng\n };\n}\n\nexport function formatStoredPlaceName(\n location: Location,\n withDetails = true\n): string {\n if (withDetails) {\n logDeprecationWarning(\"the formatStoredPlaceName withDetails parameter\");\n }\n\n let displayName =\n location.type === \"home\" || location.type === \"work\"\n ? toSentenceCase(location.type)\n : location.name;\n if (withDetails) {\n const detailText = getDetailText(location);\n if (detailText) displayName += ` (${detailText})`;\n }\n return displayName;\n}\n\nexport function matchLatLon(location1: Location, location2: Location): boolean {\n if (!location1 || !location2) return location1 === location2;\n return location1.lat === location2.lat && location1.lon === location2.lon;\n}\n\ntype TransitivePlaceRaw = {\n place_id: string;\n};\nexport function isBikeshareStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"bicycle_rent_station\") !== -1;\n}\n\nexport function isEScooterStation(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"escooter_rent_station\") !== -1;\n}\n\nexport function isCarWalkTransition(place: TransitivePlaceRaw): boolean {\n return place.place_id.lastIndexOf(\"itin_car_\") !== -1;\n}\n\nexport function isValidLat(lat: number): boolean {\n return Number.isFinite(lat) && lat >= -90 && lat <= 90;\n}\n\nexport function isValidLng(lng: number): boolean {\n return Number.isFinite(lng) && lng >= -180 && lng <= 180;\n}\n\nexport function isValidLatLng(arr: LatLngArray): boolean {\n return (\n Array.isArray(arr) &&\n arr.length === 2 &&\n isValidLat(arr[0]) &&\n isValidLng(arr[1])\n );\n}\n"],"file":"map.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentripplanner/core-utils",
3
- "version": "5.0.3-alpha.1",
3
+ "version": "6.1.0",
4
4
  "description": "Core functionality that is shared among numerous UI components",
5
5
  "engines": {
6
6
  "node": ">=13"
package/src/itinerary.ts CHANGED
@@ -445,6 +445,70 @@ export function calculatePhysicalActivity(
445
445
  };
446
446
  }
447
447
 
448
+ /**
449
+ * Sources:
450
+ * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf
451
+ * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey
452
+ * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx
453
+ * Other values extrapolated.
454
+ */
455
+ const CARBON_INTENSITY_DEFAULTS = {
456
+ walk: 0.026,
457
+ bicycle: 0.017,
458
+ car: 0.162,
459
+ tram: 0.066,
460
+ subway: 0.066,
461
+ rail: 0.066,
462
+ bus: 0.09,
463
+ ferry: 0.082,
464
+ cable_car: 0.021,
465
+ gondola: 0.021,
466
+ funicular: 0.066,
467
+ transit: 0.066,
468
+ leg_switch: 0,
469
+ airplane: 0.382,
470
+ micromobility: 0.095
471
+ };
472
+
473
+ /**
474
+ * @param {itinerary} itinerary OTP trip itinierary
475
+ * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
476
+ * @param {units} units units to be used in return value
477
+ * @return Amount of carbon in chosen unit
478
+ */
479
+ export function calculateEmissions(
480
+ itinerary: Itinerary,
481
+ carbonIntensity: Record<string, number> = {},
482
+ units?: string
483
+ ): number {
484
+ // Apply defaults for any values that we don't have.
485
+ const carbonIntensityWithDefaults = {
486
+ ...CARBON_INTENSITY_DEFAULTS,
487
+ ...carbonIntensity
488
+ };
489
+
490
+ // Distance is in meters, totalCarbon is in grams
491
+ const totalCarbon =
492
+ itinerary?.legs?.reduce((total, leg) => {
493
+ return (
494
+ (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||
495
+ 0) + total
496
+ );
497
+ }, 0) || 0;
498
+
499
+ switch (units) {
500
+ case "ounce":
501
+ return totalCarbon / 28.35;
502
+ case "kilogram":
503
+ return totalCarbon / 1000;
504
+ case "pound":
505
+ return totalCarbon / 454;
506
+ case "gram":
507
+ default:
508
+ return totalCarbon;
509
+ }
510
+ }
511
+
448
512
  export function calculateTncFares(itinerary) {
449
513
  // TODO: don't rely on deprecated methods!
450
514
  // At the moment this is safe as none of these exported variables contain strings