Skip to content
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 support for trip booking rules as per GTFS-Flex v2.1 #4

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

vpavlushkov
Copy link

@vpavlushkov vpavlushkov commented Nov 27, 2020

Description

These code changes implement the steps listed in Asana: Add support for trip booking rules as per GTFS-Flex 2.1 as required to add support for booking rules as defined in GTFS-Flex v2.1:


Comments on routing response schema

The routing response schema as per https://dev.opentripplanner.org.s3.amazonaws.com/apidoc/1.5.0/json_Leg.html has only the DRT message fields, but booking rules from GTFS-Flex v2.1 provide phone numbers and URLs too. The following mapping has been made:

  • flexDrtPickupMessage reused for pickup message configured through booking rule (with fallback to message of that rule)
  • flexDrtDropOffMessage reused for drop-off message configured through booking rule (with fallback to message of that rule)
  • flexPhoneNumber NEW used for phone number configured through pickup/drop-off booking rule
  • flexInfoUrl NEW used for info URL configured through pickup/drop-off booking rule
  • flexBookingUrl NEW used for booking URL configured through pickup/drop-off booking rule

To be completed by pull request submitter:

  • issue: Link to or create an issue that describes the relevant feature or bug. Add GitHub keywords to this PR's description (e.g., closes #45).
  • roadmap: Check the roadmap for this feature or bug. If it is not already on the roadmap, PLC will discuss as part of the review process.
  • tests: Have you added relevant test coverage? Are all the tests passing on the continuous integration service (Travis CI)?
  • formatting: Have you followed the suggested code style?
  • documentation: If you are adding a new configuration option, have you added an explanation to the configuration documentation tables and sections?
  • changelog: add a bullet point to the changelog file with description and link to the linked issue

To be completed by @opentripplanner/plc:

  • reviews and approvals by 2 members, ideally from different organizations
  • after merging: update the relevant card on the roadmap

@vpavlushkov vpavlushkov added the enhancement New feature or request label Nov 27, 2020
@vpavlushkov vpavlushkov self-assigned this Nov 27, 2020
@vpavlushkov vpavlushkov changed the title chore(otp-model): add new StopTime fields and BookingRule model Add support for trip booking rules as per GTFS-Flex v2.1 Nov 27, 2020
Copy link

@hannesj hannesj left a comment

Choose a reason for hiding this comment

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

// Up to prior day(s) booking
int priorNoticeStartDay = pickupBookingRule.getPriorNoticeStartDay();
int priorNoticeStartTime = pickupBookingRule.getPriorNoticeStartTime();
return sd.time((int) Math.round((priorNoticeStartDay * 24.0 + priorNoticeStartTime) * 60.0));
Copy link
Author

Choose a reason for hiding this comment

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

This is something I am not sure if it produces a number of seconds from now (currTime) till service date in priorNoticeStartDay days + priorNoticeStartTime hours. 🤔 There are too many factors in play: service calendar, timezone, current time and the time mappers.

Copy link
Author

Choose a reason for hiding this comment

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

I guess the only way forward here is to have unit tests that cover different types of booking rules 🤔

Copy link

Choose a reason for hiding this comment

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

The priorNoticeStartDay should probably operate on days, converting to ServiceDate and back, rather that 24 hour increments, to account for switching to an from DST.

@vpavlushkov
Copy link
Author

In cc1ee2a, booking rule properties are added to routing mapping. Note that the time calculations are not done there.

Location of the GraphQL configs still remains a mystery. 🤔

@vpavlushkov
Copy link
Author

Sketch of further development provided by @hannesj:

  • The schema is configured in schema.graphqls file, it is only about the data stricture of the output.
  • After you have changed it, there is a README.
  • You need to generate the new Java types, and implement them in here. It doesn’t compile after you’ve added the types, as the interfaces aren’t implemented.

stopTimeMapper = new StopTimeMapper(stopMapper, locationMapper, locationGroupMapper, tripMapper);

agencyAndIdMapper = new AgencyAndIdMapper();
bookingRuleMapper = new BookingRuleMapper();
Copy link

Choose a reason for hiding this comment

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

Initialisation can be moved together with declaration, as there are no parameters from the constructor used.

@@ -56,6 +56,10 @@

private final TripMapper tripMapper;

private final AgencyAndIdMapper agencyAndIdMapper;
Copy link

Choose a reason for hiding this comment

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

This is not used anywhere, delete?

/* This file is based on code copied from project OneBusAway, see the LICENSE file for further information. */
package org.opentripplanner.model;

public final class BookingRule {
Copy link

Choose a reason for hiding this comment

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

This should extend TransitEntity

return id;
}

public void setId(FeedScopedId id) {
Copy link

Choose a reason for hiding this comment

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

As other TransitEnetites, this should be set in the constructor


public final class BookingRule {

private FeedScopedId id;
Copy link

Choose a reason for hiding this comment

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

This should be final

Copy link
Author

Choose a reason for hiding this comment

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

I believe super(id) in the parent class does the trick. 🤔 At least that is the way FareAttribute class is set.

// Up to prior day(s) booking
int priorNoticeStartDay = pickupBookingRule.getPriorNoticeStartDay();
int priorNoticeStartTime = pickupBookingRule.getPriorNoticeStartTime();
return sd.time((int) Math.round((priorNoticeStartDay * 24.0 + priorNoticeStartTime) * 60.0));
Copy link

Choose a reason for hiding this comment

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

The priorNoticeStartDay should probably operate on days, converting to ServiceDate and back, rather that 24 hour increments, to account for switching to an from DST.

* @param sd - service day
* @return time
*/
public long getLatestDropOffBookingTime (int stop, long currTime, ServiceDay sd) {
Copy link

Choose a reason for hiding this comment

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

Does this make sense. The booking rules, are always calculated from the boarding time, so the above method would bee needed to check that a trip was valid.

@vpavlushkov
Copy link
Author

vpavlushkov commented Dec 22, 2020

@hannesj Requested changes are applied in 88c87a1

1cdaa9a also adds the fields to the GraphQL schema, but:

  • The four String fields are added to Leg schema as Strings
  • I see no reason of adding new Java types as the fields in question are just Strings and we only query them as a part of routing query; i.e. they needed only to be inside legs. Am I missing something? 🤔
  • Generating GraphQL resources per README fails for me, but I cannot figure out the reason yet

Screenshot 2020-12-22 at 15 31 37

* ~OBA lib started to fail building in CircleCI but works perfectly fine in my local~ -> **UPDATE** Issue with OBA lib building was a temporal glitch that got auto-resolved after retry in CircleCI

@hannesj
Copy link

hannesj commented Feb 4, 2021

I'll take a look at this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants