Search in sources :

Example 6 with TransformContext

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

the class TransformFactoryTest method testPathInUpdate.

@Test
public void testPathInUpdate() throws IOException, TransformSpecificationException {
    _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_headsign': 'path(route.longName)'}}");
    GtfsTransformStrategy transform = _transformer.getLastTransform();
    TransformContext context = new TransformContext();
    GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
    Route route = new Route();
    route.setLongName("long cat");
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "1"));
    trip.setRoute(route);
    dao.saveEntity(trip);
    transform.run(context, dao);
    assertEquals("long cat", trip.getTripHeadsign());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 7 with TransformContext

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

the class LastStopToHeadsignStrategyTest method test.

@Test
public void test() {
    LastStopToHeadsignStrategy _strategy = new LastStopToHeadsignStrategy();
    AgencyAndId tripId = new AgencyAndId();
    tripId.setId("1.1");
    tripId.setAgencyId("agency");
    Trip trip = _dao.getTripForId(tripId);
    Assert.assertNotSame("C", trip.getTripHeadsign());
    _strategy.run(new TransformContext(), _dao);
    trip = _dao.getTripForId(tripId);
    Assert.assertEquals("C", trip.getTripHeadsign());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) Test(org.junit.Test)

Example 8 with TransformContext

use of org.onebusaway.gtfs_transformer.services.TransformContext 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 9 with TransformContext

use of org.onebusaway.gtfs_transformer.services.TransformContext 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)

Example 10 with TransformContext

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

the class TransformFactoryTest method testReplaceIdInUpdate.

@Test
public void testReplaceIdInUpdate() throws IOException, TransformSpecificationException {
    _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_id': 's/^1_([0-9]*).*/$1/'}}");
    GtfsTransformStrategy transform = _transformer.getLastTransform();
    TransformContext context = new TransformContext();
    context.setDefaultAgencyId("1");
    GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "1234-this-text-to-remove"));
    dao.saveEntity(trip);
    transform.run(context, dao);
    assertEquals("1234", trip.getId().getId());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Test(org.junit.Test)

Aggregations

TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)12 Test (org.junit.Test)11 Trip (org.onebusaway.gtfs.model.Trip)11 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)11 GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)5 StopTime (org.onebusaway.gtfs.model.StopTime)3 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)2 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)2 java.io (java.io)1 URL (java.net.URL)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util (java.util)1 ExternalServices (org.onebusaway.cloud.api.ExternalServices)1 ExternalServicesBridgeFactory (org.onebusaway.cloud.api.ExternalServicesBridgeFactory)1 CSVLibrary (org.onebusaway.csv_entities.CSVLibrary)1 CSVListener (org.onebusaway.csv_entities.CSVListener)1