Search in sources :

Example 1 with ArrivalAndDepartureBean

use of org.onebusaway.transit_data.model.ArrivalAndDepartureBean 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 ArrivalAndDepartureBean

use of org.onebusaway.transit_data.model.ArrivalAndDepartureBean 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;
}
Also used : StopTimeNarrative(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 3 with ArrivalAndDepartureBean

use of org.onebusaway.transit_data.model.ArrivalAndDepartureBean 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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ScheduleDeviationHistogram(org.onebusaway.transit_data_federation.services.realtime.ScheduleDeviationHistogram) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) StopBean(org.onebusaway.transit_data.model.StopBean) HistogramBean(org.onebusaway.transit_data.model.realtime.HistogramBean)

Example 4 with ArrivalAndDepartureBean

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

the class ArrivalsAndDeparturesAction method buildPredictedArrivals.

protected void buildPredictedArrivals(List<ArrivalAndDepartureBean> arrivals, List<StopBean> list) {
    if (arrivals.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
    }
    Collections.sort(arrivals, new ArrivalAndDepartureComparator());
    long now = SystemTime.currentTimeMillis();
    boolean hasAlerts = stopsHaveAlerts(list);
    for (ArrivalAndDepartureBean adb : arrivals) {
        TripBean trip = adb.getTrip();
        RouteBean route = trip.getRoute();
        addMessage(Messages.ROUTE);
        String routeNumber = RoutePresenter.getNameForRoute(route);
        addText(_routeNumberPronunciation.modify(routeNumber));
        addText(", ");
        String headsign = trip.getTripHeadsign();
        if (headsign != null) {
            // addMessage(Messages.TO);
            String destination = _destinationPronunciation.modify(headsign);
            destination = destination.replaceAll("\\&", "and");
            addText(destination);
            addText(", ");
        }
        if (TransitDataConstants.STATUS_LEGACY_CANCELLED.equalsIgnoreCase(adb.getStatus())) {
            addText("is currently not in service");
            continue;
        }
        long t = adb.computeBestDepartureTime();
        boolean isPrediction = adb.hasPredictedDepartureTime();
        int min = (int) ((t - now) / 1000 / 60);
        if (min < 0) {
            min = -min;
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_PAST_DATE : Messages.SCHEDULED_AT_PAST_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_PAST : Messages.SCHEDULED_IN_PAST;
                addMessage(message, min);
            }
        } else {
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_FUTURE_DATE : Messages.SCHEDULED_AT_FUTURE_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_FUTURE : Messages.SCHEDULED_IN_FUTURE;
                addMessage(message, min);
            }
        }
        if (TransitDataConstants.STATUS_REROUTE.equals(adb.getStatus())) {
            addText("but is currently on adverse weather re-route.");
        }
        addText(". ");
        if (!hasAlerts && adb.getSituations() != null && adb.getSituations().size() > 0) {
            hasAlerts = true;
        }
    }
    if (hasAlerts) {
        addText(getAlertPresentText());
    }
    addMessage(Messages.ARRIVAL_INFO_DISCLAIMER);
    List<AgencyBean> agencies = AgencyPresenter.getAgenciesForArrivalAndDepartures(arrivals);
    if (!agencies.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_DATA_PROVIDED_BY);
        for (int i = 0; i < agencies.size(); i++) {
            AgencyBean agency = agencies.get(i);
            if (i == agencies.size() - 1 && agencies.size() > 1)
                addText(Messages.AND);
            addText(agency.getName());
            addText(",");
        }
    }
    addMessage(Messages.STOP_FOUND_BOOKMARK_THIS_LOCATION);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrivalAndDepartureComparator(org.onebusaway.presentation.impl.ArrivalAndDepartureComparator) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) Date(java.util.Date) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Example 5 with ArrivalAndDepartureBean

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

the class BeanFactoryV2 method getStopWithArrivalAndDepartures.

public StopWithArrivalsAndDeparturesV2Bean getStopWithArrivalAndDepartures(StopWithArrivalsAndDeparturesBean sad) {
    StopWithArrivalsAndDeparturesV2Bean bean = new StopWithArrivalsAndDeparturesV2Bean();
    bean.setStopId(sad.getStop().getId());
    addToReferences(sad.getStop());
    List<ArrivalAndDepartureV2Bean> ads = new ArrayList<ArrivalAndDepartureV2Bean>();
    for (ArrivalAndDepartureBean ad : sad.getArrivalsAndDepartures()) ads.add(getArrivalAndDeparture(ad));
    bean.setArrivalsAndDepartures(ads);
    List<String> nearbyStopIds = new ArrayList<String>();
    for (StopBean nearbyStop : sad.getNearbyStops()) {
        nearbyStopIds.add(nearbyStop.getId());
        addToReferences(nearbyStop);
    }
    bean.setNearbyStopIds(nearbyStopIds);
    List<ServiceAlertBean> situations = sad.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            addToReferences(situation);
            situationIds.add(situation.getId());
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

Aggregations

ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)21 ArrayList (java.util.ArrayList)14 StopBean (org.onebusaway.transit_data.model.StopBean)9 TripBean (org.onebusaway.transit_data.model.trips.TripBean)8 HashMap (java.util.HashMap)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 RouteBean (org.onebusaway.transit_data.model.RouteBean)6 HashSet (java.util.HashSet)4 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)4 StopsWithArrivalsAndDeparturesBean (org.onebusaway.transit_data.model.StopsWithArrivalsAndDeparturesBean)4 Date (java.util.Date)3 ArrivalsAndDeparturesQueryBean (org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean)3 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)3 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)3 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)3 ArrivalAndDepartureComparator (org.onebusaway.presentation.impl.ArrivalAndDepartureComparator)2 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)2 StopWithArrivalsAndDeparturesBean (org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean)2 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)2 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)2