Search in sources :

Example 36 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class GtfsGraphBuilderModuleTest method testBikesByDefault.

@Test
public void testBikesByDefault() throws IOException {
    // We configure two trip: one with unknown bikes_allowed and the second with no bikes
    // allowed.
    MockGtfs gtfs = getSimpleGtfs();
    gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,2");
    gtfs.putStopTimes("t0,t1", "s0,s1");
    List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
    bundleList.get(0).setDefaultBikesAllowed(true);
    _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.ALLOWED, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t0"))));
    assertEquals(BikeAccess.NOT_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)

Example 37 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class TestSpecificTransfer method testSpecificTransfer.

/**
 * Test different specific transfers
 */
public void testSpecificTransfer() {
    // Setup from trip with route
    Route fromRoute = new Route();
    fromRoute.setId(new AgencyAndId("A1", "R1"));
    Trip fromTrip = new Trip();
    fromTrip.setId(new AgencyAndId("A1", "T1"));
    fromTrip.setRoute(fromRoute);
    // Setup to trip with route
    Route toRoute = new Route();
    toRoute.setId(new AgencyAndId("A1", "R2"));
    Trip toTrip = new Trip();
    toTrip.setId(new AgencyAndId("A1", "T2"));
    toTrip.setRoute(toRoute);
    // Create full SpecificTransfer
    SpecificTransfer s1 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), fromTrip.getId(), toTrip.getId(), 1);
    assertTrue(s1.matches(fromTrip, toTrip));
    assertTrue(s1.getSpecificity() == SpecificTransfer.MAX_SPECIFICITY);
    assertTrue(s1.transferTime == 1);
    // Create empty SpecificTransfer
    SpecificTransfer s2 = new SpecificTransfer((AgencyAndId) null, null, null, null, 2);
    assertTrue(s2.matches(fromTrip, toTrip));
    assertTrue(s2.getSpecificity() == SpecificTransfer.MIN_SPECIFICITY);
    assertTrue(s2.transferTime == 2);
    // Create SpecificTransfer one trip missing
    SpecificTransfer s3 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), null, toTrip.getId(), 3);
    assertTrue(s3.matches(fromTrip, toTrip));
    assertTrue(s3.getSpecificity() == 3);
    assertTrue(s3.transferTime == 3);
    // Create SpecificTransfer one trip different
    SpecificTransfer s4 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), new AgencyAndId("A1", "T3"), toTrip.getId(), 4);
    assertFalse(s4.matches(fromTrip, toTrip));
    assertTrue(s4.getSpecificity() == SpecificTransfer.MAX_SPECIFICITY);
    assertTrue(s4.transferTime == 4);
    // Create SpecificTransfer one trip and route missing
    SpecificTransfer s5 = new SpecificTransfer(null, toRoute.getId(), null, toTrip.getId(), 5);
    assertTrue(s5.matches(fromTrip, toTrip));
    assertTrue(s5.getSpecificity() == 2);
    assertTrue(s5.transferTime == 5);
    // Create SpecificTransfer one trip only
    SpecificTransfer s6 = new SpecificTransfer(null, null, null, toTrip.getId(), 6);
    assertTrue(s6.matches(fromTrip, toTrip));
    assertTrue(s6.getSpecificity() == 2);
    assertTrue(s6.transferTime == 6);
    // Create SpecificTransfer one route only
    SpecificTransfer s7 = new SpecificTransfer(fromRoute.getId(), null, null, null, 7);
    assertTrue(s7.matches(fromTrip, toTrip));
    assertTrue(s7.getSpecificity() == 1);
    assertTrue(s7.transferTime == 7);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route)

Example 38 with Trip

use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.

the class HibernateGtfsRelationalDaoImplCaltrainTest method testGetStopTimesByTrip.

@Test
public void testGetStopTimesByTrip() {
    Trip trip = _dao.getTripForId(aid("10101272009"));
    List<StopTime> stopTimes = _dao.getStopTimesForTrip(trip);
    assertEquals(22, stopTimes.size());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 39 with Trip

use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.

the class TrimTripTransformStrategyTest method testStopTimeTrimming.

@Test
public void testStopTimeTrimming() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(6);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimes("t0", "s0,s1,s2,s3,s4,s5");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new AlwaysMatch()));
    operation.setToStopId("s1");
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    Collection<Trip> allTrips = dao.getAllTrips();
    assertEquals(1, allTrips.size());
    Trip trip = allTrips.iterator().next();
    assertEquals(new AgencyAndId("a0", "t0-s1-s4"), trip.getId());
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(2, stopTimes.size());
    assertEquals("s2", stopTimes.get(0).getStop().getId().getId());
    assertEquals("s3", stopTimes.get(1).getStop().getId().getId());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) AlwaysMatch(org.onebusaway.gtfs_transformer.match.AlwaysMatch) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 40 with Trip

use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.

the class TrimTripTransformStrategyTest method testShapeTrimming.

@Test
public void testShapeTrimming() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putLines("stops.txt", "stop_id,stop_name,stop_lat,stop_lon", "s0,S0,47.668422,-122.290149", "s1,S1,47.670300,-122.290235", "s2,S2,47.672172,-122.290213", "s3,S3,47.673985,-122.290277", "s4,S4,47.675791,-122.290213", "s5,S5,47.677626,-122.290320");
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0", "shape_id=shape0");
    _gtfs.putStopTimes("t0", "s0,s1,s2,s3,s4,s5");
    _gtfs.putLines("shapes.txt", "shape_id,shape_pt_sequence,shape_pt_lat,shape_pt_lon", "shape0,0,47.668422,-122.290149", "shape0,1,47.670300,-122.290235", "shape0,2,47.672172,-122.290213", "shape0,3,47.673985,-122.290277", "shape0,4,47.675791,-122.290213", "shape0,5,47.677626,-122.290320");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new AlwaysMatch()));
    operation.setToStopId("s0");
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    Trip trip = dao.getTripForId(new AgencyAndId("a0", "t0-s0-s4"));
    assertEquals(new AgencyAndId("a0", "shape0-s1-s3"), trip.getShapeId());
    List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(trip.getShapeId());
    assertEquals(3, shapePoints.size());
    assertEquals(47.670300, shapePoints.get(0).getLat(), 1e-6);
    assertEquals(47.673985, shapePoints.get(2).getLat(), 1e-6);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) AlwaysMatch(org.onebusaway.gtfs_transformer.match.AlwaysMatch) Test(org.junit.Test)

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10