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
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.opentripplanner.gtfs.mapping;

import org.opentripplanner.model.BookingRule;
import org.opentripplanner.util.MapUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/** Responsible for mapping GTFS BookingRule into the OTP model. */
class BookingRuleMapper {

private Map<org.onebusaway.gtfs.model.BookingRule, BookingRule> mappedBookingRules = new HashMap<>();

BookingRuleMapper(AgencyAndIdMapper agencyAndIdMapper) {
this.agencyAndIdMapper = agencyAndIdMapper;
// Some other mappers?
vpavlushkov marked this conversation as resolved.
Show resolved Hide resolved
}

Collection<BookingRule> map(Collection<org.onebusaway.gtfs.model.BookingRule> allBookingRules) {
return MapUtils.mapToList(allBookingRules, this::map);
}

/**
* Map from GTFS to OTP model, {@code null} safe.
*/
BookingRule map(org.onebusaway.gtfs.model.BookingRule orginal) {
return orginal == null ? null : mappedBookingRules.computeIfAbsent(orginal, this::doMap);
}

private BookingRule doMap(org.onebusaway.gtfs.model.BookingRule rhs) {
BookingRule lhs = new BookingRule();

lhs.setId(agencyAndIdMapper.map(rhs.getId()));
lhs.setType(rhs.getType());
lhs.setPriorNoticeDurationMin(rhs.getPriorNoticeDurationMin());
lhs.setPriorNoticeDurationMax(rhs.getPriorNoticeDurationMax());
lhs.setPriorNoticeLastDay(rhs.getPriorNoticeLastDay());
lhs.setPriorNoticeLastTime(rhs.getPriorNoticeLastTime());
lhs.setPriorNoticeStartDay(rhs.getPriorNoticeStartDay());
lhs.setPriorNoticeStartTime(rhs.getPriorNoticeStartTime());
lhs.setPriorNoticeServiceId(agencyAndIdMapper.map(rhs.getPriorNoticeServiceId()));
lhs.setMessage(rhs.getMessage());
lhs.setPickupMessage(rhs.getPickupMessage());
lhs.setDropOffMessage(rhs.getDropOffMessage());
lhs.setPhoneNumber(rhs.getPhoneNumber());
lhs.setInfoUrl(rhs.getInfoUrl());
lhs.setUrl(rhs.getUrl());

return lhs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class StopTimeMapper {
StopMapper stopMapper,
LocationMapper locationMapper,
LocationGroupMapper locationGroupMapper,
TripMapper tripMapper
TripMapper tripMapper,
BookingRuleMapper bookingRuleMapper
) {
this.stopMapper = stopMapper;
this.locationMapper = locationMapper;
this.locationGroupMapper = locationGroupMapper;
this.tripMapper = tripMapper;
this.bookingRuleMapper = bookingRuleMapper;
}

Collection<StopTime> map(Collection<org.onebusaway.gtfs.model.StopTime> times) {
Expand Down Expand Up @@ -70,6 +72,8 @@ private StopTime doMap(org.onebusaway.gtfs.model.StopTime rhs) {
lhs.setFlexWindowEnd(rhs.getMaxDepartureTime());
lhs.setFlexContinuousPickup(rhs.getContinuousPickup());
lhs.setFlexContinuousDropOff(rhs.getContinuousDropOff());
lhs.setPickupBookingRule(bookingRuleMapper.map(rhs.getPickupBookingRule()));
lhs.setDropOffBookingRule(bookingRuleMapper.map(rhs.getDropOffBookingRule()));

// Skip mapping of proxy
// private transient StopTimeProxy proxy;
Expand Down
182 changes: 182 additions & 0 deletions src/main/java/org/opentripplanner/model/BookingRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/* 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


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.


private int type;

private int priorNoticeDurationMin;

private int priorNoticeDurationMax;

private int priorNoticeLastDay;

private int priorNoticeLastTime;

private int priorNoticeStartDay;

private int priorNoticeStartTime;

private FeedScopedId priorNoticeServiceId;

private String message;

private String pickupMessage;

private String dropOffMessage;

private String phoneNumber;

private String infoUrl;

private String url;

public BookingRule() {

}

public BookingRule(BookingRule br) {
this.id = br.id;
this.type = br.type;
this.priorNoticeDurationMin = br.priorNoticeDurationMin;
this.priorNoticeDurationMax = br.priorNoticeDurationMax;
this.priorNoticeLastDay = br.priorNoticeLastDay;
this.priorNoticeLastTime = br.priorNoticeLastTime;
this.priorNoticeStartDay = br.priorNoticeStartDay;
this.priorNoticeStartTime = br.priorNoticeStartTime;
this.priorNoticeServiceId = br.priorNoticeServiceId;
this.message = br.message;
this.pickupMessage = br.pickupMessage;
this.dropOffMessage = br.dropOffMessage;
this.phoneNumber = br.phoneNumber;
this.infoUrl = br.infoUrl;
this.url = br.url;
}

public FeedScopedId getId() {
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

this.id = id;
}

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}

public int getPriorNoticeDurationMin() {
return priorNoticeDurationMin;
}

public void setPriorNoticeDurationMin(int priorNoticeDurationMin) {
this.priorNoticeDurationMin = priorNoticeDurationMin;
}

public int getPriorNoticeDurationMax() {
return priorNoticeDurationMax;
}

public void setPriorNoticeDurationMax(int priorNoticeDurationMax) {
this.priorNoticeDurationMax = priorNoticeDurationMax;
}

public int getPriorNoticeLastDay() {
return priorNoticeLastDay;
}

public void setPriorNoticeLastDay(int priorNoticeLastDay) {
this.priorNoticeLastDay = priorNoticeLastDay;
}

public int getPriorNoticeLastTime() {
return priorNoticeLastTime;
}

public void setPriorNoticeLastTime(int priorNoticeLastTime) {
this.priorNoticeLastTime = priorNoticeLastTime;
}

public int getPriorNoticeStartDay() {
return priorNoticeStartDay;
}

public void setPriorNoticeStartDay(int priorNoticeStartDay) {
this.priorNoticeStartDay = priorNoticeStartDay;
}

public int getPriorNoticeStartTime() {
return priorNoticeStartTime;
}

public void setPriorNoticeStartTime(int priorNoticeStartTime) {
this.priorNoticeStartTime = priorNoticeStartTime;
}

public FeedScopedId getPriorNoticeServiceId() {
return priorNoticeServiceId;
}

public void setPriorNoticeServiceId(FeedScopedId priorNoticeServiceId) {
this.priorNoticeServiceId = priorNoticeServiceId;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String getPickupMessage() {
return pickupMessage;
}

public void setPickupMessage(String pickupMessage) {
this.pickupMessage = pickupMessage;
}

public String getDropOffMessage() {
return dropOffMessage;
}

public void setDropOffMessage(String dropOffMessage) {
this.dropOffMessage = dropOffMessage;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getInfoUrl() {
return infoUrl;
}

public void setInfoUrl(String infoUrl) {
this.infoUrl = infoUrl;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

@Override
public String toString() {
return "<BookingRule " + this.id + ">";
}
}
23 changes: 23 additions & 0 deletions src/main/java/org/opentripplanner/model/StopTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public final class StopTime implements Comparable<StopTime> {
// Disabled by default
private int flexContinuousDropOff = MISSING_VALUE;

/** Support for GTFS-Flex v2.1 booking rules */
private BookingRule pickupBookingRule;

private BookingRule dropOffBookingRule;

public StopTime() { }

public StopTime(StopTime st) {
Expand All @@ -71,6 +76,8 @@ public StopTime(StopTime st) {
this.flexWindowEnd = st.flexWindowEnd;
this.flexContinuousPickup = st.flexContinuousPickup;
this.flexContinuousDropOff = st.flexContinuousDropOff;
this.pickupBookingRule = st.pickupBookingRule;
this.dropOffBookingRule = st.dropOffBookingRule;
}

/**
Expand Down Expand Up @@ -255,6 +262,22 @@ public void setFlexContinuousDropOff(int flexContinuousDropOff) {
this.flexContinuousDropOff = flexContinuousDropOff;
}

public BookingRule getPickupBookingRule() {
return pickupBookingRule;
}

public void setPickupBookingRule(BookingRule pickupBookingRule) {
this.pickupBookingRule = pickupBookingRule;
}

public BookingRule getDropOffBookingRule() {
return dropOffBookingRule;
}

public void setDropOffBookingRule(BookingRule dropOffBookingRule) {
this.dropOffBookingRule = dropOffBookingRule;
}

public int compareTo(StopTime o) {
return this.getStopSequence() - o.getStopSequence();
}
Expand Down