Search in sources :

Example 1 with AgencyAndId

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

the class GtfsHibernateReaderExampleMain method main.

public static void main(String[] args) throws IOException {
    if (!(args.length == 1 || args.length == 2)) {
        System.err.println("usage: gtfsPath [hibernate-config.xml]");
        System.exit(-1);
    }
    String resource = "classpath:org/onebusaway/gtfs/examples/hibernate-configuration-examples.xml";
    if (args.length == 2)
        resource = args[1];
    HibernateGtfsFactory factory = createHibernateGtfsFactory(resource);
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File(args[0]));
    GtfsMutableRelationalDao dao = factory.getDao();
    reader.setEntityStore(dao);
    reader.run();
    Collection<Stop> stops = dao.getAllStops();
    for (Stop stop : stops) System.out.println(stop.getName());
    CalendarService calendarService = factory.getCalendarService();
    Set<AgencyAndId> serviceIds = calendarService.getServiceIds();
    for (AgencyAndId serviceId : serviceIds) {
        Set<ServiceDate> dates = calendarService.getServiceDatesForServiceId(serviceId);
        ServiceDate from = null;
        ServiceDate to = null;
        for (ServiceDate date : dates) {
            from = min(from, date);
            to = max(to, date);
        }
        System.out.println("serviceId=" + serviceId + " from=" + from + " to=" + to);
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) HibernateGtfsFactory(org.onebusaway.gtfs.services.HibernateGtfsFactory) File(java.io.File) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService)

Example 2 with AgencyAndId

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

the class HibernateGtfsRelationalDaoImplCaltrainTest method testGetStopById.

@Test
public void testGetStopById() {
    AgencyAndId id = aid("Gilroy Caltrain");
    Stop stop = _dao.getStopForId(id);
    assertEquals(id, stop.getId());
    assertNull(stop.getCode());
    assertEquals("7150 Monterey Street, Gilroy", stop.getDesc());
    assertEquals(37.003084, stop.getLat(), 0.000001);
    assertEquals(-121.567091, stop.getLon(), 0.000001);
    assertEquals(0, stop.getLocationType());
    assertEquals("Gilroy Caltrain", stop.getName());
    assertEquals("6", stop.getZoneId());
    assertNull(stop.getUrl());
    assertNull(stop.getParentStation());
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Test(org.junit.Test)

Example 3 with AgencyAndId

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

the class HibernateGtfsRelationalImplBartTest method testCalendarForServiceId.

@Test
public void testCalendarForServiceId() {
    ServiceCalendar calendar = _dao.getCalendarForServiceId(new AgencyAndId("BART", "WKDY"));
    assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 4 with AgencyAndId

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

the class HibernateGtfsRelationalImplBartTest method testCalendarDateForServiceId.

@Test
public void testCalendarDateForServiceId() {
    List<ServiceCalendarDate> calendarDates = _dao.getCalendarDatesForServiceId(new AgencyAndId("BART", "WKDY"));
    assertEquals(7, calendarDates.size());
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 5 with AgencyAndId

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

the class EntityRetentionGraph method retainTrip.

private void retainTrip(Trip trip, boolean retainUp) {
    if (retainUp) {
        for (StopTime stopTime : _dao.getStopTimesForTrip(trip)) retainUp(stopTime);
        if (_retainBlocks && trip.getBlockId() != null) {
            AgencyAndId blockId = new AgencyAndId(trip.getId().getAgencyId(), trip.getBlockId());
            retainUp(new BlockIdKey(blockId));
        }
        for (Frequency frequency : _dao.getFrequenciesForTrip(trip)) retainUp(frequency);
    } else {
        retainDown(trip.getRoute());
        retainDown(new ServiceIdKey(trip.getServiceId()));
        AgencyAndId shapeId = trip.getShapeId();
        if (shapeId != null && shapeId.hasValues())
            retainDown(new ShapeIdKey(shapeId));
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ShapeIdKey(org.onebusaway.gtfs_transformer.collections.ShapeIdKey) Frequency(org.onebusaway.gtfs.model.Frequency) ServiceIdKey(org.onebusaway.gtfs_transformer.collections.ServiceIdKey) StopTime(org.onebusaway.gtfs.model.StopTime)

Aggregations

AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)102 Test (org.junit.Test)63 Trip (org.onebusaway.gtfs.model.Trip)37 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)25 Stop (org.onebusaway.gtfs.model.Stop)24 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)17 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)16 ArrayList (java.util.ArrayList)15 Route (org.onebusaway.gtfs.model.Route)15 StopTime (org.onebusaway.gtfs.model.StopTime)15 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)15 Agency (org.onebusaway.gtfs.model.Agency)13 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)12 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)11 HashSet (java.util.HashSet)10 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)10 List (java.util.List)9 Frequency (org.onebusaway.gtfs.model.Frequency)9 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)7 Set (java.util.Set)6