-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add query for cancelled trips to GTFS GraphQL API #5393
base: dev-2.x
Are you sure you want to change the base?
Add query for cancelled trips to GTFS GraphQL API #5393
Conversation
It is much more efficient to filter trips in early stage
src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls
Outdated
Show resolved
Hide resolved
src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java
Outdated
Show resolved
Hide resolved
My current understanding of what should be done:
While doing this, we should not add features which are not needed yet, or unnecessarily duplicated fields of the Trip. In my opinion, duplicating a field from the Trip object to DatedTrip level indicates that the values presumably differ. |
Yes, I would keep the implementation of @optionsome however thinks that you should include stop times. I can live without them and can add them when I need it. |
@vesameskanen can you be the second reviewer? |
This is ready for review again. I didn't end up major refactorings to the schema. If @t2gran really wants to use one TripOnServiceDate type for all trips, I can do it, but I would prefer to model trips that have some flex properties with a separate type. |
I've updated this based on yesterday's discussion. I ended up using a union for the stop call because the structure of the call would be completely different if there is a scheduled time window. The time window should be modified separately from the estimates vs how it makes sense to group schedules and estimates together when a time window is not in use. |
application/src/test/java/org/opentripplanner/apis/gtfs/GraphQLIntegrationTest.java
Show resolved
Hide resolved
TransitService transitService = getTransitService(environment); | ||
Trip trip = getTrip(environment); | ||
var serviceDate = getSource(environment).getServiceDate(); | ||
|
||
Instant midnight = ServiceDateUtils | ||
.asStartOfService(serviceDate, transitService.getTimeZone()) | ||
.toInstant(); | ||
Timetable timetable = getTimetable(environment, trip, serviceDate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is repeated several times.
@@ -67,12 +67,12 @@ public DataFetcher<BookingInfo> dropOffBookingInfo() { | |||
} | |||
|
|||
@Override | |||
public DataFetcher<String> dropoffType() { | |||
public DataFetcher<GraphQLTypes.GraphQLPickupDropoffType> dropoffType() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice.
public final class PickDropMapper { | ||
|
||
@Nullable | ||
public static GraphQLTypes.GraphQLPickupDropoffType map(PickDrop pickDrop) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I've taken the liberty to add a module test for cancelling a trip: leonardehrenfried@0423999 Can you check it out and if you like it, apply it to this branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the schema now but I made a few suggestion about the implementation.
However, I find our way of getting actual times from a TripOnServiceDate viat the Timetable quite strange. This is of course not your fault and I hope this will be tackled in the upcoming refactorings.
application/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls
Outdated
Show resolved
Hide resolved
There has been a long discussion about the API schema above. I just want to summarise my input for future reference. I quickly put together an "API domain model" for this. The diagram below is my suggestion to the design, it follows the guideline in this PR. In the future I want us to draw diagrams like the on below - they are much easier to read and discuss. If we draw at a API level or OTP domain level probably does not matter - but try to focus on the entities, value-objects and the relationships. When we agree on the "language", then it become a technical task to map it to a GraphQL schema or Java model.
|
@optionsome You have conflicts again. |
I think people can confuse the concept of a normal date vs service date.
The thing is, if we don't make the TripOnDate a union in the schema, "There might be more stop-locations than in the scheduled plan" issue (or similar issues) might be difficult to solve. Making the calls a union/interface could lessen these types of issues but I don't know if even that is a solution for the aforementioned issue.
I think we decided to call it CallTime.
I didn't make them required because I'm not sure if we always will have arrival time for the first stop or departure time for the last stop in the future.
In general, I think designing the domain is a good idea, however I think designing the schema is even more important since changing that is much more difficult.
I wasn't quite sure what is the best model for this. Should the scheduled/estimates be grouped together inside departure or arrival fields or should there be schedules and estimates which have departure and arrival fields. For the non-flex trips, grouping the estimates and schedules together feels more natural. However, with flex time windows it's not possible because there is no scheduled arrival or departure. That was the reason why I ended up using a union for the Calls so these could be modeled in different fashion. |
We did some schema design with @t2gran, I'll update this pr to match the design later: { calls { stopLocation = (Stop | StopArea | GroupOfStops) : CallStopLocation Union scheduled { plannedStatus = SKIPPED/SCHEDULED time { (TimeWindow | ArrivalDepartureTime) : CallScheduledTime timeWindow { start OffsetDateTime end OffsetDateTime } or { arrival OffsetDateTime departure OffsetDateTime } } } realTime CallRealTime { cancelled = SKIPPED/SCHEDULED arrival EstimatedTime { time delay uncertainty percentage recorded RECORDED/ESTIMATE/UNKNOWN } departure { time delay isActualTime = false } } } } |
I've implemented new version of schema now. I'm not quite sure where some of the model classes needed by the API should be. They are now in the GTFS API package and elsewhere which is probably not ideal at least. |
The schema design we did with @t2gran includes some things that I have not implemented in the scope of this pr as they are not needed for this. |
Summary
This PR adds a query, which returns information about cancelled trips, into Gtfs graphQL API. The query supports paging and filtering by feed id. It returns a list of (trip, date) pairs.
Unit tests
None. The new code has been tested manually using graphiQL endpoint. Changing trip selector in DefaultTransitService class temporarily to return UPDATED (not CANCELED) trips helps to collect test trips with any realtime modified data.
Documentation
Docs in the graphQL schema