use of org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImpl method getRouteResult.
@Override
public SearchResult getRouteResult(RouteBean routeBean) {
List<RouteDirection> directions = new ArrayList<RouteDirection>();
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
// create stop ID->stop bean map
Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
for (StopBean stopBean : stopsForRoute.getStops()) {
stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
}
// add stops in both directions
List<VehicleActivityStructure> journeyList = _realtimeService.getVehicleActivityForRoute(routeBean.getId(), null, 0, SystemTime.currentTimeMillis(), false);
Map<String, List<String>> stopIdToDistanceAwayStringMap = new HashMap<String, List<String>>();
Map<String, List<String>> stopIdToVehicleIdMap = new HashMap<String, List<String>>();
Map<String, Boolean> stopIdToRealtimeDataMap = new HashMap<String, Boolean>();
// build map of stop IDs to list of distance strings
for (VehicleActivityStructure journey : journeyList) {
// on detour?
MonitoredCallStructure monitoredCall = journey.getMonitoredVehicleJourney().getMonitoredCall();
if (monitoredCall == null) {
continue;
}
String stopId = monitoredCall.getStopPointRef().getValue();
fillDistanceAwayStringsList(journey.getMonitoredVehicleJourney(), journey.getRecordedAtTime(), stopId, stopIdToDistanceAwayStringMap);
fillVehicleIdsStringList(journey.getMonitoredVehicleJourney(), journey.getRecordedAtTime(), stopId, stopIdToVehicleIdMap);
fillRealtimeData(journey.getMonitoredVehicleJourney(), stopId, stopIdToRealtimeDataMap);
}
List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
for (StopGroupingBean stopGroupingBean : stopGroupings) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
NameBean name = stopGroupBean.getName();
String type = name.getType();
if (!type.equals("destination"))
continue;
// service in this direction
Boolean hasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), stopGroupBean.getId());
// if there are buses on route, always have "scheduled service"
Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForRoute(routeBean.getId(), stopGroupBean.getId(), SystemTime.currentTimeMillis());
if (routeHasVehiclesInService) {
hasUpcomingScheduledService = true;
}
// stops in this direction
List<StopOnRoute> stopsOnRoute = null;
if (!stopGroupBean.getStopIds().isEmpty()) {
stopsOnRoute = new ArrayList<StopOnRoute>();
for (String stopId : stopGroupBean.getStopIds()) {
if (_transitDataService.stopHasRevenueServiceOnRoute((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), stopId, routeBean.getId(), stopGroupBean.getId())) {
stopsOnRoute.add(new StopOnRoute(stopIdToStopBeanMap.get(stopId), stopIdToDistanceAwayStringMap.get(stopId), stopIdToRealtimeDataMap.get(stopId), stopIdToVehicleIdMap.get(stopId)));
}
}
}
directions.add(new RouteDirection(stopGroupBean.getName().getName(), stopGroupBean, stopsOnRoute, hasUpcomingScheduledService, null));
}
}
// service alerts in this direction
Set<String> serviceAlertDescriptions = new HashSet<String>();
List<ServiceAlertBean> serviceAlertBeans = _realtimeService.getServiceAlertsForRoute(routeBean.getId());
populateServiceAlerts(serviceAlertDescriptions, serviceAlertBeans);
return new RouteResult(routeBean, directions, serviceAlertDescriptions);
}
use of org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImpl method getDisplayStringsByHeadsignForStopAndRouteAndDirection.
// stop view
private Map<String, List<StopOnRoute>> getDisplayStringsByHeadsignForStopAndRouteAndDirection(StopBean stopBean, RouteBean routeBean, StopGroupBean stopGroupBean) {
Map<String, List<StopOnRoute>> results = new HashMap<String, List<StopOnRoute>>();
// stop visits
List<MonitoredStopVisitStructure> visitList = _realtimeService.getMonitoredStopVisitsForStop(stopBean.getId(), 0, SystemTime.currentTimeMillis());
for (MonitoredStopVisitStructure visit : visitList) {
String routeId = visit.getMonitoredVehicleJourney().getLineRef().getValue();
if (!routeBean.getId().equals(routeId))
continue;
String directionId = visit.getMonitoredVehicleJourney().getDirectionRef().getValue();
if (directionId != null && !stopGroupBean.getId().equals(directionId))
continue;
// on detour?
MonitoredCallStructure monitoredCall = visit.getMonitoredVehicleJourney().getMonitoredCall();
if (monitoredCall == null)
continue;
if (!results.containsKey(visit.getMonitoredVehicleJourney().getDestinationName().getValue()))
results.put(visit.getMonitoredVehicleJourney().getDestinationName().getValue(), new ArrayList<StopOnRoute>());
if (results.get(visit.getMonitoredVehicleJourney().getDestinationName().getValue()).size() >= 3)
continue;
String distance = getPresentableDistance(visit.getMonitoredVehicleJourney(), visit.getRecordedAtTime().getTime(), true);
String timePrediction = getPresentableTime(visit.getMonitoredVehicleJourney(), visit.getRecordedAtTime().getTime(), true);
String vehicleId = null;
if (visit.getMonitoredVehicleJourney() != null && visit.getMonitoredVehicleJourney().getVehicleRef() != null) {
vehicleId = visit.getMonitoredVehicleJourney().getVehicleRef().getValue();
} else {
// insert an empty element so it aligns with distanceAways
vehicleId = "N/A";
}
List<String> distanceAways = new ArrayList<String>();
List<String> vehicleIds = new ArrayList<String>();
if (vehicleId.contains("_"))
vehicleId = vehicleId.split("_")[1];
vehicleIds.add(vehicleId);
if (timePrediction != null) {
distanceAways.add(timePrediction);
} else {
distanceAways.add(distance);
}
results.get(visit.getMonitoredVehicleJourney().getDestinationName().getValue()).add(new StopOnRoute(stopBean, distanceAways, visit.getMonitoredVehicleJourney().isMonitored(), vehicleIds));
}
return results;
}
use of org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute in project onebusaway-application-modules by camsys.
the class SearchResultFactoryImpl method getStopResult.
@Override
public SearchResult getStopResult(StopBean stopBean, Set<RouteBean> routeFilter) {
List<RouteAtStop> routesWithArrivals = new ArrayList<RouteAtStop>();
List<RouteAtStop> routesWithNoVehiclesEnRoute = new ArrayList<RouteAtStop>();
List<RouteAtStop> routesWithNoScheduledService = new ArrayList<RouteAtStop>();
List<RouteBean> filteredRoutes = new ArrayList<RouteBean>();
Set<String> serviceAlertDescriptions = new HashSet<String>();
for (RouteBean routeBean : stopBean.getRoutes()) {
if (routeFilter != null && !routeFilter.isEmpty() && !routeFilter.contains(routeBean)) {
filteredRoutes.add(routeBean);
continue;
}
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
List<RouteDirection> directions = new ArrayList<RouteDirection>();
List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
for (StopGroupingBean stopGroupingBean : stopGroupings) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
NameBean name = stopGroupBean.getName();
String type = name.getType();
if (!type.equals("destination"))
continue;
// filter out route directions that don't stop at this stop
if (!stopGroupBean.getStopIds().contains(stopBean.getId()))
continue;
// arrivals in this direction
Map<String, List<StopOnRoute>> arrivalsForRouteAndDirection = getDisplayStringsByHeadsignForStopAndRouteAndDirection(stopBean, routeBean, stopGroupBean);
// service alerts for this route + direction
List<ServiceAlertBean> serviceAlertBeans = _realtimeService.getServiceAlertsForRouteAndDirection(routeBean.getId(), stopGroupBean.getId());
populateServiceAlerts(serviceAlertDescriptions, serviceAlertBeans);
// service in this direction
Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
// if there are buses on route, always have "scheduled service"
if (!arrivalsForRouteAndDirection.isEmpty()) {
hasUpcomingScheduledService = true;
}
if (arrivalsForRouteAndDirection.isEmpty()) {
directions.add(new RouteDirection(stopGroupBean.getName().getName(), stopGroupBean, Collections.<StopOnRoute>emptyList(), hasUpcomingScheduledService, Collections.<String>emptyList()));
} else {
for (Map.Entry<String, List<StopOnRoute>> entry : arrivalsForRouteAndDirection.entrySet()) {
directions.add(new RouteDirection(entry.getKey(), stopGroupBean, entry.getValue(), hasUpcomingScheduledService, Collections.<String>emptyList()));
}
}
}
}
// Now one RouteAtStop object exists for each direction for each route.
for (RouteDirection direction : directions) {
List<RouteDirection> directionList = Collections.<RouteDirection>singletonList(direction);
RouteAtStop routeAtStop = new RouteAtStop(routeBean, directionList, serviceAlertDescriptions);
if (!direction.getStops().isEmpty())
routesWithArrivals.add(routeAtStop);
else if (Boolean.FALSE.equals(direction.getHasUpcomingScheduledService()))
routesWithNoScheduledService.add(routeAtStop);
else
routesWithNoVehiclesEnRoute.add(routeAtStop);
}
}
return new StopResult(stopBean, routesWithArrivals, routesWithNoVehiclesEnRoute, routesWithNoScheduledService, filteredRoutes, serviceAlertDescriptions);
}
Aggregations