Search in sources :

Example 51 with Trip

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

the class PierceTransitTripHeadsignCleanupModStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao, Object entity) {
    if (!(entity instanceof Trip))
        return;
    Trip trip = (Trip) entity;
    String headsign = trip.getTripHeadsign();
    Route route = trip.getRoute();
    String shortName = route.getShortName();
    if (headsign == null || shortName == null)
        return;
    headsign = headsign.replaceAll("^" + shortName + "\\s+", "");
    headsign = headsign.replaceAll("-\\s+" + shortName + "\\s+", "- ");
    trip.setTripHeadsign(headsign);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Route(org.onebusaway.gtfs.model.Route)

Example 52 with Trip

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

the class WSFScheduleService method setBlockIdsFromSchedResponse.

private void setBlockIdsFromSchedResponse(SchedResponse resp) {
    List<SchedTerminalCombo> combos = resp.getTerminalCombos().getValue().getSchedTerminalCombo();
    for (SchedTerminalCombo stc : combos) {
        String depart = stc.getDepartingTerminalID().toString();
        String arrive = stc.getArrivingTerminalID().toString();
        for (SchedTime sched : schedTime(stc)) {
            long time = ts(sched.getDepartingTime());
            Trip trip = _tripResolutionService.resolve(depart, time, arrive);
            if (trip != null) {
                trip.setBlockId(sched.getVesselID().toString());
            } else {
                _log.warn("Skipping schedTime due to no matching trip {}", sched.toString());
            }
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) SchedTerminalCombo(gov.wa.wsdot.ferries.schedule.SchedTerminalCombo) SchedTime(gov.wa.wsdot.ferries.schedule.SchedTime)

Example 53 with Trip

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

the class MergeRouteFromReferenceStrategyById method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
    ArrayList<Route> routesToRemove = new ArrayList();
    HashMap<String, Route> referenceRoutes = new HashMap<>();
    for (Route route : reference.getAllRoutes()) {
        referenceRoutes.put(route.getId().getId(), route);
    }
    _log.info("Routes: {}, Trips: {}", dao.getAllRoutes().size(), dao.getAllTrips().size());
    for (Route route : dao.getAllRoutes()) {
        String identifier = route.getId().getId();
        Route refRoute = referenceRoutes.get(identifier);
        if (refRoute != null) {
            setRoute(route, refRoute);
        } else {
            // if yes, check if it matches w/out LTD
            if (identifier.contains("-LTD")) {
                identifier = identifier.replace("-LTD", "");
                refRoute = referenceRoutes.get(identifier);
                if (refRoute != null) {
                    updateTripHeadsign(dao, route);
                    // dao.getRouteForId only works with route ids that have not changed at all from input
                    if (dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), refRoute.getId().getId())) != null) {
                        routesToRemove.add(route);
                        for (Trip trip : dao.getTripsForRoute(route)) {
                            trip.setRoute(dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), refRoute.getId().getId())));
                        }
                    } else // otherwise, update the route id etc
                    {
                        setLTDRoute(route, refRoute);
                    }
                } else if (identifier.equals("Q6")) {
                    refRoute = referenceRoutes.get("Q06");
                    if (refRoute != null) {
                        updateTripHeadsign(dao, route);
                        if (dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), "Q6")) != null) {
                            routesToRemove.add(route);
                            for (Trip trip : dao.getTripsForRoute(route)) {
                                trip.setRoute(dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), "Q6")));
                            }
                        }
                    }
                } else {
                    _log.info("No reference route for route: " + route.getId().getId());
                }
            }
        }
    }
    _log.info("Routes to remove: " + routesToRemove.size());
    for (Route route : routesToRemove) {
        dao.removeEntity(route);
    }
    _log.info("Routes: {}, Trips: {}", dao.getAllRoutes().size(), dao.getAllTrips().size());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Route(org.onebusaway.gtfs.model.Route)

Example 54 with Trip

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

the class InterpolateStopTimesFromTimePointsStrategy method interpolateArrivalAndDepartureTimes.

private void interpolateArrivalAndDepartureTimes(GtfsMutableRelationalDao dao, Map<String, List<Trip>> tripsByBlockId) {
    for (List<Trip> trips : tripsByBlockId.values()) {
        for (Trip trip : trips) {
            List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
            double[] distanceTraveled = getDistanceTraveledForStopTimes(stopTimes);
            int[] arrivalTimes = new int[stopTimes.size()];
            int[] departureTimes = new int[stopTimes.size()];
            interpolateArrivalAndDepartureTimes(dao, stopTimes, distanceTraveled, arrivalTimes, departureTimes);
            // arrival and departure times represent adjusted values
            // set them back on the dao
            int sequence = 0;
            for (StopTime stopTime : stopTimes) {
                stopTime.setArrivalTime(arrivalTimes[sequence]);
                stopTime.setDepartureTime(departureTimes[sequence]);
                sequence++;
                dao.updateEntity(stopTime);
            }
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 55 with Trip

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

the class LastStopToHeadsignStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    for (Trip trip : dao.getAllTrips()) {
        List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
        StopLocation lastStop = stopTimes.get(stopTimes.size() - 1).getStop();
        trip.setTripHeadsign(lastStop.getName());
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) StopLocation(org.onebusaway.gtfs.model.StopLocation) StopTime(org.onebusaway.gtfs.model.StopTime)

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10