@opentripplanner/core-utils 9.0.0-alpha.5 → 9.0.0-alpha.7
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 +74 -0
- package/esm/itinerary.js.map +1 -1
- package/esm/query-gen.js +71 -63
- package/esm/query-gen.js.map +1 -1
- package/lib/core-utils.story.d.ts +22 -0
- package/lib/core-utils.story.d.ts.map +1 -0
- package/lib/core-utils.story.js +69 -0
- package/lib/core-utils.story.js.map +1 -0
- package/lib/itinerary.d.ts +26 -1
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +68 -0
- package/lib/itinerary.js.map +1 -1
- package/lib/query-gen.d.ts +12 -8
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +57 -51
- package/lib/query-gen.js.map +1 -1
- package/package.json +2 -3
- package/src/__tests__/{query-params.js → query-params.ts} +25 -23
- package/src/itinerary.ts +68 -0
- package/src/planQuery.graphql +1 -0
- package/src/query-gen.ts +79 -76
- package/tsconfig.json +3 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/esm/state.js +0 -2
- package/esm/state.js.map +0 -1
- package/lib/state.d.ts +0 -1
- package/lib/state.d.ts.map +0 -1
- package/lib/state.js +0 -2
- package/lib/state.js.map +0 -1
- package/src/state.ts +0 -0
- /package/src/__tests__/__snapshots__/{query-params.js.snap → query-params.ts.snap} +0 -0
package/esm/itinerary.js
CHANGED
|
@@ -521,4 +521,78 @@ export function getDisplayedStopId(placeOrStop) {
|
|
|
521
521
|
|
|
522
522
|
return stopCode || ((_stopId = stopId) === null || _stopId === void 0 ? void 0 : _stopId.split(":")[1]) || stopId;
|
|
523
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* Adds the fare product info to each leg in an itinerary, from the itinerary's fare property
|
|
526
|
+
* @param itinerary Itinerary with legProducts in fare object
|
|
527
|
+
* @returns Itinerary with legs that have fare products attached to them
|
|
528
|
+
*/
|
|
529
|
+
|
|
530
|
+
export function getLegsWithFares(itinerary) {
|
|
531
|
+
return itinerary.legs.map(function (leg, i) {
|
|
532
|
+
var _itinerary$fare, _itinerary$fare$legPr;
|
|
533
|
+
|
|
534
|
+
return _objectSpread(_objectSpread({}, leg), {}, {
|
|
535
|
+
fareProducts: (_itinerary$fare = itinerary.fare) === null || _itinerary$fare === void 0 ? void 0 : (_itinerary$fare$legPr = _itinerary$fare.legProducts) === null || _itinerary$fare$legPr === void 0 ? void 0 : _itinerary$fare$legPr.filter(function (lp) {
|
|
536
|
+
var _lp$legIndices;
|
|
537
|
+
|
|
538
|
+
return lp === null || lp === void 0 ? void 0 : (_lp$legIndices = lp.legIndices) === null || _lp$legIndices === void 0 ? void 0 : _lp$legIndices.includes(i);
|
|
539
|
+
}).flatMap(function (lp) {
|
|
540
|
+
return lp.products;
|
|
541
|
+
})
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
|
|
547
|
+
* @param leg Leg with fare products (must have used getLegsWithFares)
|
|
548
|
+
* @param category Rider category
|
|
549
|
+
* @param container Fare container (cash, electronic)
|
|
550
|
+
* @returns Object containing price as well as the transfer discount amount, if a transfer was used.
|
|
551
|
+
*/
|
|
552
|
+
|
|
553
|
+
export function getLegCost(leg, category, container) {
|
|
554
|
+
var _relevantFareProducts, _transferFareProduct$;
|
|
555
|
+
|
|
556
|
+
if (!leg.fareProducts) return {
|
|
557
|
+
price: undefined
|
|
558
|
+
};
|
|
559
|
+
var relevantFareProducts = leg.fareProducts.filter(function (fp) {
|
|
560
|
+
return fp.category.name === category && fp.container.name === container;
|
|
561
|
+
});
|
|
562
|
+
var totalCost = (_relevantFareProducts = relevantFareProducts.find(function (fp) {
|
|
563
|
+
return fp.name === "rideCost";
|
|
564
|
+
})) === null || _relevantFareProducts === void 0 ? void 0 : _relevantFareProducts.amount;
|
|
565
|
+
var transferFareProduct = relevantFareProducts.find(function (fp) {
|
|
566
|
+
return fp.name === "transfer";
|
|
567
|
+
});
|
|
568
|
+
return {
|
|
569
|
+
price: totalCost,
|
|
570
|
+
transferAmount: transferFareProduct === null || transferFareProduct === void 0 ? void 0 : (_transferFareProduct$ = transferFareProduct.amount) === null || _transferFareProduct$ === void 0 ? void 0 : _transferFareProduct$.cents
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Returns the total itinerary cost for a given set of legs.
|
|
575
|
+
* @param legs Itinerary legs with fare products (must have used getLegsWithFares)
|
|
576
|
+
* @param category Rider category (youth, regular, senior)
|
|
577
|
+
* @param container Fare container (cash, electronic)
|
|
578
|
+
* @returns Money object for the total itinerary cost.
|
|
579
|
+
*/
|
|
580
|
+
|
|
581
|
+
export function getItineraryCost(legs, category, container) {
|
|
582
|
+
return legs.filter(function (leg) {
|
|
583
|
+
return !!leg.fareProducts;
|
|
584
|
+
}).map(function (leg) {
|
|
585
|
+
return getLegCost(leg, category, container).price;
|
|
586
|
+
}).reduce(function (prev, cur) {
|
|
587
|
+
var _prev$currency;
|
|
588
|
+
|
|
589
|
+
return {
|
|
590
|
+
cents: prev.cents + (cur === null || cur === void 0 ? void 0 : cur.cents) || 0,
|
|
591
|
+
currency: (_prev$currency = prev.currency) !== null && _prev$currency !== void 0 ? _prev$currency : cur === null || cur === void 0 ? void 0 : cur.currency
|
|
592
|
+
};
|
|
593
|
+
}, {
|
|
594
|
+
cents: 0,
|
|
595
|
+
currency: null
|
|
596
|
+
});
|
|
597
|
+
}
|
|
524
598
|
//# sourceMappingURL=itinerary.js.map
|
package/esm/itinerary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/itinerary.ts"],"names":["polyline","turfAlong","transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","alightRule","isCoordinationRequired","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","hailedCar","reduce","maxTNCFare","minTNCFare","currency","maxCost","minCost","currencyCode","getTransitFare","fareComponent","transitFare","cents","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","carbonIntensityWithDefaults","totalCarbon","total","getDisplayedStopId","placeOrStop","stopId","stopCode","code"],"mappings":";;;;;;;AAAA,OAAOA,QAAP,MAAqB,kBAArB;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,KAA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B,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"}
|
|
1
|
+
{"version":3,"sources":["../src/itinerary.ts"],"names":["polyline","turfAlong","transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","alightRule","isCoordinationRequired","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","hailedCar","reduce","maxTNCFare","minTNCFare","currency","maxCost","minCost","currencyCode","getTransitFare","fareComponent","transitFare","cents","CARBON_INTENSITY_DEFAULTS","walk","bicycle","car","tram","subway","rail","bus","ferry","cable_car","gondola","funicular","transit","leg_switch","airplane","micromobility","calculateEmissions","carbonIntensity","carbonIntensityWithDefaults","totalCarbon","total","getDisplayedStopId","placeOrStop","stopId","stopCode","code","getLegsWithFares","fareProducts","fare","legProducts","lp","legIndices","flatMap","products","getLegCost","category","container","price","undefined","relevantFareProducts","fp","name","totalCost","amount","transferFareProduct","transferAmount","getItineraryCost","prev","cur"],"mappings":";;;;;;;AAAA,OAAOA,QAAP,MAAqB,kBAArB;AAiBA,OAAOC,SAAP,MAAsB,aAAtB,C,CAEA;;AACA,OAAO,IAAMC,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MAL0B,EAM1B,SAN0B,CAArB;AASP;AACA;AACA;AACA;;AAEA,OAAO,SAASC,eAAT,CAAyBC,MAAzB,EAAmD;AACxD,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACC,KAAnB,IAA4B,CAACD,MAAM,CAACC,KAAP,CAAaH,YAA9C,EACE,OAAOA,YAAP;AAEF,SAAOE,MAAM,CAACC,KAAP,CAAaH,YAAb,CAA0BI,GAA1B,CAA8B,UAAAC,EAAE;AAAA,WACrC,OAAOA,EAAP,KAAc,QAAd,GAAyBA,EAAE,CAACC,IAA5B,GAAmCD,EADE;AAAA,GAAhC,CAAP;AAGD;AAED,OAAO,SAASE,SAAT,CAAmBD,IAAnB,EAA0C;AAC/C,SAAON,YAAY,CAACQ,QAAb,CAAsBF,IAAtB,KAA+BA,IAAI,KAAK,SAA/C;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,qBAAT,CAA+BC,GAA/B,EAAkD;AACvD,SAAOA,GAAG,CAACC,SAAJ,KAAkB,W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5C;AAFxC,GAAP;AAID;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS+C,gBAAT,CACLxI,IADK,EAEL6H,QAFK,EAGLC,SAHK,EAIE;AACP,SAAO9H,IAAI,CACRiE,MADI,CACG,UAAAjH,GAAG;AAAA,WAAI,CAAC,CAACA,GAAG,CAACqK,YAAV;AAAA,GADN,EAEJ3K,GAFI,CAEA,UAAAM,GAAG;AAAA,WAAI4K,UAAU,CAAC5K,GAAD,EAAM6K,QAAN,EAAgBC,SAAhB,CAAV,CAAqCC,KAAzC;AAAA,GAFH,EAGJhD,MAHI,CAIH,UAAC0D,IAAD,EAAOC,GAAP;AAAA;;AAAA,WAAgB;AACdjD,MAAAA,KAAK,EAAEgD,IAAI,CAAChD,KAAL,IAAaiD,GAAb,aAAaA,GAAb,uBAAaA,GAAG,CAAEjD,KAAlB,KAA2B,CADpB;AAEdP,MAAAA,QAAQ,oBAAEuD,IAAI,CAACvD,QAAP,2DAAmBwD,GAAnB,aAAmBA,GAAnB,uBAAmBA,GAAG,CAAExD;AAFlB,KAAhB;AAAA,GAJG,EAQH;AAAEO,IAAAA,KAAK,EAAE,CAAT;AAAYP,IAAAA,QAAQ,EAAE;AAAtB,GARG,CAAP;AAUD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n ItineraryOnlyLegsRequired,\n LatLngArray,\n Leg,\n MassUnitOption,\n Money,\n Place,\n Step,\n Stop,\n TncFare\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\" || leg.alightRule === \"mustPhone\";\n}\n/**\n * Returns true if a user must ask the driver to let the user off\n * or if the user must flag the driver down for pickup.\n * \"coordinateWithDriver\" in board/alight rule encodes this info.\n */\nexport function isCoordinationRequired(leg: Leg): boolean {\n return (\n leg.boardRule === \"coordinateWithDriver\" ||\n leg.alightRule === \"coordinateWithDriver\"\n );\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isCoordinationRequired(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(\n itinerary: ItineraryOnlyLegsRequired\n): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[][] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string[],\n companies: Company[] = []\n): string {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: ItineraryOnlyLegsRequired\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\n/**\n * For an itinerary, calculates the TNC fares and returns an object with\n * these values and currency info.\n * It is assumed that the same currency is used for all TNC legs.\n */\nexport function calculateTncFares(\n itinerary: ItineraryOnlyLegsRequired\n): TncFare {\n return itinerary.legs\n .filter(leg => leg.mode === \"CAR\" && leg.hailedCar && leg.tncData)\n .reduce(\n ({ maxTNCFare, minTNCFare }, { tncData }) => {\n const { currency, maxCost, minCost } = tncData;\n return {\n // Assumes a single currency for entire itinerary.\n currencyCode: currency,\n maxTNCFare: maxTNCFare + maxCost,\n minTNCFare: minTNCFare + minCost\n };\n },\n {\n currencyCode: null,\n maxTNCFare: 0,\n minTNCFare: 0\n }\n );\n}\n\n/**\n * For a given fare component (either total fare or component parts), returns\n * an object with the fare value (in cents).\n */\nexport function getTransitFare(\n fareComponent: Money\n): {\n currencyCode: string;\n transitFare: number;\n} {\n return fareComponent\n ? {\n currencyCode: fareComponent.currency.currencyCode,\n transitFare: fareComponent.cents\n }\n : {\n currencyCode: \"USD\",\n transitFare: 0\n };\n}\n\n/**\n * Sources:\n * - https://www.itf-oecd.org/sites/default/files/docs/environmental-performance-new-mobility.pdf\n * - https://www.thrustcarbon.com/insights/how-to-calculate-emissions-from-a-ferry-journey\n * - https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx\n * Other values extrapolated.\n */\nconst CARBON_INTENSITY_DEFAULTS = {\n walk: 0.026,\n bicycle: 0.017,\n car: 0.162,\n tram: 0.066,\n subway: 0.066,\n rail: 0.066,\n bus: 0.09,\n ferry: 0.082,\n cable_car: 0.021,\n gondola: 0.021,\n funicular: 0.066,\n transit: 0.066,\n leg_switch: 0,\n airplane: 0.382,\n micromobility: 0.095\n};\n\n/**\n * @param {itinerary} itinerary OTP trip itinierary, only legs is required.\n * @param {carbonIntensity} carbonIntensity carbon intensity by mode in grams/meter\n * @param {units} units units to be used in return value\n * @return Amount of carbon in chosen unit\n */\nexport function calculateEmissions(\n // This type makes all the properties from Itinerary optional except legs.\n itinerary: ItineraryOnlyLegsRequired,\n carbonIntensity: Record<string, number> = {},\n units?: MassUnitOption\n): number {\n // Apply defaults for any values that we don't have.\n const carbonIntensityWithDefaults = {\n ...CARBON_INTENSITY_DEFAULTS,\n ...carbonIntensity\n };\n\n // Distance is in meters, totalCarbon is in grams\n const totalCarbon =\n itinerary?.legs?.reduce((total, leg) => {\n return (\n (leg.distance * carbonIntensityWithDefaults[leg.mode.toLowerCase()] ||\n 0) + total\n );\n }, 0) || 0;\n\n switch (units) {\n case \"ounce\":\n return totalCarbon / 28.35;\n case \"kilogram\":\n return totalCarbon / 1000;\n case \"pound\":\n return totalCarbon / 454;\n case \"gram\":\n default:\n return totalCarbon;\n }\n}\n\n/**\n * Returns the user-facing stop id to display for a stop or place, using the following priority:\n * 1. stop code,\n * 2. stop id without the agency id portion, if stop id contains an agency portion,\n * 3. stop id, whether null or not (this is the fallback case).\n */\nexport function getDisplayedStopId(placeOrStop: Place | Stop): string {\n let stopId;\n let stopCode;\n if (\"stopId\" in placeOrStop) {\n ({ stopCode, stopId } = placeOrStop);\n } else if (\"id\" in placeOrStop) {\n ({ code: stopCode, id: stopId } = placeOrStop);\n }\n return stopCode || stopId?.split(\":\")[1] || stopId;\n}\n\n/**\n * Adds the fare product info to each leg in an itinerary, from the itinerary's fare property\n * @param itinerary Itinerary with legProducts in fare object\n * @returns Itinerary with legs that have fare products attached to them\n */\nexport function getLegsWithFares(itinerary: Itinerary): Leg[] {\n return itinerary.legs.map((leg, i) => ({\n ...leg,\n fareProducts: itinerary.fare?.legProducts\n ?.filter(lp => lp?.legIndices?.includes(i))\n .flatMap(lp => lp.products)\n }));\n}\n\n/**\n * Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.\n * @param leg Leg with fare products (must have used getLegsWithFares)\n * @param category Rider category\n * @param container Fare container (cash, electronic)\n * @returns Object containing price as well as the transfer discount amount, if a transfer was used.\n */\nexport function getLegCost(\n leg: Leg,\n category: string,\n container: string\n): { price?: Money; transferAmount?: number } {\n if (!leg.fareProducts) return { price: undefined };\n\n const relevantFareProducts = leg.fareProducts.filter(\n fp => fp.category.name === category && fp.container.name === container\n );\n const totalCost = relevantFareProducts.find(fp => fp.name === \"rideCost\")\n ?.amount;\n const transferFareProduct = relevantFareProducts.find(\n fp => fp.name === \"transfer\"\n );\n\n return {\n price: totalCost,\n transferAmount: transferFareProduct?.amount?.cents\n };\n}\n\n/**\n * Returns the total itinerary cost for a given set of legs.\n * @param legs Itinerary legs with fare products (must have used getLegsWithFares)\n * @param category Rider category (youth, regular, senior)\n * @param container Fare container (cash, electronic)\n * @returns Money object for the total itinerary cost.\n */\nexport function getItineraryCost(\n legs: Leg[],\n category: string,\n container: string\n): Money {\n return legs\n .filter(leg => !!leg.fareProducts)\n .map(leg => getLegCost(leg, category, container).price)\n .reduce<Money>(\n (prev, cur) => ({\n cents: prev.cents + cur?.cents || 0,\n currency: prev.currency ?? cur?.currency\n }),\n { cents: 0, currency: null }\n );\n}\n"],"file":"itinerary.js"}
|
package/esm/query-gen.js
CHANGED
|
@@ -5,9 +5,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
5
5
|
|
|
6
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
7
7
|
|
|
8
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
9
8
|
import { print } from "graphql";
|
|
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 } } } };
|
|
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: "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: 2445, 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\t# Currently only supporting EN locale, used for times and text\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 } } } };
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Mode Settings can contain additional modes to add to the query,
|
|
@@ -36,9 +35,7 @@ export function extractAdditionalModes(modeSettings, enabledModes) {
|
|
|
36
35
|
}).addTransportMode;
|
|
37
36
|
|
|
38
37
|
if (transportMode) {
|
|
39
|
-
return [].concat(_toConsumableArray(prev), [
|
|
40
|
-
return o.value === cur.value;
|
|
41
|
-
}).addTransportMode]);
|
|
38
|
+
return [].concat(_toConsumableArray(prev), [transportMode]);
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
41
|
|
|
@@ -64,6 +61,11 @@ function combinations(array) {
|
|
|
64
61
|
})
|
|
65
62
|
);
|
|
66
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* This constant maps all the transport mode to a broader mode type,
|
|
66
|
+
* which is used to determine the valid combinations of modes used in query generation.
|
|
67
|
+
*/
|
|
68
|
+
|
|
67
69
|
|
|
68
70
|
export var SIMPLIFICATIONS = {
|
|
69
71
|
AIRPLANE: "TRANSIT",
|
|
@@ -82,23 +84,67 @@ export var SIMPLIFICATIONS = {
|
|
|
82
84
|
TRAM: "TRANSIT",
|
|
83
85
|
TRANSIT: "TRANSIT",
|
|
84
86
|
WALK: "WALK"
|
|
85
|
-
};
|
|
87
|
+
}; // Inclusion of "TRANSIT" alone automatically implies "WALK" in OTP
|
|
88
|
+
|
|
89
|
+
var VALID_COMBOS = [["WALK"], ["PERSONAL"], ["TRANSIT", "SHARED"], ["WALK", "SHARED"], ["TRANSIT"], ["TRANSIT", "PERSONAL"], ["TRANSIT", "CAR"]];
|
|
90
|
+
var BANNED_TOGETHER = ["SCOOTER", "BICYCLE"];
|
|
86
91
|
export var TRANSIT_SUBMODES = Object.keys(SIMPLIFICATIONS).filter(function (mode) {
|
|
87
92
|
return SIMPLIFICATIONS[mode] === "TRANSIT" && mode !== "TRANSIT";
|
|
88
93
|
});
|
|
89
94
|
export var TRANSIT_SUBMODES_AND_TRANSIT = Object.keys(SIMPLIFICATIONS).filter(function (mode) {
|
|
90
95
|
return SIMPLIFICATIONS[mode] === "TRANSIT";
|
|
91
96
|
});
|
|
97
|
+
|
|
98
|
+
function isCombinationValid(combo, queryTransitSubmodes) {
|
|
99
|
+
if (combo.length === 0) return false; // All current qualifiers currently simplify to "SHARED"
|
|
100
|
+
|
|
101
|
+
var simplifiedModes = Array.from(new Set(combo.map(function (c) {
|
|
102
|
+
return c.qualifier ? "SHARED" : SIMPLIFICATIONS[c.mode];
|
|
103
|
+
}))); // Ensure that if we have one transit mode, then we include ALL transit modes
|
|
104
|
+
|
|
105
|
+
if (simplifiedModes.includes("TRANSIT")) {
|
|
106
|
+
// Don't allow TRANSIT along with any other submodes
|
|
107
|
+
if (queryTransitSubmodes.length && combo.find(function (c) {
|
|
108
|
+
return c.mode === "TRANSIT";
|
|
109
|
+
})) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (combo.reduce(function (prev, cur) {
|
|
114
|
+
if (queryTransitSubmodes.includes(cur.mode)) {
|
|
115
|
+
return prev - 1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return prev;
|
|
119
|
+
}, queryTransitSubmodes.length) !== 0) {
|
|
120
|
+
return false;
|
|
121
|
+
} // Continue to the other checks
|
|
122
|
+
|
|
123
|
+
} // OTP doesn't support multiple non-walk modes
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if (BANNED_TOGETHER.every(function (m) {
|
|
127
|
+
return combo.find(function (c) {
|
|
128
|
+
return c.mode === m;
|
|
129
|
+
});
|
|
130
|
+
})) return false;
|
|
131
|
+
return !!VALID_COMBOS.find(function (vc) {
|
|
132
|
+
return simplifiedModes.every(function (m) {
|
|
133
|
+
return vc.includes(m);
|
|
134
|
+
}) && vc.every(function (m) {
|
|
135
|
+
return simplifiedModes.includes(m);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
92
139
|
/**
|
|
93
|
-
* Generates list of queries for OTP to get a comprehensive
|
|
140
|
+
* Generates a list of queries for OTP to get a comprehensive
|
|
94
141
|
* set of results based on the modes input.
|
|
95
142
|
* @param params OTP Query Params
|
|
96
143
|
* @returns Set of parameters to generate queries
|
|
97
144
|
*/
|
|
98
145
|
|
|
146
|
+
|
|
99
147
|
export function generateCombinations(params) {
|
|
100
|
-
var VALID_COMBOS = [["WALK"], ["PERSONAL"], ["TRANSIT", "SHARED"], ["WALK", "SHARED"], ["TRANSIT"], ["TRANSIT", "PERSONAL"], ["TRANSIT", "CAR"]];
|
|
101
|
-
var BANNED_TOGETHER = ["SCOOTER", "BICYCLE"];
|
|
102
148
|
var completeModeList = [].concat(_toConsumableArray(extractAdditionalModes(params.modeSettings, params.modes)), _toConsumableArray(params.modes)); // List of the transit *submodes* that are included in the input params
|
|
103
149
|
|
|
104
150
|
var queryTransitSubmodes = completeModeList.filter(function (mode) {
|
|
@@ -107,75 +153,37 @@ export function generateCombinations(params) {
|
|
|
107
153
|
return mode.mode;
|
|
108
154
|
});
|
|
109
155
|
return combinations(completeModeList).filter(function (combo) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var simplifiedModes = Array.from(new Set(combo.map(function (c) {
|
|
113
|
-
return c.qualifier ? "SHARED" : SIMPLIFICATIONS[c.mode];
|
|
114
|
-
}))); // Ensure that if we have one transit mode, then we include ALL transit modes
|
|
115
|
-
|
|
116
|
-
if (simplifiedModes.includes("TRANSIT")) {
|
|
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
|
-
}
|
|
123
|
-
|
|
124
|
-
if (combo.reduce(function (prev, cur) {
|
|
125
|
-
if (queryTransitSubmodes.includes(cur.mode)) {
|
|
126
|
-
return prev - 1;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return prev;
|
|
130
|
-
}, queryTransitSubmodes.length) !== 0) {
|
|
131
|
-
return false;
|
|
132
|
-
} // Continue to the other checks
|
|
133
|
-
|
|
134
|
-
} // OTP doesn't support multiple non-walk modes
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (BANNED_TOGETHER.every(function (m) {
|
|
138
|
-
return combo.find(function (c) {
|
|
139
|
-
return c.mode === m;
|
|
140
|
-
});
|
|
141
|
-
})) return false;
|
|
142
|
-
return !!VALID_COMBOS.find(function (vc) {
|
|
143
|
-
return simplifiedModes.every(function (m) {
|
|
144
|
-
return vc.includes(m);
|
|
145
|
-
}) && vc.every(function (m) {
|
|
146
|
-
return simplifiedModes.includes(m);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
156
|
+
return isCombinationValid(combo, queryTransitSubmodes);
|
|
149
157
|
}).map(function (combo) {
|
|
150
158
|
return _objectSpread(_objectSpread({}, params), {}, {
|
|
151
159
|
modes: combo
|
|
152
160
|
});
|
|
153
161
|
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
162
|
+
}
|
|
163
|
+
export function generateOtp2Query(_ref) {
|
|
164
|
+
var from = _ref.from,
|
|
165
|
+
modeSettings = _ref.modeSettings,
|
|
166
|
+
modes = _ref.modes,
|
|
167
|
+
to = _ref.to;
|
|
168
|
+
// This extracts the values from the mode settings to key value pairs
|
|
161
169
|
var modeSettingValues = modeSettings.reduce(function (prev, cur) {
|
|
162
170
|
prev[cur.key] = cur.value;
|
|
163
171
|
return prev;
|
|
164
172
|
}, {});
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
173
|
+
var bikeReluctance = modeSettingValues.bikeReluctance,
|
|
174
|
+
carReluctance = modeSettingValues.carReluctance,
|
|
175
|
+
walkReluctance = modeSettingValues.walkReluctance,
|
|
176
|
+
wheelchair = modeSettingValues.wheelchair;
|
|
169
177
|
return {
|
|
170
178
|
query: print(PlanQuery),
|
|
171
179
|
variables: {
|
|
180
|
+
bikeReluctance: bikeReluctance,
|
|
181
|
+
carReluctance: carReluctance,
|
|
172
182
|
fromPlace: "".concat(from.name, "::").concat(from.lat, ",").concat(from.lon, "}"),
|
|
183
|
+
modes: modes,
|
|
173
184
|
toPlace: "".concat(to.name, "::").concat(to.lat, ",").concat(to.lon, "}"),
|
|
174
|
-
modes: params.modes,
|
|
175
185
|
walkReluctance: walkReluctance,
|
|
176
|
-
wheelchair: wheelchair
|
|
177
|
-
bikeReluctance: bikeReluctance,
|
|
178
|
-
carReluctance: carReluctance
|
|
186
|
+
wheelchair: wheelchair
|
|
179
187
|
}
|
|
180
188
|
};
|
|
181
189
|
}
|
package/esm/query-gen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,GAA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AA,KAAK,EAAExE,KAAK,CAACyE,SAAD,CADP;AAELC,IAAAA,SAAS,EAAE;AACTC,MAAAA,SAAS,YAAKjB,IAAI,CAACkB,IAAV,eAAmBlB,IAAI,CAACmB,GAAxB,cAA+BnB,IAAI,CAACoB,GAApC,MADA;AAETC,MAAAA,OAAO,YAAKd,EAAE,CAACW,IAAR,eAAiBX,EAAE,CAACY,GAApB,cAA2BZ,EAAE,CAACa,GAA9B,MAFE;AAGTxB,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KAHL;AAITc,MAAAA,cAAc,EAAdA,cAJS;AAKTC,MAAAA,UAAU,EAAVA,UALS;AAMTC,MAAAA,cAAc,EAAdA,cANS;AAOTC,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"}
|
|
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","VALID_COMBOS","BANNED_TOGETHER","TRANSIT_SUBMODES","Object","keys","TRANSIT_SUBMODES_AND_TRANSIT","isCombinationValid","combo","queryTransitSubmodes","simplifiedModes","from","Set","c","qualifier","every","vc","generateCombinations","params","completeModeList","modes","generateOtp2Query","to","modeSettingValues","key","bikeReluctance","carReluctance","walkReluctance","wheelchair","query","PlanQuery","variables","fromPlace","name","lat","lon","toPlace"],"mappings":";;;;;;;AACA,SAASA,KAAT,QAAsB,SAAtB;;;AAqBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAT,CACLC,YADK,EAELC,YAFK,EAGY;AACjB,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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ALJ,CAGEI,cAHF;AAAA,MAIEC,UAJF,GAKIL,iBALJ,CAIEK,UAJF;AAOA,SAAO;AACLC,IAAAA,KAAK,EAAEzE,KAAK,CAAC0E,SAAD,CADP;AAELC,IAAAA,SAAS,EAAE;AACTN,MAAAA,cAAc,EAAdA,cADS;AAETC,MAAAA,aAAa,EAAbA,aAFS;AAGTM,MAAAA,SAAS,YAAKrB,IAAI,CAACsB,IAAV,eAAmBtB,IAAI,CAACuB,GAAxB,cAA+BvB,IAAI,CAACwB,GAApC,MAHA;AAITf,MAAAA,KAAK,EAALA,KAJS;AAKTgB,MAAAA,OAAO,YAAKd,EAAE,CAACW,IAAR,eAAiBX,EAAE,CAACY,GAApB,cAA2BZ,EAAE,CAACa,GAA9B,MALE;AAMTR,MAAAA,cAAc,EAAdA,cANS;AAOTC,MAAAA,UAAU,EAAVA;AAPS;AAFN,GAAP;AAYD","sourcesContent":["import { LonLatOutput } from \"@conveyal/lonlat\";\nimport { print } from \"graphql\";\nimport {\n ModeSetting,\n ModeSettingValues,\n TransportMode\n} from \"@opentripplanner/types\";\n\nimport PlanQuery from \"./planQuery.graphql\";\n\ntype OTPQueryParams = {\n from: LonLatOutput & { name?: string };\n modes: TransportMode[];\n modeSettings: ModeSetting[];\n to: LonLatOutput & { name?: string };\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): 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 [...prev, transportMode];\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\n/**\n * This constant maps all the transport mode to a broader mode type,\n * which is used to determine the valid combinations of modes used in query generation.\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\n// Inclusion of \"TRANSIT\" alone automatically implies \"WALK\" in OTP\nconst VALID_COMBOS = [\n [\"WALK\"],\n [\"PERSONAL\"],\n [\"TRANSIT\", \"SHARED\"],\n [\"WALK\", \"SHARED\"],\n [\"TRANSIT\"],\n [\"TRANSIT\", \"PERSONAL\"],\n [\"TRANSIT\", \"CAR\"]\n];\n\nconst BANNED_TOGETHER = [\"SCOOTER\", \"BICYCLE\"];\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\nfunction isCombinationValid(\n combo: TransportMode[],\n queryTransitSubmodes: string[]\n): boolean {\n if (combo.length === 0) return false;\n\n // All current qualifiers currently simplify to \"SHARED\"\n const simplifiedModes = Array.from(\n new Set(combo.map(c => (c.qualifier ? \"SHARED\" : SIMPLIFICATIONS[c.mode])))\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 (queryTransitSubmodes.length && combo.find(c => c.mode === \"TRANSIT\")) {\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))) 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\n/**\n * Generates a 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 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 => isCombinationValid(combo, queryTransitSubmodes))\n .map(combo => ({ ...params, modes: combo }));\n}\n\nexport function generateOtp2Query({\n from,\n modeSettings,\n modes,\n to\n}: OTPQueryParams): GraphQLQuery {\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 bikeReluctance,\n carReluctance,\n walkReluctance,\n wheelchair\n } = modeSettingValues;\n\n return {\n query: print(PlanQuery),\n variables: {\n bikeReluctance,\n carReluctance,\n fromPlace: `${from.name}::${from.lat},${from.lon}}`,\n modes,\n toPlace: `${to.name}::${to.lat},${to.lon}}`,\n walkReluctance,\n wheelchair\n }\n };\n}\n"],"file":"query-gen.js"}
|