Search in sources :

Example 6 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getGeometryForTrip.

/**
 * Return geometry for the trip as a packed coordinate sequence
 */
@GET
@Path("/trips/{tripId}/geometry")
public Response getGeometryForTrip(@PathParam("tripId") String tripIdString) {
    AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
    Trip trip = index.tripForId.get(tripId);
    if (trip != null) {
        TripPattern tripPattern = index.patternForTrip.get(trip);
        return getGeometryForPattern(tripPattern.code);
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 7 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getRoutesForStop.

@GET
@Path("/stops/{stopId}/routes")
public Response getRoutesForStop(@PathParam("stopId") String stopId) {
    Stop stop = index.stopForId.get(GtfsLibrary.convertIdFromString(stopId));
    if (stop == null)
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    Set<Route> routes = Sets.newHashSet();
    for (TripPattern pattern : index.patternsForStop.get(stop)) {
        routes.add(pattern.route);
    }
    return Response.status(Status.OK).entity(RouteShort.list(routes)).build();
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 8 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class GraphIndexTest method testPatternsCoherent.

/**
 * Check that bidirectional relationships between TripPatterns and Trips, Routes, and Stops are coherent.
 */
public void testPatternsCoherent() {
    for (Trip trip : graph.index.tripForId.values()) {
        TripPattern pattern = graph.index.patternForTrip.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.routeForId.values()) {
        for (TripPattern pattern : graph.index.patternsForRoute.get(route)) {
            assertEquals(pattern.route, route);
        }
    }
    for (Stop stop : graph.index.stopForId.values()) {
        for (TripPattern pattern : graph.index.patternsForStop.get(stop)) {
            assertTrue(pattern.stopPattern.containsStop(stop.getId().toString()));
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Route(org.onebusaway.gtfs.model.Route)

Example 9 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class TimetableSnapshotSourceTest method testHandleModifiedTrip.

@Test
public void testHandleModifiedTrip() throws ParseException {
    // TODO
    // GIVEN
    // Get service date of today because old dates will be purged after applying updates
    ServiceDate serviceDate = new ServiceDate(Calendar.getInstance());
    String modifiedTripId = "10.1";
    TripUpdate tripUpdate;
    {
        final TripDescriptor.Builder tripDescriptorBuilder = TripDescriptor.newBuilder();
        tripDescriptorBuilder.setTripId(modifiedTripId);
        tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.MODIFIED);
        tripDescriptorBuilder.setStartDate(serviceDate.getAsString());
        final Calendar calendar = serviceDate.getAsCalendar(graph.getTimeZone());
        final long midnightSecondsSinceEpoch = calendar.getTimeInMillis() / 1000;
        final TripUpdate.Builder tripUpdateBuilder = TripUpdate.newBuilder();
        tripUpdateBuilder.setTrip(tripDescriptorBuilder);
        {
            // Stop O
            final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
            stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
            stopTimeUpdateBuilder.setStopId("O");
            stopTimeUpdateBuilder.setStopSequence(10);
            {
                // Arrival
                final StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
                arrivalBuilder.setTime(midnightSecondsSinceEpoch + (12 * 3600) + (30 * 60));
                arrivalBuilder.setDelay(0);
            }
            {
                // Departure
                final StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
                departureBuilder.setTime(midnightSecondsSinceEpoch + (12 * 3600) + (30 * 60));
                departureBuilder.setDelay(0);
            }
        }
        {
            // Stop C
            final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
            stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
            stopTimeUpdateBuilder.setStopId("C");
            stopTimeUpdateBuilder.setStopSequence(30);
            {
                // Arrival
                final StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
                arrivalBuilder.setTime(midnightSecondsSinceEpoch + (12 * 3600) + (40 * 60));
                arrivalBuilder.setDelay(0);
            }
            {
                // Departure
                final StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
                departureBuilder.setTime(midnightSecondsSinceEpoch + (12 * 3600) + (45 * 60));
                departureBuilder.setDelay(0);
            }
        }
        {
            // Stop D
            final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
            stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SKIPPED);
            stopTimeUpdateBuilder.setStopId("D");
            stopTimeUpdateBuilder.setStopSequence(40);
            {
                // Arrival
                final StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
                arrivalBuilder.setTime(midnightSecondsSinceEpoch + (12 * 3600) + (50 * 60));
                arrivalBuilder.setDelay(0);
            }
            {
                // Departure
                final StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
                departureBuilder.setTime(midnightSecondsSinceEpoch + (12 * 3600) + (51 * 60));
                departureBuilder.setDelay(0);
            }
        }
        {
            // Stop P
            final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
            stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
            stopTimeUpdateBuilder.setStopId("P");
            stopTimeUpdateBuilder.setStopSequence(50);
            {
                // Arrival
                final StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
                arrivalBuilder.setTime(midnightSecondsSinceEpoch + (12 * 3600) + (55 * 60));
                arrivalBuilder.setDelay(0);
            }
            {
                // Departure
                final StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
                departureBuilder.setTime(midnightSecondsSinceEpoch + (12 * 3600) + (55 * 60));
                departureBuilder.setDelay(0);
            }
        }
        tripUpdate = tripUpdateBuilder.build();
    }
    // WHEN
    updater.applyTripUpdates(graph, fullDataset, Arrays.asList(tripUpdate), feedId);
    // THEN
    final TimetableSnapshot snapshot = updater.getTimetableSnapshot();
    // Original trip pattern
    {
        final AgencyAndId tripId = new AgencyAndId(feedId, modifiedTripId);
        final Trip trip = graph.index.tripForId.get(tripId);
        final TripPattern originalTripPattern = graph.index.patternForTrip.get(trip);
        final Timetable originalTimetableForToday = snapshot.resolve(originalTripPattern, serviceDate);
        final Timetable originalTimetableScheduled = snapshot.resolve(originalTripPattern, null);
        assertNotSame(originalTimetableForToday, originalTimetableScheduled);
        final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(modifiedTripId);
        assertTrue("Original trip should be found in scheduled time table", originalTripIndexScheduled > -1);
        final TripTimes originalTripTimesScheduled = originalTimetableScheduled.getTripTimes(originalTripIndexScheduled);
        assertFalse("Original trip times should not be canceled in scheduled time table", originalTripTimesScheduled.isCanceled());
        assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState());
        final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(modifiedTripId);
        assertTrue("Original trip should be found in time table for service date", originalTripIndexForToday > -1);
        final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes(originalTripIndexForToday);
        assertTrue("Original trip times should be canceled in time table for service date", originalTripTimesForToday.isCanceled());
        assertEquals(RealTimeState.CANCELED, originalTripTimesForToday.getRealTimeState());
    }
    // New trip pattern
    {
        final TripPattern newTripPattern = snapshot.getLastAddedTripPattern(feedId, modifiedTripId, serviceDate);
        assertNotNull("New trip pattern should be found", newTripPattern);
        final Timetable newTimetableForToday = snapshot.resolve(newTripPattern, serviceDate);
        final Timetable newTimetableScheduled = snapshot.resolve(newTripPattern, null);
        assertNotSame(newTimetableForToday, newTimetableScheduled);
        final int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex(modifiedTripId);
        assertTrue("New trip should be found in time table for service date", newTimetableForTodayModifiedTripIndex > -1);
        assertEquals(RealTimeState.MODIFIED, newTimetableForToday.getTripTimes(newTimetableForTodayModifiedTripIndex).getRealTimeState());
        assertEquals("New trip should not be found in scheduled time table", -1, newTimetableScheduled.getTripIndex(modifiedTripId));
    }
}
Also used : Timetable(org.opentripplanner.routing.edgetype.Timetable) TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) Calendar(java.util.Calendar) TimetableSnapshot(org.opentripplanner.routing.edgetype.TimetableSnapshot) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) Test(org.junit.Test)

Example 10 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class TimetableSnapshotSourceTest method testHandleCanceledTrip.

@Test
public void testHandleCanceledTrip() throws InvalidProtocolBufferException {
    final AgencyAndId tripId = new AgencyAndId(feedId, "1.1");
    final AgencyAndId tripId2 = new AgencyAndId(feedId, "1.2");
    final Trip trip = graph.index.tripForId.get(tripId);
    final TripPattern pattern = graph.index.patternForTrip.get(trip);
    final int tripIndex = pattern.scheduledTimetable.getTripIndex(tripId);
    final int tripIndex2 = pattern.scheduledTimetable.getTripIndex(tripId2);
    updater.applyTripUpdates(graph, fullDataset, Arrays.asList(TripUpdate.parseFrom(cancellation)), feedId);
    final TimetableSnapshot snapshot = updater.getTimetableSnapshot();
    final Timetable forToday = snapshot.resolve(pattern, serviceDate);
    final Timetable schedule = snapshot.resolve(pattern, null);
    assertNotSame(forToday, schedule);
    assertNotSame(forToday.getTripTimes(tripIndex), schedule.getTripTimes(tripIndex));
    assertSame(forToday.getTripTimes(tripIndex2), schedule.getTripTimes(tripIndex2));
    final TripTimes tripTimes = forToday.getTripTimes(tripIndex);
    for (int i = 0; i < tripTimes.getNumStops(); i++) {
        assertEquals(TripTimes.UNAVAILABLE, tripTimes.getDepartureTime(i));
        assertEquals(TripTimes.UNAVAILABLE, tripTimes.getArrivalTime(i));
    }
    assertEquals(RealTimeState.CANCELED, tripTimes.getRealTimeState());
}
Also used : Timetable(org.opentripplanner.routing.edgetype.Timetable) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) TimetableSnapshot(org.opentripplanner.routing.edgetype.TimetableSnapshot) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Test(org.junit.Test)

Aggregations

TripPattern (org.opentripplanner.routing.edgetype.TripPattern)53 Stop (org.onebusaway.gtfs.model.Stop)23 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)23 Trip (org.onebusaway.gtfs.model.Trip)20 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)19 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)19 Test (org.junit.Test)14 Route (org.onebusaway.gtfs.model.Route)14 Timetable (org.opentripplanner.routing.edgetype.Timetable)11 ArrayList (java.util.ArrayList)10 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Edge (org.opentripplanner.routing.graph.Edge)9 StopTime (org.onebusaway.gtfs.model.StopTime)8 StopPattern (org.opentripplanner.model.StopPattern)8 TimetableSnapshot (org.opentripplanner.routing.edgetype.TimetableSnapshot)8 Graph (org.opentripplanner.routing.graph.Graph)8 Agency (org.onebusaway.gtfs.model.Agency)7 ServiceDay (org.opentripplanner.routing.core.ServiceDay)7 FrequencyEntry (org.opentripplanner.routing.trippattern.FrequencyEntry)7