Search in sources :

Example 6 with StopTime

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

Example 7 with StopTime

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);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) List(java.util.List) Map(java.util.Map) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 8 with StopTime

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

Example 9 with StopTime

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

Example 10 with 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);
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) StopTime(org.onebusaway.gtfs.model.StopTime) HashSet(java.util.HashSet)

Aggregations

StopTime (org.onebusaway.gtfs.model.StopTime)37 Trip (org.onebusaway.gtfs.model.Trip)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 Test (org.junit.Test)12 Stop (org.onebusaway.gtfs.model.Stop)11 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)8 ArrayList (java.util.ArrayList)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 List (java.util.List)6 Agency (org.onebusaway.gtfs.model.Agency)6 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)5 HashSet (java.util.HashSet)4 Frequency (org.onebusaway.gtfs.model.Frequency)4 Route (org.onebusaway.gtfs.model.Route)4 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)4 HashMap (java.util.HashMap)3 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)3 FareRule (org.onebusaway.gtfs.model.FareRule)3 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)3