Search in sources :

Example 6 with TimepointPredictionRecord

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);
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopTimeEvent(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Test(org.junit.Test)

Example 7 with TimepointPredictionRecord

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;
}
Also used : ArrayList(java.util.ArrayList) TripBean(org.onebusaway.transit_data.model.trips.TripBean) MonitoredStopVisitStructure(uk.org.siri.siri.MonitoredStopVisitStructure) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) Date(java.util.Date) RouteBean(org.onebusaway.transit_data.model.RouteBean) MonitoredVehicleJourneyStructure(uk.org.siri.siri.MonitoredVehicleJourneyStructure) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean)

Example 8 with TimepointPredictionRecord

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;
}
Also used : TripForVehicleQueryBean(org.onebusaway.transit_data.model.trips.TripForVehicleQueryBean) TripDetailsQueryBean(org.onebusaway.transit_data.model.trips.TripDetailsQueryBean) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) Date(java.util.Date) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) MonitoredVehicleJourney(uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney)

Example 9 with TimepointPredictionRecord

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;
}
Also used : ArrayList(java.util.ArrayList) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) Date(java.util.Date) MonitoredVehicleJourney(uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney)

Example 10 with TimepointPredictionRecord

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;
}
Also used : ArrayList(java.util.ArrayList) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord)

Aggregations

TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)36 Test (org.junit.Test)20 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)17 ArrayList (java.util.ArrayList)10 Date (java.util.Date)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)5 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)4 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)4 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)4 StopTimeEvent (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent)3 HashMap (java.util.HashMap)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 TripBean (org.onebusaway.transit_data.model.trips.TripBean)3 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)3 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)3