Skip to content

Add previousLegs into GTFS GraphQL API - #6142

Merged
optionsome merged 12 commits into
opentripplanner:dev-2.xfrom
Aubin-MaaS:graphql-previousLegs
Nov 14, 2024
Merged

Add previousLegs into GTFS GraphQL API#6142
optionsome merged 12 commits into
opentripplanner:dev-2.xfrom
Aubin-MaaS:graphql-previousLegs

Conversation

@miklcct

@miklcct miklcct commented Oct 10, 2024

Copy link
Copy Markdown
Contributor

PR Instructions

Add previousLegs into GTFS GraphQL API in parallel of nextLegs. This already exists in Transmodel API.

Issue

Closes #6139

Unit tests

The fetcher code is not tested at all.

Documentation

Added to GraphQL schema

@miklcct
miklcct force-pushed the graphql-previousLegs branch from 5d67bf1 to 124f589 Compare October 10, 2024 15:39
@miklcct
miklcct marked this pull request as ready for review October 11, 2024 14:30
@miklcct
miklcct requested a review from a team as a code owner October 11, 2024 14:30
@habrahamsson-skanetrafiken

Copy link
Copy Markdown
Contributor

This has some merge conflicts. Can you fix them?

@t2gran t2gran added this to the 2.7 (next release) milestone Oct 16, 2024
@codecov

codecov Bot commented Oct 16, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 24.39024% with 31 lines in your changes missing coverage. Please review.

Project coverage is 69.71%. Comparing base (ee53e50) to head (d437d66).
Report is 171 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...ntripplanner/apis/gtfs/generated/GraphQLTypes.java 0.00% 31 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6142      +/-   ##
=============================================
- Coverage      69.91%   69.71%   -0.21%     
+ Complexity     17736    17685      -51     
=============================================
  Files           2006     2008       +2     
  Lines          75526    75806     +280     
  Branches        7730     7759      +29     
=============================================
+ Hits           52804    52847      +43     
- Misses         20036    20247     +211     
- Partials        2686     2712      +26     

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

@optionsome optionsome left a comment

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.

@miklcct

miklcct commented Oct 22, 2024

Copy link
Copy Markdown
Contributor Author

You could try adding GraphQL integration tests for this field in https://github.com/opentripplanner/OpenTripPlanner/blob/dev-2.x/application/src/test/resources/org/opentripplanner/apis/gtfs/queries/planConnection-extended.graphql . I'm not sure how difficult it is, you might need to edit https://github.com/opentripplanner/OpenTripPlanner/blob/dev-2.x/application/src/test/java/org/opentripplanner/apis/gtfs/GraphQLIntegrationTest.java as well.

The integration test uses a fake, hardcoded routing response from a stub routing service which has no relationship to the stub transit service, which makes me impossible to cross reference between these two in tests.

These fetchers are basically untestable in the current setup because it queries the transit service using something returned from the routing service.

@optionsome optionsome added the !New Feature A functional feature targeting the end user. label Oct 24, 2024
@optionsome optionsome changed the title add previousLegs into GTFS GraphQL API Add previousLegs into GTFS GraphQL API Oct 24, 2024
return nextOrPreviousLegs(false);
}

private DataFetcher<Iterable<Leg>> nextOrPreviousLegs(boolean includeDepartBefore) {

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.

This includeDepartBefore is a slightly difficult to understand boolean name (I know the name is copied over from the getAlternativeLegs method) but I think you could give it some more understandable name like previousLegsOnly. In general, we try to avoid boolean method variables that change the behavior. Instead, we prefer to split the methods into two different methods where the name reflects what it does. However, in this case you are just repeating the design decision made in the getAlternativeLegs method so it might be ok. We can discuss this in a developer meeting.

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 in the developer meeting and came to the conclusion that you should split this private method and also getAlternativeLegs into two methods. One for previous legs and one for next legs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The previousLegs and nextLegs are doing the same thing, with the only difference in direction. I don't want to duplicate codes so I will switch to an enum 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.

Enum isn't really any better than boolean. You can put some of the code that computes the other arguments into methods that can be used by both the nextLegs and previousLegs methods so you can avoid some duplication that way.

@miklcct miklcct Oct 29, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think I can do anything better than converting the boolean to an enum, as the result will be much more complicated.

The single flag is used for multiple purposes:

  • to sort the departures within a pattern
  • to filter the results to be before / after the requested time
  • to sort the leg results after combining them from different patterns

If I don't use such a flag, I will need two more parameters for generateLegs, one to sort the results, one to compare the stop times in the priority queue. I will also need another parameter for getAlternativeLegs to sort the legs across different trip patterns as well, so it will be 3 different interrelated new arguments passed down the call stack instead of a single flag, if these arguments become out of sync strange behavior will result.

nextLegs and previousLegs are basically the same thing. They are not different behavior. The same argument can be said of journey planning by departure time or arrival time which should be the same logic, yet I am seeing bugs which happens on arrival only but not departure (#6102).

Similarly, there are other flags in getAlternativeLegs like exactOriginStop, exactDestinationStop, filter which can't be split into different methods as well.

@miklcct
miklcct requested a review from optionsome October 29, 2024 15:25
@miklcct

miklcct commented Oct 30, 2024

Copy link
Copy Markdown
Contributor Author

I'll need to discuss the introduction of an utility enum SearchDirection with FORWARD and BACKWARD values for the whole of OpenTripPlanner, as I need to merge departure / arrival handling for frequencies in #6211.

@optionsome
optionsome requested a review from t2gran October 31, 2024 14:49
@miklcct
miklcct force-pushed the graphql-previousLegs branch 2 times, most recently from 93726ae to a3f752d Compare November 5, 2024 14:42
@miklcct
miklcct force-pushed the graphql-previousLegs branch from 5ae1e2e to 64d3978 Compare November 11, 2024 15:03

@leonardehrenfried leonardehrenfried left a comment

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.

Please replace the variable name.

@optionsome
optionsome merged commit 0584f82 into opentripplanner:dev-2.x Nov 14, 2024
t2gran pushed a commit that referenced this pull request Nov 14, 2024
@miklcct
miklcct deleted the graphql-previousLegs branch November 26, 2024 16:16
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.

add previousLegs in GTFS GraphQL Leg model

5 participants