Search in sources :

Example 6 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean 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 7 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.

the class TripAction method show.

public DefaultHttpHeaders show() throws ServiceException {
    if (!isVersion(V2))
        return setUnknownVersionResponse();
    if (hasErrors())
        return setValidationErrorsResponse();
    TripBean trip = _service.getTrip(_id);
    if (trip == null)
        return setResourceNotFoundResponse();
    BeanFactoryV2 factory = getBeanFactoryV2();
    EntryWithReferencesBean<TripV2Bean> response = factory.getResponse(trip);
    return setOkResponse(response);
}
Also used : TripV2Bean(org.onebusaway.api.model.transit.TripV2Bean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 8 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean 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)

Example 9 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesAction method buildPredictedArrivals.

protected void buildPredictedArrivals(List<ArrivalAndDepartureBean> arrivals, List<StopBean> list) {
    if (arrivals.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
    }
    Collections.sort(arrivals, new ArrivalAndDepartureComparator());
    long now = SystemTime.currentTimeMillis();
    boolean hasAlerts = stopsHaveAlerts(list);
    for (ArrivalAndDepartureBean adb : arrivals) {
        TripBean trip = adb.getTrip();
        RouteBean route = trip.getRoute();
        addMessage(Messages.ROUTE);
        String routeNumber = RoutePresenter.getNameForRoute(route);
        addText(_routeNumberPronunciation.modify(routeNumber));
        addText(", ");
        String headsign = trip.getTripHeadsign();
        if (headsign != null) {
            // addMessage(Messages.TO);
            String destination = _destinationPronunciation.modify(headsign);
            destination = destination.replaceAll("\\&", "and");
            addText(destination);
            addText(", ");
        }
        if (TransitDataConstants.STATUS_LEGACY_CANCELLED.equalsIgnoreCase(adb.getStatus())) {
            addText("is currently not in service");
            continue;
        }
        long t = adb.computeBestDepartureTime();
        boolean isPrediction = adb.hasPredictedDepartureTime();
        int min = (int) ((t - now) / 1000 / 60);
        if (min < 0) {
            min = -min;
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_PAST_DATE : Messages.SCHEDULED_AT_PAST_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_PAST : Messages.SCHEDULED_IN_PAST;
                addMessage(message, min);
            }
        } else {
            if (min > 60) {
                String message = isPrediction ? Messages.PREDICTED_AT_FUTURE_DATE : Messages.SCHEDULED_AT_FUTURE_DATE;
                addMessage(message, new Date(t));
            } else {
                String message = isPrediction ? Messages.PREDICTED_IN_FUTURE : Messages.SCHEDULED_IN_FUTURE;
                addMessage(message, min);
            }
        }
        if (TransitDataConstants.STATUS_REROUTE.equals(adb.getStatus())) {
            addText("but is currently on adverse weather re-route.");
        }
        addText(". ");
        if (!hasAlerts && adb.getSituations() != null && adb.getSituations().size() > 0) {
            hasAlerts = true;
        }
    }
    if (hasAlerts) {
        addText(getAlertPresentText());
    }
    addMessage(Messages.ARRIVAL_INFO_DISCLAIMER);
    List<AgencyBean> agencies = AgencyPresenter.getAgenciesForArrivalAndDepartures(arrivals);
    if (!agencies.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_DATA_PROVIDED_BY);
        for (int i = 0; i < agencies.size(); i++) {
            AgencyBean agency = agencies.get(i);
            if (i == agencies.size() - 1 && agencies.size() > 1)
                addText(Messages.AND);
            addText(agency.getName());
            addText(",");
        }
    }
    addMessage(Messages.STOP_FOUND_BOOKMARK_THIS_LOCATION);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrivalAndDepartureComparator(org.onebusaway.presentation.impl.ArrivalAndDepartureComparator) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) Date(java.util.Date) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Example 10 with TripBean

use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.

the class BeanFactoryV2 method getTripDetails.

public TripDetailsV2Bean getTripDetails(TripDetailsBean tripDetails) {
    TripDetailsV2Bean bean = new TripDetailsV2Bean();
    bean.setTripId(tripDetails.getTripId());
    bean.setServiceDate(tripDetails.getServiceDate());
    if (tripDetails.getFrequency() != null)
        bean.setFrequency(getFrequency(tripDetails.getFrequency()));
    TripBean trip = tripDetails.getTrip();
    if (trip != null)
        addToReferences(trip);
    TripStopTimesBean stopTimes = tripDetails.getSchedule();
    if (stopTimes != null)
        bean.setSchedule(getTripStopTimes(stopTimes));
    TripStatusBean status = tripDetails.getStatus();
    if (status != null)
        bean.setStatus(getTripStatus(status));
    List<ServiceAlertBean> situations = tripDetails.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            addToReferences(situation);
            situationIds.add(situation.getId());
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : ArrayList(java.util.ArrayList) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean)

Aggregations

TripBean (org.onebusaway.transit_data.model.trips.TripBean)28 RouteBean (org.onebusaway.transit_data.model.RouteBean)14 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)12 ArrayList (java.util.ArrayList)11 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)8 StopBean (org.onebusaway.transit_data.model.StopBean)8 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)6 FrequencyBean (org.onebusaway.transit_data.model.schedule.FrequencyBean)6 Date (java.util.Date)5 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)5 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)4 Test (org.junit.Test)4 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)3 TripStopTimesBean (org.onebusaway.transit_data.model.TripStopTimesBean)3 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)3