Search in sources :

Example 81 with Route

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

the class EnsureRouteLongNameExists method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    // <route, <headsign, count>>
    HashMap<AgencyAndId, HashMap<String, Integer>> routeToHeadsignToCount = new HashMap();
    Collection<Trip> trips = dao.getAllTrips();
    // go through each trip
    for (Trip trip : trips) {
        AgencyAndId routeId = trip.getRoute().getId();
        String headsign = trip.getTripHeadsign();
        // check route
        HashMap<String, Integer> headsignCounts = routeToHeadsignToCount.get(trip.getRoute().getId());
        if (headsignCounts == null) {
            headsignCounts = new HashMap<>();
            routeToHeadsignToCount.put(routeId, headsignCounts);
        }
        if (headsignCounts.get(headsign) == null) {
            headsignCounts.put(headsign, 0);
        }
        headsignCounts.put(headsign, headsignCounts.get(headsign) + 1);
    }
    for (Map.Entry<AgencyAndId, HashMap<String, Integer>> routeToHeadsignToCountEntry : routeToHeadsignToCount.entrySet()) {
        String h1 = "";
        String h2 = "";
        int n1 = 0;
        int n2 = 0;
        for (Map.Entry<String, Integer> headsignCount : routeToHeadsignToCountEntry.getValue().entrySet()) {
            int n = headsignCount.getValue();
            String h = headsignCount.getKey();
            if (n > n2) {
                if (n > n1) {
                    n2 = n1;
                    n1 = n;
                    h2 = h1;
                    h1 = h;
                } else {
                    n2 = n;
                    h2 = h;
                }
            }
        }
        Route route = dao.getRouteForId(routeToHeadsignToCountEntry.getKey());
        if (route.getLongName() != null) {
            route.setLongName(h1 + " - " + h2);
            dao.updateEntity(route);
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Route(org.onebusaway.gtfs.model.Route)

Example 82 with Route

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

the class AddOmnyBusData method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    int stop_count = 0;
    int route_count = 0;
    // Per MOTP-1770 all stops/routes are now OMNY enabled.
    for (Stop stop : dao.getAllStops()) {
        stop.setRegionalFareCardAccepted(1);
        stop_count++;
    }
    for (Route route : dao.getAllRoutes()) {
        route.setRegionalFareCardAccepted(1);
        route_count++;
    }
    _log.info("Set {} stops and {} routes to omny_enabled Y", stop_count, route_count);
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route)

Example 83 with Route

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

the class MergeRouteAndRemoveShuttles method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
    HashMap<String, Route> referenceRoutes = new HashMap<>();
    for (Route route : reference.getAllRoutes()) {
        referenceRoutes.put(route.getId().getId(), route);
    }
    ArrayList<Route> routesToRemove = new ArrayList<Route>();
    for (Route route : dao.getAllRoutes()) {
        String identifier = route.getId().getId();
        // remove the shuttle routes.  They all appear to be -SS
        if (identifier.contains("-SS")) {
            _log.info("Removing route: " + identifier);
            routesToRemove.add(route);
        } else if (identifier.length() > 2) {
            identifier = identifier.substring(0, 2);
        }
        Route refRoute = referenceRoutes.get(identifier);
        if (refRoute != null) {
            route.setShortName(refRoute.getShortName());
            route.setLongName(refRoute.getLongName());
            route.setType(refRoute.getType());
            route.setDesc(refRoute.getDesc());
            route.setUrl(refRoute.getUrl());
            route.setColor(refRoute.getColor());
            route.setTextColor(refRoute.getTextColor());
            route.setId(refRoute.getId());
        }
    }
    for (Route route : routesToRemove) {
        removeEntityLibrary.removeRoute(dao, route);
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Route(org.onebusaway.gtfs.model.Route)

Example 84 with Route

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

the class CalendarSimplicationStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
    Map<Set<AgencyAndId>, AgencyAndId> serviceIdsToUpdatedServiceId = new HashMap<Set<AgencyAndId>, AgencyAndId>();
    Map<AgencyAndId, List<AgencyAndId>> mergeToolIdMapping = computeMergeToolIdMapping(dao);
    for (Route route : dao.getAllRoutes()) {
        Map<TripKey, List<Trip>> tripsByKey = TripKey.groupTripsForRouteByKey(dao, route);
        Map<Set<AgencyAndId>, List<TripKey>> tripKeysByServiceIds = _library.groupTripKeysByServiceIds(tripsByKey);
        for (Set<AgencyAndId> serviceIds : tripKeysByServiceIds.keySet()) {
            AgencyAndId updatedServiceId = createUpdatedServiceId(serviceIdsToUpdatedServiceId, serviceIds);
            for (TripKey tripKey : tripKeysByServiceIds.get(serviceIds)) {
                List<Trip> tripsForKey = tripsByKey.get(tripKey);
                Trip tripToKeep = tripsForKey.get(0);
                tripToKeep.setServiceId(updatedServiceId);
                for (int i = 1; i < tripsForKey.size(); i++) {
                    Trip trip = tripsForKey.get(i);
                    removeEntityLibrary.removeTrip(dao, trip);
                }
                if (undoGoogleTransitDataFeedMergeTool) {
                    AgencyAndId updatedTripId = computeUpdatedTripIdForMergedTripsIfApplicable(mergeToolIdMapping, tripsForKey);
                    if (updatedTripId != null) {
                        tripToKeep.setId(updatedTripId);
                    }
                }
            }
        }
    }
    CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(dao);
    List<Object> newEntities = new ArrayList<Object>();
    for (Map.Entry<Set<AgencyAndId>, AgencyAndId> entry : serviceIdsToUpdatedServiceId.entrySet()) {
        Set<ServiceDate> allServiceDates = getServiceDatesForServiceIds(calendarService, entry.getKey());
        ServiceCalendarSummary summary = _library.getSummaryForServiceDates(allServiceDates);
        _library.computeSimplifiedCalendar(entry.getValue(), summary, newEntities);
    }
    saveUpdatedCalendarEntities(dao, newEntities);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) HashSet(java.util.HashSet) Set(java.util.Set) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) 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) ArrayList(java.util.ArrayList) List(java.util.List) RemoveEntityLibrary(org.onebusaway.gtfs_transformer.impl.RemoveEntityLibrary) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) Route(org.onebusaway.gtfs.model.Route)

Example 85 with Route

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

the class VerifyRouteIds method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    String agency = dao.getAllTrips().iterator().next().getId().getAgencyId();
    File routesFile = new File((String) context.getParameter("verifyRoutesFile"));
    if (!routesFile.exists()) {
        throw new IllegalStateException("verifyRouteIds Routes file does not exist: " + routesFile.getName());
    }
    List<String> routeLines = new InputLibrary().readList((String) context.getParameter("verifyRoutesFile"));
    _log.info("Length of route file: {}", routeLines.size());
    for (String routeInfo : routeLines) {
        String[] routeArray = routeInfo.split(",");
        if (routeArray == null) {
            _log.info("routeArray is null");
            continue;
        }
        if (routeArray.length < 2) {
            _log.info("routeArray.length: {} {}", routeArray.length, routeInfo);
            continue;
        }
        String routeId = routeArray[ROUTE_ID];
        String routeName = routeArray[ROUTE_NAME];
        Route route = dao.getRouteForId(new AgencyAndId(agency, routeId));
        if (route != null) {
            if (!route.getLongName().contains(routeName)) {
                _log.error("NJT MNR West of Hudson Route Id->Route name error. CSV routeId: {} routeName: {} GTFS Route id: {}, longName {}", routeId, routeName, route.getId().getId(), route.getLongName());
                throw new IllegalStateException("NJT MNR West of Hudson Route Id->Route name error. Route id is for unexpected route name");
            }
        } else {
            _log.error("NJT MNR West of Hudson Route Id->Route name error. Route id is not present in GTFS. Expected CSV routeId: {} routeName: {}", routeId, routeName);
            throw new IllegalStateException("NJT MNR West of Hudson Route Id->Route name error. Route is null");
        }
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) File(java.io.File) Route(org.onebusaway.gtfs.model.Route)

Aggregations

Route (org.onebusaway.gtfs.model.Route)90 Trip (org.onebusaway.gtfs.model.Trip)52 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 Test (org.junit.Test)33 Stop (org.onebusaway.gtfs.model.Stop)28 Agency (org.onebusaway.gtfs.model.Agency)21 ArrayList (java.util.ArrayList)16 StopTime (org.onebusaway.gtfs.model.StopTime)14 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)12 HashMap (java.util.HashMap)10 Edge (org.opentripplanner.routing.graph.Edge)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)7 List (java.util.List)6 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)6 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5