Skip to content

Commit

Permalink
Add maxStartTime/minEndTime for deviated board/alights to the plan AP…
Browse files Browse the repository at this point in the history
…I response
  • Loading branch information
sdjacobs committed Aug 24, 2017
1 parent e1e5dc5 commit 264ac13
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/main/java/org/opentripplanner/api/model/Leg.java
Expand Up @@ -264,6 +264,20 @@ public class Leg {
@JsonSerialize @JsonSerialize
public Boolean callAndRide; public Boolean callAndRide;


/* For call-n-ride leg, supply max start time / min end time */
@XmlAttribute
@JsonSerialize
public Calendar maxStartTime = null;

@XmlAttribute
@JsonSerialize
public Calendar minEndTime = null;

/* advanced book min if this is a DRT leg */
@XmlAttribute
@JsonSerialize
public int drtAdvanceBookMin;

/** /**
* Whether this leg is a transit leg or not. * Whether this leg is a transit leg or not.
* @return Boolean true if the leg is a transit leg * @return Boolean true if the leg is a transit leg
Expand Down
Expand Up @@ -200,9 +200,13 @@ public static Itinerary generateItinerary(GraphPath path, boolean showIntermedia


private static Calendar makeCalendar(State state) { private static Calendar makeCalendar(State state) {
RoutingContext rctx = state.getContext(); RoutingContext rctx = state.getContext();
TimeZone timeZone = rctx.graph.getTimeZone(); TimeZone timeZone = rctx.graph.getTimeZone();
return makeCalendar(timeZone, state.getTimeInMillis());
}

private static Calendar makeCalendar(TimeZone timeZone, long time) {
Calendar calendar = Calendar.getInstance(timeZone); Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(state.getTimeInMillis()); calendar.setTimeInMillis(time);
return calendar; return calendar;
} }


Expand Down Expand Up @@ -603,6 +607,7 @@ private static void addTripFields(Leg leg, State[] states, Locale requestedLocal
leg.tripId = trip.getId(); leg.tripId = trip.getId();
leg.tripShortName = trip.getTripShortName(); leg.tripShortName = trip.getTripShortName();
leg.tripBlockId = trip.getBlockId(); leg.tripBlockId = trip.getBlockId();
leg.drtAdvanceBookMin = trip.getDrtAdvanceBookMin();


if (serviceDay != null) { if (serviceDay != null) {
leg.serviceDate = serviceDay.getServiceDate().getAsString(); leg.serviceDate = serviceDay.getServiceDate().getAsString();
Expand All @@ -616,6 +621,25 @@ private static void addTripFields(Leg leg, State[] states, Locale requestedLocal
if (edge instanceof TemporaryDirectPatternHop) { if (edge instanceof TemporaryDirectPatternHop) {
leg.callAndRide = true; leg.callAndRide = true;
} }
if (edge instanceof PartialPatternHop) {
PartialPatternHop hop = (PartialPatternHop) edge;
int directTime = hop.getDirectVehicleTime();
TripTimes tt = states[states.length - 1].getTripTimes();
int maxTime = tt.getDemandResponseMaxTime(directTime);
int avgTime = tt.getDemandResponseAvgTime(directTime);
int delta = maxTime - avgTime;
if (directTime != 0 && delta > 0) {
if (hop.isDeviatedRouteBoard()) {
long maxStartTime = leg.startTime.getTimeInMillis() + (delta * 1000);
leg.maxStartTime = makeCalendar(leg.startTime.getTimeZone(), maxStartTime);
}
if (hop.isDeviatedRouteAlight()) {
long minEndTime = leg.endTime.getTimeInMillis() - (delta * 1000);
leg.minEndTime = makeCalendar(leg.endTime.getTimeZone(), minEndTime);
}
}
}

} }
} }


Expand Down
Expand Up @@ -253,5 +253,9 @@ public LineString getEndGeometry() {
return endGeometry; return endGeometry;
} }


public int getDirectVehicleTime() {
return startVehicleTime + endVehicleTime;
}

} }


Expand Up @@ -83,7 +83,8 @@ public void dispose() {
tov.removeIncoming(this); tov.removeIncoming(this);
} }


public int getDirectTime() { @Override
public int getDirectVehicleTime() {
return directTime; return directTime;
} }
} }

0 comments on commit 264ac13

Please sign in to comment.