Search in sources :

Example 1 with StopsWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesForStopIds.

public StopsWithArrivalsAndDeparturesBean getArrivalsAndDeparturesForStopIds(Set<AgencyAndId> ids, ArrivalsAndDeparturesQueryBean query) throws NoSuchStopServiceException {
    List<StopBean> stops = new ArrayList<StopBean>();
    List<ArrivalAndDepartureBean> allArrivalsAndDepartures = new ArrayList<ArrivalAndDepartureBean>();
    Set<AgencyAndId> allNearbyStopIds = new HashSet<AgencyAndId>();
    Map<String, ServiceAlertBean> situationsById = new HashMap<String, ServiceAlertBean>();
    Counter<TimeZone> timeZones = new Counter<TimeZone>();
    for (AgencyAndId id : ids) {
        StopBean stopBean = _stopBeanService.getStopForId(id);
        stops.add(stopBean);
        List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
        allArrivalsAndDepartures.addAll(arrivalsAndDepartures);
        List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stopBean, 100);
        allNearbyStopIds.addAll(nearbyStopIds);
        TimeZone timeZone = _agencyService.getTimeZoneForAgencyId(id.getAgencyId());
        timeZones.increment(timeZone);
        List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
        for (ServiceAlertBean situation : situations) situationsById.put(situation.getId(), situation);
    }
    allNearbyStopIds.removeAll(ids);
    List<StopBean> nearbyStops = new ArrayList<StopBean>();
    for (AgencyAndId id : allNearbyStopIds) {
        StopBean stop = _stopBeanService.getStopForId(id);
        nearbyStops.add(stop);
    }
    TimeZone timeZone = timeZones.getMax();
    if (timeZone == null)
        timeZone = TimeZone.getDefault();
    StopsWithArrivalsAndDeparturesBean result = new StopsWithArrivalsAndDeparturesBean();
    result.setStops(stops);
    result.setArrivalsAndDepartures(allArrivalsAndDepartures);
    result.setNearbyStops(nearbyStops);
    result.setSituations(new ArrayList<ServiceAlertBean>(situationsById.values()));
    result.setTimeZone(timeZone.getID());
    return result;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) TimeZone(java.util.TimeZone) Counter(org.onebusaway.collections.Counter) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) HashSet(java.util.HashSet)

Example 2 with StopsWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesForRouteAction method getRouteIdsForMatchingRoutes.

private Set<String> getRouteIdsForMatchingRoutes() {
    StopsWithArrivalsAndDeparturesBean result = _model.getResult();
    Set<String> ids = new HashSet<String>();
    for (StopBean stop : result.getStops()) {
        for (RouteBean route : stop.getRoutes()) {
            if (route.getShortName().equals(_route))
                ids.add(route.getId());
        }
    }
    return ids;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) StopBean(org.onebusaway.transit_data.model.StopBean) HashSet(java.util.HashSet)

Example 3 with StopsWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesTemplate method buildTemplate.

@Override
public void buildTemplate(ActionContext context) {
    ValueStack valueStack = context.getValueStack();
    PhoneArrivalsAndDeparturesModel model = (PhoneArrivalsAndDeparturesModel) valueStack.findValue("model");
    StopsWithArrivalsAndDeparturesBean result = model.getResult();
    buildPredictedArrivalsTemplate(result.getArrivalsAndDepartures());
    addMessage(Messages.ARRIVAL_INFO_ON_SPECIFIC_ROUTE);
    AgiActionName byRouteAction = addActionWithParameterFromMatch("1(\\d+)#", "/stop/arrivalsAndDeparturesForRoute", "route", 1);
    byRouteAction.putParam("model", model);
    addMessage(Messages.ARRIVAL_INFO_BOOKMARK_THIS_LOCATION);
    AgiActionName bookmarkAction = addAction("2", "/stop/bookmark");
    bookmarkAction.putParam("stops", result.getStops());
    addMessage(Messages.ARRIVAL_INFO_RETURN_TO_MAIN_MENU);
    addAction("3", "/index");
    addAction("(#|[04-9]|1.*\\*)", "/repeat");
    addMessage(Messages.HOW_TO_GO_BACK);
    addAction("\\*", "/back");
    addMessage(Messages.TO_REPEAT);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) PhoneArrivalsAndDeparturesModel(org.onebusaway.phone.impl.PhoneArrivalsAndDeparturesModel) AgiActionName(org.onebusaway.probablecalls.AgiActionName)

Example 4 with StopsWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesAction method displayData.

private String displayData() {
    PhoneArrivalsAndDeparturesModel model = (PhoneArrivalsAndDeparturesModel) sessionMap.get("_model");
    StopsWithArrivalsAndDeparturesBean result = model.getResult();
    buildPredictedArrivals(result.getArrivalsAndDepartures(), result.getStops());
    setNextAction("stops/arrivals-and-departures");
    _log.debug("setting navState, have stopIds=" + model.getStopIds());
    sessionMap.put("navState", new Integer(DO_ROUTING));
    sessionMap.put("stopIds", model.getStopIds());
    sessionMap.put("stops", result.getStops());
    return SUCCESS;
}
Also used : StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) PhoneArrivalsAndDeparturesModel(org.onebusaway.twilio.impl.PhoneArrivalsAndDeparturesModel)

Example 5 with StopsWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesAction method filterArrivalsAndDeparturesByRoute.

private void filterArrivalsAndDeparturesByRoute(String[] tokens) {
    // Filter by route
    Set<String> routes = new HashSet<String>();
    for (String token : tokens) {
        String[] routeNames = token.split(",");
        for (String routeName : routeNames) routes.add(routeName);
    }
    StopsWithArrivalsAndDeparturesBean result = _model.getResult();
    Iterator<ArrivalAndDepartureBean> it = result.getArrivalsAndDepartures().iterator();
    while (it.hasNext()) {
        ArrivalAndDepartureBean bean = it.next();
        TripBean trip = bean.getTrip();
        RouteBean route = trip.getRoute();
        String routeName = RoutePresenter.getNameForRoute(route);
        if (!routes.contains(routeName))
            it.remove();
    }
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) HashSet(java.util.HashSet)

Aggregations

StopsWithArrivalsAndDeparturesBean (org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean)7 HashSet (java.util.HashSet)4 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)4 ArrayList (java.util.ArrayList)3 RouteBean (org.onebusaway.transit_data.model.RouteBean)3 HashMap (java.util.HashMap)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 StopBean (org.onebusaway.transit_data.model.StopBean)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 TimeZone (java.util.TimeZone)1 Counter (org.onebusaway.collections.Counter)1 Body (org.onebusaway.nextbus.model.nextbus.Body)1 DisplayStop (org.onebusaway.nextbus.model.nextbus.DisplayStop)1 ScheduleRoute (org.onebusaway.nextbus.model.nextbus.ScheduleRoute)1 ScheduleStop (org.onebusaway.nextbus.model.nextbus.ScheduleStop)1 ScheduleTableRow (org.onebusaway.nextbus.model.nextbus.ScheduleTableRow)1 PhoneArrivalsAndDeparturesModel (org.onebusaway.phone.impl.PhoneArrivalsAndDeparturesModel)1 AgiActionName (org.onebusaway.probablecalls.AgiActionName)1 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)1 ArrivalsAndDeparturesQueryBean (org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean)1