Search in sources :

Example 6 with EstimatedCall

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;
}
Also used : Trip(org.opentripplanner.model.Trip) ZonedDateTime(java.time.ZonedDateTime) EstimatedCall(uk.org.siri.siri20.EstimatedCall)

Example 7 with EstimatedCall

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());
}
Also used : ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ZonedDateTime(java.time.ZonedDateTime) EstimatedCall(uk.org.siri.siri20.EstimatedCall)

Example 8 with EstimatedCall

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;
}
Also used : ServiceDate(org.opentripplanner.model.calendar.ServiceDate) Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList) FeedScopedId(org.opentripplanner.model.FeedScopedId) RecordedCall(uk.org.siri.siri20.RecordedCall) EstimatedCall(uk.org.siri.siri20.EstimatedCall) TripPattern(org.opentripplanner.model.TripPattern)

Aggregations

EstimatedCall (uk.org.siri.siri20.EstimatedCall)8 ZonedDateTime (java.time.ZonedDateTime)6 FeedScopedId (org.opentripplanner.model.FeedScopedId)6 Stop (org.opentripplanner.model.Stop)6 ArrayList (java.util.ArrayList)5 Trip (org.opentripplanner.model.Trip)4 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)4 RecordedCall (uk.org.siri.siri20.RecordedCall)4 HashSet (java.util.HashSet)3 StopTime (org.opentripplanner.model.StopTime)3 TripPattern (org.opentripplanner.model.TripPattern)3 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)3 EstimatedVehicleJourney (uk.org.siri.siri20.EstimatedVehicleJourney)3 TimetableHelper.createUpdatedTripTimes (org.opentripplanner.ext.siri.TimetableHelper.createUpdatedTripTimes)2 CallStatusEnumeration (uk.org.siri.siri20.CallStatusEnumeration)2 NaturalLanguageStringStructure (uk.org.siri.siri20.NaturalLanguageStringStructure)2 Agency (org.opentripplanner.model.Agency)1 Route (org.opentripplanner.model.Route)1 StopPattern (org.opentripplanner.model.StopPattern)1 RoutingService (org.opentripplanner.routing.RoutingService)1