use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class RemoveDuplicateTripsStrategy method getPatternForTrip.
private Pattern getPatternForTrip(GtfsMutableRelationalDao dao, Trip trip) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
int n = stopTimes.size();
AgencyAndId[] stopIds = new AgencyAndId[n];
int[] arrivalTimes = new int[n];
int[] departureTimes = new int[n];
for (int i = 0; i < n; i++) {
StopTime stopTime = stopTimes.get(i);
stopIds[i] = stopTime.getStop().getId();
arrivalTimes[i] = stopTime.getArrivalTime();
departureTimes[i] = stopTime.getDepartureTime();
}
return new Pattern(trip.getRoute().getId(), trip.getServiceId(), stopIds, arrivalTimes, departureTimes);
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class RemoveEmptyBlockTripsStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
Map<String, List<Trip>> tripsByBlockId = MappingLibrary.mapToValueList(dao.getAllTrips(), "blockId", String.class);
int tripsRemoved = 0;
int blocksRemoved = 0;
for (Map.Entry<String, List<Trip>> entry : tripsByBlockId.entrySet()) {
String blockId = entry.getKey();
List<Trip> trips = entry.getValue();
if (blockId == null)
continue;
boolean hasStopTimes = false;
for (Trip trip : trips) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
if (!stopTimes.isEmpty())
hasStopTimes = true;
}
if (hasStopTimes)
continue;
blocksRemoved++;
tripsRemoved += trips.size();
_log.info("removing block " + blockId);
for (Trip trip : trips) dao.removeEntity(trip);
}
UpdateLibrary.clearDaoCache(dao);
_log.info("blocksRemoved=" + blocksRemoved + " tripsRemoved=" + tripsRemoved);
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class StopSequencePattern method getPatternForStopTimes.
public static StopSequencePattern getPatternForStopTimes(List<StopTime> stopTimes) {
int n = stopTimes.size();
AgencyAndId[] stopIds = new AgencyAndId[n];
int[] arrivalTimes = new int[n];
int[] departureTimes = new int[n];
for (int i = 0; i < n; i++) {
StopTime stopTime = stopTimes.get(i);
stopIds[i] = stopTime.getStop().getId();
arrivalTimes[i] = stopTime.getArrivalTime();
departureTimes[i] = stopTime.getDepartureTime();
}
return new StopSequencePattern(stopIds, arrivalTimes, departureTimes);
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class StopTimesFactoryStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsReaderContext gtfsReaderContext = context.getReader().getGtfsReaderContext();
Trip trip = getTrip(gtfsReaderContext, dao);
List<Stop> stops = getStops(gtfsReaderContext, dao);
int[] times = getTimesForStops(stops);
for (int i = 0; i < stops.size(); ++i) {
StopTime stopTime = new StopTime();
stopTime.setStop(stops.get(i));
stopTime.setStopSequence(i);
stopTime.setArrivalTime(times[i]);
stopTime.setDepartureTime(times[i]);
stopTime.setTrip(trip);
dao.saveEntity(stopTime);
}
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class SubsectionTripTransformStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
List<Trip> tripsToAdd = new ArrayList<Trip>();
List<StopTime> stopTimesToAdd = new ArrayList<StopTime>();
List<Trip> tripsToRemove = new ArrayList<Trip>();
List<StopTime> stopTimesToRemove = new ArrayList<StopTime>();
Set<AgencyAndId> newShapeIds = new HashSet<AgencyAndId>();
for (Trip trip : dao.getAllTrips()) {
String routeId = trip.getRoute().getId().getId();
List<SubsectionOperation> operations = _operationsByRouteId.get(routeId);
if (operations == null) {
continue;
}
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
Map<String, Integer> stopToIndex = getStopIndices(stopTimes);
boolean removeOriginalTrip = false;
for (SubsectionOperation operation : operations) {
Integer fromIndex = stopToIndex.get(operation.getFromStopId());
Integer toIndex = stopToIndex.get(operation.getToStopId());
if (fromIndex == null && toIndex == null) {
if (operation.removeUnmatchedTrips) {
removeOriginalTrip = true;
}
continue;
}
removeOriginalTrip = true;
Trip newTrip = new Trip(trip);
String id = newTrip.getId().getId();
if (fromIndex != null) {
id += "-" + operation.getFromStopId();
}
if (toIndex != null) {
id += "-" + operation.getToStopId();
}
if (fromIndex == null) {
fromIndex = 0;
} else if (!operation.isIncludeFromStop()) {
fromIndex++;
}
if (toIndex == null) {
toIndex = stopTimes.size() - 1;
} else if (!operation.isIncludeToStop()) {
toIndex--;
}
newTrip.setId(new AgencyAndId("1", id));
tripsToAdd.add(newTrip);
List<StopTime> newStopTimes = new ArrayList<StopTime>();
for (int i = fromIndex; i <= toIndex; ++i) {
StopTime stopTime = new StopTime(stopTimes.get(i));
stopTime.setId(0);
stopTime.setTrip(newTrip);
newStopTimes.add(stopTime);
}
updateShape(dao, newTrip, newStopTimes, newShapeIds);
stopTimesToAdd.addAll(newStopTimes);
}
if (removeOriginalTrip) {
tripsToRemove.add(trip);
stopTimesToRemove.addAll(stopTimes);
}
}
for (StopTime stopTime : stopTimesToRemove) {
dao.removeEntity(stopTime);
}
for (Trip trip : tripsToRemove) {
dao.removeEntity(trip);
}
for (Trip trip : tripsToAdd) {
dao.saveEntity(trip);
}
for (StopTime stopTime : stopTimesToAdd) {
dao.saveEntity(stopTime);
}
((GtfsRelationalDaoImpl) dao).clearAllCaches();
Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>(dao.getAllShapeIds());
for (Trip trip : dao.getAllTrips()) {
shapeIds.remove(trip.getShapeId());
}
for (AgencyAndId shapeId : shapeIds) {
for (ShapePoint point : dao.getShapePointsForShapeId(shapeId)) {
dao.removeEntity(point);
}
}
}
Aggregations