Search in sources :

Example 26 with VehicleLocationRecord

use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.

the class GtfsRealtimeTripLibraryTest method testCreateVehicleLocationRecordForUpdate_WithStopTimeUpdates.

@Test
public void testCreateVehicleLocationRecordForUpdate_WithStopTimeUpdates() {
    StopTimeUpdate.Builder stopTimeUpdate = StopTimeUpdate.newBuilder();
    stopTimeUpdate.setStopId("stopA");
    StopTimeEvent.Builder stopTimeEvent = StopTimeEvent.newBuilder();
    stopTimeEvent.setDelay(180);
    stopTimeUpdate.setDeparture(stopTimeEvent);
    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(Arrays.asList(blockInstanceA));
    CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition();
    update.block = new BlockDescriptor();
    update.block.setBlockInstance(blockInstanceA);
    update.tripUpdates = Arrays.asList(tripUpdate);
    VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update);
    TimepointPredictionRecord tpr = record.getTimepointPredictions().get(0);
    long departure = tpr.getTimepointPredictedDepartureTime();
    // 7:30 plus 3 min delay, + now we are in ms.
    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 27 with VehicleLocationRecord

use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.

the class GtfsRealtimeTripLibraryTest method testTprInterpolation_2.

/**
 * Test that we do NOT create new timepoint prediction record when it
 * already exists.
 *
 * Current time = 7:25. Trip update delay = 2 minutes
 *          Schedule time    Real-time from feed  Timepoint predicted departure time
 * Stop A   7:30             7:33                 7:33 (and only one)
 */
@Test
public void testTprInterpolation_2() {
    _library.setCurrentTime(time(7, 25) * 1000);
    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);
    StopTimeUpdate.Builder stopTimeUpdate = stopTimeUpdateWithDepartureDelay("stopA", 180);
    TripUpdate.Builder tripUpdate = tripUpdate("tripA", _library.getCurrentTime() / 1000, 120, stopTimeUpdate);
    Mockito.when(_entitySource.getTrip("tripA")).thenReturn(tripA);
    Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
    VehicleLocationRecord record = vehicleLocationRecord(tripUpdate);
    long stopADept = getPredictedDepartureTimeByStopId(record, "stopA");
    assertEquals(stopADept, time(7, 33) * 1000);
    assertEquals(record.getTimepointPredictions().size(), 1);
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 28 with VehicleLocationRecord

use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.

the class VehicleStatusBeanServiceImpl method submitVehicleLocation.

@Override
public void submitVehicleLocation(VehicleLocationRecordBean bean) {
    VehicleLocationRecord r = new VehicleLocationRecord();
    r.setTimeOfRecord(bean.getTimeOfRecord());
    r.setTimeOfLocationUpdate(bean.getTimeOfLocationUpdate());
    r.setServiceDate(bean.getServiceDate());
    r.setBlockId(AgencyAndIdLibrary.convertFromString(bean.getBlockId()));
    r.setTripId(AgencyAndIdLibrary.convertFromString(bean.getTripId()));
    r.setVehicleId(AgencyAndIdLibrary.convertFromString(bean.getVehicleId()));
    if (bean.getPhase() != null)
        r.setPhase(EVehiclePhase.valueOf(bean.getPhase().toUpperCase()));
    r.setStatus(bean.getStatus());
    CoordinatePoint p = bean.getCurrentLocation();
    if (p != null) {
        r.setCurrentLocationLat(p.getLat());
        r.setCurrentLocationLon(p.getLon());
    }
    if (bean.isCurrentOrientationSet())
        r.setCurrentOrientation(bean.getCurrentOrientation());
    if (bean.isDistanceAlongBlockSet())
        r.setDistanceAlongBlock(bean.getDistanceAlongBlock());
    if (bean.isScheduleDeviationSet())
        r.setScheduleDeviation(bean.getScheduleDeviation());
    _vehicleLocationListener.handleVehicleLocationRecord(r);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord)

Example 29 with VehicleLocationRecord

use of org.onebusaway.realtime.api.VehicleLocationRecord 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;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) EVehiclePhase(org.onebusaway.realtime.api.EVehiclePhase) ArrayList(java.util.ArrayList) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) VehicleLocationRecordBean(org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean)

Example 30 with VehicleLocationRecord

use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.

the class BlockLocationServiceImpl method getBlockLocationRecordsAsVehicleLocationRecords.

private List<VehicleLocationCacheElements> getBlockLocationRecordsAsVehicleLocationRecords(BlockInstance blockInstance, List<BlockLocationRecord> records) {
    List<VehicleLocationCacheElements> results = new ArrayList<VehicleLocationCacheElements>();
    for (BlockLocationRecord record : records) {
        VehicleLocationRecord vlr = new VehicleLocationRecord();
        vlr.setBlockId(blockInstance.getBlock().getBlock().getId());
        if (record.isLocationSet()) {
            vlr.setCurrentLocationLat(record.getLocationLat());
            vlr.setCurrentLocationLon(record.getLocationLon());
        }
        if (record.isOrientationSet())
            vlr.setCurrentOrientation(record.getOrientation());
        if (record.isDistanceAlongBlockSet())
            vlr.setDistanceAlongBlock(record.getDistanceAlongBlock());
        vlr.setPhase(record.getPhase());
        if (record.isScheduleDeviationSet())
            vlr.setScheduleDeviation(record.getScheduleDeviation());
        vlr.setServiceDate(record.getServiceDate());
        vlr.setStatus(record.getStatus());
        vlr.setTimeOfRecord(record.getTime());
        vlr.setVehicleId(record.getVehicleId());
        VehicleLocationCacheElement element = new VehicleLocationCacheElement(vlr, null, null);
        VehicleLocationCacheElements elements = new VehicleLocationCacheElements(blockInstance, element);
        results.add(elements);
    }
    return results;
}
Also used : VehicleLocationCacheElements(org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElements) VehicleLocationCacheElement(org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElement) ArrayList(java.util.ArrayList) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord)

Aggregations

VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)17 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)16 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)10 Test (org.junit.Test)10 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)10 Date (java.util.Date)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)6 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)6 ArrayList (java.util.ArrayList)5 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)5 ScheduledBlockLocationServiceImpl (org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl)5 VehicleLocationRecordCacheImpl (org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl)5 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)5 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)5 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)5