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);
}
}
}
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);
}
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);
}
}
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);
}
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");
}
}
}
Aggregations