Search in sources :

Example 1 with StopTime

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

the class HibernateGtfsRelationalDaoImplCaltrainTest method testGetStopTimesByTrip.

@Test
public void testGetStopTimesByTrip() {
    Trip trip = _dao.getTripForId(aid("10101272009"));
    List<StopTime> stopTimes = _dao.getStopTimesForTrip(trip);
    assertEquals(22, stopTimes.size());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 2 with StopTime

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

the class HibernateGtfsRelationalDaoImplCaltrainTest method testGetStopTimesForStop.

@Test
public void testGetStopTimesForStop() {
    Stop stop = _dao.getStopForId(aid("Menlo Park Caltrain"));
    List<StopTime> stopTimes = _dao.getStopTimesForStop(stop);
    assertEquals(208, stopTimes.size());
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 3 with StopTime

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

the class EntityRetentionGraph method retainTrip.

private void retainTrip(Trip trip, boolean retainUp) {
    if (retainUp) {
        for (StopTime stopTime : _dao.getStopTimesForTrip(trip)) retainUp(stopTime);
        if (_retainBlocks && trip.getBlockId() != null) {
            AgencyAndId blockId = new AgencyAndId(trip.getId().getAgencyId(), trip.getBlockId());
            retainUp(new BlockIdKey(blockId));
        }
        for (Frequency frequency : _dao.getFrequenciesForTrip(trip)) retainUp(frequency);
    } else {
        retainDown(trip.getRoute());
        retainDown(new ServiceIdKey(trip.getServiceId()));
        AgencyAndId shapeId = trip.getShapeId();
        if (shapeId != null && shapeId.hasValues())
            retainDown(new ShapeIdKey(shapeId));
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ShapeIdKey(org.onebusaway.gtfs_transformer.collections.ShapeIdKey) Frequency(org.onebusaway.gtfs.model.Frequency) ServiceIdKey(org.onebusaway.gtfs_transformer.collections.ServiceIdKey) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 4 with StopTime

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

the class DeduplicateTripsStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Map<String, List<Trip>> tripsByCommonId = new FactoryMap<String, List<Trip>>(new ArrayList<Trip>());
    int total = 0;
    int badIds = 0;
    for (Trip trip : dao.getAllTrips()) {
        AgencyAndId aid = trip.getId();
        String id = aid.getId();
        int index = id.indexOf('_');
        if (index != -1) {
            String commonId = id.substring(index + 1);
            tripsByCommonId.get(commonId).add(trip);
        } else {
            badIds++;
        }
    }
    _log.info("trips=" + total + " badIds=" + badIds);
    int weird = 0;
    int pairs = 0;
    int patternMismatch = 0;
    int propertyMismatch = 0;
    for (List<Trip> trips : tripsByCommonId.values()) {
        if (trips.size() == 1)
            continue;
        if (trips.size() != 2) {
            System.out.println("weird: " + trips);
            weird++;
            continue;
        }
        pairs++;
        Collections.sort(trips, _tripComparator);
        Trip tripA = trips.get(0);
        Trip tripB = trips.get(1);
        List<StopTime> stopTimesA = dao.getStopTimesForTrip(tripA);
        List<StopTime> stopTimesB = dao.getStopTimesForTrip(tripB);
        StopSequencePattern patternA = StopSequencePattern.getPatternForStopTimes(stopTimesA);
        StopSequencePattern patternB = StopSequencePattern.getPatternForStopTimes(stopTimesB);
        if (!patternA.equals(patternB)) {
            System.out.println("  pattern: " + tripA.getId() + " " + tripB.getId());
            patternMismatch++;
            continue;
        }
        String property = areTripsEquivalent(tripA, tripB);
        if (property != null) {
            System.out.println("  property: " + tripA.getId() + " " + tripB.getId() + " " + property);
            propertyMismatch++;
            continue;
        }
    }
    _log.info("weird=" + weird + " pairs=" + pairs + " patternMismatch=" + patternMismatch + " propertyMismatch=" + propertyMismatch);
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) List(java.util.List) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 5 with StopTime

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

the class EnsureStopTimesIncreaseUpdateStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Map<String, List<Trip>> tripsByBlockId = TripsByBlockInSortedOrder.getTripsByBlockInSortedOrder(dao);
    int hits = 0;
    int total = 0;
    int maxDeviation = 0;
    for (List<Trip> trips : tripsByBlockId.values()) {
        for (Trip trip : trips) {
            /*
         * we've moved prev variable inside of trips loop,
         * thus we've stopped comparing trips against each other, but
         * simply compare stop times specific to a trip.
         */
            StopTime prev = null;
            List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
            int stopTimePosition = -1;
            for (StopTime stopTime : stopTimes) {
                total++;
                stopTimePosition++;
                if (prev != null) {
                    if (prev.getDepartureTime() > stopTime.getArrivalTime()) {
                        hits++;
                        int deviation = prev.getDepartureTime() - stopTime.getArrivalTime();
                        maxDeviation = Math.max(maxDeviation, deviation);
                        if (deviation > 60)
                            _log.info("out_of_order_stop_times: prev=" + prev.getDepartureTime() + " stop=" + stopTime.getArrivalTime() + " deviation=" + deviation + " for stopTime " + stopTime + " of trip" + trip + " at " + stopTimePosition + "/" + stopTimes.size());
                        stopTime.setArrivalTime(prev.getDepartureTime());
                        if (stopTime.getDepartureTime() < stopTime.getArrivalTime())
                            stopTime.setDepartureTime(stopTime.getArrivalTime());
                    }
                }
                prev = stopTime;
            }
        }
    }
    _log.info("stop times out of order: " + hits + "/" + total + " maxDeviation=" + maxDeviation);
}
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