Search in sources :

Example 31 with Agency

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

the class RoutingRequestTest method testPreferencesPenaltyForRoute.

@Test
public void testPreferencesPenaltyForRoute() {
    AgencyAndId agencyAndId = new AgencyAndId();
    Agency agency = new Agency();
    Route route = new Route();
    Trip trip = new Trip();
    RoutingRequest routingRequest = new RoutingRequest();
    trip.setRoute(route);
    route.setId(agencyAndId);
    route.setAgency(agency);
    assertEquals(0, routingRequest.preferencesPenaltyForRoute(trip.getRoute()));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 32 with Agency

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

the class RoutingContextTest method testSetServiceDays.

@Test
public void testSetServiceDays() throws Exception {
    String feedId = "FEED";
    String agencyId = "AGENCY";
    Agency agency = new Agency();
    agency.setId(agencyId);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    CalendarService calendarService = mock(CalendarService.class);
    // You're probably not supposed to do this to mocks (access their fields directly)
    // But I know of no other way to do this since the mock object has only action-free stub methods.
    routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
    when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("Europe/Budapest"));
    when(graph.getCalendarService()).thenReturn(calendarService);
    when(graph.getFeedIds()).thenReturn(Collections.singletonList("FEED"));
    when(graph.getAgencies(feedId)).thenReturn(Collections.singletonList(agency));
    when(calendarService.getTimeZoneForAgencyId(agencyId)).thenReturn(TimeZone.getTimeZone("Europe/Budapest"));
    when(routingRequest.getSecondsSinceEpoch()).thenReturn(1393750800L, 1396126800L, /* 2014-03-29T22:00:00+01:00 */
    1396132200L, /* 2014-03-29T23:30:00+01:00 */
    1396135800L, 1401696000L, 1414272600L, /* 2014-10-25T23:30:00+02:00 */
    1414276200L, /* 2014-10-26T00:30:00+02:00 */
    1414279800L);
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 3, 1), new ServiceDate(2014, 3, 2), new ServiceDate(2014, 3, 3));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 3, 28), new ServiceDate(2014, 3, 29), new ServiceDate(2014, 3, 30));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 3, 28), new ServiceDate(2014, 3, 29), new ServiceDate(2014, 3, 30));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 3, 29), new ServiceDate(2014, 3, 30), new ServiceDate(2014, 3, 31));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 6, 1), new ServiceDate(2014, 6, 2), new ServiceDate(2014, 6, 3));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 24), new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26), new ServiceDate(2014, 10, 27));
    verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26), new ServiceDate(2014, 10, 27));
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Agency(org.onebusaway.gtfs.model.Agency) Graph(org.opentripplanner.routing.graph.Graph) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) Test(org.junit.Test)

Example 33 with Agency

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

the class OnBoardDepartServiceImplTest method testOnBoardDepartureTime.

@Test
public final void testOnBoardDepartureTime() {
    Coordinate[] coordinates = new Coordinate[5];
    coordinates[0] = new Coordinate(0.0, 0.0);
    coordinates[1] = new Coordinate(0.0, 1.0);
    coordinates[2] = new Coordinate(2.0, 1.0);
    coordinates[3] = new Coordinate(5.0, 1.0);
    coordinates[4] = new Coordinate(5.0, 5.0);
    PatternDepartVertex depart = mock(PatternDepartVertex.class);
    PatternArriveVertex dwell = mock(PatternArriveVertex.class);
    PatternArriveVertex arrive = mock(PatternArriveVertex.class);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    ServiceDay serviceDay = mock(ServiceDay.class);
    // You're probably not supposed to do this to mocks (access their fields directly)
    // But I know of no other way to do this since the mock object has only action-free stub methods.
    routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
    when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    CoordinateSequenceFactory coordinateSequenceFactory = geometryFactory.getCoordinateSequenceFactory();
    CoordinateSequence coordinateSequence = coordinateSequenceFactory.create(coordinates);
    LineString geometry = new LineString(coordinateSequence, geometryFactory);
    ArrayList<Edge> hops = new ArrayList<Edge>(2);
    RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
    AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
    Agency agency = new Agency();
    Route route = new Route();
    ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(3);
    StopTime stopDepartTime = new StopTime();
    StopTime stopDwellTime = new StopTime();
    StopTime stopArriveTime = new StopTime();
    Stop stopDepart = new Stop();
    Stop stopDwell = new Stop();
    Stop stopArrive = new Stop();
    Trip trip = new Trip();
    routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
    agency.setId(agencyAndId.getAgencyId());
    route.setId(agencyAndId);
    route.setAgency(agency);
    stopDepart.setId(agencyAndId);
    stopDwell.setId(agencyAndId);
    stopArrive.setId(agencyAndId);
    stopDepartTime.setStop(stopDepart);
    stopDepartTime.setDepartureTime(0);
    stopDwellTime.setArrivalTime(20);
    stopDwellTime.setStop(stopDwell);
    stopDwellTime.setDepartureTime(40);
    stopArriveTime.setArrivalTime(60);
    stopArriveTime.setStop(stopArrive);
    stopTimes.add(stopDepartTime);
    stopTimes.add(stopDwellTime);
    stopTimes.add(stopArriveTime);
    trip.setId(agencyAndId);
    trip.setTripHeadsign("The right");
    trip.setRoute(route);
    TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    StopPattern stopPattern = new StopPattern(stopTimes);
    TripPattern tripPattern = new TripPattern(route, stopPattern);
    TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
    when(depart.getTripPattern()).thenReturn(tripPattern);
    when(dwell.getTripPattern()).thenReturn(tripPattern);
    PatternHop patternHop0 = new PatternHop(depart, dwell, stopDepart, stopDwell, 0);
    PatternHop patternHop1 = new PatternHop(dwell, arrive, stopDwell, stopArrive, 1);
    hops.add(patternHop0);
    hops.add(patternHop1);
    when(graph.getEdges()).thenReturn(hops);
    when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(dwell.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
    routingRequest.from = new GenericLocation();
    routingRequest.startingTransitTripId = agencyAndId;
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(9);
    patternHop0.setGeometry(geometry);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    coordinates = new Coordinate[3];
    coordinates[0] = new Coordinate(3.5, 1.0);
    coordinates[1] = new Coordinate(5.0, 1.0);
    coordinates[2] = new Coordinate(5.0, 5.0);
    coordinateSequence = coordinateSequenceFactory.create(coordinates);
    geometry = new LineString(coordinateSequence, geometryFactory);
    Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
    Edge edge = vertex.getOutgoing().toArray(new Edge[1])[0];
    assertEquals(vertex, edge.getFromVertex());
    assertEquals(dwell, edge.getToVertex());
    assertEquals("The right", edge.getDirection());
    assertEquals(geometry, edge.getGeometry());
    assertEquals(coordinates[0].x, vertex.getX(), 0.0);
    assertEquals(coordinates[0].y, vertex.getY(), 0.0);
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Vertex(org.opentripplanner.routing.graph.Vertex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ServiceDay(org.opentripplanner.routing.core.ServiceDay) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) RoutingContext(org.opentripplanner.routing.core.RoutingContext) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) StopPattern(org.opentripplanner.model.StopPattern) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Graph(org.opentripplanner.routing.graph.Graph) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) CoordinateSequenceFactory(com.vividsolutions.jts.geom.CoordinateSequenceFactory) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 34 with Agency

use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.

the class GtfsMultiReaderImpl method run.

@Override
public void run() {
    if (_readers.isEmpty())
        return;
    if (_entityLogger != null) {
        _entityReplacementStrategy.setEntityReplacementLogger(_entityLogger);
        _entityLogger.setStore(_store);
        _entityLogger.setRejectionStore(_rejectionStore);
    }
    try {
        StoreImpl store = new StoreImpl(_store);
        for (GtfsReader reader : _readers) {
            reader.setEntityStore(store);
            reader.addEntityHandler(new EntityCounter());
        }
        store.open();
        List<Agency> agencies = new ArrayList<Agency>();
        List<Class<?>> entityClasses = _readers.get(0).getEntityClasses();
        for (Class<?> entityClass : entityClasses) {
            _log.info("reading entities: " + entityClass.getName());
            for (GtfsReader reader : _readers) {
                // multiple feeds
                if (entityClass.equals(Agency.class))
                    reader.setAgencies(agencies);
                reader.readEntities(entityClass);
                if (entityClass.equals(Agency.class))
                    agencies = new ArrayList<Agency>(reader.getAgencies());
                store.flush();
            }
        }
        store.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) Agency(org.onebusaway.gtfs.model.Agency) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 35 with Agency

use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.

the class GtfsStatisticsTask method run.

public void run() {
    File basePath = _bundle.getPath();
    _log.info("Starting GTFS stats to basePath=" + basePath);
    GtfsStatisticsService service = new GtfsStatisticsService(_dao);
    // create logger file
    GtfsCsvLogger csvLogger = new GtfsCsvLogger();
    csvLogger.setBasePath(basePath);
    csvLogger.open();
    csvLogger.header();
    // per agency status
    Collection<Agency> agencies = service.getAllAgencies();
    for (Agency agency : agencies) {
        _log.info("processing stats for agency: " + agency.getId() + " (" + agency.getName() + ")");
        csvLogger.logStat(agency.getId(), service.getStatistic(agency.getId()));
    }
    // overall stats/totals
    Statistic all = new Statistic();
    Agency allAgency = new Agency();
    allAgency.setId(ALL_AGENCIES);
    all.setAgencyId(ALL_AGENCIES);
    all.setRouteCount(service.getRouteCount());
    all.setTripCount(service.getTripCount());
    all.setStopCount(service.getStopCount());
    all.setStopTimeCount(service.getStopTimesCount());
    all.setCalendarStartDate(service.getCalendarServiceRangeStart());
    all.setCalendarEndDate(service.getCalendarServiceRangeEnd());
    csvLogger.logStat(allAgency.getId(), all);
    _log.info("cleaning up");
    // cleanup
    csvLogger.close();
    _log.info("exiting");
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) Statistic(com.conveyal.gtfs.model.Statistic) GtfsStatisticsService(com.conveyal.gtfs.service.impl.GtfsStatisticsService) File(java.io.File)

Aggregations

Agency (org.onebusaway.gtfs.model.Agency)57 Test (org.junit.Test)28 Route (org.onebusaway.gtfs.model.Route)21 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 Trip (org.onebusaway.gtfs.model.Trip)19 Stop (org.onebusaway.gtfs.model.Stop)18 StopTime (org.onebusaway.gtfs.model.StopTime)15 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)10 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)9 ArrayList (java.util.ArrayList)8 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)7 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)7 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)6 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)5 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)5 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)5 StopPattern (org.opentripplanner.model.StopPattern)5 Graph (org.opentripplanner.routing.graph.Graph)5