use of org.opentripplanner.model.StopTime in project OpenTripPlanner by opentripplanner.
the class TimetableHelper method createModifiedStopTimes.
/**
* Apply the SIRI ET to the appropriate TripTimes from this Timetable.
* Calculate new stoppattern based on single stop cancellations
*
* @param journey SIRI-ET EstimatedVehicleJourney
* @return new copy of updated TripTimes after TripUpdate has been applied on TripTimes of trip
* with the id specified in the trip descriptor of the TripUpdate; null if something
* went wrong
*/
public static List<StopTime> createModifiedStopTimes(Timetable timetable, TripTimes oldTimes, EstimatedVehicleJourney journey, Trip trip, RoutingService routingService) {
if (journey == null) {
return null;
}
List<EstimatedCall> estimatedCalls;
List<RecordedCall> recordedCalls;
if (journey.getEstimatedCalls() != null) {
estimatedCalls = journey.getEstimatedCalls().getEstimatedCalls();
} else {
estimatedCalls = EMPTY_LIST;
}
if (journey.getRecordedCalls() != null) {
recordedCalls = journey.getRecordedCalls().getRecordedCalls();
} else {
recordedCalls = EMPTY_LIST;
}
var stops = createModifiedStops(timetable, journey, routingService);
List<StopTime> modifiedStops = new ArrayList<>();
ZonedDateTime departureDate = null;
int numberOfRecordedCalls = (journey.getRecordedCalls() != null && journey.getRecordedCalls().getRecordedCalls() != null) ? journey.getRecordedCalls().getRecordedCalls().size() : 0;
Set<Object> alreadyVisited = new HashSet<>();
// modify updated stop-times
for (int i = 0; i < stops.size(); i++) {
StopLocation stop = stops.get(i);
final StopTime stopTime = new StopTime();
stopTime.setStop(stop);
stopTime.setTrip(trip);
stopTime.setStopSequence(i);
stopTime.setDropOffType(timetable.getPattern().getAlightType(i));
stopTime.setPickupType(timetable.getPattern().getBoardType(i));
stopTime.setArrivalTime(oldTimes.getScheduledArrivalTime(i));
stopTime.setDepartureTime(oldTimes.getScheduledDepartureTime(i));
stopTime.setStopHeadsign(oldTimes.getHeadsign(i));
// TODO: Do we need to set the StopTime.id?
// stopTime.setId(oldTimes.getStopTimeIdByIndex(i));
boolean foundMatch = false;
if (i < numberOfRecordedCalls) {
for (RecordedCall recordedCall : recordedCalls) {
if (alreadyVisited.contains(recordedCall)) {
continue;
}
// Current stop is being updated
var callStopRef = recordedCall.getStopPointRef().getValue();
boolean stopsMatchById = stop.getId().getId().equals(callStopRef);
if (!stopsMatchById && stop.isPartOfStation()) {
var alternativeStop = routingService.getStopForId(new FeedScopedId(stop.getId().getFeedId(), callStopRef));
if (alternativeStop != null && stop.isPartOfSameStationAs(alternativeStop)) {
stopsMatchById = true;
stopTime.setStop(alternativeStop);
}
}
if (stopsMatchById) {
foundMatch = true;
if (recordedCall.isCancellation() != null && recordedCall.isCancellation()) {
stopTime.cancel();
}
modifiedStops.add(stopTime);
alreadyVisited.add(recordedCall);
break;
}
}
} else {
for (EstimatedCall estimatedCall : estimatedCalls) {
if (alreadyVisited.contains(estimatedCall)) {
continue;
}
if (departureDate == null) {
departureDate = (estimatedCall.getAimedDepartureTime() != null ? estimatedCall.getAimedDepartureTime() : estimatedCall.getAimedArrivalTime());
}
// Current stop is being updated
boolean stopsMatchById = stop.getId().getId().equals(estimatedCall.getStopPointRef().getValue());
if (!stopsMatchById && stop.isPartOfStation()) {
var alternativeStop = routingService.getStopForId(new FeedScopedId(stop.getId().getFeedId(), estimatedCall.getStopPointRef().getValue()));
if (alternativeStop != null && stop.isPartOfSameStationAs(alternativeStop)) {
stopsMatchById = true;
stopTime.setStop(alternativeStop);
}
}
if (stopsMatchById) {
foundMatch = true;
CallStatusEnumeration arrivalStatus = estimatedCall.getArrivalStatus();
if (arrivalStatus == CallStatusEnumeration.CANCELLED) {
stopTime.cancelDropOff();
} else if (estimatedCall.getArrivalBoardingActivity() == ArrivalBoardingActivityEnumeration.ALIGHTING) {
stopTime.setDropOffType(SCHEDULED);
} else if (estimatedCall.getArrivalBoardingActivity() == ArrivalBoardingActivityEnumeration.NO_ALIGHTING) {
stopTime.setDropOffType(NONE);
} else if (estimatedCall.getArrivalBoardingActivity() == null && i == 0) {
// First stop - default no dropoff
stopTime.setDropOffType(NONE);
}
CallStatusEnumeration departureStatus = estimatedCall.getDepartureStatus();
if (departureStatus == CallStatusEnumeration.CANCELLED) {
stopTime.cancelPickup();
} else if (estimatedCall.getDepartureBoardingActivity() == DepartureBoardingActivityEnumeration.BOARDING) {
stopTime.setPickupType(SCHEDULED);
} else if (estimatedCall.getDepartureBoardingActivity() == DepartureBoardingActivityEnumeration.NO_BOARDING) {
stopTime.setPickupType(NONE);
} else if (estimatedCall.getDepartureBoardingActivity() == null && i == (stops.size() - 1)) {
// Last stop - default no pickup
stopTime.setPickupType(NONE);
}
if (estimatedCall.isCancellation() != null && estimatedCall.isCancellation()) {
stopTime.cancel();
}
if (estimatedCall.getDestinationDisplaies() != null && !estimatedCall.getDestinationDisplaies().isEmpty()) {
NaturalLanguageStringStructure destinationDisplay = estimatedCall.getDestinationDisplaies().get(0);
stopTime.setStopHeadsign(destinationDisplay.getValue());
}
modifiedStops.add(stopTime);
alreadyVisited.add(estimatedCall);
break;
}
}
}
if (!foundMatch) {
modifiedStops.add(stopTime);
}
}
return modifiedStops;
}
use of org.opentripplanner.model.StopTime in project OpenTripPlanner by opentripplanner.
the class GeometryAndBlockProcessor method createStraightLineHopeGeometries.
private LineString[] createStraightLineHopeGeometries(List<StopTime> stopTimes, FeedScopedId shapeId) {
LineString[] geoms = new LineString[stopTimes.size() - 1];
StopTime st0;
for (int i = 0; i < stopTimes.size() - 1; ++i) {
st0 = stopTimes.get(i);
StopTime st1 = stopTimes.get(i + 1);
LineString geometry = createSimpleGeometry(st0.getStop(), st1.getStop());
geoms[i] = geometry;
// this warning is not strictly correct, but will do
issueStore.add(new BogusShapeGeometryCaught(shapeId, st0, st1));
}
return geoms;
}
use of org.opentripplanner.model.StopTime in project OpenTripPlanner by opentripplanner.
the class TripTimes method makeHeadsignsArray.
/**
* @return either an array of headsigns (one for each stop on this trip) or null if the
* headsign is the same at all stops (including null) and can be found in the Trip object.
*/
private String[] makeHeadsignsArray(final Collection<StopTime> stopTimes) {
final String tripHeadsign = trip.getTripHeadsign();
boolean useStopHeadsigns = false;
if (tripHeadsign == null) {
useStopHeadsigns = true;
} else {
for (final StopTime st : stopTimes) {
if (!(tripHeadsign.equals(st.getStopHeadsign()))) {
useStopHeadsigns = true;
break;
}
}
}
if (!useStopHeadsigns) {
// defer to trip_headsign
return null;
}
boolean allNull = true;
int i = 0;
final String[] hs = new String[stopTimes.size()];
for (final StopTime st : stopTimes) {
final String headsign = st.getStopHeadsign();
hs[i++] = headsign;
if (headsign != null)
allNull = false;
}
if (allNull) {
return null;
} else {
return hs;
}
}
use of org.opentripplanner.model.StopTime in project OpenTripPlanner by opentripplanner.
the class TripTimes method makeHeadsignViasArray.
/**
* Create 2D String array for via names for each stop in sequence.
* @return May be null if no vias are present in stop sequence.
*/
private String[][] makeHeadsignViasArray(final Collection<StopTime> stopTimes) {
if (stopTimes.stream().allMatch(st -> st.getHeadsignVias() == null || st.getHeadsignVias().isEmpty())) {
return null;
}
String[][] vias = new String[stopTimes.size()][];
int i = 0;
for (final StopTime st : stopTimes) {
if (st.getHeadsignVias() == null) {
vias[i] = EMPTY_STRING_ARRAY;
continue;
}
vias[i] = st.getHeadsignVias().toArray(EMPTY_STRING_ARRAY);
i++;
}
return vias;
}
use of org.opentripplanner.model.StopTime in project OpenTripPlanner by opentripplanner.
the class RaptorRoutingRequestTransitDataCreatorTest method createTripTimesForTest.
private TripTimes createTripTimesForTest() {
StopTime stopTime1 = new StopTime();
StopTime stopTime2 = new StopTime();
stopTime1.setDepartureTime(0);
stopTime2.setArrivalTime(7200);
return new TripTimes(new Trip(new FeedScopedId("Test", "Test")), Arrays.asList(stopTime1, stopTime2), new Deduplicator());
}
Aggregations