Search in sources :

Example 6 with StopTime

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;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri20.NaturalLanguageStringStructure) ArrayList(java.util.ArrayList) RecordedCall(uk.org.siri.siri20.RecordedCall) ZonedDateTime(java.time.ZonedDateTime) FeedScopedId(org.opentripplanner.model.FeedScopedId) EstimatedCall(uk.org.siri.siri20.EstimatedCall) StopLocation(org.opentripplanner.model.StopLocation) CallStatusEnumeration(uk.org.siri.siri20.CallStatusEnumeration) StopTime(org.opentripplanner.model.StopTime) HashSet(java.util.HashSet)

Example 7 with StopTime

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;
}
Also used : BogusShapeGeometryCaught(org.opentripplanner.graph_builder.issues.BogusShapeGeometryCaught) LineString(org.locationtech.jts.geom.LineString) ShapePoint(org.opentripplanner.model.ShapePoint) StopTime(org.opentripplanner.model.StopTime)

Example 8 with StopTime

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;
    }
}
Also used : StopTime(org.opentripplanner.model.StopTime)

Example 9 with StopTime

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;
}
Also used : StopTime(org.opentripplanner.model.StopTime)

Example 10 with StopTime

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());
}
Also used : Trip(org.opentripplanner.model.Trip) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) FeedScopedId(org.opentripplanner.model.FeedScopedId) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) StopTime(org.opentripplanner.model.StopTime)

Aggregations

StopTime (org.opentripplanner.model.StopTime)41 Trip (org.opentripplanner.model.Trip)15 ArrayList (java.util.ArrayList)11 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)10 FeedScopedId (org.opentripplanner.model.FeedScopedId)8 Test (org.junit.Test)7 TripPattern (org.opentripplanner.model.TripPattern)7 StopLocation (org.opentripplanner.model.StopLocation)6 StopPattern (org.opentripplanner.model.StopPattern)6 Stop (org.opentripplanner.model.Stop)5 Route (org.opentripplanner.model.Route)4 MultilingualString (org.rutebanken.netex.model.MultilingualString)4 StopPointInJourneyPattern (org.rutebanken.netex.model.StopPointInJourneyPattern)4 TimetabledPassingTime (org.rutebanken.netex.model.TimetabledPassingTime)4 ZonedDateTime (java.time.ZonedDateTime)3 HashSet (java.util.HashSet)3 List (java.util.List)3 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)3 VersionOfObjectRefStructure (org.rutebanken.netex.model.VersionOfObjectRefStructure)3 EstimatedCall (uk.org.siri.siri20.EstimatedCall)3