use of uk.org.siri.siri20.EstimatedCall in project OpenTripPlanner by opentripplanner.
the class SiriFuzzyTripMatcher method match.
/**
* Matches EstimatedVehicleJourney to a set of possible Trips based on tripId
*/
public Set<Trip> match(EstimatedVehicleJourney journey) {
Set<Trip> trips = null;
if (journey.getVehicleRef() != null && (journey.getVehicleModes() != null && journey.getVehicleModes().contains(VehicleModesEnumeration.RAIL))) {
trips = getCachedTripsByVehicleRef(journey.getVehicleRef().getValue());
}
if (trips == null || trips.isEmpty()) {
String serviceJourneyId = resolveDatedVehicleJourneyRef(journey);
if (serviceJourneyId != null) {
trips = getCachedTripsBySiriId(serviceJourneyId);
}
}
if (trips == null || trips.isEmpty()) {
List<EstimatedCall> estimatedCalls = journey.getEstimatedCalls().getEstimatedCalls();
EstimatedCall lastStop = estimatedCalls.get(estimatedCalls.size() - 1);
String lastStopPoint = lastStop.getStopPointRef().getValue();
ZonedDateTime arrivalTime = lastStop.getAimedArrivalTime() != null ? lastStop.getAimedArrivalTime() : lastStop.getAimedDepartureTime();
if (arrivalTime != null) {
trips = getMatchingTripsOnStopOrSiblings(lastStopPoint, arrivalTime);
}
}
return trips;
}
use of uk.org.siri.siri20.EstimatedCall in project OpenTripPlanner by opentripplanner.
the class SiriTimetableSnapshotSource method getServiceDateForEstimatedVehicleJourney.
private ServiceDate getServiceDateForEstimatedVehicleJourney(EstimatedVehicleJourney estimatedVehicleJourney) {
ZonedDateTime date;
if (estimatedVehicleJourney.getRecordedCalls() != null && !estimatedVehicleJourney.getRecordedCalls().getRecordedCalls().isEmpty()) {
date = estimatedVehicleJourney.getRecordedCalls().getRecordedCalls().get(0).getAimedDepartureTime();
} else {
EstimatedCall firstCall = estimatedVehicleJourney.getEstimatedCalls().getEstimatedCalls().get(0);
date = firstCall.getAimedDepartureTime();
}
if (date == null) {
return null;
}
return new ServiceDate(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
}
use of uk.org.siri.siri20.EstimatedCall in project OpenTripPlanner by opentripplanner.
the class SiriTimetableSnapshotSource method getPatternForTrip.
private TripPattern getPatternForTrip(Trip trip, EstimatedVehicleJourney journey) {
Set<ServiceDate> serviceDates = routingService.getCalendarService().getServiceDatesForServiceId(trip.getServiceId());
List<RecordedCall> recordedCalls = (journey.getRecordedCalls() != null ? journey.getRecordedCalls().getRecordedCalls() : new ArrayList<>());
List<EstimatedCall> estimatedCalls = journey.getEstimatedCalls().getEstimatedCalls();
String journeyFirstStopId;
ServiceDate journeyDate;
if (recordedCalls != null && !recordedCalls.isEmpty()) {
RecordedCall recordedCall = recordedCalls.get(0);
journeyFirstStopId = recordedCall.getStopPointRef().getValue();
journeyDate = new ServiceDate(Date.from(recordedCall.getAimedDepartureTime().toInstant()));
} else if (estimatedCalls != null && !estimatedCalls.isEmpty()) {
EstimatedCall estimatedCall = estimatedCalls.get(0);
journeyFirstStopId = estimatedCall.getStopPointRef().getValue();
journeyDate = new ServiceDate(Date.from(estimatedCall.getAimedDepartureTime().toInstant()));
} else {
return null;
}
String journeyLastStopId = estimatedCalls.get(estimatedCalls.size() - 1).getStopPointRef().getValue();
TripPattern lastAddedTripPattern = null;
if (getTimetableSnapshot() != null) {
lastAddedTripPattern = getTimetableSnapshot().getLastAddedTripPattern(trip.getId(), journeyDate);
}
TripPattern tripPattern;
if (lastAddedTripPattern != null) {
tripPattern = lastAddedTripPattern;
} else {
tripPattern = routingService.getPatternForTrip().get(trip);
}
Stop firstStop = tripPattern.getStop(0);
Stop lastStop = tripPattern.getStop(tripPattern.getStops().size() - 1);
if (serviceDates.contains(journeyDate)) {
boolean firstStopIsMatch = firstStop.getId().getId().equals(journeyFirstStopId);
boolean lastStopIsMatch = lastStop.getId().getId().equals(journeyLastStopId);
if (!firstStopIsMatch && firstStop.isPartOfStation()) {
Stop otherFirstStop = routingService.getStopForId(new FeedScopedId(firstStop.getId().getFeedId(), journeyFirstStopId));
firstStopIsMatch = firstStop.isPartOfSameStationAs(otherFirstStop);
}
if (!lastStopIsMatch && lastStop.isPartOfStation()) {
Stop otherLastStop = routingService.getStopForId(new FeedScopedId(lastStop.getId().getFeedId(), journeyLastStopId));
lastStopIsMatch = lastStop.isPartOfSameStationAs(otherLastStop);
}
if (firstStopIsMatch & lastStopIsMatch) {
// Found matches
return tripPattern;
}
return null;
}
return null;
}
Aggregations