use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl in project onebusaway-application-modules by camsys.
the class RouteCollectionEntriesFactory method createRouteShortNameRouteCollectionMapping.
private void createRouteShortNameRouteCollectionMapping(TransitGraphImpl graph) {
Map<AgencyAndId, List<RouteEntryImpl>> routesByKey = new HashMap<AgencyAndId, List<RouteEntryImpl>>();
for (RouteEntryImpl routeEntry : graph.getRoutes()) {
Route route = _gtfsDao.getRouteForId(routeEntry.getId());
AgencyAndId key = getRouteCollectionIdForRoute(route);
List<RouteEntryImpl> forKey = routesByKey.get(key);
if (forKey == null) {
forKey = new ArrayList<RouteEntryImpl>();
routesByKey.put(key, forKey);
}
forKey.add(routeEntry);
}
for (Map.Entry<AgencyAndId, List<RouteEntryImpl>> entry : routesByKey.entrySet()) {
AgencyAndId key = entry.getKey();
List<RouteEntryImpl> routesForKey = entry.getValue();
ArrayList<RouteEntry> children = new ArrayList<RouteEntry>();
children.addAll(routesForKey);
children.trimToSize();
key = _uniqueService.unique(key);
RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
routeCollectionEntry.setId(key);
routeCollectionEntry.setChildren(children);
graph.putRouteCollectionEntry(routeCollectionEntry);
for (RouteEntryImpl route : routesForKey) route.setParent(routeCollectionEntry);
}
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl in project onebusaway-application-modules by camsys.
the class RouteCollectionEntriesFactory method createOneToOneRouteCollectionMapping.
private void createOneToOneRouteCollectionMapping(TransitGraphImpl graph) {
for (RouteEntryImpl routeEntry : graph.getRoutes()) {
RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
routeCollectionEntry.setId(routeEntry.getId());
ArrayList<RouteEntry> routes = new ArrayList<RouteEntry>();
routes.add(routeEntry);
routes.trimToSize();
routeCollectionEntry.setChildren(routes);
graph.putRouteCollectionEntry(routeCollectionEntry);
routeEntry.setParent(routeCollectionEntry);
}
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl in project onebusaway-application-modules by camsys.
the class GenerateNarrativesTaskTest method testGenerateRouteNarratives.
@Test
public void testGenerateRouteNarratives() {
RouteEntryImpl r1 = route("routeA1");
RouteEntryImpl r2 = route("routeA2");
RouteCollectionEntryImpl rc = routeCollection("routeA", r1, r2);
TripEntry t1 = trip("t1");
TripEntry t2 = trip("t2");
TripEntry t3 = trip("t3");
// r2's values should win out over r1's because it has more trips
r1.setTrips(Arrays.asList(t1));
r2.setTrips(Arrays.asList(t2, t3));
Mockito.when(_transitGraphDao.getAllRouteCollections()).thenReturn(Arrays.asList((RouteCollectionEntry) rc));
Route route1 = new Route();
route1.setId(r1.getId());
route1.setBikesAllowed(0);
route1.setColor("#000000");
route1.setDesc("Route One Desc");
route1.setLongName("Route One");
route1.setShortName("One");
route1.setTextColor("#ff0000");
route1.setType(3);
route1.setUrl("http://agency.gov/route-one");
Route route2 = new Route();
route2.setId(r2.getId());
route2.setBikesAllowed(1);
route2.setColor("#0000ff");
route2.setDesc("Route Two Desc");
route2.setLongName("Route Two");
route2.setShortName("Two");
route2.setTextColor("#000000");
route2.setType(3);
route2.setUrl("http://agency.gov/route-two");
Mockito.when(_gtfsDao.getRouteForId(r1.getId())).thenReturn(route1);
Mockito.when(_gtfsDao.getRouteForId(r2.getId())).thenReturn(route2);
_task.generateRouteNarratives(_provider);
RouteCollectionNarrative narrative = _provider.getNarrativeForRouteCollectionId(rc.getId());
assertEquals(route2.getColor(), narrative.getColor());
assertEquals(route2.getDesc(), narrative.getDescription());
assertEquals(route2.getLongName(), narrative.getLongName());
assertEquals(route2.getShortName(), narrative.getShortName());
assertEquals(route2.getTextColor(), narrative.getTextColor());
assertEquals(route2.getType(), narrative.getType());
assertEquals(route2.getUrl(), narrative.getUrl());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl in project onebusaway-application-modules by camsys.
the class RouteEntriesFactoryTest method testProcessRoutes.
@Test
public void testProcessRoutes() {
GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
Agency agency = new Agency();
agency.setId("A");
Route routeA = new Route();
routeA.setAgency(agency);
routeA.setId(new AgencyAndId("A", "routeA"));
Route routeB = new Route();
routeB.setAgency(agency);
routeB.setId(new AgencyAndId("A", "routeB"));
Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(routeA, routeB));
TransitGraphImpl graph = new TransitGraphImpl();
RouteEntriesFactory factory = new RouteEntriesFactory();
factory.setGtfsDao(gtfsDao);
factory.setUniqueService(new UniqueServiceImpl());
factory.processRoutes(graph);
RouteEntryImpl routeEntryA = graph.getRouteForId(routeA.getId());
RouteEntryImpl routeEntryB = graph.getRouteForId(routeB.getId());
List<RouteEntry> routes = graph.getAllRoutes();
assertEquals(2, routes.size());
assertTrue(routes.contains(routeEntryA));
assertTrue(routes.contains(routeEntryB));
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl in project onebusaway-application-modules by camsys.
the class TripEntriesFactory method processTrips.
public void processTrips(TransitGraphImpl graph) {
Collection<Route> routes = _gtfsDao.getAllRoutes();
int routeIndex = 0;
for (Route route : routes) {
_log.info("route processed: " + routeIndex + "/" + routes.size());
routeIndex++;
List<Trip> tripsForRoute = _gtfsDao.getTripsForRoute(route);
int tripCount = tripsForRoute.size();
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(tripCount);
_log.info("trips to process: " + tripCount);
int tripIndex = 0;
RouteEntryImpl routeEntry = graph.getRouteForId(route.getId());
ArrayList<TripEntry> tripEntries = new ArrayList<TripEntry>();
for (Trip trip : tripsForRoute) {
tripIndex++;
if (tripIndex % logInterval == 0)
_log.info("trips processed: " + tripIndex + "/" + tripsForRoute.size());
TripEntryImpl tripEntry = processTrip(graph, trip);
if (tripEntry != null) {
tripEntry.setRoute(routeEntry);
tripEntries.add(tripEntry);
}
}
tripEntries.trimToSize();
routeEntry.setTrips(tripEntries);
}
if (_stopTimeEntriesFactory.getInvalidStopToShapeMappingExceptionCount() > 0 && _throwExceptionOnInvalidStopToShapeMappingException) {
throw new IllegalStateException("Multiple instances of InvalidStopToShapeMappingException thrown: count=" + _stopTimeEntriesFactory.getInvalidStopToShapeMappingExceptionCount() + ". For more information on errors of this kind, see:\n" + " https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
}
graph.refreshTripMapping();
}
Aggregations