Skip to content

Add Leg.stopCalls with full flex information to GTFS API - #6757

Merged
leonardehrenfried merged 20 commits into
opentripplanner:dev-2.xfrom
ibi-group:flex-graphql-types
Aug 15, 2025
Merged

leonardehrenfried merged 20 commits into
opentripplanner:dev-2.xfrom
ibi-group:flex-graphql-types

Conversation

@leonardehrenfried

@leonardehrenfried leonardehrenfried commented Jul 18, 2025 •

Copy link
Copy Markdown
Member

Summary

Adds the field Leg.calls to the GTFS API. This is intended as a replacement for both intermediatePlaces and intermediateStops by providing the full information about the calls of a leg, in particular the full information about flex windows and flex stop types.

It uses the the StopCall type introduced in #5393 and adds flex-specific data to it.

Unit tests

Lots added.

Documentation

Javadoc.

cc @miles-grant-ibigroup

@leonardehrenfried
leonardehrenfried requested a review from a team as a code owner July 18, 2025 09:56
@leonardehrenfried leonardehrenfried added the !New Feature A functional feature targeting the end user. label Jul 18, 2025
@codecov

codecov Bot commented Jul 18, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.38462% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.76%. Comparing base (83dcc7f) to head (4239dcc).
⚠️ Report is 25 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...tfs/datafetchers/CallStopLocationTypeResolver.java 0.00% 4 Missing and 1 partial ⚠️
...fs/datafetchers/CallScheduledTimeTypeResolver.java 33.33% 2 Missing and 2 partials ⚠️
...pentripplanner/apis/gtfs/datafetchers/LegImpl.java 33.33% 4 Missing ⚠️
...nner/apis/gtfs/datafetchers/LocationGroupImpl.java 57.14% 3 Missing ⚠️
...ipplanner/apis/gtfs/datafetchers/StopCallImpl.java 86.66% 1 Missing and 1 partial ⚠️
...tripplanner/apis/gtfs/model/CallScheduledTime.java 66.66% 0 Missing and 2 partials ⚠️
...ipplanner/apis/gtfs/service/ApiTransitService.java 75.00% 2 Missing ⚠️
...ipplanner/apis/gtfs/datafetchers/LocationImpl.java 80.00% 1 Missing ⚠️
...model/model/timetable/DatedServiceJourneyType.java 0.00% 1 Missing ⚠️
...transmodel/model/timetable/ServiceJourneyType.java 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6757      +/-   ##
=============================================
- Coverage      71.76%   71.76%   -0.01%     
- Complexity     19317    19327      +10     
=============================================
  Files           2088     2090       +2     
  Lines          78711    78770      +59     
  Branches        8020     8027       +7     
=============================================
+ Hits           56487    56526      +39     
- Misses         19367    19385      +18     
- Partials        2857     2859       +2     

☔ 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

Copy link
Copy Markdown
Member Author

@binh-dam-ibigroup If you want to test this, you can do it with the Clackamas GTFS feed and the following query

query PortlandFlex {
  planConnection(
    origin: {location: {coordinate: {latitude: 45.35670, longitude: -122.5944}}}
    destination: {location: {coordinate: {latitude: 45.31406, longitude: -122.5589}}}
    dateTime: {earliestDeparture: "2025-07-16T10:30-07:00"}
    modes: {direct: [FLEX, WALK], directOnly: true}
  ) {
    edges {
      node {
        legs {
          mode
          from {
            name
            stop {
              name
            }
            departure {
              scheduledTime
            }
          }
          to {
            name
            stop {
              name
            }
            arrival {
              scheduledTime
            }
          }
          route {
            gtfsId
            longName
            shortName
          }
          stopCalls {
            stopLocation {
              __typename
              ... on Stop {
              	gtfsId
                __typename
              }
              ... on Location {
                gtfsId
                __typename
              }
              
            }
            schedule {
              time {
                __typename
              }
            }
          }
        }
      }
    }
  }
}

@binh-dam-ibigroup binh-dam-ibigroup 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.

Well-written and works after trying different configs. I made a few minor suggestions.

try {
CallSchedule schedule = impl.schedule().get(env);
assertEquals(new CallSchedule(new TimeWindow(TEN_AM, TEN_AM.plusMinutes(30))), schedule);
} catch (Exception e) {

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.

Previous test has Exception in the method declaration instead of a try/catch block, it should probably be the same here. You could also combine the two tests into a parameterized test.

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.

I agree but there is a complication, namely that this one activates the flex feature for the duration of the test, which means that the code is executed in a Runnable. This means that the exception is not propagated and needs to be handled explicitly. I don't like it either.

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.

Probably worth adding a comment about that.

Co-authored-by: Binh Dam <56846598+binh-dam-ibigroup@users.noreply.github.com>
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.model.PickDrop;
import org.opentripplanner.model.TripTimeOnDate;

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.

Unnecessary import?

originates and the Place where the leg ends. For non-transit legs, null.
"""
intermediatePlaces: [Place]
intermediatePlaces: [Place] @deprecated(reason : "Use `leg.stopCalls` instead")

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.

So this was always just stops despite using the place type?

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.

Yes, it was only stops:

For non-transit legs it returned null.

type Location {
"The geometry representing the geographic extend of the location."
geometry: StopGeometries!
gtfsId: String!

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.

Add a generic comment describing the id's structure like we usually have.

This is mostly used by demand-responsive services.
"""
type LocationGroup {
gtfsId: String!

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.

Same as above.

Comment on lines +910 to +911
"The members that are part of the group."
members: [Stop!]!

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.

Btw can these stops be stations? I think we should document it here regardless of how it is.

@leonardehrenfried leonardehrenfried Aug 10, 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.

I think that the assumption is that can only be regular stops, but if you forced it you could convince yourself that a station is allowed: https://gtfs.org/documentation/schedule/reference/#location_group_stopstxt

I will add a note but perhaps this could use a clarification in the spec.

Comment on lines +2477 to +2481
"A time window when a vehicle visit a stop, area or group of stops."
type TimeWindow {
end: OffsetDateTime!
start: OffsetDateTime!
}

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.

Are the start and end inclusive/exclusive?

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.

Start is easily answered: it is inclusive.

End is defined as "the time that the service ends" so technically the last pick up time would be 17:59:59.999 and not 18:00. It would look pretty odd in a travel plan though so I'm not sure that it's worth being very strict with the spec here.

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.

Yeah I was just wondering if people would configure it with a minute granularity like 00:00-00:59 and then there is a whole minute where it's slightly unclear if the service is on or not.

@@ -0,0 +1,41 @@
package org.opentripplanner.updater.trip;

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.

Sort of a weird package for this as we don't have support for flex in trip updates.

import org.opentripplanner.transit.service.TimetableRepository;
import org.opentripplanner.updater.trip.FlexTripInput.FlexStop;

public class RealtimeTestEnvironmentBuilder {

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.

Same concern again, why do we use a realtime test environment for flex stuff?

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.

The RealTimeTestEnvironement is the easiest way to build a full TransitService so you don't have to build the whole data model (stop times, trip, route, agency, trip times, timetables...) by hand.

The other option is to make a builder just for flex stuff but that would share much of the same code. What do you think of elevating this to a general purpose "data model builder" and renaming it?

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.

We discussed this on Tuesday and it's fine to use this test environment here for now.

@optionsome

Copy link
Copy Markdown
Member

There is a conflict

@binh-dam-ibigroup binh-dam-ibigroup 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'm good with the latest documentation changes and cleanups.

@leonardehrenfried
leonardehrenfried merged commit 986ef15 into opentripplanner:dev-2.x Aug 15, 2025
t2gran pushed a commit that referenced this pull request Aug 15, 2025
@leonardehrenfried
leonardehrenfried deleted the flex-graphql-types branch August 15, 2025 12:26
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.

4 participants