Search in sources :

Example 36 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class RoutingServiceTest method testPatternsCoherent.

/**
 * Check that bidirectional relationships between TripPatterns and Trips, Routes, and Stops are coherent.
 */
public void testPatternsCoherent() {
    for (Trip trip : graph.index.getTripForId().values()) {
        TripPattern pattern = graph.index.getPatternForTrip().get(trip);
        assertTrue(pattern.getTrips().contains(trip));
    }
    /* This one depends on a feed where each TripPattern appears on only one route. */
    for (Route route : graph.index.getAllRoutes()) {
        for (TripPattern pattern : graph.index.getPatternsForRoute().get(route)) {
            assertEquals(pattern.route, route);
        }
    }
    for (Stop stop : graph.index.getAllStops()) {
        for (TripPattern pattern : graph.index.getPatternsForStop(stop)) {
            assertTrue(pattern.stopPattern.containsStop(stop.getId().toString()));
        }
    }
}
Also used : Trip(org.opentripplanner.model.Trip) Stop(org.opentripplanner.model.Stop) TripPattern(org.opentripplanner.model.TripPattern) Route(org.opentripplanner.model.Route)

Example 37 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class RoutingServiceTest method testSpatialIndex.

public void testSpatialIndex() {
    String feedId = graph.getFeedIds().iterator().next();
    Stop stopJ = graph.index.getStopForId(new FeedScopedId(feedId, "J"));
    Stop stopL = graph.index.getStopForId(new FeedScopedId(feedId, "L"));
    Stop stopM = graph.index.getStopForId(new FeedScopedId(feedId, "M"));
    TransitStopVertex stopvJ = graph.index.getStopVertexForStop().get(stopJ);
    TransitStopVertex stopvL = graph.index.getStopVertexForStop().get(stopL);
    TransitStopVertex stopvM = graph.index.getStopVertexForStop().get(stopM);
    // There are a two other stops within 100 meters of stop J.
    Envelope env = new Envelope(new Coordinate(stopJ.getLon(), stopJ.getLat()));
    env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(100, stopJ.getLat()), SphericalDistanceLibrary.metersToDegrees(100));
    List<TransitStopVertex> stops = graph.index.getStopSpatialIndex().query(env);
    assertTrue(stops.contains(stopvJ));
    assertTrue(stops.contains(stopvL));
    assertTrue(stops.contains(stopvM));
    // Query can overselect
    assertTrue(stops.size() >= 3);
}
Also used : Stop(org.opentripplanner.model.Stop) Coordinate(org.locationtech.jts.geom.Coordinate) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) FeedScopedId(org.opentripplanner.model.FeedScopedId) Envelope(org.locationtech.jts.geom.Envelope)

Example 38 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class TripTimesTest method testApply.

@Test
public void testApply() {
    Trip trip = new Trip();
    trip.setId(tripId);
    List<StopTime> stopTimes = new LinkedList<StopTime>();
    StopTime stopTime0 = new StopTime();
    StopTime stopTime1 = new StopTime();
    StopTime stopTime2 = new StopTime();
    Stop stop0 = Stop.stopForTest(stops[0].getId(), 0.0, 0.0);
    Stop stop1 = Stop.stopForTest(stops[1].getId(), 0.0, 0.0);
    Stop stop2 = Stop.stopForTest(stops[2].getId(), 0.0, 0.0);
    stopTime0.setStop(stop0);
    stopTime0.setDepartureTime(0);
    stopTime0.setStopSequence(0);
    stopTime1.setStop(stop1);
    stopTime1.setArrivalTime(30);
    stopTime1.setDepartureTime(60);
    stopTime1.setStopSequence(1);
    stopTime2.setStop(stop2);
    stopTime2.setArrivalTime(90);
    stopTime2.setStopSequence(2);
    stopTimes.add(stopTime0);
    stopTimes.add(stopTime1);
    stopTimes.add(stopTime2);
    TripTimes differingTripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    TripTimes updatedTripTimesA = new TripTimes(differingTripTimes);
    updatedTripTimesA.updateArrivalTime(1, 89);
    updatedTripTimesA.updateDepartureTime(1, 98);
    assertFalse(updatedTripTimesA.timesIncreasing());
}
Also used : Trip(org.opentripplanner.model.Trip) Stop(org.opentripplanner.model.Stop) LinkedList(java.util.LinkedList) StopTime(org.opentripplanner.model.StopTime) Test(org.junit.Test)

Example 39 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class StopAndStationMapperTest method mapStopPlaceAndQuays.

@Test
public void mapStopPlaceAndQuays() {
    Collection<StopPlace> stopPlaces = new ArrayList<>();
    StopPlace stopPlaceNew = createStopPlace("NSR:StopPlace:1", "Oslo S", "2", 59.909584, 10.755165, VehicleModeEnumeration.TRAM);
    StopPlace stopPlaceOld = createStopPlace("NSR:StopPlace:1", "Oslo S", "1", 59.909584, 10.755165, VehicleModeEnumeration.TRAM);
    stopPlaces.add(stopPlaceNew);
    stopPlaces.add(stopPlaceOld);
    Quay quay1a = createQuay("NSR:Quay:1", "", "1", 59.909323, 10.756205, "a");
    Quay quay1b = createQuay("NSR:Quay:1", "", "2", 59.909911, 10.753008, "A");
    Quay quay2 = createQuay("NSR:Quay:2", "", "1", 59.909911, 10.753008, "B");
    Quay quay3 = createQuay("NSR:Quay:3", "", "1", 59.909911, 10.753008, "C");
    stopPlaceNew.setQuays(new Quays_RelStructure().withQuayRefOrQuay(quay1b).withQuayRefOrQuay(quay2));
    stopPlaceOld.setQuays(new Quays_RelStructure().withQuayRefOrQuay(quay1a).withQuayRefOrQuay(quay3));
    HierarchicalVersionMapById<Quay> quaysById = new HierarchicalVersionMapById<>();
    quaysById.add(quay1a);
    quaysById.add(quay1a);
    quaysById.add(quay2);
    quaysById.add(quay3);
    StopAndStationMapper stopMapper = new StopAndStationMapper(MappingSupport.ID_FACTORY, quaysById, null, new DataImportIssueStore(false));
    stopMapper.mapParentAndChildStops(stopPlaces);
    Collection<Stop> stops = stopMapper.resultStops;
    Collection<Station> stations = stopMapper.resultStations;
    assertEquals(3, stops.size());
    assertEquals(1, stations.size());
    Station parentStop = stations.stream().filter(s -> s.getId().getId().equals("NSR:StopPlace:1")).findFirst().get();
    Stop childStop1 = stops.stream().filter(s -> s.getId().getId().equals("NSR:Quay:1")).findFirst().get();
    Stop childStop2 = stops.stream().filter(s -> s.getId().getId().equals("NSR:Quay:2")).findFirst().get();
    Stop childStop3 = stops.stream().filter(s -> s.getId().getId().equals("NSR:Quay:3")).findFirst().get();
    assertEquals("NSR:StopPlace:1", parentStop.getId().getId());
    assertEquals("NSR:Quay:1", childStop1.getId().getId());
    assertEquals("NSR:Quay:2", childStop2.getId().getId());
    assertEquals("NSR:Quay:3", childStop3.getId().getId());
    assertEquals(59.909911, childStop1.getLat(), 0.0001);
    assertEquals(10.753008, childStop1.getLon(), 0.0001);
    assertEquals("A", childStop1.getCode());
}
Also used : StopPlace(org.rutebanken.netex.model.StopPlace) HierarchicalVersionMapById(org.opentripplanner.netex.loader.util.HierarchicalVersionMapById) Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList) Quays_RelStructure(org.rutebanken.netex.model.Quays_RelStructure) Station(org.opentripplanner.model.Station) Quay(org.rutebanken.netex.model.Quay) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) Test(org.junit.Test)

Example 40 with Stop

use of org.opentripplanner.model.Stop in project OpenTripPlanner by opentripplanner.

the class TimetableSnapshotSourceTest method testHandleAddedTrip.

@Test
public void testHandleAddedTrip() throws ParseException {
    // GIVEN
    // Get service date of today because old dates will be purged after applying updates
    final ServiceDate serviceDate = new ServiceDate(Calendar.getInstance());
    final String addedTripId = "added_trip";
    TripUpdate tripUpdate;
    {
        final TripDescriptor.Builder tripDescriptorBuilder = TripDescriptor.newBuilder();
        tripDescriptorBuilder.setTripId(addedTripId);
        tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.ADDED);
        tripDescriptorBuilder.setStartDate(serviceDate.asCompactString());
        final Calendar calendar = serviceDate.getAsCalendar(graph.getTimeZone());
        final long midnightSecondsSinceEpoch = calendar.getTimeInMillis() / 1000;
        final TripUpdate.Builder tripUpdateBuilder = TripUpdate.newBuilder();
        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        {
            // Stop A
            final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
            stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
            stopTimeUpdateBuilder.setStopId("A");
            {
                // Arrival
                final StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
                arrivalBuilder.setTime(midnightSecondsSinceEpoch + (8 * 3600) + (30 * 60));
                arrivalBuilder.setDelay(0);
            }
            {
                // Departure
                final StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
                departureBuilder.setTime(midnightSecondsSinceEpoch + (8 * 3600) + (30 * 60));
                departureBuilder.setDelay(0);
            }
        }
        {
            // Stop C
            final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
            stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
            stopTimeUpdateBuilder.setStopId("C");
            {
                // Arrival
                final StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
                arrivalBuilder.setTime(midnightSecondsSinceEpoch + (8 * 3600) + (40 * 60));
                arrivalBuilder.setDelay(0);
            }
            {
                // Departure
                final StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
                departureBuilder.setTime(midnightSecondsSinceEpoch + (8 * 3600) + (45 * 60));
                departureBuilder.setDelay(0);
            }
        }
        {
            // Stop E
            final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
            stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
            stopTimeUpdateBuilder.setStopId("E");
            {
                // Arrival
                final StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
                arrivalBuilder.setTime(midnightSecondsSinceEpoch + (8 * 3600) + (55 * 60));
                arrivalBuilder.setDelay(0);
            }
            {
                // Departure
                final StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
                departureBuilder.setTime(midnightSecondsSinceEpoch + (8 * 3600) + (55 * 60));
                departureBuilder.setDelay(0);
            }
        }
        tripUpdate = tripUpdateBuilder.build();
    }
    // WHEN
    updater.applyTripUpdates(graph, fullDataset, Arrays.asList(tripUpdate), feedId);
    // THEN
    // Find new pattern in graph starting from stop A
    Stop stopA = graph.index.getStopForId(new FeedScopedId(feedId, "A"));
    // Get trip pattern of last (most recently added) outgoing edge
    // FIXME create a new test to see that add-trip realtime updates work
    TripPattern tripPattern = null;
    assertNotNull("Added trip pattern should be found", tripPattern);
    final TimetableSnapshot snapshot = updater.getTimetableSnapshot();
    final Timetable forToday = snapshot.resolve(tripPattern, serviceDate);
    final Timetable schedule = snapshot.resolve(tripPattern, null);
    assertNotSame(forToday, schedule);
    final int forTodayAddedTripIndex = forToday.getTripIndex(addedTripId);
    assertTrue("Added trip should be found in time table for service date", forTodayAddedTripIndex > -1);
    assertEquals(RealTimeState.ADDED, forToday.getTripTimes(forTodayAddedTripIndex).getRealTimeState());
    final int scheduleTripIndex = schedule.getTripIndex(addedTripId);
    assertEquals("Added trip should not be found in scheduled time table", -1, scheduleTripIndex);
}
Also used : Timetable(org.opentripplanner.model.Timetable) TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) Stop(org.opentripplanner.model.Stop) GtfsContextBuilder.contextBuilder(org.opentripplanner.gtfs.GtfsContextBuilder.contextBuilder) Calendar(java.util.Calendar) TimetableSnapshot(org.opentripplanner.model.TimetableSnapshot) TripPattern(org.opentripplanner.model.TripPattern) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) FeedScopedId(org.opentripplanner.model.FeedScopedId) Test(org.junit.Test)

Aggregations

Stop (org.opentripplanner.model.Stop)73 FeedScopedId (org.opentripplanner.model.FeedScopedId)25 ArrayList (java.util.ArrayList)24 TripPattern (org.opentripplanner.model.TripPattern)24 Trip (org.opentripplanner.model.Trip)21 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)13 RoutingService (org.opentripplanner.routing.RoutingService)13 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)13 HashSet (java.util.HashSet)12 Station (org.opentripplanner.model.Station)12 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)11 List (java.util.List)10 Test (org.junit.Test)8 Route (org.opentripplanner.model.Route)8 StopTime (org.opentripplanner.model.StopTime)8 Collectors (java.util.stream.Collectors)7 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ApiStop (org.opentripplanner.api.model.ApiStop)7 TripTimeShort (org.opentripplanner.model.TripTimeShort)7