Search in sources :

Example 6 with StopLocation

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);
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) Stop(org.onebusaway.gtfs.model.Stop) StopLocation(org.onebusaway.gtfs.model.StopLocation) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 7 with StopLocation

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);
    }
}
Also used : ShapePoint(org.onebusaway.gtfs.model.ShapePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopLocation(org.onebusaway.gtfs.model.StopLocation) ShapePoint(org.onebusaway.gtfs.model.ShapePoint)

Aggregations

StopLocation (org.onebusaway.gtfs.model.StopLocation)7 StopTime (org.onebusaway.gtfs.model.StopTime)5 Stop (org.onebusaway.gtfs.model.Stop)4 Trip (org.onebusaway.gtfs.model.Trip)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)1