use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method testStopRewriting.
@Test
public void testStopRewriting() {
StopTimeUpdate.Builder stopTimeUpdate = StopTimeUpdate.newBuilder();
stopTimeUpdate.setStopId("replaceA");
StopTimeEvent.Builder stopTimeEvent = StopTimeEvent.newBuilder();
stopTimeEvent.setDelay(180);
stopTimeUpdate.setDeparture(stopTimeEvent);
stopTimeUpdate.setStopSequence(0);
TripUpdate tripUpdate = TripUpdate.newBuilder().setTrip(TripDescriptor.newBuilder().setTripId("tripA")).setDelay(120).setTimestamp(123456789).addStopTimeUpdate(stopTimeUpdate).build();
TripEntryImpl tripA = trip("tripA");
stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
BlockEntryImpl blockA = block("blockA");
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Collections.singletonList(blockInstanceA));
CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition();
update.block = new BlockDescriptor();
update.block.setBlockInstance(blockInstanceA);
update.tripUpdates = Collections.singletonList(tripUpdate);
StopModificationStrategy strategy = Mockito.mock(StopModificationStrategy.class);
Mockito.when(strategy.convertStopId("replaceA")).thenReturn("stopA");
_library.setStopModificationStrategy(strategy);
VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update);
assertEquals(123456789000L, record.getTimeOfRecord());
assertEquals(120, record.getScheduleDeviation(), 0.0);
TimepointPredictionRecord tpr = record.getTimepointPredictions().get(0);
long departure = tpr.getTimepointPredictedDepartureTime();
assertEquals(departure, time(7, 33) * 1000);
}
use of org.onebusaway.realtime.api.TimepointPredictionRecord 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.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class RealtimeServiceImpl method getVehicleActivityForVehicle.
@Override
public VehicleActivityStructure getVehicleActivityForVehicle(String vehicleId, int maximumOnwardCalls, long currentTime, String tripId) {
TripForVehicleQueryBean query = new TripForVehicleQueryBean();
query.setTime(new Date(currentTime));
query.setVehicleId(vehicleId);
TripDetailsInclusionBean inclusion = new TripDetailsInclusionBean();
inclusion.setIncludeTripStatus(true);
inclusion.setIncludeTripBean(true);
query.setInclusion(inclusion);
TripDetailsBean tripDetailsForCurrentTrip = _transitDataService.getTripDetailsForVehicleAndTime(query);
if (tripDetailsForCurrentTrip == null) {
TripDetailsQueryBean detailsQuery = new TripDetailsQueryBean();
detailsQuery.setTime(currentTime);
detailsQuery.setTripId(tripId);
tripDetailsForCurrentTrip = _transitDataService.getSingleTripDetails(detailsQuery);
}
if (tripDetailsForCurrentTrip == null || !_presentationService.include(tripDetailsForCurrentTrip.getStatus()))
return null;
VehicleActivityStructure output = new VehicleActivityStructure();
// Check for Realtime Data
if (!tripDetailsForCurrentTrip.getStatus().isPredicted()) {
output.setRecordedAtTime(new Date(getTime()));
} else {
output.setRecordedAtTime(new Date(tripDetailsForCurrentTrip.getStatus().getLastUpdateTime()));
}
List<TimepointPredictionRecord> timePredictionRecords = null;
timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(vehicleId).getAgencyId(), tripDetailsForCurrentTrip.getStatus());
output.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
SiriSupport.fillMonitoredVehicleJourney(output.getMonitoredVehicleJourney(), tripDetailsForCurrentTrip.getTrip(), tripDetailsForCurrentTrip.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetailsForCurrentTrip.getStatus().isPredicted(), currentTime, false);
return output;
}
use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class RealtimeServiceImpl method getVehicleActivityForRoute.
/**
* SIRI METHODS
*/
@Override
public List<VehicleActivityStructure> getVehicleActivityForRoute(String routeId, String directionId, int maximumOnwardCalls, long currentTime, boolean showRawLocation) {
List<VehicleActivityStructure> output = new ArrayList<VehicleActivityStructure>();
ListBean<TripDetailsBean> trips = getAllTripsForRoute(routeId, currentTime);
for (TripDetailsBean tripDetails : trips.getList()) {
// filter out interlined routes
if (routeId != null && !tripDetails.getTrip().getRoute().getId().equals(routeId))
continue;
// filtered out by user
if (tripDetails.getTrip().getDirectionId() != null) {
if (directionId != null && !tripDetails.getTrip().getDirectionId().equals(directionId)) {
continue;
}
}
if (!_presentationService.include(tripDetails.getStatus()))
continue;
VehicleActivityStructure activity = new VehicleActivityStructure();
// Check for Realtime Data
if (!tripDetails.getStatus().isPredicted()) {
activity.setRecordedAtTime(new Date(getTime()));
} else {
activity.setRecordedAtTime(new Date(tripDetails.getStatus().getLastUpdateTime()));
}
List<TimepointPredictionRecord> timePredictionRecords = null;
timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(routeId).getAgencyId(), tripDetails.getStatus());
activity.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
SiriSupport.fillMonitoredVehicleJourney(activity.getMonitoredVehicleJourney(), tripDetails.getTrip(), tripDetails.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetails.getStatus().isPredicted(), currentTime, showRawLocation);
output.add(activity);
}
Collections.sort(output, new Comparator<VehicleActivityStructure>() {
public int compare(VehicleActivityStructure arg0, VehicleActivityStructure arg1) {
try {
SiriExtensionWrapper wrapper0 = (SiriExtensionWrapper) arg0.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
SiriExtensionWrapper wrapper1 = (SiriExtensionWrapper) arg1.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
return wrapper0.getDistances().getDistanceFromCall().compareTo(wrapper1.getDistances().getDistanceFromCall());
} catch (Exception e) {
return -1;
}
}
});
return output;
}
use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class RealtimeServiceImpl method createTimePredictionRecordsForStop.
private List<TimepointPredictionRecord> createTimePredictionRecordsForStop(ArrivalAndDepartureBean adBean, String stopId) {
List<TimepointPredictionRecord> tprs = new ArrayList<TimepointPredictionRecord>();
TimepointPredictionRecord tpr = new TimepointPredictionRecord();
tpr.setTimepointId(AgencyAndIdLibrary.convertFromString(stopId));
tpr.setTimepointScheduledTime(adBean.getScheduledArrivalTime());
tpr.setTimepointPredictedArrivalTime(adBean.getPredictedArrivalTime());
tpr.setTimepointPredictedDepartureTime(adBean.getPredictedDepartureTime());
tprs.add(tpr);
return tprs;
}
Aggregations