Search in sources :

Example 6 with StopsWithArrivalsAndDeparturesBean

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

the class ScheduleAction method getModel.

@Override
public Body<ScheduleRoute> getModel() {
    Body<ScheduleRoute> body = new Body<ScheduleRoute>();
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    if (this.isValid(body, routeIds)) {
        AgencyBean agency = _transitDataService.getAgency(agencyId);
        List<HashMap<String, HashSet<ScheduleStop>>> blockStopsMapList = new ArrayList<HashMap<String, HashSet<ScheduleStop>>>();
        blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
        blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
        blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
        blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
        // Get All the Stops for a specific route
        for (AgencyAndId routeId : routeIds) {
            String route = AgencyAndId.convertToString(routeId);
            StopsForRouteBean stopsForRoute = _service.getStopsForRoute(route);
            for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
                for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                    // Weekday Trips
                    for (Long weekdayTime : DateUtil.getWeekdayDateTimes(agency.getTimezone())) {
                        ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
                        query.setTime(weekdayTime);
                        query.setMinutesBefore(0);
                        query.setMinutesAfter(MINUTES_IN_DAY);
                        StopsWithArrivalsAndDeparturesBean stopsWithArrivals = _service.getStopsWithArrivalsAndDepartures(stopGroupBean.getStopIds(), query);
                        for (ArrivalAndDepartureBean arrivalsAndDeparture : stopsWithArrivals.getArrivalsAndDepartures()) {
                            // Filter Arrivals and Departures By Route
                            if (arrivalsAndDeparture.getTrip().getRoute().getId().equals(route)) {
                                ScheduleStop scheduleStop = new ScheduleStop();
                                scheduleStop.setTag(getIdNoAgency(arrivalsAndDeparture.getStop().getId()));
                                scheduleStop.setEpochTime(arrivalsAndDeparture.getScheduledArrivalTime());
                                scheduleStop.setStopName(arrivalsAndDeparture.getStop().getName());
                                if (arrivalsAndDeparture.getTrip().getDirectionId().equals("0")) {
                                    addStopByBlockId(blockStopsMapList.get(0), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
                                } else if (arrivalsAndDeparture.getTrip().getDirectionId().equals("1")) {
                                    addStopByBlockId(blockStopsMapList.get(1), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
                                }
                            }
                        }
                    }
                    // Weekend Trips
                    for (Long weekendTime : DateUtil.getWeekendDateTimes(agency.getTimezone())) {
                        ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
                        query.setTime(weekendTime);
                        query.setMinutesBefore(0);
                        query.setMinutesAfter(MINUTES_IN_DAY);
                        StopsWithArrivalsAndDeparturesBean stopsWithArrivals = _service.getStopsWithArrivalsAndDepartures(stopGroupBean.getStopIds(), query);
                        for (ArrivalAndDepartureBean arrivalsAndDeparture : stopsWithArrivals.getArrivalsAndDepartures()) {
                            // Filter Arrivals and Departures By Route
                            if (arrivalsAndDeparture.getTrip().getRoute().getId().equals(route)) {
                                ScheduleStop scheduleStop = new ScheduleStop();
                                scheduleStop.setTag(getIdNoAgency(arrivalsAndDeparture.getStop().getId()));
                                scheduleStop.setEpochTime(arrivalsAndDeparture.getScheduledArrivalTime());
                                scheduleStop.setStopName(arrivalsAndDeparture.getStop().getName());
                                if (arrivalsAndDeparture.getTrip().getDirectionId().equals("0")) {
                                    addStopByBlockId(blockStopsMapList.get(2), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
                                } else if (arrivalsAndDeparture.getTrip().getDirectionId().equals("1")) {
                                    addStopByBlockId(blockStopsMapList.get(3), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
                                }
                            }
                        }
                    }
                }
            }
            // Routes
            for (int n = 0; n < blockStopsMapList.size(); n++) {
                HashMap<String, HashSet<ScheduleStop>> blockStopsMap = blockStopsMapList.get(n);
                ScheduleRoute scheduleRoute = new ScheduleRoute();
                scheduleRoute.setTitle(stopsForRoute.getRoute().getLongName());
                scheduleRoute.setDirection(Integer.toString(n % 2));
                scheduleRoute.setTag(getIdNoAgency(stopsForRoute.getRoute().getId()));
                scheduleRoute.setServiceClass(n < 3 ? "wkd" : "wkend");
                // Blocks
                for (Entry<String, HashSet<ScheduleStop>> entry : blockStopsMap.entrySet()) {
                    int tripStopTimeCounter = 0;
                    String blockId = entry.getKey();
                    HashSet<ScheduleStop> blockStops = entry.getValue();
                    ScheduleTableRow scheduleTr = new ScheduleTableRow(getIdNoAgency(blockId));
                    // Stop Times
                    for (ScheduleStop stop : blockStops) {
                        if (tripStopTimeCounter == 0) {
                            DisplayStop displayStop = new DisplayStop();
                            displayStop.setTag(stop.getTag());
                            displayStop.setValue(stop.getStopName());
                            scheduleRoute.getStops().add(displayStop);
                        }
                        // scheduleStop.setValue(value);
                        scheduleTr.getStops().add(stop);
                    }
                    scheduleRoute.getScheduleTableRow().add(scheduleTr);
                }
                body.getResponse().add(scheduleRoute);
            }
        }
    }
    return body;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) ScheduleStop(org.onebusaway.nextbus.model.nextbus.ScheduleStop) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean) ScheduleTableRow(org.onebusaway.nextbus.model.nextbus.ScheduleTableRow) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) Body(org.onebusaway.nextbus.model.nextbus.Body) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) HashSet(java.util.HashSet) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) ScheduleRoute(org.onebusaway.nextbus.model.nextbus.ScheduleRoute)

Example 7 with StopsWithArrivalsAndDeparturesBean

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

the class ArrivalsAndDeparturesForRouteAction method execute.

@Override
public String execute() throws Exception {
    Set<String> routeIds = getRouteIdsForMatchingRoutes();
    List<ArrivalAndDepartureBean> arrivals = new ArrayList<ArrivalAndDepartureBean>();
    StopsWithArrivalsAndDeparturesBean m = _model.getResult();
    for (ArrivalAndDepartureBean pab : m.getArrivalsAndDepartures()) {
        RouteBean route = pab.getTrip().getRoute();
        if (routeIds.contains(route.getId()) || _route.equals(route.getShortName())) {
            arrivals.add(pab);
        }
    }
    m = new StopsWithArrivalsAndDeparturesBean(m.getStops(), arrivals, m.getNearbyStops(), m.getSituations());
    _model.setResult(m);
    return SUCCESS;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrayList(java.util.ArrayList) StopsWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

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