Search in sources :

Example 21 with GtfsMutableRelationalDao

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

the class TripMergeStrategy method save.

@Override
protected void save(GtfsMergeContext context, IdentityBean<?> entity) {
    GtfsRelationalDao source = context.getSource();
    GtfsMutableRelationalDao target = context.getTarget();
    Trip trip = (Trip) entity;
    // save them out; when the trip is renamed stop time refs will be lost
    List<StopTime> stopTimes = source.getStopTimesForTrip(trip);
    super.save(context, entity);
    for (StopTime stopTime : stopTimes) {
        stopTime.setId(0);
        stopTime.setTrip(trip);
        target.saveEntity(stopTime);
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 22 with GtfsMutableRelationalDao

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

the class DeduplicateServiceIdsStrategyTest method test.

@Test
public void test() throws IOException {
    _gtfs.putTrips(2, "r0", "sid0,sid1");
    _gtfs.putCalendars(2, "start_date=20120630", "end_date=20121224", "mask=1111100");
    GtfsMutableRelationalDao dao = _gtfs.read();
    assertEquals(2, dao.getAllCalendars().size());
    _strategy.run(_context, dao);
    assertEquals(1, dao.getAllCalendars().size());
    AgencyAndId serviceId = new AgencyAndId("a0", "sid0");
    assertNotNull(dao.getCalendarForServiceId(serviceId));
    for (Trip trip : dao.getAllTrips()) {
        assertEquals(serviceId, trip.getServiceId());
    }
    assertNull(dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1")));
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 23 with GtfsMutableRelationalDao

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

the class ShapeDirectionTransformStrategyTest 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.putLines("trips.txt", "trip_id,route_id,service_id,direction_id,shape_id", "t0,r0,sid0,0,shp0", "t1,r0,sid0,1,shp0");
    _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,02:30:00,02:30:00", "t1,s0,0,01:00:00,01:05:00", "t1,s1,1,01:30:00,01:30:00", "t1,s2,2,02:30:00,02:30:00");
    _gtfs.putLines("shapes.txt", "shape_id,shape_pt_sequence,shape_pt_lat,shape_pt_lon", "shp0,1,1,1", "shp0,2,2,2", "shp0,3,3,3");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TransformContext tc = new TransformContext();
    tc.setDefaultAgencyId("a0");
    _strategy.setShapeId("shp0");
    _strategy.setShapeDirection("0");
    _strategy.run(tc, dao);
    UpdateLibrary.clearDaoCache(dao);
    Collection<ShapePoint> newShapePoints = dao.getShapePointsForShapeId(AgencyAndId.convertFromString("a0_shp0R"));
    assertFalse(newShapePoints.isEmpty());
    ShapePoint sp0 = newShapePoints.iterator().next();
    assertEquals(sp0.getLat(), 3, 0);
    assertEquals(sp0.getLon(), 3, 0);
    Trip t = dao.getTripForId(AgencyAndId.convertFromString("a0_t1"));
    assertEquals(t.getDirectionId(), "1");
    assertEquals(t.getShapeId().getId(), "shp0R");
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) Trip(org.onebusaway.gtfs.model.Trip) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) Test(org.junit.Test)

Example 24 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)

Example 25 with GtfsMutableRelationalDao

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

the class TrimTripTransformStrategyTest method testMatching.

@Test
public void testMatching() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(6);
    _gtfs.putRoutes(2);
    _gtfs.putTrips(2, "r0,r1", "sid0");
    _gtfs.putStopTimes("t0,t1", "s0,s1,s2,s3,s4,s5");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new PropertyValueEntityMatch(new PropertyPathExpression("route.id.id"), new SimpleValueMatcher("r1"))));
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    {
        Trip trip = dao.getTripForId(new AgencyAndId("a0", "t0"));
        List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
        assertEquals(6, stopTimes.size());
    }
    {
        Trip trip = dao.getTripForId(new AgencyAndId("a0", "t1-s4"));
        List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
        assertEquals(4, stopTimes.size());
        assertEquals("s0", stopTimes.get(0).getStop().getId().getId());
        assertEquals("s3", stopTimes.get(3).getStop().getId().getId());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) SimpleValueMatcher(org.onebusaway.gtfs_transformer.match.SimpleValueMatcher) PropertyPathExpression(org.onebusaway.collections.beans.PropertyPathExpression) List(java.util.List) PropertyValueEntityMatch(org.onebusaway.gtfs_transformer.match.PropertyValueEntityMatch) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) Test(org.junit.Test)

Aggregations

GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)29 Test (org.junit.Test)16 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 Trip (org.onebusaway.gtfs.model.Trip)9 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)7 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)5 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)5 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)4 Stop (org.onebusaway.gtfs.model.Stop)4 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)4 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)4 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)4 Collection (java.util.Collection)3 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)3 StopTime (org.onebusaway.gtfs.model.StopTime)3 HibernateGtfsFactory (org.onebusaway.gtfs.services.HibernateGtfsFactory)3 TypedEntityMatch (org.onebusaway.gtfs_transformer.match.TypedEntityMatch)3 TrimOperation (org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation)3 File (java.io.File)2