Search in sources :

Example 21 with GtfsRelationalDao

use of org.onebusaway.gtfs.services.GtfsRelationalDao 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 GtfsRelationalDao

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

the class TripMergeStrategy method rejectDuplicateOverDifferences.

/**
   * Even if we have detected that two trips are duplicates, they might have
   * slight differences that prevent them from being represented as one merged
   * trip. For example, if a trip in a subsequent feed adds, removes, or
   * modifies a stop time, we might avoid merging the two trips such that the
   * schedule is correct in the merged feed.
   * 
   * TODO: Think about how this should be applied in relation to the service
   * calendars of the two trips.
   */
@Override
protected boolean rejectDuplicateOverDifferences(GtfsMergeContext context, Trip sourceEntity, Trip targetDuplicate) {
    GtfsRelationalDao source = context.getSource();
    GtfsRelationalDao target = context.getTarget();
    List<StopTime> sourceStopTimes = source.getStopTimesForTrip(sourceEntity);
    List<StopTime> targetStopTimes = target.getStopTimesForTrip(targetDuplicate);
    if (sourceStopTimes.size() != targetStopTimes.size()) {
        return true;
    }
    for (int i = 0; i < sourceStopTimes.size(); ++i) {
        StopTime sourceStopTime = sourceStopTimes.get(i);
        StopTime targetStopTime = targetStopTimes.get(i);
        if (!sourceStopTime.getStop().equals(targetStopTime.getStop())) {
            return true;
        }
        if (sourceStopTime.getArrivalTime() != targetStopTime.getArrivalTime() || sourceStopTime.getDepartureTime() != targetStopTime.getDepartureTime()) {
            return true;
        }
    }
    return false;
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 23 with GtfsRelationalDao

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

the class CalendarSimplicationStrategyTest method testEmptyServiceDate.

@Test
public void testEmptyServiceDate() {
    _gtfs.putAgencies(1);
    _gtfs.putStops(1);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimes("t0", "s0");
    GtfsRelationalDao dao = transform();
    AgencyAndId serviceId = new AgencyAndId("a0", "sid0");
    ServiceCalendar c = dao.getCalendarForServiceId(serviceId);
    assertNull(c);
    List<ServiceCalendarDate> serviceDates = dao.getCalendarDatesForServiceId(serviceId);
    assertEquals(0, serviceDates.size());
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 24 with GtfsRelationalDao

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

the class GtfsTransformerTest method testRemoveCalendarCollection.

@Test
public void testRemoveCalendarCollection() throws Exception {
    GtfsRelationalDao dao = transform("{'op':'remove', 'match':{'collection':'calendar', 'service_id':'sid1'}}");
    assertNull(dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1")));
    assertNull(dao.getTripForId(new AgencyAndId("a0", "t1")));
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 25 with GtfsRelationalDao

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

the class GtfsTransformerTest method transform.

private GtfsRelationalDao transform(String transformSpec) throws Exception {
    _transformer.getTransformFactory().addModificationsFromString(transformSpec);
    _transformer.setGtfsInputDirectory(_gtfs.getPath());
    _transformer.run();
    GtfsRelationalDao dao = _transformer.getDao();
    UpdateLibrary.clearDaoCache(dao);
    return dao;
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao)

Aggregations

GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)29 Test (org.junit.Test)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 Trip (org.onebusaway.gtfs.model.Trip)8 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)7 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)6 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)5 Stop (org.onebusaway.gtfs.model.Stop)5 StopTime (org.onebusaway.gtfs.model.StopTime)5 Agency (org.onebusaway.gtfs.model.Agency)3 TripMergeStrategy (org.onebusaway.gtfs_merge.strategies.TripMergeStrategy)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Frequency (org.onebusaway.gtfs.model.Frequency)2 Route (org.onebusaway.gtfs.model.Route)2 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)2 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)2 AgencyMergeStrategy (org.onebusaway.gtfs_merge.strategies.AgencyMergeStrategy)2 StopMergeStrategy (org.onebusaway.gtfs_merge.strategies.StopMergeStrategy)2 Serializable (java.io.Serializable)1