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);
}
}
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;
}
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());
}
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")));
}
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;
}
Aggregations