Skip to content

Commit

Permalink
Add PickDrop enum and simplify StopPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Gard Mellemstrand committed Jul 23, 2021
1 parent 051a26f commit a4238b9
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.ArrayList;
import java.util.List;

import static org.opentripplanner.model.StopPattern.PICKDROP_NONE;
import static org.opentripplanner.model.PickDrop.NONE;

public class FlexTripsMapper {

Expand Down Expand Up @@ -54,7 +54,7 @@ static public List<FlexTrip> createFlexTrips(OtpTransitServiceBuilder builder) {
private static boolean hasContinuousStops(List<StopTime> stopTimes) {
return stopTimes
.stream()
.anyMatch(st -> st.getFlexContinuousPickup() != PICKDROP_NONE || st.getFlexContinuousDropOff() != PICKDROP_NONE);
.anyMatch(st -> st.getFlexContinuousPickup() != NONE.getGtfsCode() || st.getFlexContinuousDropOff() != NONE.getGtfsCode());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.opentripplanner.model.StopPattern.PICKDROP_NONE;
import static org.opentripplanner.model.StopTime.MISSING_VALUE;

import static org.opentripplanner.model.PickDrop.NONE;

/**
* A scheduled deviated trip is similar to a regular scheduled trip, except that is continues stop
* locations, which are not stops, but other types, such as groups of stops or location areas.
Expand All @@ -40,7 +41,7 @@ public class ScheduledDeviatedTrip extends FlexTrip {
public static boolean isScheduledFlexTrip(List<StopTime> stopTimes) {
Predicate<StopTime> notStopType = Predicate.not(st -> st.getStop() instanceof Stop);
Predicate<StopTime> notContinuousStop = stopTime ->
stopTime.getFlexContinuousDropOff() == PICKDROP_NONE && stopTime.getFlexContinuousPickup() == PICKDROP_NONE;
stopTime.getFlexContinuousDropOff() == NONE.getGtfsCode() && stopTime.getFlexContinuousPickup() == NONE.getGtfsCode();
return stopTimes.stream().anyMatch(notStopType)
&& stopTimes.stream().allMatch(notContinuousStop);
}
Expand Down Expand Up @@ -77,7 +78,7 @@ public Stream<FlexAccessTemplate> getFlexAccessTemplates(
ArrayList<FlexAccessTemplate> res = new ArrayList<>();

for (int toIndex = fromIndex + 1; toIndex < stopTimes.length; toIndex++) {
if (stopTimes[toIndex].dropOffType == PICKDROP_NONE) continue;
if (stopTimes[toIndex].dropOffType == NONE.getGtfsCode()) continue;
for (StopLocation stop : expandStops(stopTimes[toIndex].stop)) {
res.add(new FlexAccessTemplate(access, this, fromIndex, toIndex, stop, date, scheduledCalculator));
}
Expand All @@ -99,7 +100,7 @@ public Stream<FlexEgressTemplate> getFlexEgressTemplates(
ArrayList<FlexEgressTemplate> res = new ArrayList<>();

for (int fromIndex = toIndex - 1; fromIndex >= 0; fromIndex--) {
if (stopTimes[fromIndex].pickupType == PICKDROP_NONE) continue;
if (stopTimes[fromIndex].pickupType == NONE.getGtfsCode()) continue;
for (StopLocation stop : expandStops(stopTimes[fromIndex].stop)) {
res.add(new FlexEgressTemplate(egress, this, fromIndex, toIndex, stop, date, scheduledCalculator));
}
Expand Down Expand Up @@ -164,7 +165,7 @@ private Collection<StopLocation> expandStops(StopLocation stop) {

private int getFromIndex(NearbyStop accessEgress) {
for (int i = 0; i < stopTimes.length; i++) {
if (stopTimes[i].pickupType == PICKDROP_NONE) continue; // No pickup allowed here
if (stopTimes[i].pickupType == NONE.getGtfsCode()) continue; // No pickup allowed here
StopLocation stop = stopTimes[i].stop;
if (stop instanceof FlexLocationGroup) {
if (((FlexLocationGroup) stop).getLocations().contains(accessEgress.stop)) {
Expand All @@ -182,7 +183,7 @@ private int getFromIndex(NearbyStop accessEgress) {

private int getToIndex(NearbyStop accessEgress) {
for (int i = stopTimes.length - 1; i >= 0; i--) {
if (stopTimes[i].dropOffType == PICKDROP_NONE) continue; // No drop off allowed here
if (stopTimes[i].dropOffType == NONE.getGtfsCode()) continue; // No drop off allowed here
StopLocation stop = stopTimes[i].stop;
if (stop instanceof FlexLocationGroup) {
if (((FlexLocationGroup) stop).getLocations().contains(accessEgress.stop)) {
Expand Down Expand Up @@ -216,8 +217,8 @@ private ScheduledDeviatedStopTime(StopTime st) {
// TODO: Store the window for a stop, and allow the user to have an "unguaranteed"
// pickup/dropoff between the start and end of the window

this.pickupType = st.getPickupType();
this.dropOffType = st.getDropOffType();
this.pickupType = st.getPickupType().getGtfsCode();
this.dropOffType = st.getDropOffType().getGtfsCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.opentripplanner.model.StopPattern.PICKDROP_NONE;

import static org.opentripplanner.model.PickDrop.NONE;

/**
* This type of FlexTrip is used when a taxi-type service is modeled, which operates in one or
Expand All @@ -41,7 +40,7 @@ public class UnscheduledTrip extends FlexTrip {
public static boolean isUnscheduledTrip(List<StopTime> stopTimes) {
Predicate<StopTime> noExplicitTimes = Predicate.not(st -> st.isArrivalTimeSet() || st.isDepartureTimeSet());
Predicate<StopTime> notContinuousStop = stopTime ->
stopTime.getFlexContinuousDropOff() == PICKDROP_NONE && stopTime.getFlexContinuousPickup() == PICKDROP_NONE;
stopTime.getFlexContinuousDropOff() == NONE.getGtfsCode() && stopTime.getFlexContinuousPickup() == NONE.getGtfsCode();
return stopTimes.size() == N_STOPS
&& stopTimes.stream().allMatch(noExplicitTimes)
&& stopTimes.stream().allMatch(notContinuousStop);
Expand Down Expand Up @@ -72,7 +71,7 @@ public Stream<FlexAccessTemplate> getFlexAccessTemplates(
int fromIndex = getFromIndex(access);

if (fromIndex != 0) { return Stream.empty(); }
if (stopTimes[1].dropOffType == PICKDROP_NONE) { return Stream.empty(); }
if (stopTimes[1].dropOffType == NONE.getGtfsCode()) { return Stream.empty(); }

ArrayList<FlexAccessTemplate> res = new ArrayList<>();

Expand All @@ -90,7 +89,7 @@ public Stream<FlexEgressTemplate> getFlexEgressTemplates(
int toIndex = getToIndex(egress);

if (toIndex != 1) { return Stream.empty(); }
if (stopTimes[0].pickupType == PICKDROP_NONE) { return Stream.empty(); }
if (stopTimes[0].pickupType == NONE.getGtfsCode()) { return Stream.empty(); }

ArrayList<FlexEgressTemplate> res = new ArrayList<>();

Expand Down Expand Up @@ -165,7 +164,7 @@ private Collection<StopLocation> expandStops(StopLocation stop) {

private int getFromIndex(NearbyStop accessEgress) {
for (int i = 0; i < stopTimes.length; i++) {
if (stopTimes[i].pickupType == PICKDROP_NONE) continue;
if (stopTimes[i].pickupType == NONE.getGtfsCode()) continue;
StopLocation stop = stopTimes[i].stop;
if (stop instanceof FlexLocationGroup) {
if (((FlexLocationGroup) stop).getLocations().contains(accessEgress.stop)) {
Expand All @@ -183,7 +182,7 @@ private int getFromIndex(NearbyStop accessEgress) {

private int getToIndex(NearbyStop accessEgress) {
for (int i = stopTimes.length - 1; i >= 0; i--) {
if (stopTimes[i].dropOffType == PICKDROP_NONE) continue;
if (stopTimes[i].dropOffType == NONE.getGtfsCode()) continue;
StopLocation stop = stopTimes[i].stop;
if (stop instanceof FlexLocationGroup) {
if (((FlexLocationGroup) stop).getLocations().contains(accessEgress.stop)) {
Expand Down Expand Up @@ -214,8 +213,8 @@ private UnscheduledStopTime(StopTime st) {
flexWindowStart = st.getFlexWindowStart();
flexWindowEnd = st.getFlexWindowEnd();

pickupType = st.getPickupType();
dropOffType = st.getDropOffType();
pickupType = st.getPickupType().getGtfsCode();
dropOffType = st.getDropOffType().getGtfsCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import static org.opentripplanner.ext.siri.TimetableHelper.createModifiedStopTimes;
import static org.opentripplanner.ext.siri.TimetableHelper.createModifiedStops;
import static org.opentripplanner.ext.siri.TimetableHelper.createUpdatedTripTimes;
import static org.opentripplanner.model.StopPattern.PICKDROP_NONE;
import static org.opentripplanner.model.StopPattern.PICKDROP_SCHEDULED;
import static org.opentripplanner.model.PickDrop.NONE;
import static org.opentripplanner.model.PickDrop.SCHEDULED;

/**
* This class should be used to create snapshots of lookup tables of realtime data. This is
Expand Down Expand Up @@ -563,15 +563,15 @@ private boolean handleAddedTrip(Graph graph, String feedId, EstimatedVehicleJou
}

if (estimatedCall.getArrivalBoardingActivity() == ArrivalBoardingActivityEnumeration.ALIGHTING) {
stopTime.setDropOffType(PICKDROP_SCHEDULED);
stopTime.setDropOffType(SCHEDULED);
} else {
stopTime.setDropOffType(PICKDROP_NONE);
stopTime.setDropOffType(NONE);
}

if (estimatedCall.getDepartureBoardingActivity() == DepartureBoardingActivityEnumeration.BOARDING) {
stopTime.setPickupType(PICKDROP_SCHEDULED);
stopTime.setPickupType(SCHEDULED);
} else {
stopTime.setPickupType(PICKDROP_NONE);
stopTime.setPickupType(NONE);
}

if (estimatedCall.getDestinationDisplaies() != null && !estimatedCall.getDestinationDisplaies().isEmpty()) {
Expand Down Expand Up @@ -773,7 +773,7 @@ private boolean handleModifiedTrip(Graph graph, String feedId, EstimatedVehicleJ
for (TripTimes tripTimes : times) {
Trip trip = tripTimes.trip;
for (TripPattern pattern : patterns) {
if (tripTimes.getNumStops() == pattern.stopPattern.stops.length) {
if (tripTimes.getNumStops() == pattern.stopPattern.getStops().length) {
if (!tripTimes.isCanceled()) {
/*
UPDATED and MODIFIED tripTimes should be handled the same way to always allow latest realtime-update
Expand Down Expand Up @@ -1245,9 +1245,9 @@ private Set<Trip> getTripForJourney(Set<Trip> trips, EstimatedVehicleJourney jou

TripPattern pattern = routingService.getPatternForTrip().get(trip);

if (stopNumber < pattern.stopPattern.stops.length) {
if (stopNumber < pattern.stopPattern.getStops().length) {
boolean firstReportedStopIsFound = false;
Stop stop = pattern.stopPattern.stops[stopNumber - 1];
Stop stop = pattern.stopPattern.getStops()[stopNumber - 1];
if (firstStopId.equals(stop.getId().getId())) {
firstReportedStopIsFound = true;
}
Expand Down
42 changes: 21 additions & 21 deletions src/ext/java/org/opentripplanner/ext/siri/TimetableHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import java.util.Set;
import java.util.TimeZone;

import static org.opentripplanner.model.StopPattern.PICKDROP_NONE;
import static org.opentripplanner.model.StopPattern.PICKDROP_SCHEDULED;
import static org.opentripplanner.model.PickDrop.NONE;
import static org.opentripplanner.model.PickDrop.SCHEDULED;

public class TimetableHelper {

Expand Down Expand Up @@ -93,7 +93,7 @@ public static TripTimes createUpdatedTripTimes(final Graph graph, Timetable time

boolean stopPatternChanged = false;

Stop[] modifiedStops = timetable.pattern.stopPattern.stops;
Stop[] modifiedStops = timetable.pattern.stopPattern.getStops();

Trip trip = getTrip(tripId, timetable);

Expand Down Expand Up @@ -156,8 +156,8 @@ public static TripTimes createUpdatedTripTimes(final Graph graph, Timetable time
newTimes.setCancelledStop(callCounter, recordedCall.isCancellation());
}

newTimes.setDropoffType(callCounter, timetable.pattern.stopPattern.dropoffs[callCounter]);
newTimes.setPickupType(callCounter, timetable.pattern.stopPattern.pickups[callCounter]);
newTimes.setDropoffType(callCounter, timetable.pattern.stopPattern.getDropoff(callCounter).getGtfsCode());
newTimes.setPickupType(callCounter, timetable.pattern.stopPattern.getPickup(callCounter).getGtfsCode());

int arrivalTime = newTimes.getArrivalTime(callCounter);
int realtimeArrivalTime = arrivalTime;
Expand Down Expand Up @@ -237,12 +237,12 @@ public static TripTimes createUpdatedTripTimes(final Graph graph, Timetable time
// Update dropoff-/pickuptype only if status is cancelled
CallStatusEnumeration arrivalStatus = estimatedCall.getArrivalStatus();
if (arrivalStatus == CallStatusEnumeration.CANCELLED) {
newTimes.setDropoffType(callCounter, PICKDROP_NONE);
newTimes.setDropoffType(callCounter, NONE.getGtfsCode());
}

CallStatusEnumeration departureStatus = estimatedCall.getDepartureStatus();
if (departureStatus == CallStatusEnumeration.CANCELLED) {
newTimes.setPickupType(callCounter, PICKDROP_NONE);
newTimes.setPickupType(callCounter, NONE.getGtfsCode());
}

int arrivalTime = newTimes.getArrivalTime(callCounter);
Expand Down Expand Up @@ -285,8 +285,8 @@ public static TripTimes createUpdatedTripTimes(final Graph graph, Timetable time
}
if (!foundMatch) {

if (timetable.pattern.stopPattern.pickups[callCounter] == PICKDROP_NONE &&
timetable.pattern.stopPattern.dropoffs[callCounter] == PICKDROP_NONE) {
if (timetable.pattern.stopPattern.getPickup(callCounter) == NONE &&
timetable.pattern.stopPattern.getDropoff(callCounter) == NONE) {
// When newTimes contains stops without pickup/dropoff - set both arrival/departure to previous stop's departure
// This necessary to accommodate the case when delay is reduced/eliminated between to stops with pickup/dropoff, and
// multiple non-pickup/dropoff stops are in between.
Expand Down Expand Up @@ -330,7 +330,7 @@ public static TripTimes createUpdatedTripTimes(final Graph graph, Timetable time
return null;
}

if (newTimes.getNumStops() != timetable.pattern.stopPattern.stops.length) {
if (newTimes.getNumStops() != timetable.pattern.stopPattern.getStops().length) {
return null;
}

Expand Down Expand Up @@ -371,7 +371,7 @@ public static List<Stop> createModifiedStops(Timetable timetable, EstimatedVehic
}

//Get all scheduled stops
Stop[] stops = timetable.pattern.stopPattern.stops;
Stop[] stops = timetable.pattern.stopPattern.getStops();

// Keeping track of visited stop-objects to allow multiple visits to a stop.
List<Object> alreadyVisited = new ArrayList<>();
Expand Down Expand Up @@ -479,8 +479,8 @@ public static List<StopTime> createModifiedStopTimes(Timetable timetable, TripTi
stopTime.setStop(stop);
stopTime.setTrip(trip);
stopTime.setStopSequence(i);
stopTime.setDropOffType(timetable.pattern.stopPattern.dropoffs[i]);
stopTime.setPickupType(timetable.pattern.stopPattern.pickups[i]);
stopTime.setDropOffType(timetable.pattern.stopPattern.getDropoff(i));
stopTime.setPickupType(timetable.pattern.stopPattern.getPickup(i));
stopTime.setArrivalTime(oldTimes.getScheduledArrivalTime(i));
stopTime.setDepartureTime(oldTimes.getScheduledDepartureTime(i));
stopTime.setStopHeadsign(oldTimes.getHeadsign(i));
Expand Down Expand Up @@ -516,26 +516,26 @@ public static List<StopTime> createModifiedStopTimes(Timetable timetable, TripTi

CallStatusEnumeration arrivalStatus = estimatedCall.getArrivalStatus();
if (arrivalStatus == CallStatusEnumeration.CANCELLED) {
stopTime.setDropOffType(PICKDROP_NONE);
stopTime.setDropOffType(NONE);
} else if (estimatedCall.getArrivalBoardingActivity() == ArrivalBoardingActivityEnumeration.ALIGHTING) {
stopTime.setDropOffType(PICKDROP_SCHEDULED);
stopTime.setDropOffType(SCHEDULED);
} else if (estimatedCall.getArrivalBoardingActivity() == ArrivalBoardingActivityEnumeration.NO_ALIGHTING) {
stopTime.setDropOffType(PICKDROP_NONE);
stopTime.setDropOffType(NONE);
} else if (estimatedCall.getArrivalBoardingActivity() == null && i == 0) {
//First stop - default no pickup
stopTime.setDropOffType(PICKDROP_NONE);
stopTime.setDropOffType(NONE);
}

CallStatusEnumeration departureStatus = estimatedCall.getDepartureStatus();
if (departureStatus == CallStatusEnumeration.CANCELLED) {
stopTime.setPickupType(PICKDROP_NONE);
stopTime.setPickupType(NONE);
} else if (estimatedCall.getDepartureBoardingActivity() == DepartureBoardingActivityEnumeration.BOARDING) {
stopTime.setPickupType(PICKDROP_SCHEDULED);
stopTime.setPickupType(SCHEDULED);
} else if (estimatedCall.getDepartureBoardingActivity() == DepartureBoardingActivityEnumeration.NO_BOARDING) {
stopTime.setPickupType(PICKDROP_NONE);
stopTime.setPickupType(NONE);
} else if (estimatedCall.getDepartureBoardingActivity() == null && i == (stops.size()-1)) {
//Last stop - default no dropoff
stopTime.setPickupType(PICKDROP_NONE);
stopTime.setPickupType(NONE);
}

if (estimatedCall.getDestinationDisplaies() != null && !estimatedCall.getDestinationDisplaies().isEmpty()) {
Expand Down
Loading

0 comments on commit a4238b9

Please sign in to comment.