use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImpl method getStopBeansForRoute.
private List<StopBean> getStopBeansForRoute(AgencyAndId routeId) {
Collection<AgencyAndId> stopIds = _routeService.getStopsForRouteCollection(routeId);
List<StopBean> stops = new ArrayList<StopBean>();
for (AgencyAndId stopId : stopIds) {
StopBean stop = _stopBeanService.getStopForId(stopId);
stops.add(stop);
}
return stops;
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method getStopTimeInstanceAsBean.
/**
**
* Private Methods
***
*/
private ArrivalAndDepartureBean getStopTimeInstanceAsBean(long time, ArrivalAndDepartureInstance instance, Map<AgencyAndId, StopBean> stopBeanCache) {
ArrivalAndDepartureBean pab = new ArrivalAndDepartureBean();
pab.setServiceDate(instance.getServiceDate());
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
BlockTripEntry blockTrip = blockStopTime.getTrip();
StopTimeEntry stopTime = blockStopTime.getStopTime();
StopEntry stop = stopTime.getStop();
TripEntry trip = stopTime.getTrip();
TripBean tripBean = _tripBeanService.getTripForId(trip.getId());
pab.setTrip(tripBean);
pab.setBlockTripSequence(blockTrip.getSequence());
pab.setArrivalEnabled(stopTime.getSequence() > 0);
pab.setDepartureEnabled(stopTime.getSequence() + 1 < trip.getStopTimes().size());
StopTimeNarrative stopTimeNarrative = _narrativeService.getStopTimeForEntry(stopTime);
pab.setRouteShortName(stopTimeNarrative.getRouteShortName());
pab.setTripHeadsign(stopTimeNarrative.getStopHeadsign());
StopBean stopBean = stopBeanCache.get(stop.getId());
if (stopBean == null) {
stopBean = _stopBeanService.getStopForId(stop.getId());
stopBeanCache.put(stop.getId(), stopBean);
}
pab.setStop(stopBean);
pab.setStopSequence(stopTime.getSequence());
pab.setTotalStopsInTrip(stopTime.getTotalStopsInTrip());
pab.setStatus("default");
pab.setScheduledArrivalTime(instance.getScheduledArrivalTime());
pab.setScheduledDepartureTime(instance.getScheduledDepartureTime());
FrequencyEntry frequency = instance.getFrequencyLabel();
pab.setFrequency(null);
if (frequency != null) {
FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(instance.getServiceDate(), frequency);
pab.setFrequency(fb);
}
return pab;
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method getArrivalAndDepartureForStop.
@Override
public ArrivalAndDepartureBean getArrivalAndDepartureForStop(ArrivalAndDepartureQuery query) {
long time = query.getTime();
ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
if (instance == null) {
return null;
}
ArrivalAndDepartureBean bean = getStopTimeInstanceAsBean(time, instance, new HashMap<AgencyAndId, StopBean>());
applyBlockLocationToBean(instance, bean, time);
applySituationsToBean(time, instance, bean);
if (!this.useScheduleDeviationHistory) {
return bean;
}
int step = 120;
ScheduleDeviationHistogram histo = _realTimeHistoryService.getScheduleDeviationHistogramForArrivalAndDepartureInstance(instance, step);
if (histo != null) {
int[] sds = histo.getScheduleDeviations();
double[] values = new double[sds.length];
String[] labels = new String[sds.length];
for (int i = 0; i < sds.length; i++) {
int sd = sds[i];
values[i] = sd;
labels[i] = Integer.toString(sd / 60);
}
HistogramBean hb = new HistogramBean();
hb.setValues(values);
hb.setCounts(histo.getCounts());
hb.setLabels(labels);
bean.setScheduleDeviationHistogram(hb);
}
return bean;
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getRouteResult.
private RouteResult getRouteResult(RouteBean routeBean, Map<Filters, String> filters) {
List<RouteDirection> directions = new ArrayList<RouteDirection>();
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
// Filter Values
String directionIdFilter = filters.get(Filters.DIRECTION_REF);
String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
// create stop ID->stop bean map
Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
for (StopBean stopBean : stopsForRoute.getStops()) {
stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
}
List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
for (StopGroupingBean stopGroupingBean : stopGroupings) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
NameBean name = stopGroupBean.getName();
String type = name.getType();
String directionId = stopGroupBean.getId();
// Destination and DirectionId Filter
if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
continue;
List<String> polylines = new ArrayList<String>();
for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
polylines.add(polyline.getPoints());
}
// TODO - Re-evaluate the best method to determine upcoming scheduled service
Boolean routeHasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), directionId);
// if there are buses on route, always have "scheduled service"
Boolean routeHasVehiclesInService = getVehiclesInServiceForRoute(routeBean.getId(), directionId, SystemTime.currentTimeMillis());
if (routeHasVehiclesInService) {
routeHasUpcomingScheduledService = true;
}
String hasUpcomingScheduledServiceVal = String.valueOf(routeHasUpcomingScheduledService);
// String hasUpcomingScheduledServiceVal = String.valueOf(routeHasVehiclesInService);
if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter) || routeHasUpcomingScheduledService == null || !routeHasUpcomingScheduledService)
continue;
// stops in this direction
List<StopOnRoute> stopsOnRoute = null;
if (!stopGroupBean.getStopIds().isEmpty()) {
stopsOnRoute = new ArrayList<StopOnRoute>();
for (String stopId : stopGroupBean.getStopIds()) {
// service in this direction
StopBean stopBean = stopIdToStopBeanMap.get(stopId);
Boolean stopHasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
stopsOnRoute.add(new StopOnRoute(stopBean, stopHasUpcomingScheduledService));
}
}
directions.add(new RouteDirection(stopGroupBean, polylines, stopsOnRoute, routeHasUpcomingScheduledService));
}
}
return new RouteResult(routeBean, directions);
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method processAnnotatedStopPoints.
private void processAnnotatedStopPoints(List<String> agencyIds, List<AgencyAndId> routeIds, List<StopBean> stopBeans, List<AnnotatedStopPointStructure> annotatedStopPoints, Map<Filters, String> filters, Map<String, StopsForRouteBean> stopsForRouteCache, DetailLevel detailLevel, long currentTime) {
for (StopBean stopBean : stopBeans) {
List<StopsForRouteBean> stopsForRouteList = new ArrayList<StopsForRouteBean>();
boolean filterByLineRef = (routeIds != null && routeIds.size() > 0) ? true : false;
boolean containsLineRef = false;
// Get a list of all the routes for the stop
for (RouteBean route : stopBean.getRoutes()) {
// Filter By AgencyID
if (route.getAgency() == null || !agencyIds.contains(route.getAgency().getId()))
continue;
// Add list of stops retreived from route to cache
StopsForRouteBean stopsForRoute = stopsForRouteCache.get(route.getId());
if (stopsForRoute == null) {
stopsForRoute = _transitDataService.getStopsForRoute(route.getId());
stopsForRouteCache.put(route.getId(), stopsForRoute);
}
if (stopsForRoute != null)
stopsForRouteList.add(stopsForRoute);
if (filterByLineRef && routeIds.contains(AgencyAndIdLibrary.convertFromString(route.getId())))
containsLineRef = true;
}
// Filter By LineRef
if (filterByLineRef && !containsLineRef)
continue;
// Get Stops with List of Routes, Direction, and Upcoming Service Info
StopRouteDirection stopRouteDirection = getStopRouteDirection(stopBean, stopsForRouteList, filters);
// Skip if No Route Directions Found
if (stopRouteDirection == null)
continue;
// Used to filter stops that don't have any routes that match hasUpcomingScheduledStop
if (stopRouteDirection.getRouteDirections() == null || stopRouteDirection.getRouteDirections().size() == 0)
continue;
AnnotatedStopPointStructure annotatedStopPoint = new AnnotatedStopPointStructure();
boolean isValid = SiriSupportV2.fillAnnotatedStopPointStructure(annotatedStopPoint, stopRouteDirection, filters, detailLevel, currentTime);
if (isValid)
annotatedStopPoints.add(annotatedStopPoint);
}
}
Aggregations