use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class EntityRetentionGraph method retainStop.
private void retainStop(Stop stop, boolean retainUp) {
if (retainUp) {
for (StopTime stopTime : _dao.getStopTimesForStop(stop)) retainUp(stopTime);
} else {
String parentStationId = stop.getParentStation();
if (parentStationId != null) {
AgencyAndId id = stop.getId();
Stop parent = _dao.getStopForId(new AgencyAndId(id.getAgencyId(), parentStationId));
retainDown(parent);
}
/**
* Need to make sure a stop's agency is included as well, since the agency
* might not be included by any routes serving that stop
*/
AgencyAndId stopId = stop.getId();
String agencyId = stopId.getAgencyId();
Agency agency = _dao.getAgencyForId(agencyId);
if (agency != null) {
retainDown(agency);
}
}
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class ShiftNegativeStopTimesUpdateStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
Set<ShiftedServiceCalendar> shiftedIds = new HashSet<ShiftedServiceCalendar>();
for (Trip trip : dao.getAllTrips()) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
int minTime = getMinStopTime(stopTimes);
if (minTime >= 0) {
continue;
}
int dayShift = getDayShiftForNegativeStopTime(minTime);
shiftStopTimes(stopTimes, dayShift * SECONDS_IN_DAY);
ShiftedServiceCalendar shifted = new ShiftedServiceCalendar(trip.getServiceId(), -dayShift);
shiftedIds.add(shifted);
trip.setServiceId(shifted.getShiftedServiceId());
}
CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(dao);
CalendarSimplicationLibrary library = new CalendarSimplicationLibrary();
for (ShiftedServiceCalendar shifted : shiftedIds) {
Set<ServiceDate> allServiceDates = calendarService.getServiceDatesForServiceId(shifted.getOriginalServiceId());
Set<ServiceDate> shiftedServiceDates = shiftServiceDates(allServiceDates, shifted.getDayOffset());
ServiceCalendarSummary summary = library.getSummaryForServiceDates(shiftedServiceDates);
List<Object> newEntities = new ArrayList<Object>();
library.computeSimplifiedCalendar(shifted.getShiftedServiceId(), summary, newEntities);
for (Object newEntity : newEntities) {
dao.saveEntity(newEntity);
}
}
UpdateLibrary.clearDaoCache(dao);
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class RemoveDuplicateTripsStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
Map<Pattern, List<Trip>> tripsByPattern = new FactoryMap<Pattern, List<Trip>>(new ArrayList<Trip>());
for (Trip trip : dao.getAllTrips()) {
Pattern pattern = getPatternForTrip(dao, trip);
tripsByPattern.get(pattern).add(trip);
}
int duplicateTrips = 0;
for (List<Trip> trips : tripsByPattern.values()) {
if (trips.size() == 1)
continue;
for (int i = 1; i < trips.size(); i++) {
Trip trip = trips.get(i);
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
for (StopTime stopTime : stopTimes) dao.removeEntity(stopTime);
dao.removeEntity(trip);
duplicateTrips++;
}
}
UpdateLibrary.clearDaoCache(dao);
_log.info("removed " + duplicateTrips + " duplicate trips");
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class RemoveRepeatedStopTimesInSameTripStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
int removed = 0;
int total = 0;
for (Trip trip : dao.getAllTrips()) {
StopTime prev = null;
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
for (StopTime stopTime : stopTimes) {
total++;
if (prev != null) {
if (prev.getStop().getId().equals(stopTime.getStop().getId())) {
stopTime.setArrivalTime(Math.min(prev.getArrivalTime(), stopTime.getArrivalTime()));
stopTime.setDepartureTime(Math.max(prev.getDepartureTime(), stopTime.getDepartureTime()));
dao.removeEntity(prev);
removed++;
}
}
prev = stopTime;
}
}
_log.info("removed=" + removed + " total=" + total);
UpdateLibrary.clearDaoCache(dao);
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class RemoveRepeatedStopTimesStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
int removed = 0;
int total = 0;
Map<String, List<Trip>> tripsByBlockId = TripsByBlockInSortedOrder.getTripsByBlockInSortedOrder(dao);
for (List<Trip> trips : tripsByBlockId.values()) {
StopTime prev = null;
for (Trip trip : trips) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
for (StopTime stopTime : stopTimes) {
total++;
if (prev != null) {
if (prev.getStop().getId().equals(stopTime.getStop().getId())) {
stopTime.setArrivalTime(Math.min(prev.getArrivalTime(), stopTime.getArrivalTime()));
stopTime.setDepartureTime(Math.max(prev.getDepartureTime(), stopTime.getDepartureTime()));
dao.removeEntity(prev);
removed++;
}
}
prev = stopTime;
}
}
}
_log.info("removed=" + removed + " total=" + total);
UpdateLibrary.clearDaoCache(dao);
}
Aggregations