use of org.onebusaway.transit_data.model.trips.TripStatusBean in project onebusaway-application-modules by camsys.
the class VehicleLocationsAction method getVehiclesForRoute.
private List<Vehicle> getVehiclesForRoute(String routeId, ListBean<TripDetailsBean> trips) {
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(6);
List<Vehicle> vehiclesList = new ArrayList<Vehicle>();
for (TripDetailsBean tripDetails : trips.getList()) {
TripStatusBean tripStatus = tripDetails.getStatus();
// filter out interlined routes
if (routeId != null && !tripDetails.getTrip().getRoute().getId().equals(routeId))
continue;
Vehicle vehicle = new Vehicle();
String vehicleId = null;
if (tripStatus.getVehicleId() != null) {
vehicleId = getIdNoAgency(tripStatus.getVehicleId());
} else
continue;
vehicle.setId(vehicleId);
vehicle.setLat(new BigDecimal(df.format(tripStatus.getLocation().getLat())));
vehicle.setLon(new BigDecimal(df.format(tripStatus.getLocation().getLon())));
vehicle.setHeading((int) tripStatus.getOrientation());
vehicle.setDirTag(tripStatus.getActiveTrip().getDirectionId());
vehicle.setPredictable(tripStatus.isPredicted());
vehicle.setRouteTag(getIdNoAgency(tripStatus.getActiveTrip().getRoute().getId()));
vehicle.setTripTag(getIdNoAgency(tripStatus.getActiveTrip().getId()));
vehicle.setBlock(getIdNoAgency(tripStatus.getActiveTrip().getBlockId()));
int secondsSinceUpdate = 0;
if (tripStatus.getLastUpdateTime() > 0)
secondsSinceUpdate = (int) TimeUnit.MILLISECONDS.toSeconds(SystemTime.currentTimeMillis() - tripStatus.getLastUpdateTime());
vehicle.setSecsSinceReport(secondsSinceUpdate);
vehiclesList.add(vehicle);
}
return vehiclesList;
}
use of org.onebusaway.transit_data.model.trips.TripStatusBean in project onebusaway-application-modules by camsys.
the class TripStatusBeanServiceImpl method getTripEntryAndBlockLocationAsTripDetails.
private TripDetailsBean getTripEntryAndBlockLocationAsTripDetails(BlockTripInstance blockTripInstance, BlockLocation blockLocation, TripDetailsInclusionBean inclusion, long time) {
TripBean trip = null;
long serviceDate = blockTripInstance.getServiceDate();
FrequencyBean frequency = null;
TripStopTimesBean stopTimes = null;
TripStatusBean status = null;
AgencyAndId vehicleId = null;
boolean missing = false;
FrequencyEntry frequencyLabel = blockTripInstance.getFrequencyLabel();
if (frequencyLabel != null) {
frequency = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
}
BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
TripEntry tripEntry = blockTrip.getTrip();
if (inclusion.isIncludeTripBean()) {
trip = _tripBeanService.getTripForId(tripEntry.getId());
if (trip == null)
missing = true;
}
if (inclusion.isIncludeTripSchedule()) {
stopTimes = _tripStopTimesBeanService.getStopTimesForBlockTrip(blockTripInstance);
if (stopTimes == null)
missing = true;
}
if (inclusion.isIncludeTripStatus() && blockLocation != null) {
status = getBlockLocationAsStatusBean(blockLocation, time);
if (status == null)
missing = true;
else
vehicleId = AgencyAndIdLibrary.convertFromString(status.getVehicleId());
}
List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, blockTripInstance, vehicleId);
if (missing)
return null;
String tripId = AgencyAndIdLibrary.convertToString(tripEntry.getId());
TripDetailsBean bean = new TripDetailsBean();
bean.setTripId(tripId);
bean.setServiceDate(serviceDate);
bean.setFrequency(frequency);
bean.setTrip(trip);
bean.setSchedule(stopTimes);
bean.setStatus(status);
bean.setSituations(situations);
return bean;
}
use of org.onebusaway.transit_data.model.trips.TripStatusBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method applyBlockLocationToBean.
private void applyBlockLocationToBean(ArrivalAndDepartureInstance instance, ArrivalAndDepartureBean bean, long targetTime) {
boolean hasFrequency = instance.getFrequency() != null;
if (instance.isPredictedArrivalTimeSet()) {
bean.setPredictedArrivalTime(instance.getPredictedArrivalTime());
if (hasFrequency)
bean.setScheduledArrivalTime(bean.getPredictedArrivalTime());
}
if (instance.isPredictedDepartureTimeSet()) {
bean.setPredictedDepartureTime(instance.getPredictedDepartureTime());
if (hasFrequency)
bean.setScheduledDepartureTime(bean.getPredictedDepartureTime());
}
BlockStopTimeEntry stopTime = instance.getBlockStopTime();
BlockLocation blockLocation = instance.getBlockLocation();
if (blockLocation == null)
return;
bean.setPredicted(blockLocation.isPredicted());
// Distance from stop
if (blockLocation.isDistanceAlongBlockSet()) {
double distanceFromStop = stopTime.getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock();
bean.setDistanceFromStop(distanceFromStop);
} else {
double distanceFromStop = stopTime.getDistanceAlongBlock() - blockLocation.getScheduledDistanceAlongBlock();
bean.setDistanceFromStop(distanceFromStop);
}
// Number of stops away
if (blockLocation.getNextStop() != null) {
BlockStopTimeEntry nextStopTime = blockLocation.getNextStop();
bean.setNumberOfStopsAway(stopTime.getBlockSequence() - nextStopTime.getBlockSequence());
}
if (blockLocation.getLastUpdateTime() > 0)
bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
if (blockLocation.getVehicleId() != null)
bean.setVehicleId(AgencyAndIdLibrary.convertToString(blockLocation.getVehicleId()));
TripStatusBean tripStatusBean = _tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocation, targetTime);
bean.setTripStatus(tripStatusBean);
}
use of org.onebusaway.transit_data.model.trips.TripStatusBean in project onebusaway-application-modules by camsys.
the class VehiclePositionsForAgencyActionTest 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);
TripBean trip = new TripBean();
trip.setId("1_t0");
trip.setRoute(route);
tripStatus.setActiveTrip(trip);
vehicle.setLocation(new CoordinatePoint(47.0, -122.0));
}
{
VehicleStatusBean vehicle = new VehicleStatusBean();
vehicles.add(vehicle);
vehicle.setLastUpdateTime(5678 * 1000);
vehicle.setVehicleId("1_v2");
TripStatusBean tripStatus = new TripStatusBean();
vehicle.setTripStatus(tripStatus);
TripBean trip = new TripBean();
trip.setId("1_t1");
trip.setRoute(route);
tripStatus.setActiveTrip(trip);
vehicle.setLocation(new CoordinatePoint(47.1, -122.1));
}
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());
VehiclePosition vehiclePosition = entity.getVehicle();
assertEquals("t0", vehiclePosition.getTrip().getTripId());
assertEquals("r1", vehiclePosition.getTrip().getRouteId());
assertEquals("v1", vehiclePosition.getVehicle().getId());
assertEquals(1234, vehiclePosition.getTimestamp());
assertEquals(47.0, vehiclePosition.getPosition().getLatitude(), 0.01);
assertEquals(-122.0, vehiclePosition.getPosition().getLongitude(), 0.01);
}
{
FeedEntity entity = feed.getEntity(1);
assertEquals("2", entity.getId());
VehiclePosition vehiclePosition = entity.getVehicle();
assertEquals("t1", vehiclePosition.getTrip().getTripId());
assertEquals("r1", vehiclePosition.getTrip().getRouteId());
assertEquals("v2", vehiclePosition.getVehicle().getId());
assertEquals(5678, vehiclePosition.getTimestamp());
assertEquals(47.1, vehiclePosition.getPosition().getLatitude(), 0.01);
assertEquals(-122.1, vehiclePosition.getPosition().getLongitude(), 0.01);
}
}
use of org.onebusaway.transit_data.model.trips.TripStatusBean 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());
}
}
Aggregations