Search in sources :

Example 56 with StopBean

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

the class BeanFactoryV2 method getTripStatus.

public TripStatusV2Bean getTripStatus(TripStatusBean tripStatus) {
    TripStatusV2Bean bean = new TripStatusV2Bean();
    TripBean activeTrip = tripStatus.getActiveTrip();
    if (activeTrip != null) {
        bean.setActiveTripId(activeTrip.getId());
        bean.setBlockTripSequence(tripStatus.getBlockTripSequence());
        addToReferences(activeTrip);
    }
    bean.setServiceDate(tripStatus.getServiceDate());
    FrequencyBean frequency = tripStatus.getFrequency();
    if (frequency != null)
        bean.setFrequency(getFrequency(frequency));
    bean.setScheduledDistanceAlongTrip(tripStatus.getScheduledDistanceAlongTrip());
    bean.setTotalDistanceAlongTrip(tripStatus.getTotalDistanceAlongTrip());
    bean.setPosition(tripStatus.getLocation());
    if (tripStatus.isOrientationSet())
        bean.setOrientation(tripStatus.getOrientation());
    StopBean closestStop = tripStatus.getClosestStop();
    if (closestStop != null) {
        bean.setClosestStop(closestStop.getId());
        addToReferences(closestStop);
        bean.setClosestStopTimeOffset(tripStatus.getClosestStopTimeOffset());
    }
    StopBean nextStop = tripStatus.getNextStop();
    if (nextStop != null) {
        bean.setNextStop(nextStop.getId());
        addToReferences(nextStop);
        bean.setNextStopTimeOffset(tripStatus.getNextStopTimeOffset());
    }
    bean.setPhase(tripStatus.getPhase());
    bean.setStatus(tripStatus.getStatus());
    bean.setPredicted(tripStatus.isPredicted());
    if (tripStatus.getLastUpdateTime() > 0)
        bean.setLastUpdateTime(tripStatus.getLastUpdateTime());
    if (tripStatus.getLastLocationUpdateTime() > 0)
        bean.setLastLocationUpdateTime(tripStatus.getLastLocationUpdateTime());
    if (tripStatus.isLastKnownDistanceAlongTripSet())
        bean.setLastKnownDistanceAlongTrip(tripStatus.getLastKnownDistanceAlongTrip());
    bean.setLastKnownLocation(tripStatus.getLastKnownLocation());
    if (tripStatus.isLastKnownOrientationSet())
        bean.setLastKnownOrientation(tripStatus.getLastKnownOrientation());
    if (tripStatus.isScheduleDeviationSet())
        bean.setScheduleDeviation((int) tripStatus.getScheduleDeviation());
    if (tripStatus.isDistanceAlongTripSet())
        bean.setDistanceAlongTrip(tripStatus.getDistanceAlongTrip());
    bean.setVehicleId(tripStatus.getVehicleId());
    List<ServiceAlertBean> situations = tripStatus.getSituations();
    if (situations != null && !situations.isEmpty()) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            situationIds.add(situation.getId());
            addToReferences(situation);
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) ArrayList(java.util.ArrayList) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 57 with StopBean

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

the class StopByNumberAction method execute.

@Override
public String execute() throws ServiceException {
    if (_text != null)
        _text.trim();
    if (_text == null || _text.length() == 0)
        return INPUT;
    String[] tokens = _text.trim().split("\\s+");
    if (tokens.length == 0)
        return INPUT;
    CoordinateBounds serviceArea = _serviceAreaService.getServiceArea();
    if (serviceArea == null) {
        pushNextAction("stop-by-number", "text", _text);
        return "query-default-search-location";
    }
    _stopQuery = tokens[0];
    SearchQueryBean searchQuery = new SearchQueryBean();
    searchQuery.setBounds(serviceArea);
    searchQuery.setMaxCount(5);
    searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
    searchQuery.setQuery(_stopQuery);
    StopsBean results = _transitDataService.getStops(searchQuery);
    _stops = results.getStops();
    int stopIndex = 0;
    if (_stops.isEmpty()) {
        return "noStopsFound";
    } else if (_stops.size() > 1) {
        if (0 <= _selectedIndex && _selectedIndex < _stops.size()) {
            stopIndex = _selectedIndex;
        } else {
            pushNextAction("stop-by-number", "text", _text);
            pushNextAction("handle-multi-selection");
            return "multipleStopsFound";
        }
    }
    StopBean stop = _stops.get(stopIndex);
    _stopId = stop.getId();
    _args = new String[tokens.length - 1];
    System.arraycopy(tokens, 1, _args, 0, _args.length);
    return "arrivals-and-departures";
}
Also used : SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean)

Example 58 with StopBean

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

the class PredictionsForMultiStopsAction method isValid.

private boolean isValid(Body<Predictions> body) {
    if (!isValidAgency(body, agencyId)) {
        return false;
    }
    if (stops == null) {
        body.getErrors().add(new BodyError(ErrorMsg.STOP_STOPS_NULL.getDescription()));
        return false;
    }
    for (String stop : stops) {
        String[] stopArray = stop.split("\\|");
        if (stopArray.length < 2) {
            String error = "The stop " + stop + " is invalid because it did not contain a route, optional dir, and stop tag";
            body.getErrors().add(new BodyError(error));
            return false;
        }
        try {
            String stopId = _tdsMappingService.getStopIdFromStopCode(stopArray[1]);
            StopBean stopBean;
            try {
                stopBean = _transitDataService.getStop(stopId);
            } catch (ServiceException se) {
                // The user didn't provide an agency id in stopId, so use provided
                // agency
                String stopIdVal = new AgencyAndId(agencyId, stopId).toString();
                stopBean = _transitDataService.getStop(stopIdVal);
            }
            boolean routeExists = false;
            for (RouteBean routeBean : stopBean.getRoutes()) {
                if (routeBean.getId().equals(_tdsMappingService.getRouteIdFromShortName(stopArray[0]))) {
                    routeExists = true;
                    break;
                }
            }
            if (!routeExists) {
                String error = "For agency=" + getA() + " route r=" + stopArray[0] + " is not currently available. It might be initializing still.";
                body.getErrors().add(new BodyError(error));
                return false;
            }
            String routeTag = getIdNoAgency(_tdsMappingService.getRouteIdFromShortName(stopArray[0]));
            String routeStop = getIdNoAgency(_tdsMappingService.getStopIdFromStopCode(stopArray[1]));
            mappedStops.add(routeTag + "|" + routeStop);
        } catch (ServiceException se) {
            String error = "For agency=" + getA() + " stop s=" + stopArray[1] + " is on none of the directions for r=" + stopArray[0] + " so cannot determine which stop to provide data for.";
            body.getErrors().add(new BodyError(error));
            return false;
        }
    }
    return true;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) ServiceException(org.onebusaway.exceptions.ServiceException) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 59 with StopBean

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

the class PredictionsForMultiStopsAction method getStopIdParams.

private String getStopIdParams() {
    StringBuilder sb = new StringBuilder();
    for (String stopId : stops) {
        StopBean stopBean = _transitDataService.getStop(stopId);
        for (RouteBean routeBean : stopBean.getRoutes()) {
            sb.append("rs=");
            sb.append(routeBean.getId());
            sb.append("|");
            sb.append(stopId);
            sb.append("&");
        }
    }
    return sb.toString();
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 60 with StopBean

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

the class ArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.

/**
 **
 * {@link ArrivalsAndDeparturesBeanService} Interface
 ***
 */
@Override
public List<ArrivalAndDepartureBean> getArrivalsAndDeparturesByStopId(AgencyAndId stopId, ArrivalsAndDeparturesQueryBean query) {
    StopEntry stop = _transitGraphDao.getStopEntryForId(stopId, true);
    long time = query.getTime();
    int minutesBefore = Math.max(query.getMinutesBefore(), query.getFrequencyMinutesBefore());
    int minutesAfter = Math.max(query.getMinutesAfter(), query.getFrequencyMinutesAfter());
    long fromTime = time - minutesBefore * 60 * 1000;
    long toTime = time + minutesAfter * 60 * 1000;
    long nonFrequencyFromTime = time - query.getMinutesBefore() * 60 * 1000;
    long nonFrequencyToTime = time + query.getMinutesAfter() * 60 * 1000;
    long frequencyFromTime = time - query.getFrequencyMinutesBefore() * 60 * 1000;
    long frequencyToTime = time + query.getFrequencyMinutesAfter() * 60 * 1000;
    TargetTime target = new TargetTime(time, time);
    List<ArrivalAndDepartureInstance> instances = _arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(stop, target, fromTime, toTime);
    List<ArrivalAndDepartureBean> beans = new ArrayList<ArrivalAndDepartureBean>();
    Map<AgencyAndId, StopBean> stopBeanCache = new HashMap<AgencyAndId, StopBean>();
    for (ArrivalAndDepartureInstance instance : instances) {
        FrequencyEntry frequency = instance.getFrequency();
        long from = frequency != null ? frequencyFromTime : nonFrequencyFromTime;
        long to = frequency != null ? frequencyToTime : nonFrequencyToTime;
        if (!isArrivalAndDepartureInRange(instance, from, to))
            continue;
        ArrivalAndDepartureBean bean = getStopTimeInstanceAsBean(time, instance, stopBeanCache);
        applyBlockLocationToBean(instance, bean, time);
        Boolean isNegativeScheduledArrivalsEnabled = _gtfsRealtimeNegativeArrivals.getShowNegativeScheduledArrivalByAgencyId(instance.getBlockTrip().getTrip().getId().getAgencyId());
        if (isNegativeScheduledArrivalsEnabled != null && !isNegativeScheduledArrivalsEnabled && bean.getNumberOfStopsAway() < 0 && bean.getPredictedArrivalTime() <= 0)
            continue;
        applySituationsToBean(time, instance, bean);
        beans.add(bean);
    }
    Collections.sort(beans, new ArrivalAndDepartureComparator());
    return beans;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) StopBean(org.onebusaway.transit_data.model.StopBean)

Aggregations

StopBean (org.onebusaway.transit_data.model.StopBean)69 ArrayList (java.util.ArrayList)34 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 RouteBean (org.onebusaway.transit_data.model.RouteBean)22 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)17 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)15 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)15 HashMap (java.util.HashMap)12 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)9 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)9 NameBean (org.onebusaway.transit_data.model.NameBean)9 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)8 TripBean (org.onebusaway.transit_data.model.trips.TripBean)8 HashSet (java.util.HashSet)7 StopsBean (org.onebusaway.transit_data.model.StopsBean)7 List (java.util.List)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 Test (org.junit.Test)5 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)5 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)5