use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class RouteStopsInCommonDuplicateScoringStrategy method getAllStopsForRoute.
private Set<Stop> getAllStopsForRoute(GtfsRelationalDao dao, Route route) {
Set<Stop> stops = new HashSet<Stop>();
List<Trip> tripsForRoute = new ArrayList<Trip>();
// make this thread safe
tripsForRoute.addAll(dao.getTripsForRoute(route));
for (Trip trip : tripsForRoute) {
List<StopTime> stopTimesForTrip = new ArrayList<StopTime>();
stopTimesForTrip.addAll(dao.getStopTimesForTrip(trip));
for (StopTime stopTime : stopTimesForTrip) {
stops.add(stopTime.getStop());
}
}
return stops;
}
use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class StopMergeStrategy method save.
@Override
protected void save(GtfsMergeContext context, IdentityBean<?> entity) {
GtfsRelationalDao source = context.getSource();
GtfsMutableRelationalDao target = context.getTarget();
Stop stop = (Stop) entity;
super.save(context, entity);
}
use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class TrimTripTransformStrategy 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;
}
Stop firstStop = stopTimes.get(0).getStop();
Stop lastStop = stopTimes.get(stopTimes.size() - 1).getStop();
String id = shapeId.getId() + "-" + firstStop.getId().getId() + "-" + lastStop.getId().getId();
AgencyAndId newShapeId = new AgencyAndId(shapeId.getAgencyId(), id);
trip.setShapeId(newShapeId);
if (!newShapeIds.add(newShapeId)) {
return;
}
int shapePointFrom = getClosestShapePointToStop(points, firstStop);
int shapePointTo = getClosestShapePointToStop(points, lastStop);
for (int index = shapePointFrom; index <= shapePointTo; ++index) {
ShapePoint point = new ShapePoint(points.get(index));
point.setId(0);
point.setShapeId(newShapeId);
dao.saveEntity(point);
}
}
use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class TripKey method getTripKeyForTrip.
public static TripKey getTripKeyForTrip(GtfsMutableRelationalDao dao, Trip trip) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
Stop[] stops = new Stop[stopTimes.size()];
int[] arrivalTimes = new int[stopTimes.size()];
int[] departureTimes = new int[stopTimes.size()];
for (int i = 0; i < stopTimes.size(); i++) {
StopTime stopTime = stopTimes.get(i);
stops[i] = stopTime.getStop();
arrivalTimes[i] = stopTime.getArrivalTime();
departureTimes[i] = stopTime.getDepartureTime();
}
return new TripKey(stops, arrivalTimes, departureTimes);
}
use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.
the class EntityRetentionGraphTest method testRetainStop.
@Test
public void testRetainStop() {
Stop stop = _dao.getStopForId(aid("A"));
_graph.retainUp(stop);
// 9 stop_times + 3 trips + 1 route + 1 agency + 3 stops + 1 service id + 1
// calendar
assertEquals(19, _graph.getSize());
assertTrue(_graph.isRetained(_dao.getStopForId(aid("A"))));
assertTrue(_graph.isRetained(_dao.getStopForId(aid("B"))));
assertTrue(_graph.isRetained(_dao.getStopForId(aid("C"))));
assertFalse(_graph.isRetained(_dao.getStopForId(aid("D"))));
assertTrue(_graph.isRetained(_dao.getTripForId(aid("1.1"))));
assertTrue(_graph.isRetained(_dao.getTripForId(aid("1.2"))));
assertTrue(_graph.isRetained(_dao.getTripForId(aid("1.3"))));
assertFalse(_graph.isRetained(_dao.getTripForId(aid("2.1"))));
assertTrue(_graph.isRetained(_dao.getRouteForId(aid("1"))));
assertFalse(_graph.isRetained(_dao.getRouteForId(aid("2"))));
assertTrue(_graph.isRetained(_dao.getAgencyForId("agency")));
_graph.retainUp(stop);
assertEquals(19, _graph.getSize());
}
Aggregations