Search in sources :

Example 6 with GtfsBundle

use of org.opentripplanner.graph_builder.model.GtfsBundle in project OpenTripPlanner by opentripplanner.

the class GtfsTest method setUp.

protected void setUp() {
    File gtfs = new File("src/test/resources/" + getFeedName());
    File gtfsRealTime = new File("src/test/resources/" + getFeedName() + ".pb");
    GtfsBundle gtfsBundle = new GtfsBundle(gtfs);
    feedId = new GtfsFeedId.Builder().id("FEED").build();
    gtfsBundle.setFeedId(feedId);
    List<GtfsBundle> gtfsBundleList = Collections.singletonList(gtfsBundle);
    GtfsModule gtfsGraphBuilderImpl = new GtfsModule(gtfsBundleList);
    alertsUpdateHandler = new AlertsUpdateHandler();
    graph = new Graph();
    router = new Router("TEST", graph);
    gtfsBundle.setTransfersTxtDefinesStationPaths(true);
    gtfsGraphBuilderImpl.buildGraph(graph, null);
    // Set the agency ID to be used for tests to the first one in the feed.
    agencyId = graph.getAgencies(feedId.getId()).iterator().next().getId();
    System.out.printf("Set the agency ID for this test to %s\n", agencyId);
    graph.index(new DefaultStreetVertexIndexFactory());
    timetableSnapshotSource = new TimetableSnapshotSource(graph);
    timetableSnapshotSource.purgeExpiredData = (false);
    graph.timetableSnapshotSource = (timetableSnapshotSource);
    alertPatchServiceImpl = new AlertPatchServiceImpl(graph);
    alertsUpdateHandler.setAlertPatchService(alertPatchServiceImpl);
    alertsUpdateHandler.setFeedId(feedId.getId());
    try {
        final boolean fullDataset = false;
        InputStream inputStream = new FileInputStream(gtfsRealTime);
        FeedMessage feedMessage = FeedMessage.PARSER.parseFrom(inputStream);
        List<FeedEntity> feedEntityList = feedMessage.getEntityList();
        List<TripUpdate> updates = new ArrayList<TripUpdate>(feedEntityList.size());
        for (FeedEntity feedEntity : feedEntityList) {
            updates.add(feedEntity.getTripUpdate());
        }
        timetableSnapshotSource.applyTripUpdates(graph, fullDataset, updates, feedId.getId());
        alertsUpdateHandler.update(feedMessage);
    } catch (Exception exception) {
    }
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Router(org.opentripplanner.standalone.Router) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) AlertPatchServiceImpl(org.opentripplanner.routing.impl.AlertPatchServiceImpl) FileInputStream(java.io.FileInputStream) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) GtfsModule(org.opentripplanner.graph_builder.module.GtfsModule) Graph(org.opentripplanner.routing.graph.Graph) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) File(java.io.File) TimetableSnapshotSource(org.opentripplanner.updater.stoptime.TimetableSnapshotSource) AlertsUpdateHandler(org.opentripplanner.updater.alerts.AlertsUpdateHandler)

Example 7 with GtfsBundle

use of org.opentripplanner.graph_builder.model.GtfsBundle in project OpenTripPlanner by opentripplanner.

the class FakeGraph method addTransit.

/**
 * Add transit (not just stops) to a Columbus graph
 */
public static void addTransit(Graph gg) throws Exception {
    // using conveyal GTFS lib to build GTFS so a lot of code does not have to be rewritten later
    // once we're using the conveyal GTFS lib for everything we ought to be able to do this
    // without even writing out the GTFS to a file.
    GTFSFeed feed = new GTFSFeed();
    Agency a = createDummyAgency("agency", "Agency", "America/New_York");
    feed.agency.put("agency", a);
    Route r = new Route();
    r.route_short_name = "1";
    r.route_long_name = "High Street";
    r.route_type = 3;
    r.agency = a;
    r.route_id = "route";
    feed.routes.put(r.route_id, r);
    Service s = createDummyService();
    feed.services.put(s.service_id, s);
    com.conveyal.gtfs.model.Stop s1 = new com.conveyal.gtfs.model.Stop();
    s1.stop_id = s1.stop_name = "s1";
    s1.stop_lat = 40.2182;
    s1.stop_lon = -83.0889;
    feed.stops.put(s1.stop_id, s1);
    com.conveyal.gtfs.model.Stop s2 = new com.conveyal.gtfs.model.Stop();
    s2.stop_id = s2.stop_name = "s2";
    s2.stop_lat = 39.9621;
    s2.stop_lon = -83.0007;
    feed.stops.put(s2.stop_id, s2);
    // make timetabled trips
    for (int departure = 7 * 3600; departure < 20 * 3600; departure += FREQUENCY) {
        Trip t = new Trip();
        t.trip_id = "trip" + departure;
        t.service = s;
        t.route = r;
        feed.trips.put(t.trip_id, t);
        StopTime st1 = new StopTime();
        st1.trip_id = t.trip_id;
        st1.arrival_time = departure;
        st1.departure_time = departure;
        st1.stop_id = s1.stop_id;
        st1.stop_sequence = 1;
        feed.stop_times.put(new Fun.Tuple2(st1.trip_id, st1.stop_sequence), st1);
        StopTime st2 = new StopTime();
        st2.trip_id = t.trip_id;
        st2.arrival_time = departure + TRAVEL_TIME;
        st2.departure_time = departure + TRAVEL_TIME;
        st2.stop_sequence = 2;
        st2.stop_id = s2.stop_id;
        feed.stop_times.put(new Fun.Tuple2(st2.trip_id, st2.stop_sequence), st2);
    }
    File tempFile = File.createTempFile("gtfs", ".zip");
    feed.toFile(tempFile.getAbsolutePath());
    // phew. load it into the graph.
    GtfsModule gtfs = new GtfsModule(Arrays.asList(new GtfsBundle(tempFile)));
    gtfs.buildGraph(gg, new HashMap<>());
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) com.conveyal.gtfs.model(com.conveyal.gtfs.model) GTFSFeed(com.conveyal.gtfs.GTFSFeed) File(java.io.File) Fun(org.mapdb.Fun)

Example 8 with GtfsBundle

use of org.opentripplanner.graph_builder.model.GtfsBundle in project OpenTripPlanner by opentripplanner.

the class FakeGraph method addMultiplePatterns.

/**
 * Add a transit line with multiple patterns to a Columbus graph. Most trips serve stops s1, s2, s3 but some serve only s1, s3
 */
public static void addMultiplePatterns(Graph gg) throws Exception {
    // using conveyal GTFS lib to build GTFS so a lot of code does not have to be rewritten later
    // once we're using the conveyal GTFS lib for everything we ought to be able to do this
    // without even writing out the GTFS to a file.
    GTFSFeed feed = new GTFSFeed();
    Agency a = createDummyAgency("agency", "Agency", "America/New_York");
    feed.agency.put("agency", a);
    Route r = new Route();
    r.route_short_name = "1";
    r.route_long_name = "High Street";
    r.route_type = 3;
    r.agency = a;
    r.route_id = "route";
    feed.routes.put(r.route_id, r);
    Service s = createDummyService();
    feed.services.put(s.service_id, s);
    com.conveyal.gtfs.model.Stop s1 = new com.conveyal.gtfs.model.Stop();
    s1.stop_id = s1.stop_name = "s1";
    s1.stop_lat = 40.2182;
    s1.stop_lon = -83.0889;
    feed.stops.put(s1.stop_id, s1);
    com.conveyal.gtfs.model.Stop s2 = new com.conveyal.gtfs.model.Stop();
    s2.stop_id = s2.stop_name = "s2";
    s2.stop_lat = 39.9621;
    s2.stop_lon = -83.0007;
    feed.stops.put(s2.stop_id, s2);
    com.conveyal.gtfs.model.Stop s3 = new com.conveyal.gtfs.model.Stop();
    s3.stop_id = s3.stop_name = "s3";
    s3.stop_lat = 39.9510;
    s3.stop_lon = -83.0007;
    feed.stops.put(s3.stop_id, s3);
    // make timetabled trips
    for (int departure = 7 * 3600, dcount = 0; departure < 20 * 3600; departure += FREQUENCY) {
        Trip t = new Trip();
        t.trip_id = "trip" + departure;
        t.service = s;
        t.route = r;
        feed.trips.put(t.trip_id, t);
        StopTime st1 = new StopTime();
        st1.trip_id = t.trip_id;
        st1.arrival_time = departure;
        st1.departure_time = departure;
        st1.stop_id = s1.stop_id;
        st1.stop_sequence = 1;
        feed.stop_times.put(new Fun.Tuple2(st1.trip_id, st1.stop_sequence), st1);
        // occasionally skip second stop
        boolean secondStop = dcount++ % 10 != 0;
        if (secondStop) {
            StopTime st2 = new StopTime();
            st2.trip_id = t.trip_id;
            st2.arrival_time = departure + TRAVEL_TIME;
            st2.departure_time = departure + TRAVEL_TIME;
            st2.stop_sequence = 2;
            st2.stop_id = s2.stop_id;
            feed.stop_times.put(new Fun.Tuple2(st2.trip_id, st2.stop_sequence), st2);
        }
        StopTime st3 = new StopTime();
        st3.trip_id = t.trip_id;
        st3.arrival_time = departure + (secondStop ? 2 : 1) * TRAVEL_TIME;
        st3.departure_time = departure + (secondStop ? 2 : 1) * TRAVEL_TIME;
        st3.stop_sequence = 3;
        st3.stop_id = s3.stop_id;
        feed.stop_times.put(new Fun.Tuple2(st3.trip_id, st3.stop_sequence), st3);
    }
    File tempFile = File.createTempFile("gtfs", ".zip");
    feed.toFile(tempFile.getAbsolutePath());
    // phew. load it into the graph.
    GtfsModule gtfs = new GtfsModule(Arrays.asList(new GtfsBundle(tempFile)));
    gtfs.buildGraph(gg, new HashMap<>());
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) com.conveyal.gtfs.model(com.conveyal.gtfs.model) GTFSFeed(com.conveyal.gtfs.GTFSFeed) File(java.io.File) Fun(org.mapdb.Fun)

Example 9 with GtfsBundle

use of org.opentripplanner.graph_builder.model.GtfsBundle in project OpenTripPlanner by opentripplanner.

the class FakeGraph method addTransitMultipleLines.

/**
 * Add many transit lines to a lot of stops
 */
public static void addTransitMultipleLines(Graph g) throws Exception {
    // using conveyal GTFS lib to build GTFS so a lot of code does not have to be rewritten later
    // once we're using the conveyal GTFS lib for everything we ought to be able to do this
    // without even writing out the GTFS to a file.
    GTFSFeed feed = new GTFSFeed();
    Agency a = createDummyAgency("agency", "Agency", "America/New_York");
    feed.agency.put("agency", a);
    Route r = new Route();
    r.route_short_name = "1";
    r.route_long_name = "High Street";
    r.route_type = 3;
    r.agency = a;
    r.route_id = "route";
    feed.routes.put(r.route_id, r);
    Service s = createDummyService();
    feed.services.put(s.service_id, s);
    int stopIdx = 0;
    while (stopIdx < 10000) {
        com.conveyal.gtfs.model.Stop s1 = new com.conveyal.gtfs.model.Stop();
        s1.stop_id = s1.stop_name = "s" + stopIdx++;
        s1.stop_lat = 39.9354 + (stopIdx % 100) * 1e-3;
        s1.stop_lon = -83.0589 + (stopIdx / 100) * 1e-3;
        feed.stops.put(s1.stop_id, s1);
        com.conveyal.gtfs.model.Stop s2 = new com.conveyal.gtfs.model.Stop();
        s2.stop_id = s2.stop_name = "s" + stopIdx++;
        s2.stop_lat = 39.9354 + (stopIdx % 100) * 1e-3;
        s2.stop_lon = -83.0589 + (stopIdx / 100) * 1e-3;
        feed.stops.put(s2.stop_id, s2);
        // make timetabled trips
        int departure = 8 * 3600;
        Trip t = new Trip();
        t.trip_id = "trip" + departure + "_" + stopIdx;
        t.service = s;
        t.route = r;
        feed.trips.put(t.trip_id, t);
        StopTime st1 = new StopTime();
        st1.trip_id = t.trip_id;
        st1.arrival_time = departure;
        st1.departure_time = departure;
        st1.stop_id = s1.stop_id;
        st1.stop_sequence = 1;
        feed.stop_times.put(new Fun.Tuple2(st1.trip_id, st1.stop_sequence), st1);
        StopTime st2 = new StopTime();
        st2.trip_id = t.trip_id;
        st2.arrival_time = departure + 500;
        st2.departure_time = departure + 500;
        st2.stop_sequence = 2;
        st2.stop_id = s2.stop_id;
        feed.stop_times.put(new Fun.Tuple2(st2.trip_id, st2.stop_sequence), st2);
    }
    File tempFile = File.createTempFile("gtfs", ".zip");
    feed.toFile(tempFile.getAbsolutePath());
    // phew. load it into the graph.
    GtfsModule gtfs = new GtfsModule(Arrays.asList(new GtfsBundle(tempFile)));
    gtfs.buildGraph(g, new HashMap<>());
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) com.conveyal.gtfs.model(com.conveyal.gtfs.model) GTFSFeed(com.conveyal.gtfs.GTFSFeed) File(java.io.File) Fun(org.mapdb.Fun)

Example 10 with GtfsBundle

use of org.opentripplanner.graph_builder.model.GtfsBundle in project OpenTripPlanner by opentripplanner.

the class GtfsGraphBuilderModuleTest method testNoBikesByDefault.

@Test
public void testNoBikesByDefault() throws IOException {
    // We configure two trip: one with unknown bikes_allowed and the second with bikes
    // allowed.
    MockGtfs gtfs = getSimpleGtfs();
    gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,1");
    gtfs.putStopTimes("t0,t1", "s0,s1");
    List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
    bundleList.get(0).setDefaultBikesAllowed(false);
    _builder = new GtfsModule(bundleList);
    Graph graph = new Graph();
    _builder.buildGraph(graph, _extra);
    graph.index(new DefaultStreetVertexIndexFactory());
    // Feed id is used instead of the agency id for OBA entities.
    GtfsBundle gtfsBundle = bundleList.get(0);
    GtfsFeedId feedId = gtfsBundle.getFeedId();
    Trip trip = graph.index.tripForId.get(new AgencyAndId(feedId.getId(), "t0"));
    TripPattern pattern = graph.index.patternForTrip.get(trip);
    List<Trip> trips = pattern.getTrips();
    assertEquals(BikeAccess.UNKNOWN, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t0"))));
    assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t1"))));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Test(org.junit.Test)

Aggregations

GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)11 File (java.io.File)7 GTFSFeed (com.conveyal.gtfs.GTFSFeed)5 com.conveyal.gtfs.model (com.conveyal.gtfs.model)5 Fun (org.mapdb.Fun)5 Stop (org.onebusaway.gtfs.model.Stop)5 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)5 Graph (org.opentripplanner.routing.graph.Graph)3 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)3 Test (org.junit.Test)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 Trip (org.onebusaway.gtfs.model.Trip)2 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)2 GtfsModule (org.opentripplanner.graph_builder.module.GtfsModule)2 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)1 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1 FileInputStream (java.io.FileInputStream)1