use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getArrivalAndDeparture.
public ArrivalAndDepartureV2Bean getArrivalAndDeparture(ArrivalAndDepartureBean ad) {
TripBean trip = ad.getTrip();
RouteBean route = trip.getRoute();
StopBean stop = ad.getStop();
ArrivalAndDepartureV2Bean bean = new ArrivalAndDepartureV2Bean();
bean.setTripId(trip.getId());
addToReferences(trip);
bean.setServiceDate(ad.getServiceDate());
bean.setVehicleId(ad.getVehicleId());
bean.setStopId(stop.getId());
addToReferences(stop);
bean.setStopSequence(ad.getStopSequence());
bean.setBlockTripSequence(ad.getBlockTripSequence());
bean.setTotalStopsInTrip(ad.getTotalStopsInTrip());
bean.setRouteId(route.getId());
addToReferences(route);
String routeShortName = ad.getRouteShortName();
if (routeShortName == null || routeShortName.isEmpty())
routeShortName = trip.getRouteShortName();
if (routeShortName == null || routeShortName.isEmpty())
routeShortName = route.getShortName();
bean.setRouteShortName(routeShortName);
bean.setRouteLongName(route.getLongName());
String tripHeadsign = ad.getTripHeadsign();
if (tripHeadsign == null || tripHeadsign.isEmpty())
tripHeadsign = trip.getTripHeadsign();
bean.setTripHeadsign(tripHeadsign);
bean.setArrivalEnabled(ad.isArrivalEnabled());
bean.setDepartureEnabled(ad.isDepartureEnabled());
bean.setScheduledArrivalTime(ad.getScheduledArrivalTime());
bean.setScheduledDepartureTime(ad.getScheduledDepartureTime());
bean.setPredictedArrivalTime(ad.getPredictedArrivalTime());
bean.setPredictedDepartureTime(ad.getPredictedDepartureTime());
bean.setScheduledArrivalInterval(getTimeInterval(ad.getScheduledArrivalInterval()));
bean.setScheduledDepartureInterval(getTimeInterval(ad.getScheduledDepartureInterval()));
bean.setPredictedArrivalInterval(getTimeInterval(ad.getPredictedArrivalInterval()));
bean.setPredictedDepartureInterval(getTimeInterval(ad.getPredictedDepartureInterval()));
if (ad.getFrequency() != null)
bean.setFrequency(getFrequency(ad.getFrequency()));
bean.setStatus(ad.getStatus());
if (ad.isDistanceFromStopSet())
bean.setDistanceFromStop(ad.getDistanceFromStop());
bean.setNumberOfStopsAway(ad.getNumberOfStopsAway());
TripStatusBean tripStatus = ad.getTripStatus();
if (tripStatus != null)
bean.setTripStatus(getTripStatus(tripStatus));
bean.setPredicted(ad.isPredicted());
bean.setLastUpdateTime(ad.getLastUpdateTime());
List<ServiceAlertBean> situations = ad.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;
}
use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class TripUpdatesForAgencyAction method fillFeedMessage.
@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(agencyId, timestamp);
for (VehicleStatusBean vehicle : vehicles.getList()) {
TripStatusBean tripStatus = vehicle.getTripStatus();
if (tripStatus == null) {
continue;
}
TripBean activeTrip = tripStatus.getActiveTrip();
RouteBean route = activeTrip.getRoute();
FeedEntity.Builder entity = feed.addEntityBuilder();
entity.setId(Integer.toString(feed.getEntityCount()));
TripUpdate.Builder tripUpdate = entity.getTripUpdateBuilder();
TripDescriptor.Builder tripDesc = tripUpdate.getTripBuilder();
tripDesc.setTripId(normalizeId(activeTrip.getId()));
tripDesc.setRouteId(normalizeId(route.getId()));
VehicleDescriptor.Builder vehicleDesc = tripUpdate.getVehicleBuilder();
vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
if (tripStatus.getTimepointPredictions() != null && tripStatus.getTimepointPredictions().size() > 0) {
for (TimepointPredictionBean timepointPrediction : tripStatus.getTimepointPredictions()) {
AgencyAndId stopId = modifiedStopId(agencyId, timepointPrediction.getTimepointId());
if (!stopId.getAgencyId().equals(agencyId))
continue;
TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = tripUpdate.addStopTimeUpdateBuilder();
stopTimeUpdate.setStopId(normalizeId(stopId.toString()));
TripUpdate.StopTimeEvent.Builder arrival = stopTimeUpdate.getArrivalBuilder();
if (timepointPrediction.getTimepointPredictedArrivalTime() != -1) {
arrival.setTime(timepointPrediction.getTimepointPredictedArrivalTime() / 1000L);
}
TripUpdate.StopTimeEvent.Builder departure = stopTimeUpdate.getDepartureBuilder();
if (timepointPrediction.getTimepointPredictedDepartureTime() != -1) {
departure.setTime(timepointPrediction.getTimepointPredictedDepartureTime() / 1000L);
}
}
tripUpdate.setTimestamp(vehicle.getLastUpdateTime() / 1000);
} else {
StopBean nextStop = tripStatus.getNextStop();
if (nextStop != null) {
AgencyAndId stopId = modifiedStopId(agencyId, nextStop.getId());
if (stopId.getAgencyId().equals(agencyId)) {
TripUpdate.StopTimeUpdate.Builder stopTimeUpdate = tripUpdate.addStopTimeUpdateBuilder();
stopTimeUpdate.setStopId(normalizeId(stopId.toString()));
TripUpdate.StopTimeEvent.Builder departure = stopTimeUpdate.getDepartureBuilder();
departure.setTime(timestamp / 1000 + tripStatus.getNextStopTimeOffset());
}
}
}
tripUpdate.setDelay((int) tripStatus.getScheduleDeviation());
tripUpdate.setTimestamp(vehicle.getLastUpdateTime() / 1000);
}
}
use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesForStopAction method getArrivalsAsV1.
private List<ArrivalAndDepartureBeanV1> getArrivalsAsV1(StopWithArrivalsAndDeparturesBean result) {
List<ArrivalAndDepartureBeanV1> v1s = new ArrayList<ArrivalAndDepartureBeanV1>();
for (ArrivalAndDepartureBean bean : result.getArrivalsAndDepartures()) {
TripBean trip = bean.getTrip();
RouteBean route = trip.getRoute();
StopBean stop = bean.getStop();
ArrivalAndDepartureBeanV1 v1 = new ArrivalAndDepartureBeanV1();
v1.setPredictedArrivalTime(bean.getPredictedArrivalTime());
v1.setPredictedDepartureTime(bean.getPredictedDepartureTime());
v1.setRouteId(route.getId());
if (trip.getRouteShortName() != null)
v1.setRouteShortName(trip.getRouteShortName());
else
v1.setRouteShortName(route.getShortName());
v1.setScheduledArrivalTime(bean.getScheduledArrivalTime());
v1.setScheduledDepartureTime(bean.getScheduledDepartureTime());
v1.setStatus(bean.getStatus());
v1.setStopId(stop.getId());
v1.setTripHeadsign(trip.getTripHeadsign());
v1.setTripId(trip.getId());
v1s.add(v1);
}
return v1s;
}
use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceImpl method getMonitoredStopVisitsForStop.
@Override
public List<MonitoredStopVisitStructure> getMonitoredStopVisitsForStop(String stopId, int maximumOnwardCalls, long currentTime) {
List<MonitoredStopVisitStructure> output = new ArrayList<MonitoredStopVisitStructure>();
for (ArrivalAndDepartureBean adBean : getArrivalsAndDeparturesForStop(stopId, currentTime)) {
TripStatusBean statusBeanForCurrentTrip = adBean.getTripStatus();
TripBean tripBeanForAd = adBean.getTrip();
final RouteBean routeBean = tripBeanForAd.getRoute();
if (statusBeanForCurrentTrip == null) {
_log.debug("status drop");
continue;
}
if (!_presentationService.include(statusBeanForCurrentTrip) || !_presentationService.include(adBean, statusBeanForCurrentTrip)) {
_log.debug("presentation drop for vehicle=" + statusBeanForCurrentTrip.getVehicleId());
continue;
}
if (!_transitDataService.stopHasRevenueServiceOnRoute((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), stopId, routeBean.getId(), adBean.getTrip().getDirectionId())) {
_log.debug("non reveunue drop");
continue;
}
// Filter out if the vehicle has realtime information and is ahead of current stop
if (statusBeanForCurrentTrip.isPredicted() && !(adBean.hasPredictedArrivalTime() || adBean.hasPredictedDepartureTime())) {
_log.debug("no realtime drop");
continue;
}
if (statusBeanForCurrentTrip.getVehicleId() != null) {
_log.debug("valid vehicle " + statusBeanForCurrentTrip.getVehicleId());
}
MonitoredStopVisitStructure stopVisit = new MonitoredStopVisitStructure();
// Check for Realtime Data
if (!statusBeanForCurrentTrip.isPredicted()) {
stopVisit.setRecordedAtTime(new Date(getTime()));
} else {
stopVisit.setRecordedAtTime(new Date(statusBeanForCurrentTrip.getLastUpdateTime()));
}
List<TimepointPredictionRecord> timePredictionRecords = null;
timePredictionRecords = createTimePredictionRecordsForStop(adBean, stopId);
stopVisit.setMonitoredVehicleJourney(new MonitoredVehicleJourneyStructure());
SiriSupport.fillMonitoredVehicleJourney(stopVisit.getMonitoredVehicleJourney(), tripBeanForAd, statusBeanForCurrentTrip, adBean.getStop(), OnwardCallsMode.STOP_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, statusBeanForCurrentTrip.isPredicted(), currentTime, false);
output.add(stopVisit);
}
Collections.sort(output, new Comparator<MonitoredStopVisitStructure>() {
public int compare(MonitoredStopVisitStructure arg0, MonitoredStopVisitStructure arg1) {
try {
Date expectedArrival0 = arg0.getMonitoredVehicleJourney().getMonitoredCall().getExpectedArrivalTime();
Date expectedArrival1 = arg1.getMonitoredVehicleJourney().getMonitoredCall().getExpectedArrivalTime();
return expectedArrival0.compareTo(expectedArrival1);
} catch (Exception e) {
return -1;
}
}
});
return output;
}
use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesModel method getRouteKeyForArrivalAndDeparture.
private String getRouteKeyForArrivalAndDeparture(ArrivalAndDepartureBean bean) {
String name = bean.getRouteShortName();
if (name != null)
return name;
TripBean trip = bean.getTrip();
name = trip.getRouteShortName();
if (name != null)
return name;
RouteBean route = trip.getRoute();
name = route.getShortName();
if (name != null)
return name;
return route.getId();
}
Aggregations