use of org.onebusaway.gtfs.model.StopLocation in project onebusaway-gtfs-modules by OneBusAway.
the class UpdateTripHeadsignExcludeNonreference method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
int update = 0;
int fallback = 0;
int noChange = 0;
int shuttle = 0;
for (Trip trip : dao.getAllTrips()) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
if (stopTimes != null && stopTimes.size() > 0) {
StopLocation lastStop = stopTimes.get(stopTimes.size() - 1).getStop();
Stop referenceStop = reference.getStopForId(lastStop.getId());
if (trip.getTripHeadsign() == null || referenceStop != null) {
String tripHeadSign = stopTimes.get(stopTimes.size() - 1).getStop().getName();
if (tripHeadSign != null) {
trip.setTripHeadsign(tripHeadSign);
update++;
} else {
fallbackSetHeadsign(trip);
fallback++;
}
} else {
noChange++;
if (trip.getTripHeadsign().contains("SHUTTLE")) {
shuttle++;
}
}
} else {
fallbackSetHeadsign(trip);
fallback++;
}
}
_log.info("trip headsign update:{} fallback: {} no change: {} shuttle: {}", update, fallback, noChange, shuttle);
}
use of org.onebusaway.gtfs.model.StopLocation in project onebusaway-gtfs-modules by OneBusAway.
the class SubsectionTripTransformStrategy method updateShape.
private void updateShape(GtfsMutableRelationalDao dao, Trip trip, List<StopTime> stopTimes, Set<AgencyAndId> newShapeIds) {
if (stopTimes.size() < 2) {
trip.setShapeId(null);
return;
}
AgencyAndId shapeId = trip.getShapeId();
if (shapeId == null || !shapeId.hasValues()) {
return;
}
List<ShapePoint> points = dao.getShapePointsForShapeId(shapeId);
if (points.isEmpty()) {
return;
}
StopLocation firstStop = stopTimes.get(0).getStop();
StopLocation lastStop = stopTimes.get(stopTimes.size() - 1).getStop();
String id = shapeId.getId() + "-" + firstStop.getId().getId() + "-" + lastStop.getId().getId();
AgencyAndId newShapeId = new AgencyAndId("1", id);
trip.setShapeId(newShapeId);
if (!newShapeIds.add(newShapeId)) {
return;
}
if (!(firstStop instanceof Stop)) {
// TODO Correct error type
throw new Error(firstStop + " must be stop");
}
if (!(lastStop instanceof Stop)) {
// TODO Correct error type
throw new Error(firstStop + " must be stop");
}
int shapePointFrom = getClosestShapePointToStop(points, (Stop) firstStop);
int shapePointTo = getClosestShapePointToStop(points, (Stop) lastStop);
for (int index = shapePointFrom; index <= shapePointTo; ++index) {
ShapePoint point = new ShapePoint(points.get(index));
point.setId(0);
point.setShapeId(newShapeId);
dao.saveEntity(point);
}
}
Aggregations