@opentripplanner/core-utils
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -185,3 +185,3 @@ "use strict"; | ||
const hasInterStopGeometry = !!leg.interStopGeometry; | ||
const hasIntermediateStopGeomerty = hasInterStopGeometry && leg.intermediateStops && leg.interStopGeometry.length === leg.intermediateStops.length + 1; // create leg-specific pattern | ||
const hasIntermediateStopGeometry = hasInterStopGeometry && leg.intermediateStops && leg.interStopGeometry.length === leg.intermediateStops.length + 1; // create leg-specific pattern | ||
@@ -216,3 +216,3 @@ const ptnId = `ptn_${patternId}`; | ||
stop_id: stop.stopId, | ||
geometry: hasIntermediateStopGeomerty && leg.interStopGeometry[i].points | ||
geometry: hasIntermediateStopGeometry && leg.interStopGeometry[i].points | ||
}); | ||
@@ -231,3 +231,3 @@ }); | ||
stop_id: leg.to.stopId, | ||
geometry: hasInterStopGeometry && leg.interStopGeometry[leg.interStopGeometry.length - 1].points | ||
geometry: hasInterStopGeometry && (hasIntermediateStopGeometry ? leg.interStopGeometry[leg.interStopGeometry.length - 1].points : leg.legGeometry.points) | ||
}); // add route to the route dictionary | ||
@@ -234,0 +234,0 @@ |
@@ -15,4 +15,7 @@ "use strict"; | ||
exports.planParamsToQuery = planParamsToQuery; | ||
exports.getRoutingParams = getRoutingParams; | ||
exports.defaultParams = void 0; | ||
var _moment = _interopRequireDefault(require("moment")); | ||
var _qs = _interopRequireDefault(require("qs")); | ||
@@ -205,2 +208,84 @@ | ||
return query; | ||
} | ||
/** | ||
* Create an object that can be used as a querystring in making an OTP | ||
* PlannerResource request. | ||
* | ||
* See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html | ||
* | ||
* @param {Object} config The OTP application config. See types#configType | ||
* @param {Object} currentQuery The current query parameters as saved in the | ||
* application state. This method does some extra logic on top of this data | ||
* in order to create a request suitable for OTP. See types#queryType | ||
* @param {boolean} ignoreRealtimeUpdates If true, will create a request that | ||
* does not use realtime data. | ||
*/ | ||
function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) { | ||
const routingType = currentQuery.routingType; | ||
const isItinerary = routingType === "ITINERARY"; | ||
let params = {}; // Start with the universe of OTP parameters defined in query-params.js: | ||
_queryParams.default.filter(qp => { | ||
// A given parameter is included in the request if all of the following: | ||
// 1. Must apply to the active routing type (ITINERARY or PROFILE) | ||
// 2. Must be included in the current user-defined query | ||
// 3. Must pass the parameter's applicability test, if one is specified | ||
return qp.routingTypes.indexOf(routingType) !== -1 && qp.name in currentQuery && (typeof qp.applicable !== "function" || qp.applicable(currentQuery, config)); | ||
}).forEach(qp => { | ||
// Translate the applicable parameters according to their rewrite | ||
// functions (if provided) | ||
const rewriteFunction = isItinerary ? qp.itineraryRewrite : qp.profileRewrite; | ||
params = Object.assign(params, rewriteFunction ? rewriteFunction(currentQuery[qp.name]) : { | ||
[qp.name]: currentQuery[qp.name] | ||
}); | ||
}); // Additional processing specific to ITINERARY mode | ||
if (isItinerary) { | ||
// override ignoreRealtimeUpdates if provided | ||
if (typeof ignoreRealtimeUpdates === "boolean") { | ||
params.ignoreRealtimeUpdates = ignoreRealtimeUpdates; | ||
} // check date/time validity; ignore both if either is invalid | ||
const dateValid = (0, _moment.default)(params.date, _time.OTP_API_DATE_FORMAT).isValid(); | ||
const timeValid = (0, _moment.default)(params.time, _time.OTP_API_TIME_FORMAT).isValid(); | ||
if (!dateValid || !timeValid) { | ||
delete params.time; | ||
delete params.date; | ||
} // temp: set additional parameters for CAR_HAIL or CAR_RENT trips | ||
if (params.mode && (params.mode.includes("CAR_HAIL") || params.mode.includes("CAR_RENT"))) { | ||
params.minTransitDistance = "50%"; // increase search timeout because these queries can take a while | ||
params.searchTimeout = 10000; | ||
} // set onlyTransitTrips for car rental searches | ||
if (params.mode && params.mode.includes("CAR_RENT")) { | ||
params.onlyTransitTrips = true; | ||
} // Additional processing specific to PROFILE mode | ||
} else { | ||
// check start and end time validity; ignore both if either is invalid | ||
const startTimeValid = (0, _moment.default)(params.startTime, _time.OTP_API_TIME_FORMAT).isValid(); | ||
const endTimeValid = (0, _moment.default)(params.endTime, _time.OTP_API_TIME_FORMAT).isValid(); | ||
if (!startTimeValid || !endTimeValid) { | ||
delete params.startTimeValid; | ||
delete params.endTimeValid; | ||
} | ||
} // TODO: check that valid from/to locations are provided | ||
// hack to add walking to driving/TNC trips | ||
if ((0, _itinerary.hasCar)(params.mode)) { | ||
params.mode += ",WALK"; | ||
} | ||
return params; | ||
} |
@@ -560,4 +560,16 @@ "use strict"; | ||
const configuredCompanyType = _propTypes.default.shape({ | ||
/** | ||
* The id of the company. This is typically in all-caps. | ||
*/ | ||
id: _propTypes.default.string.isRequired, | ||
/** | ||
* A human readable text value that can be displayed to users. | ||
*/ | ||
label: _propTypes.default.string.isRequired, | ||
/** | ||
* A comma-separated list of applicable modes of travel that the company | ||
* offers. | ||
*/ | ||
modes: _propTypes.default.string.isRequired | ||
@@ -564,0 +576,0 @@ }); |
{ | ||
"name": "@opentripplanner/core-utils", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Core functionality that is shared among numerous UI components", | ||
@@ -20,3 +20,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "94be67f4904e6298ee757f9ee86a7e0bf72f8fb9" | ||
"gitHead": "f9d17b0c3f7e3ee90b4ef172e571943376fa8d8a" | ||
} |
@@ -165,3 +165,3 @@ import moment from "moment"; | ||
const hasInterStopGeometry = !!leg.interStopGeometry; | ||
const hasIntermediateStopGeomerty = | ||
const hasIntermediateStopGeometry = | ||
hasInterStopGeometry && | ||
@@ -201,3 +201,3 @@ leg.intermediateStops && | ||
geometry: | ||
hasIntermediateStopGeomerty && leg.interStopGeometry[i].points | ||
hasIntermediateStopGeometry && leg.interStopGeometry[i].points | ||
}); | ||
@@ -218,3 +218,5 @@ }); | ||
hasInterStopGeometry && | ||
leg.interStopGeometry[leg.interStopGeometry.length - 1].points | ||
(hasIntermediateStopGeometry | ||
? leg.interStopGeometry[leg.interStopGeometry.length - 1].points | ||
: leg.legGeometry.points) | ||
}); | ||
@@ -221,0 +223,0 @@ |
111
src/query.js
@@ -0,1 +1,2 @@ | ||
import moment from "moment"; | ||
import qs from "qs"; | ||
@@ -5,2 +6,3 @@ | ||
getTransitModes, | ||
hasCar, | ||
hasTransit, | ||
@@ -12,3 +14,8 @@ isAccessMode, | ||
import queryParams from "./query-params"; | ||
import { getCurrentTime, getCurrentDate } from "./time"; | ||
import { | ||
getCurrentTime, | ||
getCurrentDate, | ||
OTP_API_DATE_FORMAT, | ||
OTP_API_TIME_FORMAT | ||
} from "./time"; | ||
@@ -214,1 +221,103 @@ /* The list of default parameters considered in the settings panel */ | ||
} | ||
/** | ||
* Create an object that can be used as a querystring in making an OTP | ||
* PlannerResource request. | ||
* | ||
* See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html | ||
* | ||
* @param {Object} config The OTP application config. See types#configType | ||
* @param {Object} currentQuery The current query parameters as saved in the | ||
* application state. This method does some extra logic on top of this data | ||
* in order to create a request suitable for OTP. See types#queryType | ||
* @param {boolean} ignoreRealtimeUpdates If true, will create a request that | ||
* does not use realtime data. | ||
*/ | ||
export function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) { | ||
const routingType = currentQuery.routingType; | ||
const isItinerary = routingType === "ITINERARY"; | ||
let params = {}; | ||
// Start with the universe of OTP parameters defined in query-params.js: | ||
queryParams | ||
.filter(qp => { | ||
// A given parameter is included in the request if all of the following: | ||
// 1. Must apply to the active routing type (ITINERARY or PROFILE) | ||
// 2. Must be included in the current user-defined query | ||
// 3. Must pass the parameter's applicability test, if one is specified | ||
return ( | ||
qp.routingTypes.indexOf(routingType) !== -1 && | ||
qp.name in currentQuery && | ||
(typeof qp.applicable !== "function" || | ||
qp.applicable(currentQuery, config)) | ||
); | ||
}) | ||
.forEach(qp => { | ||
// Translate the applicable parameters according to their rewrite | ||
// functions (if provided) | ||
const rewriteFunction = isItinerary | ||
? qp.itineraryRewrite | ||
: qp.profileRewrite; | ||
params = Object.assign( | ||
params, | ||
rewriteFunction | ||
? rewriteFunction(currentQuery[qp.name]) | ||
: { [qp.name]: currentQuery[qp.name] } | ||
); | ||
}); | ||
// Additional processing specific to ITINERARY mode | ||
if (isItinerary) { | ||
// override ignoreRealtimeUpdates if provided | ||
if (typeof ignoreRealtimeUpdates === "boolean") { | ||
params.ignoreRealtimeUpdates = ignoreRealtimeUpdates; | ||
} | ||
// check date/time validity; ignore both if either is invalid | ||
const dateValid = moment(params.date, OTP_API_DATE_FORMAT).isValid(); | ||
const timeValid = moment(params.time, OTP_API_TIME_FORMAT).isValid(); | ||
if (!dateValid || !timeValid) { | ||
delete params.time; | ||
delete params.date; | ||
} | ||
// temp: set additional parameters for CAR_HAIL or CAR_RENT trips | ||
if ( | ||
params.mode && | ||
(params.mode.includes("CAR_HAIL") || params.mode.includes("CAR_RENT")) | ||
) { | ||
params.minTransitDistance = "50%"; | ||
// increase search timeout because these queries can take a while | ||
params.searchTimeout = 10000; | ||
} | ||
// set onlyTransitTrips for car rental searches | ||
if (params.mode && params.mode.includes("CAR_RENT")) { | ||
params.onlyTransitTrips = true; | ||
} | ||
// Additional processing specific to PROFILE mode | ||
} else { | ||
// check start and end time validity; ignore both if either is invalid | ||
const startTimeValid = moment( | ||
params.startTime, | ||
OTP_API_TIME_FORMAT | ||
).isValid(); | ||
const endTimeValid = moment(params.endTime, OTP_API_TIME_FORMAT).isValid(); | ||
if (!startTimeValid || !endTimeValid) { | ||
delete params.startTimeValid; | ||
delete params.endTimeValid; | ||
} | ||
} | ||
// TODO: check that valid from/to locations are provided | ||
// hack to add walking to driving/TNC trips | ||
if (hasCar(params.mode)) { | ||
params.mode += ",WALK"; | ||
} | ||
return params; | ||
} |
@@ -515,4 +515,14 @@ import PropTypes from "prop-types"; | ||
export const configuredCompanyType = PropTypes.shape({ | ||
/** | ||
* The id of the company. This is typically in all-caps. | ||
*/ | ||
id: PropTypes.string.isRequired, | ||
/** | ||
* A human readable text value that can be displayed to users. | ||
*/ | ||
label: PropTypes.string.isRequired, | ||
/** | ||
* A comma-separated list of applicable modes of travel that the company | ||
* offers. | ||
*/ | ||
modes: PropTypes.string.isRequired | ||
@@ -519,0 +529,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167083
4834