@opentripplanner/core-utils 9.0.0-alpha.3 → 9.0.0-alpha.5
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 +4 -3
- package/esm/itinerary.js.map +1 -1
- package/esm/query-gen.js +62 -16
- package/esm/query-gen.js.map +1 -1
- package/lib/itinerary.d.ts +7 -7
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +4 -3
- package/lib/itinerary.js.map +1 -1
- package/lib/query-gen.d.ts +25 -3
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +55 -14
- package/lib/query-gen.js.map +1 -1
- package/package.json +3 -4
- package/src/__tests__/query-params.js +61 -2
- package/src/itinerary.ts +14 -8
- package/src/planQuery.graphql +39 -1
- package/src/query-gen.ts +101 -47
- package/tsconfig.tsbuildinfo +1 -1
package/esm/itinerary.js
CHANGED
|
@@ -462,13 +462,14 @@ var CARBON_INTENSITY_DEFAULTS = {
|
|
|
462
462
|
micromobility: 0.095
|
|
463
463
|
};
|
|
464
464
|
/**
|
|
465
|
-
* @param
|
|
466
|
-
* @param
|
|
465
|
+
* @param {itinerary} itinerary OTP trip itinierary, only legs is required.
|
|
466
|
+
* @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
|
|
467
467
|
* @param {units} units units to be used in return value
|
|
468
468
|
* @return Amount of carbon in chosen unit
|
|
469
469
|
*/
|
|
470
470
|
|
|
471
|
-
export function calculateEmissions(
|
|
471
|
+
export function calculateEmissions( // This type makes all the properties from Itinerary optional except legs.
|
|
472
|
+
itinerary) {
|
|
472
473
|
var _itinerary$legs;
|
|
473
474
|
|
|
474
475
|
var carbonIntensity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
package/esm/itinerary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/itinerary.ts"],"names":["polyline","turfAlong","transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","alightRule","isCoordinationRequired","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","hailedCar","reduce","maxTNCFare","minTNCFare","currency","maxCost","minCost","currencyCode","getTransitFare","fareComponent","transitFare","cents","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","carbonIntensityWithDefaults","totalCarbon","total","getDisplayedStopId","placeOrStop","stopId","stopCode","code"],"mappings":";;;;;;;AAAA,OAAOA,QAAP,MAAqB,kBAArB;AAeA,OAAOC,SAAP,MAAsB,aAAtB,C,CAEA;;AACA,OAAO,IAAMC,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MAL0B,EAM1B,SAN0B,CAArB;AASP;AACA;AACA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C,WAA5B,EAA+D;AAAA;;AACpE,MAAIC,MAAJ;AACA,MAAIC,QAAJ;;AACA,MAAI,YAAYF,WAAhB,EAA6B;AACxBE,IAAAA,QADwB,GACHF,WADG,CACxBE,QADwB;AACdD,IAAAA,MADc,GACHD,WADG,CACdC,MADc;AAE5B,GAFD,MAEO,IAAI,QAAQD,WAAZ,EAAyB;AACrBE,IAAAA,QADqB,GACIF,WADJ,CAC3BG,IAD2B;AACPF,IAAAA,MADO,GACID,WADJ,CACXlD,EADW;AAE/B;;AACD,SAAOoD,QAAQ,gBAAID,MAAJ,4CAAI,QAAQ7I,KAAR,CAAc,GAAd,EAAmB,CAAnB,CAAJ,CAAR,IAAqC6I,MAA5C;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Money,\n Place,\n Step,\n Stop,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\" || leg.alightRule === \"mustPhone\";\n}\n/**\n * Returns true if a user must ask the driver to let the user off\n * or if the user must flag the driver down for pickup.\n * \"coordinateWithDriver\" in board/alight rule encodes this info.\n */\nexport function isCoordinationRequired(leg: Leg): boolean {\n return (\n leg.boardRule === \"coordinateWithDriver\" ||\n leg.alightRule === \"coordinateWithDriver\"\n );\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isCoordinationRequired(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[][] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string[],\n companies: Company[] = []\n): string {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: Itinerary\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(itinerary: Itinerary): TncFare {\n return itinerary.legs\n .filter(leg => leg.mode === \"CAR\" && leg.hailedCar && leg.tncData)\n .reduce(\n ({ maxTNCFare, minTNCFare }, { tncData }) => {\n const { currency, maxCost, minCost } = tncData;\n return {\n // Assumes a single currency for entire itinerary.\n currencyCode: currency,\n maxTNCFare: maxTNCFare + maxCost,\n minTNCFare: minTNCFare + minCost\n };\n },\n {\n currencyCode: null,\n maxTNCFare: 0,\n minTNCFare: 0\n }\n );\n}\n\n/**\n * For a given fare component (either total fare or component parts), returns\n * an object with the fare value (in cents).\n */\nexport function getTransitFare(\n fareComponent: Money\n): {\n currencyCode: string;\n transitFare: number;\n} {\n return fareComponent\n ? {\n currencyCode: fareComponent.currency.currencyCode,\n transitFare: fareComponent.cents\n }\n : {\n currencyCode: \"USD\",\n transitFare: 0\n };\n}\n\n/**\n * Sources:\n * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf\n * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey\n * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx\n * Other values extrapolated.\n */\nconst CARBON_INTENSITY_DEFAULTS = {\n walk: 0.026,\n bicycle: 0.017,\n car: 0.162,\n tram: 0.066,\n subway: 0.066,\n rail: 0.066,\n bus: 0.09,\n ferry: 0.082,\n cable_car: 0.021,\n gondola: 0.021,\n funicular: 0.066,\n transit: 0.066,\n leg_switch: 0,\n airplane: 0.382,\n micromobility: 0.095\n};\n\n/**\n * @param {itinerary} itinerary OTP trip itinierary\n * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter\n * @param {units} units units to be used in return value\n * @return Amount of carbon in chosen unit\n */\nexport function calculateEmissions(\n itinerary: Itinerary,\n carbonIntensity: Record<string, number> = {},\n units?: string\n): number {\n // Apply defaults for any values that we don't have.\n const carbonIntensityWithDefaults = {\n ...CARBON_INTENSITY_DEFAULTS,\n ...carbonIntensity\n };\n\n // Distance is in meters, totalCarbon is in grams\n const totalCarbon =\n itinerary?.legs?.reduce((total, leg) => {\n return (\n (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||\n 0) + total\n );\n }, 0) || 0;\n\n switch (units) {\n case \"ounce\":\n return totalCarbon / 28.35;\n case \"kilogram\":\n return totalCarbon / 1000;\n case \"pound\":\n return totalCarbon / 454;\n case \"gram\":\n default:\n return totalCarbon;\n }\n}\n\n/**\n * Returns the user-facing stop id to display for a stop or place, using the following priority:\n * 1. stop code,\n * 2. stop id without the agency id portion, if stop id contains an agency portion,\n * 3. stop id, whether null or not (this is the fallback case).\n */\nexport function getDisplayedStopId(placeOrStop: Place | Stop): string {\n let stopId;\n let stopCode;\n if (\"stopId\" in placeOrStop) {\n ({ stopCode, stopId } = placeOrStop);\n } else if (\"id\" in placeOrStop) {\n ({ code: stopCode, id: stopId } = placeOrStop);\n }\n return stopCode || stopId?.split(\":\")[1] || stopId;\n}\n"],"file":"itinerary.js"}
|
|
1
|
+
{"version":3,"sources":["../src/itinerary.ts"],"names":["polyline","turfAlong","transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","alightRule","isCoordinationRequired","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","hailedCar","reduce","maxTNCFare","minTNCFare","currency","maxCost","minCost","currencyCode","getTransitFare","fareComponent","transitFare","cents","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","carbonIntensityWithDefaults","totalCarbon","total","getDisplayedStopId","placeOrStop","stopId","stopCode","code"],"mappings":";;;;;;;AAAA,OAAOA,QAAP,MAAqB,kBAArB;AAgBA,OAAOC,SAAP,MAAsB,aAAtB,C,CAEA;;AACA,OAAO,IAAMC,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MAL0B,EAM1B,SAN0B,CAArB;AASP;AACA;AACA;AACA;;AAEA,OAAO,SAASC,eAAT,CAAyBC,MAAzB,EAAmD;AACxD,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACC,KAAnB,IAA4B,CAACD,MAAM,CAACC,KAAP,CAAaH,YAA9C,EACE,OAAOA,YAAP;AAEF,SAAOE,MAAM,CAACC,KAAP,CAAaH,YAAb,CAA0BI,GAA1B,CAA8B,UAAAC,EAAE;AAAA,WACrC,OAAOA,EAAP,KAAc,QAAd,GAAyBA,EAAE,CAACC,IAA5B,GAAmCD,EADE;AAAA,GAAhC,CAAP;AAGD;AAED,OAAO,SAASE,SAAT,CAAmBD,IAAnB,EAA0C;AAC/C,SAAON,YAAY,CAACQ,QAAb,CAAsBF,IAAtB,KAA+BA,IAAI,KAAK,SAA/C;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,qBAAT,CAA+BC,GAA/B,EAAkD;AACvD,SAAOA,GAAG,CAACC,SAAJ,KAAkB,WAAlB,IAAiCD,GAAG,CAACE,UAAJ,KAAmB,WAA3D;AACD;AACD;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,sBAAT,CAAgCH,GAAhC,EAAmD;AACxD,SACE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,CAAwB,UAAC+B,KAAD,EAAQ9J,GAAR,EAAgB;AACtC,WACE,CAACA,GAAG,CAAC+D,QAAJ,GAAe6F,2BAA2B,CAAC5J,GAAG,CAACJ,IAAJ,CAASwC,WAAT,EAAD,CAA1C,IACC,CADF,IACO0H,KAFT;AAID,GALD,EAKG,CALH,MAKS,CANX;;AAQA,UAAQ5F,KAAR;AACE,SAAK,OAAL;AACE,aAAO2F,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;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,kBAAT,CAA4BC,WAA5B,EAA+D;AAAA;;AACpE,MAAIC,MAAJ;AACA,MAAIC,QAAJ;;AACA,MAAI,YAAYF,WAAhB,EAA6B;AACxBE,IAAAA,QADwB,GACHF,WADG,CACxBE,QADwB;AACdD,IAAAA,MADc,GACHD,WADG,CACdC,MADc;AAE5B,GAFD,MAEO,IAAI,QAAQD,WAAZ,EAAyB;AACrBE,IAAAA,QADqB,GACIF,WADJ,CAC3BG,IAD2B;AACPF,IAAAA,MADO,GACID,WADJ,CACXlD,EADW;AAE/B;;AACD,SAAOoD,QAAQ,gBAAID,MAAJ,4CAAI,QAAQ7I,KAAR,CAAc,GAAd,EAAmB,CAAnB,CAAJ,CAAR,IAAqC6I,MAA5C;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n 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"],"file":"itinerary.js"}
|
package/esm/query-gen.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
3
|
|
|
3
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
5
|
|
|
@@ -6,8 +7,44 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
7
|
|
|
7
8
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
8
9
|
import { print } from "graphql";
|
|
9
|
-
var PlanQuery = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "PlanQuery" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "fromPlace" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "toPlace" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "modes" } }, type: { kind: "ListType", type: { kind: "NamedType", name: { kind: "Name", value: "TransportMode" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "time" } }, type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "date" } }, type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "wheelchair" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Boolean" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "bikeReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "carReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "walkReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "arriveBy" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Boolean" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "intermediatePlaces" } }, type: { kind: "ListType", type: { kind: "NamedType", name: { kind: "Name", value: "InputCoordinates" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "preferred" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputPreferred" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "unpreferred" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputUnpreferred" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "banned" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputBanned" } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "plan" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "fromPlace" }, value: { kind: "Variable", name: { kind: "Name", value: "fromPlace" } } }, { kind: "Argument", name: { kind: "Name", value: "toPlace" }, value: { kind: "Variable", name: { kind: "Name", value: "toPlace" } } }, { kind: "Argument", name: { kind: "Name", value: "transportModes" }, value: { kind: "Variable", name: { kind: "Name", value: "modes" } } }, { kind: "Argument", name: { kind: "Name", value: "locale" }, value: { kind: "StringValue", value: "en", block: false } }, { kind: "Argument", name: { kind: "Name", value: "time" }, value: { kind: "Variable", name: { kind: "Name", value: "time" } } }, { kind: "Argument", name: { kind: "Name", value: "date" }, value: { kind: "Variable", name: { kind: "Name", value: "date" } } }, { kind: "Argument", name: { kind: "Name", value: "wheelchair" }, value: { kind: "Variable", name: { kind: "Name", value: "wheelchair" } } }, { kind: "Argument", name: { kind: "Name", value: "bikeReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "bikeReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "carReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "carReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "walkReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "walkReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "arriveBy" }, value: { kind: "Variable", name: { kind: "Name", value: "arriveBy" } } }, { kind: "Argument", name: { kind: "Name", value: "intermediatePlaces" }, value: { kind: "Variable", name: { kind: "Name", value: "intermediatePlaces" } } }, { kind: "Argument", name: { kind: "Name", value: "preferred" }, value: { kind: "Variable", name: { kind: "Name", value: "preferred" } } }, { kind: "Argument", name: { kind: "Name", value: "unpreferred" }, value: { kind: "Variable", name: { kind: "Name", value: "unpreferred" } } }, { kind: "Argument", name: { kind: "Name", value: "banned" }, value: { kind: "Variable", name: { kind: "Name", value: "banned" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "itineraries" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "duration" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "endTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "startTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "waitingTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "walkTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "legs" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "duration" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "endTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "mode" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "realTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "realtimeState" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "startTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "transitLeg" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "agency" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "timezone" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "legGeometry" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "length" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "points" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "intermediateStops" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", alias: { kind: "Name", value: "stopCode" }, name: { kind: "Name", value: "code" }, arguments: [], directives: [] }, { kind: "Field", alias: { kind: "Name", value: "stopId" }, name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "locationType" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "route" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "shortName" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "color" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "textColor" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "from" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "vertexType" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stop" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "code" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "to" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "vertexType" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stop" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "code" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "steps" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "elevationProfile" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "elevation" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }] } }], loc: { start: 0, end: 1587, source: { body: "query PlanQuery(\n\t$fromPlace: String!,\n\t$toPlace: String!,\n\t$modes: [TransportMode],\n\t$time: String,\n\t$date: String,\n\t$wheelchair: Boolean,\n\t$bikeReluctance: Float,\n\t$carReluctance: Float,\n\t$walkReluctance: Float,\n\t$arriveBy: Boolean,\n\t$intermediatePlaces: [InputCoordinates],\n\t$preferred: InputPreferred,\n\t$unpreferred: InputUnpreferred,\n\t$banned: InputBanned,\n) {\n\tplan(\n\t\tfromPlace: $fromPlace\n\t\ttoPlace: $toPlace\n\t\ttransportModes: $modes\n\t\tlocale: \"en\",\n\t\ttime: $time,\n\t\tdate: $date,\n\t\twheelchair: $wheelchair,\n\t\tbikeReluctance: $bikeReluctance,\n\t\tcarReluctance: $carReluctance,\n\t\twalkReluctance: $walkReluctance,\n\t\tarriveBy: $arriveBy,\n\t\tintermediatePlaces: $intermediatePlaces,\n\t\tpreferred: $preferred,\n\t\tunpreferred: $unpreferred,\n\t\tbanned: $banned,\n\t) {\n\t\titineraries {\n\t\t\tduration\n\t\t\tendTime\n\t\t\tstartTime\n\t\t\twaitingTime\n\t\t\twalkTime\n\t\t\tlegs {\n\t\t\t\tdistance\n\t\t\t\tduration\n\t\t\t\tendTime\n\t\t\t\tmode\n\t\t\t\trealTime\n\t\t\t\trealtimeState\t\n\t\t\t\tstartTime\n\t\t\t\ttransitLeg\n\t\t\t\tagency {\n\t\t\t\t\tname\n\t\t\t\t\tid\n\t\t\t\t\ttimezone\n\t\t\t\t\turl\n\t\t\t\t}\n\t\t\t\tlegGeometry {\n\t\t\t\t\tlength\n\t\t\t\t\tpoints\n\t\t\t\t}\n\t\t\t\tintermediateStops {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tstopCode: code\n\t\t\t\t\tstopId: id\n\t\t\t\t\tlocationType\n\t\t\t\t}\n\t\t\t\troute {\n\t\t\t\t\tshortName\n\t\t\t\t\tcolor\n\t\t\t\t\ttextColor\n\t\t\t\t\tid\n\t\t\t\t\ttype\n\t\t\t\t}\n\t\t\t\tfrom {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tvertexType\n\t\t\t\t\tstop {\n\t\t\t\t\t\tid\n\t\t\t\t\t\tcode\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tto {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tvertexType\n\t\t\t\t\tstop {\n\t\t\t\t\t\tid\n\t\t\t\t\t\tcode\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsteps {\n\t\t\t\t\tdistance\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\televationProfile {\n\t\t\t\t\t\tdistance\n\t\t\t\t\t\televation\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
10
|
+
var PlanQuery = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "PlanQuery" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "fromPlace" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "toPlace" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "modes" } }, type: { kind: "ListType", type: { kind: "NamedType", name: { kind: "Name", value: "TransportMode" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "time" } }, type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "date" } }, type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "wheelchair" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Boolean" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "bikeReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "carReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "walkReluctance" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Float" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "arriveBy" } }, type: { kind: "NamedType", name: { kind: "Name", value: "Boolean" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "intermediatePlaces" } }, type: { kind: "ListType", type: { kind: "NamedType", name: { kind: "Name", value: "InputCoordinates" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "preferred" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputPreferred" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "unpreferred" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputUnpreferred" } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "banned" } }, type: { kind: "NamedType", name: { kind: "Name", value: "InputBanned" } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "plan" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "fromPlace" }, value: { kind: "Variable", name: { kind: "Name", value: "fromPlace" } } }, { kind: "Argument", name: { kind: "Name", value: "toPlace" }, value: { kind: "Variable", name: { kind: "Name", value: "toPlace" } } }, { kind: "Argument", name: { kind: "Name", value: "transportModes" }, value: { kind: "Variable", name: { kind: "Name", value: "modes" } } }, { kind: "Argument", name: { kind: "Name", value: "locale" }, value: { kind: "StringValue", value: "en", block: false } }, { kind: "Argument", name: { kind: "Name", value: "time" }, value: { kind: "Variable", name: { kind: "Name", value: "time" } } }, { kind: "Argument", name: { kind: "Name", value: "date" }, value: { kind: "Variable", name: { kind: "Name", value: "date" } } }, { kind: "Argument", name: { kind: "Name", value: "wheelchair" }, value: { kind: "Variable", name: { kind: "Name", value: "wheelchair" } } }, { kind: "Argument", name: { kind: "Name", value: "bikeReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "bikeReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "carReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "carReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "walkReluctance" }, value: { kind: "Variable", name: { kind: "Name", value: "walkReluctance" } } }, { kind: "Argument", name: { kind: "Name", value: "arriveBy" }, value: { kind: "Variable", name: { kind: "Name", value: "arriveBy" } } }, { kind: "Argument", name: { kind: "Name", value: "intermediatePlaces" }, value: { kind: "Variable", name: { kind: "Name", value: "intermediatePlaces" } } }, { kind: "Argument", name: { kind: "Name", value: "preferred" }, value: { kind: "Variable", name: { kind: "Name", value: "preferred" } } }, { kind: "Argument", name: { kind: "Name", value: "unpreferred" }, value: { kind: "Variable", name: { kind: "Name", value: "unpreferred" } } }, { kind: "Argument", name: { kind: "Name", value: "banned" }, value: { kind: "Variable", name: { kind: "Name", value: "banned" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "itineraries" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "duration" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "endTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "startTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "waitingTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "walkTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "legs" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "duration" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "endTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "mode" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "realTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "realtimeState" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "startTime" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "transitLeg" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "trip" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "gtfsId" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "agency" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "timezone" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alerts" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "alertHeaderText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertDescriptionText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertUrl" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "effectiveStartDate" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "legGeometry" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "length" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "points" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "intermediateStops" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", alias: { kind: "Name", value: "stopCode" }, name: { kind: "Name", value: "code" }, arguments: [], directives: [] }, { kind: "Field", alias: { kind: "Name", value: "stopId" }, name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "locationType" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "route" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "shortName" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "color" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "textColor" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "type" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alerts" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "alertHeaderText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertDescriptionText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertUrl" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "effectiveStartDate" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "from" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "vertexType" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stop" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "code" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alerts" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "alertHeaderText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertDescriptionText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertUrl" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "effectiveStartDate" }, arguments: [], directives: [] }] } }] } }] } }, { kind: "Field", name: { kind: "Name", value: "to" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "vertexType" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stop" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "code" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alerts" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "alertHeaderText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertDescriptionText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertUrl" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "effectiveStartDate" }, arguments: [], directives: [] }] } }] } }] } }, { kind: "Field", name: { kind: "Name", value: "steps" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lat" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "lon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "relativeDirection" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "absoluteDirection" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "stayOn" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "streetName" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "area" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alerts" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "alertHeaderText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertDescriptionText" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "alertUrl" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "effectiveStartDate" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "elevationProfile" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "distance" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "elevation" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }] } }], loc: { start: 0, end: 2380, source: { body: "query PlanQuery(\n\t$fromPlace: String!,\n\t$toPlace: String!,\n\t$modes: [TransportMode],\n\t$time: String,\n\t$date: String,\n\t$wheelchair: Boolean,\n\t$bikeReluctance: Float,\n\t$carReluctance: Float,\n\t$walkReluctance: Float,\n\t$arriveBy: Boolean,\n\t$intermediatePlaces: [InputCoordinates],\n\t$preferred: InputPreferred,\n\t$unpreferred: InputUnpreferred,\n\t$banned: InputBanned,\n) {\n\tplan(\n\t\tfromPlace: $fromPlace\n\t\ttoPlace: $toPlace\n\t\ttransportModes: $modes\n\t\tlocale: \"en\",\n\t\ttime: $time,\n\t\tdate: $date,\n\t\twheelchair: $wheelchair,\n\t\tbikeReluctance: $bikeReluctance,\n\t\tcarReluctance: $carReluctance,\n\t\twalkReluctance: $walkReluctance,\n\t\tarriveBy: $arriveBy,\n\t\tintermediatePlaces: $intermediatePlaces,\n\t\tpreferred: $preferred,\n\t\tunpreferred: $unpreferred,\n\t\tbanned: $banned,\n\t) {\n\t\titineraries {\n\t\t\tduration\n\t\t\tendTime\n\t\t\tstartTime\n\t\t\twaitingTime\n\t\t\twalkTime\n\t\t\tlegs {\n\t\t\t\tdistance\n\t\t\t\tduration\n\t\t\t\tendTime\n\t\t\t\tmode\n\t\t\t\trealTime\n\t\t\t\trealtimeState\t\n\t\t\t\tstartTime\n\t\t\t\ttransitLeg\n\t\t\t\ttrip {\n\t\t\t\t\tid\n\t\t\t\t\tgtfsId\n\t\t\t\t}\n\t\t\t\tagency {\n\t\t\t\t\tname\n\t\t\t\t\tid\n\t\t\t\t\ttimezone\n\t\t\t\t\turl\n\t\t\t\t\talerts {\n alertHeaderText\n alertDescriptionText\n alertUrl\n effectiveStartDate\n }\n\t\t\t\t}\n\t\t\t\tlegGeometry {\n\t\t\t\t\tlength\n\t\t\t\t\tpoints\n\t\t\t\t}\n\t\t\t\tintermediateStops {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tstopCode: code\n\t\t\t\t\tstopId: id\n\t\t\t\t\tlocationType\n\t\t\t\t}\n\t\t\t\troute {\n\t\t\t\t\tshortName\n\t\t\t\t\tcolor\n\t\t\t\t\ttextColor\n\t\t\t\t\tid\n\t\t\t\t\ttype\n\t\t\t\t\talerts {\n alertHeaderText\n alertDescriptionText\n alertUrl\n effectiveStartDate\n }\n\t\t\t\t}\n\t\t\t\tfrom {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tvertexType\n\t\t\t\t\tstop {\n\t\t\t\t\t\tid\n\t\t\t\t\t\tcode\n\t\t\t\t\t\talerts {\n\t\t\t\t\t\t\talertHeaderText\n\t\t\t\t\t\t\talertDescriptionText\n\t\t\t\t\t\t\talertUrl\n\t\t\t\t\t\t\teffectiveStartDate\n\t\t\t\t\t\t}\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tto {\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n\t\t\t\t\tname\n\t\t\t\t\tvertexType\n\t\t\t\t\tstop {\n\t\t\t\t\t\tid\n\t\t\t\t\t\tcode\n\t\t\t\t\t\talerts {\n\t\t\t\t\t\t\talertHeaderText\n\t\t\t\t\t\t\talertDescriptionText\n\t\t\t\t\t\t\talertUrl\n\t\t\t\t\t\t\teffectiveStartDate\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsteps {\n\t\t\t\t\tdistance\n\t\t\t\t\tlat\n\t\t\t\t\tlon\n relativeDirection\n absoluteDirection\n stayOn\n streetName\n area\n alerts{\n alertHeaderText\n alertDescriptionText\n alertUrl\n effectiveStartDate\n }\n\t\t\t\t\televationProfile {\n\t\t\t\t\t\tdistance\n\t\t\t\t\t\televation\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Mode Settings can contain additional modes to add to the query,
|
|
14
|
+
* this function extracts those additional modes from the settings
|
|
15
|
+
* and returns them in an array.
|
|
16
|
+
* @param modeSettings List of mode settings with values populated
|
|
17
|
+
* @returns Additional transport modes to add to query
|
|
18
|
+
*/
|
|
19
|
+
export function extractAdditionalModes(modeSettings, enabledModes) {
|
|
20
|
+
return modeSettings.reduce(function (prev, cur) {
|
|
21
|
+
// First, ensure that the mode associated with this setting is even enabled
|
|
22
|
+
if (!enabledModes.map(function (m) {
|
|
23
|
+
return m.mode;
|
|
24
|
+
}).includes(cur.applicableMode)) {
|
|
25
|
+
return prev;
|
|
26
|
+
} // In checkboxes, mode must be enabled and have a transport mode in it
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if (cur.type === "CHECKBOX" && cur.addTransportMode && cur.value) {
|
|
30
|
+
return [].concat(_toConsumableArray(prev), [cur.addTransportMode]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (cur.type === "DROPDOWN") {
|
|
34
|
+
var transportMode = cur.options.find(function (o) {
|
|
35
|
+
return o.value === cur.value;
|
|
36
|
+
}).addTransportMode;
|
|
37
|
+
|
|
38
|
+
if (transportMode) {
|
|
39
|
+
return [].concat(_toConsumableArray(prev), [cur.options.find(function (o) {
|
|
40
|
+
return o.value === cur.value;
|
|
41
|
+
}).addTransportMode]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return prev;
|
|
46
|
+
}, []);
|
|
47
|
+
}
|
|
11
48
|
/**
|
|
12
49
|
* Generates every possible mathematical subset of the input TransportModes.
|
|
13
50
|
* Uses code from:
|
|
@@ -15,6 +52,7 @@ var PlanQuery = { kind: "Document", definitions: [{ kind: "OperationDefinition",
|
|
|
15
52
|
* @param array Array of input transport modes
|
|
16
53
|
* @returns 2D array representing every possible subset of transport modes from input
|
|
17
54
|
*/
|
|
55
|
+
|
|
18
56
|
function combinations(array) {
|
|
19
57
|
if (!array) return [];
|
|
20
58
|
return (// eslint-disable-next-line no-bitwise
|
|
@@ -51,16 +89,24 @@ export var TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(function (mode
|
|
|
51
89
|
export var TRANSIT_SUBMODES_AND_TRANSIT = Object.keys(SIMPLIFICATIONS).filter(function (mode) {
|
|
52
90
|
return SIMPLIFICATIONS[mode] === "TRANSIT";
|
|
53
91
|
});
|
|
92
|
+
/**
|
|
93
|
+
* Generates list of queries for OTP to get a comprehensive
|
|
94
|
+
* set of results based on the modes input.
|
|
95
|
+
* @param params OTP Query Params
|
|
96
|
+
* @returns Set of parameters to generate queries
|
|
97
|
+
*/
|
|
98
|
+
|
|
54
99
|
export function generateCombinations(params) {
|
|
55
100
|
var VALID_COMBOS = [["WALK"], ["PERSONAL"], ["TRANSIT", "SHARED"], ["WALK", "SHARED"], ["TRANSIT"], ["TRANSIT", "PERSONAL"], ["TRANSIT", "CAR"]];
|
|
56
|
-
var BANNED_TOGETHER = ["SCOOTER", "BICYCLE"];
|
|
101
|
+
var BANNED_TOGETHER = ["SCOOTER", "BICYCLE"];
|
|
102
|
+
var completeModeList = [].concat(_toConsumableArray(extractAdditionalModes(params.modeSettings, params.modes)), _toConsumableArray(params.modes)); // List of the transit *submodes* that are included in the input params
|
|
57
103
|
|
|
58
|
-
var queryTransitSubmodes =
|
|
104
|
+
var queryTransitSubmodes = completeModeList.filter(function (mode) {
|
|
59
105
|
return TRANSIT_SUBMODES.includes(mode.mode);
|
|
60
106
|
}).map(function (mode) {
|
|
61
107
|
return mode.mode;
|
|
62
108
|
});
|
|
63
|
-
return combinations(
|
|
109
|
+
return combinations(completeModeList).filter(function (combo) {
|
|
64
110
|
if (combo.length === 0) return false; // All current qualifiers currently simplify to "SHARED"
|
|
65
111
|
|
|
66
112
|
var simplifiedModes = Array.from(new Set(combo.map(function (c) {
|
|
@@ -68,9 +114,12 @@ export function generateCombinations(params) {
|
|
|
68
114
|
}))); // Ensure that if we have one transit mode, then we include ALL transit modes
|
|
69
115
|
|
|
70
116
|
if (simplifiedModes.includes("TRANSIT")) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
117
|
+
// Don't allow TRANSIT along with any other submodes
|
|
118
|
+
if (queryTransitSubmodes.length && combo.find(function (c) {
|
|
119
|
+
return c.mode === "TRANSIT";
|
|
120
|
+
})) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
74
123
|
|
|
75
124
|
if (combo.reduce(function (prev, cur) {
|
|
76
125
|
if (queryTransitSubmodes.includes(cur.mode)) {
|
|
@@ -80,7 +129,8 @@ export function generateCombinations(params) {
|
|
|
80
129
|
return prev;
|
|
81
130
|
}, queryTransitSubmodes.length) !== 0) {
|
|
82
131
|
return false;
|
|
83
|
-
}
|
|
132
|
+
} // Continue to the other checks
|
|
133
|
+
|
|
84
134
|
} // OTP doesn't support multiple non-walk modes
|
|
85
135
|
|
|
86
136
|
|
|
@@ -96,9 +146,7 @@ export function generateCombinations(params) {
|
|
|
96
146
|
return simplifiedModes.includes(m);
|
|
97
147
|
});
|
|
98
148
|
});
|
|
99
|
-
})
|
|
100
|
-
// ONLY IF there's multiple of them!
|
|
101
|
-
.map(function (combo) {
|
|
149
|
+
}).map(function (combo) {
|
|
102
150
|
return _objectSpread(_objectSpread({}, params), {}, {
|
|
103
151
|
modes: combo
|
|
104
152
|
});
|
|
@@ -117,15 +165,13 @@ export function generateOtp2Query(params) {
|
|
|
117
165
|
var walkReluctance = modeSettingValues.walkReluctance,
|
|
118
166
|
wheelchair = modeSettingValues.wheelchair,
|
|
119
167
|
bikeReluctance = modeSettingValues.bikeReluctance,
|
|
120
|
-
carReluctance = modeSettingValues.carReluctance
|
|
121
|
-
allowBikeRental = modeSettingValues.allowBikeRental;
|
|
168
|
+
carReluctance = modeSettingValues.carReluctance;
|
|
122
169
|
return {
|
|
123
170
|
query: print(PlanQuery),
|
|
124
171
|
variables: {
|
|
125
|
-
fromPlace:
|
|
126
|
-
toPlace:
|
|
172
|
+
fromPlace: "".concat(from.name, "::").concat(from.lat, ",").concat(from.lon, "}"),
|
|
173
|
+
toPlace: "".concat(to.name, "::").concat(to.lat, ",").concat(to.lon, "}"),
|
|
127
174
|
modes: params.modes,
|
|
128
|
-
allowBikeRental: allowBikeRental,
|
|
129
175
|
walkReluctance: walkReluctance,
|
|
130
176
|
wheelchair: wheelchair,
|
|
131
177
|
bikeReluctance: bikeReluctance,
|
package/esm/query-gen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/query-gen.ts"],"names":["print","combinations","array","Array","length","fill","map","e1","i","filter","e2","j","SIMPLIFICATIONS","AIRPLANE","BICYCLE","BUS","CABLE_CAR","CAR","FERRY","FLEX","FUNICULAR","GONDOLA","RAIL","SCOOTER","SUBWAY","TRAM","TRANSIT","WALK","TRANSIT_SUBMODES","Object","keys","mode","TRANSIT_SUBMODES_AND_TRANSIT","generateCombinations","params","VALID_COMBOS","BANNED_TOGETHER","queryTransitSubmodes","modes","includes","combo","simplifiedModes","from","Set","c","qualifier","flatModes","m","reduce","prev","cur","every","find","vc","generateOtp2Query","to","modeSettings","modeSettingValues","key","value","walkReluctance","wheelchair","bikeReluctance","carReluctance","allowBikeRental","query","PlanQuery","variables","fromPlace","lat","lon","join","toPlace"],"mappings":";;;;;;AAAA;AACA,SAASA,KAAT,QAAsB,SAAtB;;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,YAAT,CAAsBC,KAAtB,EAAiE;AAC/D,MAAI,CAACA,KAAL,EAAY,OAAO,EAAP;AACZ,SACE;AACA,QAAIC,KAAJ,CAAU,KAAKD,KAAK,CAACE,MAArB,EACGC,IADH,CACQ,IADR,EAEE;AAFF,KAGGC,GAHH,CAGO,UAACC,EAAD,EAAKC,CAAL;AAAA,aAAWN,KAAK,CAACO,MAAN,CAAa,UAACC,EAAD,EAAKC,CAAL;AAAA,eAAWH,CAAC,GAAI,KAAKG,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,cADF;AAAA,MAEEC,UAFF,GAMIJ,iBANJ,CAEEI,UAFF;AAAA,MAGEC,cAHF,GAMIL,iBANJ,CAGEK,cAHF;AAAA,MAIEC,aAJF,GAMIN,iBANJ,CAIEM,aAJF;AAAA,MAKEC,eALF,GAMIP,iBANJ,CAKEO,eALF;AAQA,SAAO;AACLC,IAAAA,KAAK,EAAEjE,KAAK,CAACkE,SAAD,CADP;AAELC,IAAAA,SAAS,EAAE;AACTC,MAAAA,SAAS,EAAE,CAAC1B,IAAI,CAAC2B,GAAN,EAAW3B,IAAI,CAAC4B,GAAhB,EAAqBC,IAArB,CAA0B,GAA1B,CADF;AAETC,MAAAA,OAAO,EAAE,CAACjB,EAAE,CAACc,GAAJ,EAASd,EAAE,CAACe,GAAZ,EAAiBC,IAAjB,CAAsB,GAAtB,CAFA;AAGTjC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KAHL;AAIT0B,MAAAA,eAAe,EAAfA,eAJS;AAKTJ,MAAAA,cAAc,EAAdA,cALS;AAMTC,MAAAA,UAAU,EAAVA,UANS;AAOTC,MAAAA,cAAc,EAAdA,cAPS;AAQTC,MAAAA,aAAa,EAAbA;AARS;AAFN,GAAP;AAaD","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { print } from \"graphql\";\nimport {\n ModeSetting,\n ModeSettingValues,\n TransportMode\n} from \"@opentripplanner/types\";\nimport { LonLatOutput } from \"@conveyal/lonlat\";\nimport PlanQuery from \"./planQuery.graphql\";\n\ntype OTPQueryParams = {\n to: LonLatOutput;\n from: LonLatOutput;\n modes: Array<TransportMode>;\n modeSettings: ModeSetting[];\n};\n\n/**\n * Generates every possible mathematical subset of the input TransportModes.\n * Uses code from:\n * https://stackoverflow.com/questions/5752002/find-all-possible-subset-combos-in-an-array\n * @param array Array of input transport modes\n * @returns 2D array representing every possible subset of transport modes from input\n */\nfunction combinations(array: TransportMode[]): TransportMode[][] {\n if (!array) return [];\n return (\n // eslint-disable-next-line no-bitwise\n new Array(1 << array.length)\n .fill(null)\n // eslint-disable-next-line no-bitwise\n .map((e1, i) => array.filter((e2, j) => i & (1 << j)))\n );\n}\nexport const SIMPLIFICATIONS = {\n AIRPLANE: \"TRANSIT\",\n BICYCLE: \"PERSONAL\",\n BUS: \"TRANSIT\",\n CABLE_CAR: \"TRANSIT\",\n CAR: \"CAR\",\n FERRY: \"TRANSIT\",\n FLEX: \"SHARED\", // TODO: this allows FLEX+WALK. Is this reasonable?\n FUNICULAR: \"TRANSIT\",\n GONDOLA: \"TRANSIT\",\n RAIL: \"TRANSIT\",\n SCOOTER: \"PERSONAL\",\n SUBWAY: \"TRANSIT\",\n TRAM: \"TRANSIT\",\n TRANSIT: \"TRANSIT\",\n WALK: \"WALK\"\n};\n\nexport const TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(\n mode => SIMPLIFICATIONS[mode] === \"TRANSIT\" && mode !== \"TRANSIT\"\n);\nexport const TRANSIT_SUBMODES_AND_TRANSIT = Object.keys(SIMPLIFICATIONS).filter(\n mode => SIMPLIFICATIONS[mode] === \"TRANSIT\"\n);\n\nexport function generateCombinations(params: OTPQueryParams): OTPQueryParams[] {\n const VALID_COMBOS = [\n [\"WALK\"],\n [\"PERSONAL\"],\n [\"TRANSIT\", \"SHARED\"],\n [\"WALK\", \"SHARED\"],\n [\"TRANSIT\"],\n [\"TRANSIT\", \"PERSONAL\"],\n [\"TRANSIT\", \"CAR\"]\n ];\n\n const BANNED_TOGETHER = [\"SCOOTER\", \"BICYCLE\"];\n\n // List of the transit submodes that are included in the input params\n const queryTransitSubmodes = params.modes\n .filter(mode => TRANSIT_SUBMODES.includes(mode.mode))\n .map(mode => mode.mode);\n\n return (\n combinations(params.modes)\n .filter(combo => {\n if (combo.length === 0) return false;\n\n // All current qualifiers currently simplify to \"SHARED\"\n const simplifiedModes = Array.from(\n new Set(\n combo.map(c => (c.qualifier ? \"SHARED\" : SIMPLIFICATIONS[c.mode]))\n )\n );\n\n // Ensure that if we have one transit mode, then we include ALL transit modes\n if (simplifiedModes.includes(\"TRANSIT\")) {\n const flatModes = combo.map(m => m.mode);\n if (\n combo.reduce((prev, cur) => {\n if (queryTransitSubmodes.includes(cur.mode)) {\n return prev - 1;\n }\n return prev;\n }, queryTransitSubmodes.length) !== 0\n ) {\n return false;\n }\n }\n\n // OTP doesn't support multiple non-walk modes\n if (BANNED_TOGETHER.every(m => combo.find(c => c.mode === m)))\n return false;\n\n return !!VALID_COMBOS.find(\n vc =>\n simplifiedModes.every(m => vc.includes(m)) &&\n vc.every(m => simplifiedModes.includes(m))\n );\n })\n // create new filter that removes subTransit modes from appearing on their own\n // ONLY IF there's multiple of them!\n .map(combo => ({ ...params, modes: combo }))\n );\n}\n\n// eslint-disable-next-line import/prefer-default-export\nexport function generateOtp2Query(params: OTPQueryParams): any {\n const { to, from, modeSettings } = params;\n\n // This extracts the values from the mode settings to key value pairs\n const modeSettingValues = modeSettings.reduce((prev, cur) => {\n prev[cur.key] = cur.value;\n return prev;\n }, {}) as ModeSettingValues;\n\n const {\n walkReluctance,\n wheelchair,\n bikeReluctance,\n carReluctance,\n allowBikeRental\n } = modeSettingValues;\n\n return {\n query: print(PlanQuery),\n variables: {\n fromPlace: [from.lat, from.lon].join(\",\"),\n toPlace: [to.lat, to.lon].join(\",\"),\n modes: params.modes,\n allowBikeRental,\n walkReluctance,\n wheelchair,\n bikeReluctance,\n carReluctance\n }\n };\n}\n"],"file":"query-gen.js"}
|
|
1
|
+
{"version":3,"sources":["../src/query-gen.ts"],"names":["print","extractAdditionalModes","modeSettings","enabledModes","reduce","prev","cur","map","m","mode","includes","applicableMode","type","addTransportMode","value","transportMode","options","find","o","combinations","array","Array","length","fill","e1","i","filter","e2","j","SIMPLIFICATIONS","AIRPLANE","BICYCLE","BUS","CABLE_CAR","CAR","FERRY","FLEX","FUNICULAR","GONDOLA","RAIL","SCOOTER","SUBWAY","TRAM","TRANSIT","WALK","TRANSIT_SUBMODES","Object","keys","TRANSIT_SUBMODES_AND_TRANSIT","generateCombinations","params","VALID_COMBOS","BANNED_TOGETHER","completeModeList","modes","queryTransitSubmodes","combo","simplifiedModes","from","Set","c","qualifier","every","vc","generateOtp2Query","to","modeSettingValues","key","walkReluctance","wheelchair","bikeReluctance","carReluctance","query","PlanQuery","variables","fromPlace","name","lat","lon","toPlace"],"mappings":";;;;;;;AAAA;AACA,SAASA,KAAT,QAAsB,SAAtB;;;AAqBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAT,CACLC,YADK,EAELC,YAFK,EAGiB;AACtB,SAAOD,YAAY,CAACE,MAAb,CAAqC,UAACC,IAAD,EAAOC,GAAP,EAAe;AACzD;AACA,QAAI,CAACH,YAAY,CAACI,GAAb,CAAiB,UAAAC,CAAC;AAAA,aAAIA,CAAC,CAACC,IAAN;AAAA,KAAlB,EAA8BC,QAA9B,CAAuCJ,GAAG,CAACK,cAA3C,CAAL,EAAiE;AAC/D,aAAON,IAAP;AACD,KAJwD,CAMzD;;;AACA,QAAIC,GAAG,CAACM,IAAJ,KAAa,UAAb,IAA2BN,GAAG,CAACO,gBAA/B,IAAmDP,GAAG,CAACQ,KAA3D,EAAkE;AAChE,0CAAWT,IAAX,IAAiBC,GAAG,CAACO,gBAArB;AACD;;AACD,QAAIP,GAAG,CAACM,IAAJ,KAAa,UAAjB,EAA6B;AAC3B,UAAMG,aAAa,GAAGT,GAAG,CAACU,OAAJ,CAAYC,IAAZ,CAAiB,UAAAC,CAAC;AAAA,eAAIA,CAAC,CAACJ,KAAF,KAAYR,GAAG,CAACQ,KAApB;AAAA,OAAlB,EACnBD,gBADH;;AAEA,UAAIE,aAAJ,EAAmB;AACjB,4CACKV,IADL,IAEEC,GAAG,CAACU,OAAJ,CAAYC,IAAZ,CAAiB,UAAAC,CAAC;AAAA,iBAAIA,CAAC,CAACJ,KAAF,KAAYR,GAAG,CAACQ,KAApB;AAAA,SAAlB,EAA6CD,gBAF/C;AAID;AACF;;AACD,WAAOR,IAAP;A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TC,MAAAA,aAAa,EAAbA;AAPS;AAFN,GAAP;AAYD","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { print } from \"graphql\";\nimport {\n ModeSetting,\n ModeSettingValues,\n TransportMode\n} from \"@opentripplanner/types\";\nimport { LonLatOutput } from \"@conveyal/lonlat\";\nimport PlanQuery from \"./planQuery.graphql\";\n\ntype OTPQueryParams = {\n to: LonLatOutput & { name?: string };\n from: LonLatOutput & { name?: string };\n modes: Array<TransportMode>;\n modeSettings: ModeSetting[];\n};\n\ntype GraphQLQuery = {\n query: string;\n variables: Record<string, unknown>;\n};\n\n/**\n * Mode Settings can contain additional modes to add to the query,\n * this function extracts those additional modes from the settings\n * and returns them in an array.\n * @param modeSettings List of mode settings with values populated\n * @returns Additional transport modes to add to query\n */\nexport function extractAdditionalModes(\n modeSettings: ModeSetting[],\n enabledModes: TransportMode[]\n): Array<TransportMode> {\n return modeSettings.reduce<TransportMode[]>((prev, cur) => {\n // First, ensure that the mode associated with this setting is even enabled\n if (!enabledModes.map(m => m.mode).includes(cur.applicableMode)) {\n return prev;\n }\n\n // In checkboxes, mode must be enabled and have a transport mode in it\n if (cur.type === \"CHECKBOX\" && cur.addTransportMode && cur.value) {\n return [...prev, cur.addTransportMode];\n }\n if (cur.type === \"DROPDOWN\") {\n const transportMode = cur.options.find(o => o.value === cur.value)\n .addTransportMode;\n if (transportMode) {\n return [\n ...prev,\n cur.options.find(o => o.value === cur.value).addTransportMode\n ];\n }\n }\n return prev;\n }, []);\n}\n\n/**\n * Generates every possible mathematical subset of the input TransportModes.\n * Uses code from:\n * https://stackoverflow.com/questions/5752002/find-all-possible-subset-combos-in-an-array\n * @param array Array of input transport modes\n * @returns 2D array representing every possible subset of transport modes from input\n */\nfunction combinations(array: TransportMode[]): TransportMode[][] {\n if (!array) return [];\n return (\n // eslint-disable-next-line no-bitwise\n new Array(1 << array.length)\n .fill(null)\n // eslint-disable-next-line no-bitwise\n .map((e1, i) => array.filter((e2, j) => i & (1 << j)))\n );\n}\n\nexport const SIMPLIFICATIONS = {\n AIRPLANE: \"TRANSIT\",\n BICYCLE: \"PERSONAL\",\n BUS: \"TRANSIT\",\n CABLE_CAR: \"TRANSIT\",\n CAR: \"CAR\",\n FERRY: \"TRANSIT\",\n FLEX: \"SHARED\", // TODO: this allows FLEX+WALK. Is this reasonable?\n FUNICULAR: \"TRANSIT\",\n GONDOLA: \"TRANSIT\",\n RAIL: \"TRANSIT\",\n SCOOTER: \"PERSONAL\",\n SUBWAY: \"TRANSIT\",\n TRAM: \"TRANSIT\",\n TRANSIT: \"TRANSIT\",\n WALK: \"WALK\"\n};\n\nexport const TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(\n mode => SIMPLIFICATIONS[mode] === \"TRANSIT\" && mode !== \"TRANSIT\"\n);\nexport const TRANSIT_SUBMODES_AND_TRANSIT = Object.keys(SIMPLIFICATIONS).filter(\n mode => SIMPLIFICATIONS[mode] === \"TRANSIT\"\n);\n\n/**\n * Generates list of queries for OTP to get a comprehensive\n * set of results based on the modes input.\n * @param params OTP Query Params\n * @returns Set of parameters to generate queries\n */\nexport function generateCombinations(params: OTPQueryParams): OTPQueryParams[] {\n const VALID_COMBOS = [\n [\"WALK\"],\n [\"PERSONAL\"],\n [\"TRANSIT\", \"SHARED\"],\n [\"WALK\", \"SHARED\"],\n [\"TRANSIT\"],\n [\"TRANSIT\", \"PERSONAL\"],\n [\"TRANSIT\", \"CAR\"]\n ];\n\n const BANNED_TOGETHER = [\"SCOOTER\", \"BICYCLE\"];\n\n const completeModeList = [\n ...extractAdditionalModes(params.modeSettings, params.modes),\n ...params.modes\n ];\n\n // List of the transit *submodes* that are included in the input params\n const queryTransitSubmodes = completeModeList\n .filter(mode => TRANSIT_SUBMODES.includes(mode.mode))\n .map(mode => mode.mode);\n\n return combinations(completeModeList)\n .filter(combo => {\n if (combo.length === 0) return false;\n\n // All current qualifiers currently simplify to \"SHARED\"\n const simplifiedModes = Array.from(\n new Set(\n combo.map(c => (c.qualifier ? \"SHARED\" : SIMPLIFICATIONS[c.mode]))\n )\n );\n\n // Ensure that if we have one transit mode, then we include ALL transit modes\n if (simplifiedModes.includes(\"TRANSIT\")) {\n // Don't allow TRANSIT along with any other submodes\n if (\n queryTransitSubmodes.length &&\n combo.find(c => c.mode === \"TRANSIT\")\n ) {\n return false;\n }\n\n if (\n combo.reduce((prev, cur) => {\n if (queryTransitSubmodes.includes(cur.mode)) {\n return prev - 1;\n }\n return prev;\n }, queryTransitSubmodes.length) !== 0\n ) {\n return false;\n }\n // Continue to the other checks\n }\n\n // OTP doesn't support multiple non-walk modes\n if (BANNED_TOGETHER.every(m => combo.find(c => c.mode === m)))\n return false;\n\n return !!VALID_COMBOS.find(\n vc =>\n simplifiedModes.every(m => vc.includes(m)) &&\n vc.every(m => simplifiedModes.includes(m))\n );\n })\n .map(combo => ({ ...params, modes: combo }));\n}\n\n// eslint-disable-next-line import/prefer-default-export\nexport function generateOtp2Query(params: OTPQueryParams): GraphQLQuery {\n const { to, from, modeSettings } = params;\n\n // This extracts the values from the mode settings to key value pairs\n const modeSettingValues = modeSettings.reduce((prev, cur) => {\n prev[cur.key] = cur.value;\n return prev;\n }, {}) as ModeSettingValues;\n\n const {\n walkReluctance,\n wheelchair,\n bikeReluctance,\n carReluctance\n } = modeSettingValues;\n\n return {\n query: print(PlanQuery),\n variables: {\n fromPlace: `${from.name}::${from.lat},${from.lon}}`,\n toPlace: `${to.name}::${to.lat},${to.lon}}`,\n modes: params.modes,\n walkReluctance,\n wheelchair,\n bikeReluctance,\n carReluctance\n }\n };\n}\n"],"file":"query-gen.js"}
|
package/lib/itinerary.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Company, Config, ElevationProfile, FlexBookingInfo,
|
|
1
|
+
import { Company, Config, ElevationProfile, FlexBookingInfo, ItineraryOnlyLegsRequired, LatLngArray, Leg, MassUnitOption, Money, Place, Step, Stop, TncFare } from "@opentripplanner/types";
|
|
2
2
|
export declare const transitModes: string[];
|
|
3
3
|
/**
|
|
4
4
|
* @param {config} config OTP-RR configuration object
|
|
@@ -67,7 +67,7 @@ export declare function toSentenceCase(str: string): string;
|
|
|
67
67
|
* Derive the company string based on mode and network associated with leg.
|
|
68
68
|
*/
|
|
69
69
|
export declare function getCompanyFromLeg(leg: Leg): string;
|
|
70
|
-
export declare function getItineraryBounds(itinerary:
|
|
70
|
+
export declare function getItineraryBounds(itinerary: ItineraryOnlyLegsRequired): LatLngArray[];
|
|
71
71
|
/**
|
|
72
72
|
* Return a coords object that encloses the given leg's geometry.
|
|
73
73
|
*/
|
|
@@ -98,7 +98,7 @@ export declare function getCompanyForNetwork(networkString: string, companies?:
|
|
|
98
98
|
*/
|
|
99
99
|
export declare function getCompaniesLabelFromNetworks(networks: string[], companies?: Company[]): string;
|
|
100
100
|
export declare function getTNCLocation(leg: Leg, type: string): string;
|
|
101
|
-
export declare function calculatePhysicalActivity(itinerary:
|
|
101
|
+
export declare function calculatePhysicalActivity(itinerary: ItineraryOnlyLegsRequired): {
|
|
102
102
|
bikeDuration: number;
|
|
103
103
|
caloriesBurned: number;
|
|
104
104
|
walkDuration: number;
|
|
@@ -108,7 +108,7 @@ export declare function calculatePhysicalActivity(itinerary: Itinerary): {
|
|
|
108
108
|
* these values and currency info.
|
|
109
109
|
* It is assumed that the same currency is used for all TNC legs.
|
|
110
110
|
*/
|
|
111
|
-
export declare function calculateTncFares(itinerary:
|
|
111
|
+
export declare function calculateTncFares(itinerary: ItineraryOnlyLegsRequired): TncFare;
|
|
112
112
|
/**
|
|
113
113
|
* For a given fare component (either total fare or component parts), returns
|
|
114
114
|
* an object with the fare value (in cents).
|
|
@@ -118,12 +118,12 @@ export declare function getTransitFare(fareComponent: Money): {
|
|
|
118
118
|
transitFare: number;
|
|
119
119
|
};
|
|
120
120
|
/**
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
121
|
+
* @param {itinerary} itinerary OTP trip itinierary, only legs is required.
|
|
122
|
+
* @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
|
|
123
123
|
* @param {units} units units to be used in return value
|
|
124
124
|
* @return Amount of carbon in chosen unit
|
|
125
125
|
*/
|
|
126
|
-
export declare function calculateEmissions(itinerary:
|
|
126
|
+
export declare function calculateEmissions(itinerary: ItineraryOnlyLegsRequired, carbonIntensity?: Record<string, number>, units?: MassUnitOption): number;
|
|
127
127
|
/**
|
|
128
128
|
* Returns the user-facing stop id to display for a stop or place, using the following priority:
|
|
129
129
|
* 1. stop code,
|
package/lib/itinerary.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,WAAW,EACX,GAAG,EACH,cAAc,EACd,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,OAAO,EACR,MAAM,wBAAwB,CAAC;AAIhC,eAAO,MAAM,YAAY,UAOxB,CAAC;AAEF;;;GAGG;AAEH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAOxD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAEvD;AACD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAKxD;AACD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAExC;AAED,wBAAgB,wBAAwB,CAA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,CAAC,MAAM,EAAE,MAAM,CAAM,EAC5C,KAAK,CAAC,EAAE,cAAc,GACrB,MAAM,CA2BR;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,CASpE"}
|
package/lib/itinerary.js
CHANGED
|
@@ -516,13 +516,14 @@ const CARBON_INTENSITY_DEFAULTS = {
|
|
|
516
516
|
micromobility: 0.095
|
|
517
517
|
};
|
|
518
518
|
/**
|
|
519
|
-
* @param
|
|
520
|
-
* @param
|
|
519
|
+
* @param {itinerary} itinerary OTP trip itinierary, only legs is required.
|
|
520
|
+
* @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter
|
|
521
521
|
* @param {units} units units to be used in return value
|
|
522
522
|
* @return Amount of carbon in chosen unit
|
|
523
523
|
*/
|
|
524
524
|
|
|
525
|
-
function calculateEmissions(
|
|
525
|
+
function calculateEmissions( // This type makes all the properties from Itinerary optional except legs.
|
|
526
|
+
itinerary, carbonIntensity = {}, units) {
|
|
526
527
|
var _itinerary$legs;
|
|
527
528
|
|
|
528
529
|
// Apply defaults for any values that we don't have.
|