Search in sources :

Example 56 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class StopTimeEntriesFactoryTest method test.

@Test
public void test() {
    TransitGraphImpl graph = new TransitGraphImpl();
    Stop stopA = new Stop();
    stopA.setId(aid("stopA"));
    graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
    Stop stopB = new Stop();
    stopB.setId(aid("stopB"));
    graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
    Stop stopC = new Stop();
    stopC.setId(aid("stopC"));
    graph.putStopEntry(stop("stopC", 47.66847942216854, -122.37545336180114));
    graph.refreshStopMapping();
    Agency agency = new Agency();
    agency.setId("1");
    agency.setTimezone("America/Los_Angeles");
    Route route = new Route();
    route.setAgency(agency);
    Trip trip = new Trip();
    trip.setRoute(route);
    trip.setServiceId(aid("serviceId"));
    TripEntryImpl tripEntry = trip("trip");
    StopTime stA = new StopTime();
    stA.setId(100);
    stA.setArrivalTime(time(9, 00));
    stA.setDepartureTime(time(9, 05));
    stA.setStopSequence(100);
    stA.setStop(stopA);
    stA.setTrip(trip);
    StopTime stB = new StopTime();
    stB.setId(101);
    stB.setStopSequence(101);
    stB.setStop(stopB);
    stB.setTrip(trip);
    StopTime stC = new StopTime();
    stC.setId(102);
    stC.setArrivalTime(time(10, 00));
    stC.setDepartureTime(time(10, 05));
    stC.setStopSequence(102);
    stC.setStop(stopC);
    stC.setTrip(trip);
    StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
    factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    List<StopTime> stopTimes = Arrays.asList(stA, stB, stC);
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
    shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
    shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
    ShapePoints shapePoints = shapePointsFactory.create();
    List<StopTimeEntryImpl> entries = factory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
    assertEquals(stopTimes.size(), entries.size());
    StopTimeEntryImpl entry = entries.get(0);
    assertEquals(0, entry.getAccumulatedSlackTime());
    assertEquals(time(9, 00), entry.getArrivalTime());
    assertEquals(time(9, 05), entry.getDepartureTime());
    assertEquals(0, entry.getSequence());
    assertEquals(181.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(5 * 60, entry.getSlackTime());
    entry = entries.get(1);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(9, 28, 31), entry.getArrivalTime());
    assertEquals(time(9, 28, 31), entry.getDepartureTime());
    assertEquals(1, entry.getSequence());
    assertEquals(738.7, entry.getShapeDistTraveled(), 0.1);
    assertEquals(0, entry.getSlackTime());
    entry = entries.get(2);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(10, 00), entry.getArrivalTime());
    assertEquals(time(10, 05), entry.getDepartureTime());
    assertEquals(2, entry.getSequence());
    assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(5 * 60, entry.getSlackTime());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntriesFactory(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopTimeEntriesFactory) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) DistanceAlongShapeLibrary(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 57 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class TripEntriesFactory method processTrips.

public void processTrips(TransitGraphImpl graph) {
    Collection<Route> routes = _gtfsDao.getAllRoutes();
    int routeIndex = 0;
    for (Route route : routes) {
        _log.info("route processed: " + routeIndex + "/" + routes.size());
        routeIndex++;
        List<Trip> tripsForRoute = _gtfsDao.getTripsForRoute(route);
        int tripCount = tripsForRoute.size();
        int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(tripCount);
        _log.info("trips to process: " + tripCount);
        int tripIndex = 0;
        RouteEntryImpl routeEntry = graph.getRouteForId(route.getId());
        ArrayList<TripEntry> tripEntries = new ArrayList<TripEntry>();
        for (Trip trip : tripsForRoute) {
            tripIndex++;
            if (tripIndex % logInterval == 0)
                _log.info("trips processed: " + tripIndex + "/" + tripsForRoute.size());
            TripEntryImpl tripEntry = processTrip(graph, trip);
            if (tripEntry != null) {
                tripEntry.setRoute(routeEntry);
                tripEntries.add(tripEntry);
            }
        }
        tripEntries.trimToSize();
        routeEntry.setTrips(tripEntries);
    }
    if (_stopTimeEntriesFactory.getInvalidStopToShapeMappingExceptionCount() > 0 && _throwExceptionOnInvalidStopToShapeMappingException) {
        throw new IllegalStateException("Multiple instances of InvalidStopToShapeMappingException thrown: count=" + _stopTimeEntriesFactory.getInvalidStopToShapeMappingExceptionCount() + ".  For more information on errors of this kind, see:\n" + "  https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
    }
    graph.refreshTripMapping();
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) ArrayList(java.util.ArrayList) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) Route(org.onebusaway.gtfs.model.Route) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)

Example 58 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class DistanceAlongShapeMain method readStopTimes.

private List<StopTimeEntryImpl> readStopTimes(String path) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(path));
    String line = null;
    Map<String, StopEntryImpl> stops = new HashMap<String, StopEntryImpl>();
    int index = 0;
    TripEntryImpl trip = UnitTestingSupport.trip("trip");
    List<StopTimeEntryImpl> stopTimes = new ArrayList<StopTimeEntryImpl>();
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(" ");
        String stopId = tokens[0];
        double lat = Double.parseDouble(tokens[1]);
        double lon = Double.parseDouble(tokens[2]);
        StopEntryImpl stop = stops.get(stopId);
        if (stop == null) {
            stop = UnitTestingSupport.stop(stopId, lat, lon);
            stops.put(stopId, stop);
        }
        StopTimeEntryImpl stopTime = UnitTestingSupport.stopTime(index, stop, trip, index, index, Double.NaN);
        stopTimes.add(stopTime);
    }
    reader.close();
    return stopTimes;
}
Also used : HashMap(java.util.HashMap) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) ArrayList(java.util.ArrayList) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)58 Test (org.junit.Test)43 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)29 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)22 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)20 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)14 Trip (org.onebusaway.gtfs.model.Trip)10 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)10 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)10 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 ArrayList (java.util.ArrayList)9 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)8 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)7 Route (org.onebusaway.gtfs.model.Route)6 Stop (org.onebusaway.gtfs.model.Stop)6 StopTime (org.onebusaway.gtfs.model.StopTime)6