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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations