Search in sources :

Example 11 with StopTime

use of org.onebusaway.gtfs.model.StopTime 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;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 12 with StopTime

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

the class WSFScheduleService method resolve.

public Trip resolve(String departingTerminalId, long departureTime, String arrivingTerminalId) {
    ServiceDate initialServiceDate = new ServiceDate(new Date(departureTime * 1000));
    int lookBackDays = (_maxStopTime / 86400) + 1;
    AgencyAndId stopId = new AgencyAndId(_agencyId, departingTerminalId);
    AgencyAndId routeId = new AgencyAndId(_agencyId, departingTerminalId + arrivingTerminalId);
    for (StopTime st : _dao.getAllStopTimes()) {
        if (st.getStop().getId().equals(stopId) && st.getTrip().getRoute().getId().equals(routeId)) {
            ServiceDate sd = initialServiceDate;
            for (int i = 0; i < lookBackDays; i++) {
                if (_csd.getServiceIdsForDate(sd).contains(st.getTrip().getServiceId()) && st.getDepartureTime() == (departureTime - (sd.getAsCalendar(_agencyTimeZone).getTimeInMillis() / 1000))) {
                    return st.getTrip();
                }
                sd = sd.previous();
            }
        }
    }
    _log.warn("no trip found for resolve(departId=" + departingTerminalId + ", departureTime=" + departureTime + ", arrivalId=" + arrivingTerminalId + ")");
    return null;
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 13 with StopTime

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

the class StopMergeStrategy method replaceDuplicateEntry.

@Override
protected void replaceDuplicateEntry(GtfsMergeContext context, Stop oldStop, Stop newStop) {
    GtfsRelationalDao source = context.getSource();
    for (StopTime stopTime : source.getStopTimesForStop(oldStop)) {
        stopTime.setStop(newStop);
    }
    MergeSupport.bulkReplaceValueInProperties(source.getAllTransfers(), oldStop, newStop, "fromStop", "toStop");
    MergeSupport.bulkReplaceValueInProperties(source.getAllPathways(), oldStop, newStop, "fromStop", "toStop");
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 14 with StopTime

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

the class TrimTripTransformStrategy method getStopIndices.

private Map<String, Integer> getStopIndices(List<StopTime> stopTimes) {
    Map<String, Integer> indices = new HashMap<String, Integer>();
    int index = 0;
    for (StopTime stopTime : stopTimes) {
        String id = stopTime.getStop().getId().getId();
        if (!indices.containsKey(id)) {
            indices.put(id, index);
        }
        index++;
    }
    return indices;
}
Also used : HashMap(java.util.HashMap) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 15 with StopTime

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