Skip to content

Add filter for minimum bike parking distance - #4626

Merged
leonardehrenfried merged 17 commits into
opentripplanner:dev-2.xfrom
mfdz:stadtnavi-filters
Dec 8, 2022
Merged

leonardehrenfried merged 17 commits into
opentripplanner:dev-2.xfrom
mfdz:stadtnavi-filters

Conversation

@leonardehrenfried

@leonardehrenfried leonardehrenfried commented Nov 22, 2022 •

Copy link
Copy Markdown
Member

Summary

This PR introduces two new filters for the Stadtnavi project's use cases:

- Flex only to destination: this is useful if you advertise a flex service that "brings you home". There you want to remove any itinerary that has a long-ish walking leg at the end.

  • minBikeParkingDistance: this filter removes results that have only a very short bike leg before parking it and using public transport. In such a case we don't want to show a bike route at all but rather suggest walking the 300 meter or so to the stop.

Unit tests

Lots added.

Documentation

Autogenerated.

cc @hbruch

@leonardehrenfried leonardehrenfried added the !New Feature A functional feature targeting the end user. label Nov 22, 2022
@leonardehrenfried
leonardehrenfried requested a review from a team as a code owner November 22, 2022 21:41
@leonardehrenfried
leonardehrenfried force-pushed the stadtnavi-filters branch 2 times, most recently from 15ffac9 to cf486ad Compare November 22, 2022 21:42

@vesameskanen vesameskanen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if RemoveBikeParkWithShortBikeFilter.java should be renamed. The filter works well in cases where you take the bike into a vehicle instead of parking it. It does not make sense to drag the bike around without using it.

@leonardehrenfried

Copy link
Copy Markdown
Member Author

@vesameskanen while there is nothing parking-specific in the filter class itself, it's only ativated when the mode is BIKE_PARK. Are you interested in making it work for bike + transit searches, too?

If so, should the same limits apply?

@vesameskanen

Copy link
Copy Markdown
Contributor

Yes, I was wondering if code could be easily reused for other purposes in addition to BIKE_PARK street mode. I guess that might involve more parameters, as the purpose should be configurable. Minimum distance could be pretty much the same, but maybe the filter could be applied twice with different parameters.

On side note: this filter, when applied alone, has an unpleasant side effect of removing best bike park suggestion and leaving some silly ones available. I got an itinerary with cycling to a park site away from the target station and much longer walk instead of the simple filtered one. Is there a way to prevent that, maybe using another filter before the new minimum distance filter? Perhaps the order of filtering actions is very significant here?

@vesameskanen

Copy link
Copy Markdown
Contributor

Forget the side note, I just picked a bad start point which got mapped to a longer cycling route. Sorry.

@leonardehrenfried

Copy link
Copy Markdown
Member Author

Yes, I was wondering if code could be easily reused for other purposes in addition to BIKE_PARK street mode. I guess that might involve more parameters, as the purpose should be configurable. Minimum distance could be pretty much the same, but maybe the filter could be applied twice with different parameters.

It should not be too difficult to implement this. We could reuse the same parameter or have two: one for BIKE_PARK and one for bike + transit.

Do you have a suggestion how it should work?

@codecov-commenter

codecov-commenter commented Nov 25, 2022 •

Copy link
Copy Markdown

Codecov Report

Base: 60.61% // Head: 60.67% // Increases project coverage by +0.05% 🎉

Coverage data is based on head (b1b486f) compared to base (dabe775).
Patch coverage: 95.45% of modified lines in pull request are covered.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #4626      +/-   ##
=============================================
+ Coverage      60.61%   60.67%   +0.05%     
- Complexity     12212    12255      +43     
=============================================
  Files           1581     1581              
  Lines          63417    63514      +97     
  Branches        6992     6999       +7     
=============================================
+ Hits           38438    38534      +96     
- Misses         22800    22802       +2     
+ Partials        2179     2178       -1     
Impacted Files Coverage Δ
...pentripplanner/ext/flex/edgetype/FlexTripEdge.java 92.00% <ø> (-0.31%) ⬇️
...entripplanner/routing/algorithm/RoutingWorker.java 81.53% <75.00%> (-0.43%) ⬇️
.../org/opentripplanner/ext/flex/FlexServiceDate.java 87.50% <100.00%> (ø)
...java/org/opentripplanner/model/plan/Itinerary.java 89.47% <100.00%> (+0.06%) ⬆️
...m/filterchain/ItineraryListFilterChainBuilder.java 91.81% <100.00%> (+0.30%) ⬆️
...onflagger/RemoveItinerariesWithShortStreetLeg.java 100.00% <100.00%> (ø)
...rithm/mapping/RouteRequestToFilterChainMapper.java 81.25% <100.00%> (+0.60%) ⬆️
...request/preference/ItineraryFilterPreferences.java 97.77% <100.00%> (+0.15%) ⬆️
...ne/config/routerequest/ItineraryFiltersConfig.java 89.32% <100.00%> (+0.66%) ⬆️
...ph_builder/module/osm/tagmapping/OsmTagMapper.java 80.48% <0.00%> (-12.20%) ⬇️
... and 36 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@vesameskanen

Copy link
Copy Markdown
Contributor

I am - very - sorry for slow feedback. The new approach looks good to me, but could the actual filter be parametrized with a given street mode? I am afraid that there will surely be a need for filtering 100 meter car park ride legs, super short scooter rentals etc.

public RemoveItinerariesWithShortStreetLeg(double minDistance, TraverseMode mode) ...

@leonardehrenfried

Copy link
Copy Markdown
Member Author

@vesameskanen Would you like the traverse mode also to be configurable through JSON or do you want to add that when you need it?

@vesameskanen

Copy link
Copy Markdown
Contributor

I guess filtering is usually quite static need so parsing the values from json might be useful. New JSON params do not have to be implemented within the scope of this PR , though. New config parameters which activate street mode specific filtering can be added later.

@leonardehrenfried

Copy link
Copy Markdown
Member Author

I guess filtering is usually quite static need so parsing the values from json might be useful. New JSON params do not have to be implemented within the scope of this PR , though. New config parameters which activate street mode specific filtering can be added later.

I've implemented this in 84842e9

/**
* Remove all itineraries where all the final leg is more than x minutes of walking.
*/
public class FlexOnlyToDestinationFilter implements ItineraryListFilter {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to implement this similar to how maxTransferDuration is used, that way we could do the filtering already before the search?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a very good point which I had not thought about.

@t2gran t2gran added this to the 2.3 milestone Dec 1, 2022
@leonardehrenfried leonardehrenfried changed the title Add filters for flex-to-destination and minimum bike parking distance Add filter for minimum bike parking distance Dec 1, 2022
}

public TestItineraryBuilder flex(int start, int end, Place to) {
if (lastPlace == null) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hannesj

I'm going to leave this code in here even though it's not used right now. Took me a while to figure everything out and it will become useful at some stage.

vesameskanen
vesameskanen previously approved these changes Dec 5, 2022
Comment on lines +133 to +141
var modes = request.journey().modes();
boolean hasBikePark = List
.of(modes.accessMode, modes.egressMode)
.contains(StreetMode.BIKE_TO_PARK);

double minBikeParkingDistance = NOT_SET;
if (hasBikePark) {
minBikeParkingDistance = request.preferences().itineraryFilter().minBikeParkingDistance();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this, not to make the already complex method any mor complex. I'm also not really happy about using org.opentripplanner.routing.algorithm.filterchain.ItineraryListFilterChainBuilder.NOT_SET from here, can we find a better solution?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we simply check if the limit is greater than zero?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good idea

…n/ItineraryListFilterChainBuilder.java

Co-authored-by: Hannes Junnila <hannes.junnila@gmail.com>
@leonardehrenfried
leonardehrenfried merged commit c05f68e into opentripplanner:dev-2.x Dec 8, 2022
t2gran pushed a commit that referenced this pull request Dec 8, 2022
@leonardehrenfried
leonardehrenfried deleted the stadtnavi-filters branch December 8, 2022 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!New Feature A functional feature targeting the end user.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants