Search in sources :

Example 36 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarExtensionStrategyTest method testCalendarDateExtension.

@Test
public void testCalendarDateExtension() throws IOException {
    _gtfs.putCalendarDates("sid0=20121217,20121218,20121219,20121220,20121221," + "20121224,20121225,20121226,20121227,20121228", "sid1=20121222,20121223,20121229,20121230");
    GtfsMutableRelationalDao dao = _gtfs.read();
    ServiceDate endDate = new ServiceDate(2013, 01, 06);
    _strategy.setEndDate(endDate);
    _strategy.run(_context, dao);
    CalendarService service = CalendarServiceDataFactoryImpl.createService(dao);
    {
        Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid0"));
        assertEquals(15, dates.size());
        assertTrue(dates.contains(new ServiceDate(2012, 12, 31)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 01)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 02)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 03)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 04)));
    }
    {
        Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid1"));
        assertEquals(6, dates.size());
        assertTrue(dates.contains(new ServiceDate(2013, 01, 05)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 06)));
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Set(java.util.Set) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) Test(org.junit.Test)

Example 37 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarExtensionStrategyTest method testCalendarExtension.

@Test
public void testCalendarExtension() throws IOException {
    _gtfs.putCalendars(2, "start_date=20120630,20120731", "end_date=20121224,20121231", "mask=1111100,0000011");
    GtfsMutableRelationalDao dao = _gtfs.read();
    ServiceDate endDate = new ServiceDate(2013, 12, 31);
    _strategy.setEndDate(endDate);
    _strategy.run(_context, dao);
    {
        ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid0"));
        assertEquals(endDate, calendar.getEndDate());
    }
    {
        ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1"));
        assertEquals(endDate, calendar.getEndDate());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 38 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class InterpolateStopTimesFromTimePointsStrategyTest method runFirstStopNonTimepoint.

@Test
public /**
 * ensure we handle first stop on trip not a timepoint.
 */
void runFirstStopNonTimepoint() throws Exception {
    _gtfs.putAgencies(1);
    _gtfs.putStops(7);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimesWithDistances("t0", "51609,42319,5247,5249,56096,16117", "0,340.1,2242.3,3166,8591.6,15005.6", "0,1,0,1,1,0");
    GtfsMutableRelationalDao dao = _gtfs.read();
    _strategy.run(_context, dao);
    Collection<Trip> allTrips = dao.getAllTrips();
    assertEquals(1, allTrips.size());
    Trip trip = allTrips.iterator().next();
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(6, stopTimes.size());
    assertEquals(0, stopTimes.get(0).getTimepoint());
    assertTrue(stopTimes.get(0).isArrivalTimeSet());
    assertTrue(stopTimes.get(0).isShapeDistTraveledSet());
    assertEquals(0, stopTimes.get(0).getShapeDistTraveled(), 0.001);
    assertEquals(time(9, 5), stopTimes.get(0).getArrivalTime());
    assertEquals(1, stopTimes.get(1).getTimepoint());
    assertTrue(stopTimes.get(1).isArrivalTimeSet());
    assertEquals(time(9, 5), stopTimes.get(1).getArrivalTime());
    assertEquals(0, stopTimes.get(2).getTimepoint());
    assertTrue(stopTimes.get(2).isArrivalTimeSet());
    assertEquals(time(9, 11, 43), stopTimes.get(2).getArrivalTime());
    assertEquals(1, stopTimes.get(3).getTimepoint());
    assertTrue(stopTimes.get(3).isArrivalTimeSet());
    assertEquals(time(9, 15), stopTimes.get(3).getArrivalTime());
    assertEquals(1, stopTimes.get(4).getTimepoint());
    assertTrue(stopTimes.get(4).isArrivalTimeSet());
    assertEquals(time(9, 20), stopTimes.get(4).getArrivalTime());
    assertEquals(0, stopTimes.get(5).getTimepoint());
    assertTrue(stopTimes.get(5).isArrivalTimeSet());
    assertEquals(time(9, 25), stopTimes.get(5).getArrivalTime());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 39 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class RemoveNonRevenueStopsStrategyTest method testExcludeTerminals.

@Test
public void testExcludeTerminals() throws IOException {
    RemoveNonRevenueStopsExcludingTerminalsStrategy _strategy = new RemoveNonRevenueStopsExcludingTerminalsStrategy();
    _gtfs.putAgencies(1);
    _gtfs.putStops(3);
    _gtfs.putRoutes(1);
    _gtfs.putCalendars(1, "start_date=20120903", "end_date=20121016", "mask=1111100");
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time,drop_off_type,pickup_type", "t0,s0,0,01:00:00,01:05:00,1,1", "t0,s1,1,01:30:00,01:30:00,0,0", "t0,s2,2,02:30:00,02:30:00,1,1", "t0,s0,3,03:00:00,03:00:00,0,0", "t0,s2,4,03:30:00,03:30:00,1,1");
    GtfsMutableRelationalDao dao = _gtfs.read();
    _strategy.run(new TransformContext(), dao);
    Trip trip = dao.getTripForId(_gtfs.id("t0"));
    assertEquals("sid0", trip.getServiceId().getId());
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(4, stopTimes.size());
    assertEquals(1, stopTimes.get(3).getPickupType());
    assertEquals(0, stopTimes.get(2).getPickupType());
    assertEquals(1, stopTimes.get(0).getPickupType());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 40 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao in project onebusaway-gtfs-modules by OneBusAway.

the class ShiftNegativeStopTimesUpdateStrategyTest method test.

@Test
public void test() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(3);
    _gtfs.putRoutes(1);
    _gtfs.putCalendars(1, "start_date=20120903", "end_date=20121016", "mask=1111100");
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time", "t0,s0,0,-01:00:00,-01:05:00", "t0,s1,1,-01:30:00,-01:30:00", "t0,s2,2,00:30:00,00:30:00");
    GtfsMutableRelationalDao dao = _gtfs.read();
    _strategy.run(new TransformContext(), dao);
    Trip trip = dao.getTripForId(_gtfs.id("t0"));
    assertEquals("sid0 -1", trip.getServiceId().getId());
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(3, stopTimes.size());
    {
        StopTime stopTime = stopTimes.get(0);
        assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:00:00"));
        assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:05:00"));
    }
    {
        StopTime stopTime = stopTimes.get(1);
        assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:30:00"));
        assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:30:00"));
    }
    {
        StopTime stopTime = stopTimes.get(2);
        assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("24:30:00"));
        assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("24:30:00"));
    }
    ServiceCalendar c = dao.getCalendarForServiceId(trip.getServiceId());
    assertEquals(c.getStartDate(), new ServiceDate(2012, 9, 2));
    assertEquals(c.getEndDate(), new ServiceDate(2012, 10, 15));
    assertEquals(1, c.getMonday());
    assertEquals(1, c.getTuesday());
    assertEquals(1, c.getWednesday());
    assertEquals(1, c.getThursday());
    assertEquals(0, c.getFriday());
    assertEquals(0, c.getSaturday());
    assertEquals(1, c.getSunday());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) StopTime(org.onebusaway.gtfs.model.StopTime) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Aggregations

GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)57 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)25 Test (org.junit.Test)24 Trip (org.onebusaway.gtfs.model.Trip)22 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)14 Stop (org.onebusaway.gtfs.model.Stop)11 StopTime (org.onebusaway.gtfs.model.StopTime)11 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)11 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)9 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)9 ExternalServices (org.onebusaway.cloud.api.ExternalServices)8 ExternalServicesBridgeFactory (org.onebusaway.cloud.api.ExternalServicesBridgeFactory)8 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)7 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)7 GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)7 Route (org.onebusaway.gtfs.model.Route)6 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)6 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)5 HashSet (java.util.HashSet)4