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) {
}
}
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<>());
}
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<>());
}
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<>());
}
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"))));
}
Aggregations