use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesForStopAction method show.
public DefaultHttpHeaders show() throws ServiceException {
if (hasErrors())
return setValidationErrorsResponse();
if (_query.getTime() == 0)
_query.setTime(SystemTime.currentTimeMillis());
StopWithArrivalsAndDeparturesBean result = _service.getStopWithArrivalsAndDepartures(_id, _query);
if (result == null)
return setResourceNotFoundResponse();
if (isVersion(V1)) {
// Convert data to v1 form
List<ArrivalAndDepartureBeanV1> arrivals = getArrivalsAsV1(result);
StopWithArrivalsAndDeparturesBeanV1 v1 = new StopWithArrivalsAndDeparturesBeanV1(result.getStop(), arrivals, result.getNearbyStops());
return setOkResponse(v1);
} else if (isVersion(V2)) {
BeanFactoryV2 factory = getBeanFactoryV2();
return setOkResponse(factory.getResponse(result));
} else {
return setUnknownVersionResponse();
}
}
use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class SiriSupport method fillOnwardCalls.
private static void fillOnwardCalls(MonitoredVehicleJourneyStructure monitoredVehicleJourney, BlockInstanceBean blockInstance, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, OnwardCallsMode onwardCallsMode, PresentationService presentationService, TransitDataService transitDataService, Map<String, TimepointPredictionRecord> stopLevelPredictions, int maximumOnwardCalls, boolean hasRealtimeData, long responseTimestamp) {
String tripIdOfMonitoredCall = framedJourneyTripBean.getId();
monitoredVehicleJourney.setOnwardCalls(new OnwardCallsStructure());
// no need to go further if this is the case!
if (maximumOnwardCalls == 0) {
return;
}
List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips();
double distanceOfVehicleAlongBlock = 0;
int blockTripStopsAfterTheVehicle = 0;
int onwardCallsAdded = 0;
boolean foundActiveTrip = false;
for (int i = 0; i < blockTrips.size(); i++) {
BlockTripBean blockTrip = blockTrips.get(i);
if (!foundActiveTrip) {
if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
distanceOfVehicleAlongBlock += currentVehicleTripStatus.getDistanceAlongTrip();
foundActiveTrip = true;
} else {
// so to get the size of this one, we have to look at the next.
if (i + 1 < blockTrips.size()) {
distanceOfVehicleAlongBlock = blockTrips.get(i + 1).getDistanceAlongBlock();
}
// bus has already served this trip, so no need to go further
continue;
}
}
if (onwardCallsMode == OnwardCallsMode.STOP_MONITORING) {
// always include onward calls for the trip the monitored call is on ONLY.
if (!blockTrip.getTrip().getId().equals(tripIdOfMonitoredCall)) {
continue;
}
}
boolean foundMatch = false;
HashMap<String, Integer> visitNumberForStopMap = new HashMap<String, Integer>();
for (BlockStopTimeBean stopTime : blockTrip.getBlockStopTimes()) {
int visitNumber = getVisitNumber(visitNumberForStopMap, stopTime.getStopTime().getStop());
StopBean stop = stopTime.getStopTime().getStop();
double distanceOfCallAlongTrip = stopTime.getDistanceAlongBlock() - blockTrip.getDistanceAlongBlock();
double distanceOfVehicleFromCall = stopTime.getDistanceAlongBlock() - distanceOfVehicleAlongBlock;
// on future trips, count always.
if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
if (!hasRealtimeData) {
if (stop.getId().equals(currentVehicleTripStatus.getNextStop().getId()))
foundMatch = true;
if (foundMatch) {
blockTripStopsAfterTheVehicle++;
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
StopWithArrivalsAndDeparturesBean result = transitDataService.getStopWithArrivalsAndDepartures(stop.getId(), query);
// We can't assume the first result is the correct result
Collections.sort(result.getArrivalsAndDepartures(), new SortByTime());
if (result.getArrivalsAndDepartures().isEmpty()) {
// bad data? abort!
continue;
}
ArrivalAndDepartureBean arrivalAndDeparture = result.getArrivalsAndDepartures().get(0);
distanceOfVehicleFromCall = arrivalAndDeparture.getDistanceFromStop();
// responseTimestamp = arrivalAndDeparture.getScheduledArrivalTime();
} else
continue;
} else if (stopTime.getDistanceAlongBlock() >= distanceOfVehicleAlongBlock) {
blockTripStopsAfterTheVehicle++;
} else {
// stop is behind the bus--no need to go further
continue;
}
// future trip--bus hasn't reached this trip yet, so count all stops
} else {
blockTripStopsAfterTheVehicle++;
}
monitoredVehicleJourney.getOnwardCalls().getOnwardCall().add(getOnwardCallStructure(stop, presentationService, distanceOfCallAlongTrip, distanceOfVehicleFromCall, visitNumber, blockTripStopsAfterTheVehicle - 1, stopLevelPredictions.get(stopTime.getStopTime().getStop().getId()), hasRealtimeData, responseTimestamp, (currentVehicleTripStatus.getServiceDate() + stopTime.getStopTime().getArrivalTime() * 1000)));
onwardCallsAdded++;
if (onwardCallsAdded >= maximumOnwardCalls) {
return;
}
}
// if we get here, we added our stops
return;
}
return;
}
use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceImpl method getArrivalsAndDeparturesForStop.
private List<ArrivalAndDepartureBean> getArrivalsAndDeparturesForStop(String stopId, long currentTime) {
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(currentTime);
query.setMinutesBefore(5);
query.setMinutesAfter(65);
StopWithArrivalsAndDeparturesBean stopWithArrivalsAndDepartures = _transitDataService.getStopWithArrivalsAndDepartures(stopId, query);
return stopWithArrivalsAndDepartures.getArrivalsAndDepartures();
}
use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getArrivalsAndDeparturesForStop.
private List<ArrivalAndDepartureBean> getArrivalsAndDeparturesForStop(String stopId, long currentTime) {
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(currentTime);
query.setMinutesBefore(5 * 60);
query.setMinutesAfter(5 * 60);
StopWithArrivalsAndDeparturesBean stopWithArrivalsAndDepartures = _transitDataService.getStopWithArrivalsAndDepartures(stopId, query);
return stopWithArrivalsAndDepartures.getArrivalsAndDepartures();
}
use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.
the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.
public StopWithArrivalsAndDeparturesBean getArrivalsAndDeparturesByStopId(AgencyAndId id, ArrivalsAndDeparturesQueryBean query) {
StopBean stop = _stopBeanService.getStopForId(id);
if (stop == null)
return null;
List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stop, 100);
List<StopBean> nearbyStops = new ArrayList<StopBean>();
for (AgencyAndId nearbyStopId : nearbyStopIds) nearbyStops.add(_stopBeanService.getStopForId(nearbyStopId));
List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
return new StopWithArrivalsAndDeparturesBean(stop, arrivalsAndDepartures, nearbyStops, situations);
}
Aggregations