use of org.onebusaway.transit_data.model.trips.TimepointPredictionBean in project onebusaway-application-modules by camsys.
the class TrivialPredictionHelperService method getPredictionRecordsForTrip.
@Override
public List<TimepointPredictionRecord> getPredictionRecordsForTrip(String agencyId, TripStatusBean tripStatus) {
List<TimepointPredictionRecord> records = null;
if (agencyId == null)
return records;
if (tripStatus == null)
return records;
if (!tripStatus.isPredicted())
return records;
records = new ArrayList<TimepointPredictionRecord>();
List<TimepointPredictionBean> beans = tripStatus.getTimepointPredictions();
if (beans != null && beans.size() > 0) {
for (TimepointPredictionBean bean : beans) {
TimepointPredictionRecord tpr = new TimepointPredictionRecord();
tpr.setTimepointId(AgencyAndIdLibrary.convertFromString(bean.getTimepointId()));
tpr.setTimepointScheduledTime(bean.getTimepointScheduledTime());
tpr.setTimepointPredictedArrivalTime(bean.getTimepointPredictedArrivalTime());
tpr.setTimepointPredictedDepartureTime(bean.getTimepointPredictedDepartureTime());
tpr.setStopSequence(bean.getStopSequence());
tpr.setTripId(AgencyAndIdLibrary.convertFromString(bean.getTripId()));
records.add(tpr);
}
return records;
}
TimepointPredictionRecord tpr = new TimepointPredictionRecord();
tpr.setTimepointId(AgencyAndIdLibrary.convertFromString(tripStatus.getNextStop().getId()));
tpr.setTimepointScheduledTime(tripStatus.getLastUpdateTime() + tripStatus.getNextStopTimeOffset() * 1000);
tpr.setTimepointPredictedArrivalTime((long) (tpr.getTimepointScheduledTime() + tripStatus.getScheduleDeviation()));
tpr.setTimepointPredictedDepartureTime((long) (tpr.getTimepointScheduledTime() + tripStatus.getScheduleDeviation()));
records.add(tpr);
return records;
}
use of org.onebusaway.transit_data.model.trips.TimepointPredictionBean 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.TimepointPredictionBean in project onebusaway-application-modules by camsys.
the class TripStatusBeanServiceImpl method getBlockLocationAsStatusBean.
@Override
public TripStatusBean getBlockLocationAsStatusBean(BlockLocation blockLocation, long time) {
TripStatusBean bean = new TripStatusBean();
bean.setStatus("default");
BlockInstance blockInstance = blockLocation.getBlockInstance();
long serviceDate = blockInstance.getServiceDate();
bean.setServiceDate(serviceDate);
bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
bean.setLastLocationUpdateTime(blockLocation.getLastLocationUpdateTime());
bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
bean.setLocation(blockLocation.getLocation());
bean.setOrientation(blockLocation.getOrientation());
bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
if (blockLocation.isLastKnownOrientationSet())
bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
BlockTripInstance activeTripInstance = blockLocation.getActiveTripInstance();
if (activeTripInstance != null) {
BlockTripEntry activeBlockTrip = activeTripInstance.getBlockTrip();
bean.setScheduledDistanceAlongTrip(blockLocation.getScheduledDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
bean.setDistanceAlongTrip(blockLocation.getDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
TripEntry activeTrip = activeBlockTrip.getTrip();
bean.setTotalDistanceAlongTrip(activeTrip.getTotalTripDistance());
TripBean activeTripBean = _tripBeanService.getTripForId(activeTrip.getId());
bean.setActiveTrip(activeTripBean);
bean.setBlockTripSequence(activeBlockTrip.getSequence());
if (blockLocation.isLastKnownDistanceAlongBlockSet()) {
bean.setLastKnownDistanceAlongTrip(blockLocation.getLastKnownDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
}
FrequencyEntry frequencyLabel = activeTripInstance.getFrequencyLabel();
if (frequencyLabel != null) {
FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
bean.setFrequency(fb);
}
} else {
_log.warn("no active block trip for block location: blockInstance=" + blockLocation.getBlockInstance() + " time=" + time);
}
BlockStopTimeEntry closestStop = blockLocation.getClosestStop();
if (closestStop != null) {
StopTimeEntry stopTime = closestStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setClosestStop(stopBean);
bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
}
BlockStopTimeEntry nextStop = blockLocation.getNextStop();
if (nextStop != null) {
StopTimeEntry stopTime = nextStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setNextStop(stopBean);
bean.setNextStopTimeOffset(blockLocation.getNextStopTimeOffset());
bean.setNextStopDistanceFromVehicle(blockLocation.getNextStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
}
BlockStopTimeEntry previousStop = blockLocation.getPreviousStop();
if (previousStop != null) {
StopTimeEntry stopTime = previousStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setPreviousStop(stopBean);
bean.setPreviousStopTimeOffset(blockLocation.getPreviousStopTimeOffset());
bean.setPreviousStopDistanceFromVehicle(blockLocation.getPreviousStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
}
EVehiclePhase phase = blockLocation.getPhase();
if (phase != null)
bean.setPhase(phase.toLabel());
String status = blockLocation.getStatus();
if (status != null)
bean.setStatus(status);
if (blockLocation.getVehicleType() != null)
bean.setVehicleType(blockLocation.getVehicleType().toLabel());
bean.setPredicted(blockLocation.isPredicted());
AgencyAndId vid = blockLocation.getVehicleId();
if (vid != null)
bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
if (activeTripInstance != null) {
List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, activeTripInstance, blockLocation.getVehicleId());
if (!situations.isEmpty())
bean.setSituations(situations);
}
if (blockLocation.getTimepointPredictions() != null && blockLocation.getTimepointPredictions().size() > 0) {
List<TimepointPredictionBean> timepointPredictions = new ArrayList<TimepointPredictionBean>();
for (TimepointPredictionRecord tpr : blockLocation.getTimepointPredictions()) {
TimepointPredictionBean tpb = new TimepointPredictionBean();
tpb.setTimepointId(tpr.getTimepointId().toString());
tpb.setTripId(tpr.getTripId().toString());
tpb.setStopSequence(tpr.getStopSequence());
tpb.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
tpb.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
timepointPredictions.add(tpb);
}
bean.setTimepointPredictions(timepointPredictions);
}
return bean;
}
Aggregations