Search in sources :

Example 1 with TripStatusBean

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;
}
Also used : Vehicle(org.onebusaway.nextbus.model.nextbus.Vehicle) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) BigDecimal(java.math.BigDecimal)

Example 2 with TripStatusBean

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean)

Example 3 with TripStatusBean

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);
}
Also used : TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 4 with 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);
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) Date(java.util.Date) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) ResponseBean(org.onebusaway.api.model.ResponseBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) Test(org.junit.Test)

Example 5 with TripStatusBean

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());
    }
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) Date(java.util.Date) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) StopBean(org.onebusaway.transit_data.model.StopBean) ResponseBean(org.onebusaway.api.model.ResponseBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) Test(org.junit.Test)

Aggregations

TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)16 TripBean (org.onebusaway.transit_data.model.trips.TripBean)12 ArrayList (java.util.ArrayList)8 RouteBean (org.onebusaway.transit_data.model.RouteBean)6 StopBean (org.onebusaway.transit_data.model.StopBean)5 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)4 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)4 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)4 Date (java.util.Date)3 Test (org.junit.Test)3 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)3 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)3 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)3 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)2 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)2 VehicleDescriptor (com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)2 VehiclePosition (com.google.transit.realtime.GtfsRealtime.VehiclePosition)2