Search in sources :

Example 46 with Agency

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

the class CalendarServiceDataFactoryImplSyntheticTest method testBadTimezone.

@Test
public void testBadTimezone() throws IOException {
    CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
    Agency agencyA = agency("A", "America/SomewhereThatDoesNotExist");
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    factory.setGtfsDao(dao);
    saveEntities(dao, agencyA);
    try {
        factory.createData();
        fail("should detect that TimeZone ID is not valid");
    } catch (UnknownAgencyTimezoneException ex) {
    }
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Test(org.junit.Test)

Example 47 with Agency

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

the class CalendarServiceDataFactoryImplSyntheticTest method testDaylightSavingTime.

@Test
public void testDaylightSavingTime() {
    CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
    Agency agencyA = agency("A", "America/Los_Angeles");
    AgencyAndId serviceId = new AgencyAndId("A", "2");
    ServiceDate dStart = new ServiceDate(2012, 3, 1);
    ServiceDate dEnd = new ServiceDate(2012, 3, 31);
    ServiceCalendar c = calendar(serviceId, dStart, dEnd, "1111111");
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    factory.setGtfsDao(dao);
    saveEntities(dao, agencyA);
    saveEntities(dao, c);
    CalendarServiceData data = factory.createData();
    List<ServiceDate> serviceDates = data.getServiceDatesForServiceId(serviceId);
    assertTrue(serviceDates.contains(new ServiceDate(2012, 3, 11)));
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 48 with Agency

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

the class TranslationServiceImplTest method testTranslations.

@Test
public void testTranslations() throws IOException {
    String agencyId = "agency";
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    GtfsTestData.readGtfs(dao, GtfsTestData.getTestAgencyGtfs(), agencyId);
    TranslationServiceImpl ts = new TranslationServiceImpl();
    ts.setData(TranslationServiceDataFactoryImpl.createData(dao));
    Agency agency = dao.getAgencyForId(agencyId);
    assertEquals("Fake Agency Spanish", ts.getTranslatedEntity("es", Agency.class, agency).getName());
    assertEquals("Fake Agency French", ts.getTranslatedEntity("fr", Agency.class, agency).getName());
    Stop stop = dao.getStopForId(aid("A"));
    assertEquals("A Spanish", ts.getTranslatedEntity("es", Stop.class, stop).getName());
    assertEquals("A French", ts.getTranslatedEntity("fr", Stop.class, stop).getName());
    Route route = dao.getRouteForId(aid("3"));
    assertEquals("3 Spanish", ts.getTranslatedEntity("es", Route.class, route).getLongName());
    assertEquals("3 French", ts.getTranslatedEntity("fr", Route.class, route).getLongName());
    Trip trip3 = dao.getTripForId(aid("3.1"));
    assertEquals("headsign Spanish", ts.getTranslatedEntity("es", Trip.class, trip3).getTripHeadsign());
    assertEquals("headsign French", ts.getTranslatedEntity("fr", Trip.class, trip3).getTripHeadsign());
    Trip trip4 = dao.getTripForId(aid("4.3"));
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip4);
    StopTime st1 = stopTimes.get(0);
    StopTime st2 = stopTimes.get(1);
    assertEquals("to G Spanish", ts.getTranslatedEntity("es", StopTime.class, st1).getStopHeadsign());
    assertEquals("to H Spanish", ts.getTranslatedEntity("es", StopTime.class, st2).getStopHeadsign());
    assertEquals("to G French", ts.getTranslatedEntity("fr", StopTime.class, st1).getStopHeadsign());
    assertEquals("to H French", ts.getTranslatedEntity("fr", StopTime.class, st2).getStopHeadsign());
    FeedInfo feedInfo = dao.getAllFeedInfos().iterator().next();
    assertEquals("Fake Feed Publisher Spanish", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherName());
    assertEquals("http://fake.example.es", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherUrl());
    assertEquals("Fake Feed Publisher French", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherName());
    assertEquals("http://fake.example.fr", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherUrl());
    // Check default translations
    assertEquals("Fake Agency", ts.getTranslatedEntity("en", Agency.class, agency).getName());
    assertEquals("A", ts.getTranslatedEntity("en", Stop.class, stop).getName());
    assertEquals("3", ts.getTranslatedEntity("en", Route.class, route).getLongName());
    assertEquals("headsign", ts.getTranslatedEntity("en", Trip.class, trip3).getTripHeadsign());
    assertEquals("to G", ts.getTranslatedEntity("en", StopTime.class, st1).getStopHeadsign());
    assertEquals("to H", ts.getTranslatedEntity("en", StopTime.class, st2).getStopHeadsign());
    assertEquals("Fake Feed Publisher", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherName());
    assertEquals("http://fake.example.com", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherUrl());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) Stop(org.onebusaway.gtfs.model.Stop) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 49 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 50 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