Skip to content

Commit 519b06d

Browse files
Merge pull request #1366 from opentripplanner/strict-valid-mode-combos
acceptableValidModeCombos configuration
2 parents e5bac05 + 0e94f51 commit 519b06d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Diff for: example-config.yml

+12
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ routingTypes:
348348

349349
# Itinerary options
350350
itinerary:
351+
# Provides an array of valid mode combinations that returned itineraries will be filtered against
352+
# If left blank, all itineraries deemed valid by OTP will be returned
353+
validModeCombinations: [
354+
['WALK'],
355+
['WALK', 'PERSONAL'],
356+
['WALK', 'TRANSIT', 'SHARED'],
357+
['WALK', 'SHARED'],
358+
['WALK', 'TRANSIT'],
359+
['WALK', 'TRANSIT', 'PERSONAL'],
360+
['WALK', 'TRANSIT', 'CAR'],
361+
['CAR']
362+
]
351363
# Show fares for each transit leg (false if omitted).
352364
# (Requires using LineItinerary.)
353365
showRouteFares: false

Diff for: lib/actions/apiV2.js

+17
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
982982
{}
983983

984984
const strictModes = !!config?.itinerary?.strictItineraryFiltering
985+
const validModeCombinations = config?.itinerary?.validModeCombinations
985986

986987
// Filter mode definitions based on active mode keys
987988
const activeModeButtons = config.modes?.modeButtons.filter((mb) =>
@@ -1114,6 +1115,22 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
11141115
activeModeStrings.includes(SIMPLIFICATIONS[leg.mode])
11151116
)
11161117
)
1118+
// If "acceptableValidModeCombos" is provided, filter out itineraries that do not match our list of valid mode combinations
1119+
// (e.g. "WALK" + "DRIVE")
1120+
// TODO: Remove this once we switch to planConnection API
1121+
if (validModeCombinations?.length > 0) {
1122+
filteredItineraries = filteredItineraries.filter((itin) => {
1123+
const modeCombo = Array.from(
1124+
new Set(itin.legs.map((leg) => SIMPLIFICATIONS[leg.mode]))
1125+
)
1126+
return validModeCombinations.find(
1127+
(vc) =>
1128+
modeCombo.length === vc.length &&
1129+
vc.every((m) => modeCombo.includes(m))
1130+
)
1131+
})
1132+
}
1133+
11171134
// ... Otherwise return all itineraries.
11181135
}
11191136

0 commit comments

Comments
 (0)