use of org.onebusaway.transit_data.model.VehicleStatusBean in project onebusaway-application-modules by camsys.
the class TripUpdatesForAgencyActionTest method test.
@Test
public void test() {
long now = System.currentTimeMillis();
List<VehicleStatusBean> vehicles = new ArrayList<VehicleStatusBean>();
RouteBean.Builder routeBuilder = RouteBean.builder();
routeBuilder.setId("1_r1");
RouteBean route = routeBuilder.create();
{
VehicleStatusBean vehicle = new VehicleStatusBean();
vehicles.add(vehicle);
vehicle.setLastUpdateTime(1234 * 1000);
vehicle.setVehicleId("1_v1");
TripStatusBean tripStatus = new TripStatusBean();
vehicle.setTripStatus(tripStatus);
tripStatus.setScheduleDeviation(2 * 60);
TripBean trip = new TripBean();
trip.setId("1_t0");
trip.setRoute(route);
tripStatus.setActiveTrip(trip);
StopBean stop = new StopBean();
stop.setId("1_s2");
tripStatus.setNextStop(stop);
tripStatus.setNextStopTimeOffset(5 * 60);
}
{
VehicleStatusBean vehicle = new VehicleStatusBean();
vehicles.add(vehicle);
vehicle.setLastUpdateTime(5678 * 1000);
vehicle.setVehicleId("1_v2");
TripStatusBean tripStatus = new TripStatusBean();
vehicle.setTripStatus(tripStatus);
tripStatus.setScheduleDeviation(3 * 60);
TripBean trip = new TripBean();
trip.setId("1_t1");
trip.setRoute(route);
tripStatus.setActiveTrip(trip);
StopBean stop = new StopBean();
stop.setId("1_s3");
tripStatus.setNextStop(stop);
tripStatus.setNextStopTimeOffset(10 * 60);
}
ListBean<VehicleStatusBean> bean = new ListBean<VehicleStatusBean>();
bean.setList(vehicles);
Mockito.when(_service.getAllVehiclesForAgency("1", now)).thenReturn(bean);
_action.setId("1");
_action.setTime(new Date(now));
_action.show();
ResponseBean model = _action.getModel();
FeedMessage feed = (FeedMessage) model.getData();
assertEquals(now / 1000, feed.getHeader().getTimestamp());
assertEquals(2, feed.getEntityCount());
{
FeedEntity entity = feed.getEntity(0);
assertEquals("1", entity.getId());
TripUpdate tripUpdate = entity.getTripUpdate();
assertEquals("t0", tripUpdate.getTrip().getTripId());
assertEquals("r1", tripUpdate.getTrip().getRouteId());
assertEquals("v1", tripUpdate.getVehicle().getId());
assertEquals(1234, tripUpdate.getTimestamp());
assertEquals(120, tripUpdate.getDelay());
assertEquals(1, tripUpdate.getStopTimeUpdateCount());
StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
assertEquals("s2", stopTimeUpdate.getStopId());
assertEquals(now / 1000 + 5 * 60, stopTimeUpdate.getDeparture().getTime());
}
{
FeedEntity entity = feed.getEntity(1);
assertEquals("2", entity.getId());
TripUpdate tripUpdate = entity.getTripUpdate();
assertEquals("t1", tripUpdate.getTrip().getTripId());
assertEquals("r1", tripUpdate.getTrip().getRouteId());
assertEquals("v2", tripUpdate.getVehicle().getId());
assertEquals(5678, tripUpdate.getTimestamp());
assertEquals(180, tripUpdate.getDelay());
assertEquals(1, tripUpdate.getStopTimeUpdateCount());
StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
assertEquals("s3", stopTimeUpdate.getStopId());
assertEquals(now / 1000 + 10 * 60, stopTimeUpdate.getDeparture().getTime());
}
}
use of org.onebusaway.transit_data.model.VehicleStatusBean 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.VehicleStatusBean in project onebusaway-application-modules by camsys.
the class VehiclePositionsForAgencyAction 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()) {
FeedEntity.Builder entity = feed.addEntityBuilder();
entity.setId(Integer.toString(feed.getEntityCount()));
VehiclePosition.Builder vehiclePosition = entity.getVehicleBuilder();
TripStatusBean tripStatus = vehicle.getTripStatus();
if (tripStatus != null) {
TripBean activeTrip = tripStatus.getActiveTrip();
RouteBean route = activeTrip.getRoute();
TripDescriptor.Builder tripDesc = vehiclePosition.getTripBuilder();
tripDesc.setTripId(normalizeId(activeTrip.getId()));
tripDesc.setRouteId(normalizeId(route.getId()));
}
VehicleDescriptor.Builder vehicleDesc = vehiclePosition.getVehicleBuilder();
vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
CoordinatePoint location = vehicle.getLocation();
if (location != null) {
Position.Builder position = vehiclePosition.getPositionBuilder();
position.setLatitude((float) location.getLat());
position.setLongitude((float) location.getLon());
}
vehiclePosition.setTimestamp(vehicle.getLastUpdateTime() / 1000);
}
}
use of org.onebusaway.transit_data.model.VehicleStatusBean in project onebusaway-application-modules by camsys.
the class VehiclesForAgencyAction method show.
public DefaultHttpHeaders show() throws IOException, ServiceException {
if (!isVersion(V2))
return setUnknownVersionResponse();
if (hasErrors())
return setValidationErrorsResponse();
long time = SystemTime.currentTimeMillis();
if (_time != 0)
time = _time;
BeanFactoryV2 factory = getBeanFactoryV2();
try {
ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(_id, time);
return setOkResponse(factory.getVehicleStatusResponse(vehicles));
} catch (OutOfServiceAreaServiceException ex) {
return setOkResponse(factory.getEmptyList(VehicleStatusV2Bean.class, true));
}
}
use of org.onebusaway.transit_data.model.VehicleStatusBean in project onebusaway-application-modules by camsys.
the class VehicleStatusBeanServiceImpl method getStatusAsBean.
/**
**
*
***
*/
private VehicleStatusBean getStatusAsBean(VehicleStatus status, long time) {
VehicleLocationRecord record = status.getRecord();
VehicleStatusBean bean = new VehicleStatusBean();
bean.setLastUpdateTime(record.getTimeOfRecord());
bean.setLastLocationUpdateTime(record.getTimeOfLocationUpdate());
EVehiclePhase phase = record.getPhase();
if (phase != null)
bean.setPhase(phase.toLabel());
bean.setStatus(record.getStatus());
if (record.isCurrentLocationSet())
bean.setLocation(new CoordinatePoint(record.getCurrentLocationLat(), record.getCurrentLocationLon()));
bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
TripDetailsBean details = _tripDetailsBeanService.getTripForVehicle(record.getVehicleId(), time, new TripDetailsInclusionBean(true, false, true));
if (details != null && details.getStatus() != null) {
bean.setTrip(details.getTrip());
bean.setTripStatus(details.getStatus());
}
List<VehicleLocationRecord> allRecords = status.getAllRecords();
if (!CollectionsLibrary.isEmpty(allRecords)) {
List<VehicleLocationRecordBean> allRecordBeans = new ArrayList<VehicleLocationRecordBean>();
bean.setAllRecords(allRecordBeans);
for (VehicleLocationRecord r : allRecords) {
VehicleLocationRecordBean rBean = getVehicleLocationRecordAsBean(r);
allRecordBeans.add(rBean);
}
}
return bean;
}
Aggregations