Skip to content

Enforce flex rule: at least two stop times per trip - #6828

Merged
leonardehrenfried merged 5 commits into
opentripplanner:dev-2.xfrom
ibi-group:single-flex-time
Sep 19, 2025
Merged

leonardehrenfried merged 5 commits into
opentripplanner:dev-2.xfrom
ibi-group:single-flex-time

Conversation

@leonardehrenfried

Copy link
Copy Markdown
Member

Summary

Both the GTFS and NeTEx specs require flex trips, just like regular ones, to have at least 2 stop times/passing times.

Even though our flex routing engine doesn't produce a result when you have a trip with a single stop time, we nevertheless import the data anyway and then do nothing with it. It may end up in API response which can be quite confusing.

For this reason, this PR rejects flex trips with fewer than 2 stop times and adds an issue to the store.

Issue

No.

Unit tests

Added.

@leonardehrenfried
leonardehrenfried requested a review from a team as a code owner August 28, 2025 09:34
@leonardehrenfried leonardehrenfried added +Sandbox This will be implemented as a Sandbox feature !Technical Debt Improve code quality, no functional changes. labels Aug 28, 2025
@codecov

codecov Bot commented Aug 28, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.08%. Comparing base (c5fd182) to head (4fc2ef3).
⚠️ Report is 200 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
.../org/opentripplanner/ext/flex/FlexTripsMapper.java 80.00% 0 Missing and 1 partial ⚠️
.../main/java/org/opentripplanner/model/StopTime.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6828      +/-   ##
=============================================
+ Coverage      71.99%   72.08%   +0.08%     
- Complexity     19437    19521      +84     
=============================================
  Files           2100     2105       +5     
  Lines          78774    78972     +198     
  Branches        7963     8009      +46     
=============================================
+ Hits           56717    56927     +210     
+ Misses         19249    19221      -28     
- Partials        2808     2824      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leonardehrenfried leonardehrenfried changed the title Enforce flex rule of multiple stop times per trip Enforce flex rule: at least two stop times per trip Aug 28, 2025
@optionsome optionsome self-assigned this Aug 28, 2025
// result.add(new ContinuousPickupDropOffTrip(trip, stopTimes));
} else if (
stopTimes.size() < 2 &&
stopTimes.stream().anyMatch(st -> st.hasFlexWindow() || st.hasFlexibleStop())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the need for this check? Can these stoptimes be any stop times or are they filtered somewhere to be just "flex" stop times? Should this check be moved to be the first if so you don't have to account for this edge case in the other checks?

@leonardehrenfried leonardehrenfried Aug 29, 2025

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.

These are all stop times, not just the flex ones therefore you need something like that.

If I took your comment literally, then I can move the longish if statement to the top and that would look like that: leonardehrenfried@ddf302a

However, I don't find this any better.

Thinking a bit bigger, we could have a first step where I extract only the flex stop times and in a second one we sort it into the two types of flex trips and add the issues.

What do you think of that?

@leonardehrenfried
leonardehrenfried marked this pull request as draft August 29, 2025 14:35
@leonardehrenfried
leonardehrenfried marked this pull request as ready for review August 29, 2025 15:43
@optionsome
optionsome self-requested a review September 9, 2025 09:42
Comment thread application/src/ext/java/org/opentripplanner/ext/flex/FlexTripsMapper.java Outdated
leonardehrenfried and others added 2 commits September 9, 2025 17:21
…sMapper.java

Co-authored-by: Joel Lappalainen <lappalj8@gmail.com>
@t2gran t2gran added this to the 2.9 (next release) milestone Sep 10, 2025

@vpaturet vpaturet 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.

Remark: Some flex trips consist in a single area where passengers can be picked up and then dropped off. In practice these trips are modeled with 2 flexible stops that refer to the same area. In this case, the invariant "at least 2 stops" still holds true.

@leonardehrenfried
leonardehrenfried merged commit 99e1fc1 into opentripplanner:dev-2.x Sep 19, 2025
7 checks passed
@leonardehrenfried
leonardehrenfried deleted the single-flex-time branch September 19, 2025 07:32
t2gran pushed a commit that referenced this pull request Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+Sandbox This will be implemented as a Sandbox feature !Technical Debt Improve code quality, no functional changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants