Search in sources :

Example 26 with StopTime

use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.

the class EntityRetentionGraph method retainStop.

private void retainStop(Stop stop, boolean retainUp) {
    if (retainUp) {
        for (StopTime stopTime : _dao.getStopTimesForStop(stop)) retainUp(stopTime);
    } else {
        String parentStationId = stop.getParentStation();
        if (parentStationId != null) {
            AgencyAndId id = stop.getId();
            Stop parent = _dao.getStopForId(new AgencyAndId(id.getAgencyId(), parentStationId));
            retainDown(parent);
        }
        /**
       * Need to make sure a stop's agency is included as well, since the agency
       * might not be included by any routes serving that stop
       */
        AgencyAndId stopId = stop.getId();
        String agencyId = stopId.getAgencyId();
        Agency agency = _dao.getAgencyForId(agencyId);
        if (agency != null) {
            retainDown(agency);
        }
    }
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 27 with StopTime

use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.

the class ShiftNegativeStopTimesUpdateStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Set<ShiftedServiceCalendar> shiftedIds = new HashSet<ShiftedServiceCalendar>();
    for (Trip trip : dao.getAllTrips()) {
        List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
        int minTime = getMinStopTime(stopTimes);
        if (minTime >= 0) {
            continue;
        }
        int dayShift = getDayShiftForNegativeStopTime(minTime);
        shiftStopTimes(stopTimes, dayShift * SECONDS_IN_DAY);
        ShiftedServiceCalendar shifted = new ShiftedServiceCalendar(trip.getServiceId(), -dayShift);
        shiftedIds.add(shifted);
        trip.setServiceId(shifted.getShiftedServiceId());
    }
    CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(dao);
    CalendarSimplicationLibrary library = new CalendarSimplicationLibrary();
    for (ShiftedServiceCalendar shifted : shiftedIds) {
        Set<ServiceDate> allServiceDates = calendarService.getServiceDatesForServiceId(shifted.getOriginalServiceId());
        Set<ServiceDate> shiftedServiceDates = shiftServiceDates(allServiceDates, shifted.getDayOffset());
        ServiceCalendarSummary summary = library.getSummaryForServiceDates(shiftedServiceDates);
        List<Object> newEntities = new ArrayList<Object>();
        library.computeSimplifiedCalendar(shifted.getShiftedServiceId(), summary, newEntities);
        for (Object newEntity : newEntities) {
            dao.saveEntity(newEntity);
        }
    }
    UpdateLibrary.clearDaoCache(dao);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) ArrayList(java.util.ArrayList) ServiceCalendarSummary(org.onebusaway.gtfs_transformer.updates.CalendarSimplicationLibrary.ServiceCalendarSummary) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) HashSet(java.util.HashSet) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 28 with StopTime

use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.

the class RemoveDuplicateTripsStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Map<Pattern, List<Trip>> tripsByPattern = new FactoryMap<Pattern, List<Trip>>(new ArrayList<Trip>());
    for (Trip trip : dao.getAllTrips()) {
        Pattern pattern = getPatternForTrip(dao, trip);
        tripsByPattern.get(pattern).add(trip);
    }
    int duplicateTrips = 0;
    for (List<Trip> trips : tripsByPattern.values()) {
        if (trips.size() == 1)
            continue;
        for (int i = 1; i < trips.size(); i++) {
            Trip trip = trips.get(i);
            List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
            for (StopTime stopTime : stopTimes) dao.removeEntity(stopTime);
            dao.removeEntity(trip);
            duplicateTrips++;
        }
    }
    UpdateLibrary.clearDaoCache(dao);
    _log.info("removed " + duplicateTrips + " duplicate trips");
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Trip(org.onebusaway.gtfs.model.Trip) ArrayList(java.util.ArrayList) List(java.util.List) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 29 with StopTime

use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.

the class RemoveRepeatedStopTimesInSameTripStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    int removed = 0;
    int total = 0;
    for (Trip trip : dao.getAllTrips()) {
        StopTime prev = null;
        List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
        for (StopTime stopTime : stopTimes) {
            total++;
            if (prev != null) {
                if (prev.getStop().getId().equals(stopTime.getStop().getId())) {
                    stopTime.setArrivalTime(Math.min(prev.getArrivalTime(), stopTime.getArrivalTime()));
                    stopTime.setDepartureTime(Math.max(prev.getDepartureTime(), stopTime.getDepartureTime()));
                    dao.removeEntity(prev);
                    removed++;
                }
            }
            prev = stopTime;
        }
    }
    _log.info("removed=" + removed + " total=" + total);
    UpdateLibrary.clearDaoCache(dao);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 30 with StopTime

use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.

the class RemoveRepeatedStopTimesStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    int removed = 0;
    int total = 0;
    Map<String, List<Trip>> tripsByBlockId = TripsByBlockInSortedOrder.getTripsByBlockInSortedOrder(dao);
    for (List<Trip> trips : tripsByBlockId.values()) {
        StopTime prev = null;
        for (Trip trip : trips) {
            List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
            for (StopTime stopTime : stopTimes) {
                total++;
                if (prev != null) {
                    if (prev.getStop().getId().equals(stopTime.getStop().getId())) {
                        stopTime.setArrivalTime(Math.min(prev.getArrivalTime(), stopTime.getArrivalTime()));
                        stopTime.setDepartureTime(Math.max(prev.getDepartureTime(), stopTime.getDepartureTime()));
                        dao.removeEntity(prev);
                        removed++;
                    }
                }
                prev = stopTime;
            }
        }
    }
    _log.info("removed=" + removed + " total=" + total);
    UpdateLibrary.clearDaoCache(dao);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) List(java.util.List) StopTime(org.onebusaway.gtfs.model.StopTime)

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