Search in sources :

Example 11 with ScheduledBlockLocation

use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord.

/**
 * Set up the BlockLocationServiceImpl for the test, using the given
 * timepointPredictions
 *
 * This method creates a normal route with a single trip and two stops in a block
 *
 * stop_id     trip_id    stop_sequence
 *    A           1             0
 *    B           1             1
 *
 * @param timepointPredictions real-time predictions to apply to the
 *          BlockLocationServiceImpl
 * @return a list of ArrivalAndDepartureInstances which is used to access
 *         predicted arrival/departure times for a stop, for comparison
 *         against the expected values
 */
private List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord(List<TimepointPredictionRecord> timepointPredictions) {
    TargetTime target = new TargetTime(mCurrentTime, mCurrentTime);
    // Setup block
    BlockEntryImpl block = block("blockA");
    stopTime(0, mStopA, mTrip1, time(13, 30), time(13, 35), 1000);
    stopTime(1, mStopB, mTrip1, time(13, 45), time(13, 50), 2000);
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA"), lsids()), mTrip1);
    BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
    BlockStopTimeEntry bstBA = blockConfig.getStopTimes().get(0);
    // Setup block location instance for trip B
    BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBA.getTrip());
    blockLocationB.setBlockInstance(blockInstance);
    blockLocationB.setClosestStop(bstBA);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);
    blockLocationB.setTimepointPredictions(timepointPredictions);
    // Mock StopTimeInstance with time frame
    long stopTimeFrom = dateAsLong("2015-07-23 00:00");
    long stopTimeTo = dateAsLong("2015-07-24 00:00");
    StopTimeInstance sti1 = new StopTimeInstance(bstAB, blockInstance.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationB);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstBA, blockInstance.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
    Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
    Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(mStopB, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2));
    // Create and add vehicle location record cache
    VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
    VehicleLocationRecord vlr = new VehicleLocationRecord();
    vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
    vlr.setTripId(mTrip1.getId());
    vlr.setTimepointPredictions(blockLocationB.getTimepointPredictions());
    vlr.setTimeOfRecord(mCurrentTime);
    vlr.setVehicleId(new AgencyAndId("1", "123"));
    // Create ScheduledBlockLocation for cache
    ScheduledBlockLocation sbl = new ScheduledBlockLocation();
    sbl.setActiveTrip(blockLocationB.getActiveTrip());
    // Add data to cache
    _cache.addRecord(blockInstance, vlr, sbl, null);
    _blockLocationService.setVehicleLocationRecordCache(_cache);
    ScheduledBlockLocationServiceImpl scheduledBlockLocationServiceImpl = new ScheduledBlockLocationServiceImpl();
    _blockLocationService.setScheduledBlockLocationService(scheduledBlockLocationServiceImpl);
    // Call ArrivalAndDepartureService
    return _service.getArrivalsAndDeparturesForStopInTimeRange(mStopB, target, stopTimeFrom, stopTimeTo);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) VehicleLocationRecordCacheImpl(org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) ScheduledBlockLocationServiceImpl(org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 12 with ScheduledBlockLocation

use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImplTest method test00b.

@Test
public void test00b() {
    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(_blockConfig, time(9, 59));
    assertEquals(_tripA, position.getActiveTrip());
    assertEquals(_stopTimeA, position.getClosestStop());
    assertEquals(60, position.getClosestStopTimeOffset());
    assertNull(position.getPreviousStop());
    assertEquals(_stopTimeA, position.getNextStop());
    assertEquals(60, position.getNextStopTimeOffset());
    assertEquals(140.0, position.getDistanceAlongBlock(), 0.0);
    assertEquals(47.668911387520204, position.getLocation().getLat(), 1e-6);
    assertEquals(-122.38756951346872, position.getLocation().getLon(), 1e-6);
    assertEquals(270.8, position.getOrientation(), 0.1);
    assertEquals(time(9, 59), position.getScheduledTime());
    assertTrue(position.isInService());
    assertEquals(0, position.getStopTimeIndex());
    position = _service.getScheduledBlockLocationFromDistanceAlongBlock(_blockConfig, 140.0);
    assertEquals(_tripA, position.getActiveTrip());
    assertEquals(_stopTimeA, position.getClosestStop());
    assertEquals(60, position.getClosestStopTimeOffset());
    assertNull(position.getPreviousStop());
    assertEquals(_stopTimeA, position.getNextStop());
    assertEquals(60, position.getNextStopTimeOffset());
    assertEquals(140.0, position.getDistanceAlongBlock(), 0.0);
    assertEquals(47.668911387520204, position.getLocation().getLat(), 1e-6);
    assertEquals(-122.38756951346872, position.getLocation().getLon(), 1e-6);
    assertEquals(270.8, position.getOrientation(), 0.1);
    assertEquals(time(9, 59), position.getScheduledTime());
    assertTrue(position.isInService());
    assertEquals(0, position.getStopTimeIndex());
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) Test(org.junit.Test)

Example 13 with ScheduledBlockLocation

use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImplTest method test00a.

@Test
public void test00a() {
    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(_blockConfig, time(9, 55));
    assertEquals(_tripA, position.getActiveTrip());
    assertEquals(_stopTimeA, position.getClosestStop());
    assertEquals(300, position.getClosestStopTimeOffset());
    assertNull(position.getPreviousStop());
    assertEquals(_stopTimeA, position.getNextStop());
    assertEquals(300, position.getNextStopTimeOffset());
    assertEquals(0.0, position.getDistanceAlongBlock(), 0.0);
    assertEquals(47.670170374084805, position.getLocation().getLat(), 1e-6);
    assertEquals(-122.3875880241394, position.getLocation().getLon(), 1e-6);
    assertEquals(270.8, position.getOrientation(), 0.1);
    assertEquals(time(9, 55), position.getScheduledTime());
    assertFalse(position.isInService());
    assertEquals(0, position.getStopTimeIndex());
    ScheduledBlockLocation next = _service.getScheduledBlockLocationFromScheduledTime(position, time(9, 57));
    assertEquals(time(9, 57), next.getScheduledTime());
    next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 00));
    assertEquals(time(10, 00), next.getScheduledTime());
    next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 10));
    assertEquals(time(10, 10), next.getScheduledTime());
    next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 17));
    assertEquals(time(10, 17), next.getScheduledTime());
    next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 20));
    assertEquals(time(10, 20), next.getScheduledTime());
    position = _service.getScheduledBlockLocationFromDistanceAlongBlock(_blockConfig, -100);
    assertNull(position);
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) Test(org.junit.Test)

Example 14 with ScheduledBlockLocation

use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImplTest method test05.

@Test
public void test05() {
    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(_blockConfig, time(10, 17));
    assertEquals(_tripA, position.getActiveTrip());
    assertEquals(_stopTimeB, position.getClosestStop());
    assertEquals(-120, position.getClosestStopTimeOffset());
    assertEquals(_stopTimeB, position.getPreviousStop());
    assertEquals(_stopTimeC, position.getNextStop());
    assertEquals(180, position.getNextStopTimeOffset());
    assertEquals(960, position.getDistanceAlongBlock(), 0.0);
    assertEquals(47.66471023595962, position.getLocation().getLat(), 1e-6);
    assertEquals(-122.37984571150027, position.getLocation().getLon(), 1e-6);
    assertEquals(328.5, position.getOrientation(), 0.1);
    assertTrue(position.isInService());
    assertEquals(2, position.getStopTimeIndex());
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) Test(org.junit.Test)

Example 15 with ScheduledBlockLocation

use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.

the class ScheduledBlockLocationServiceImplTest method testHint02.

@Test
public void testHint02() {
    ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(_blockConfig, time(10, 12));
    ScheduledBlockLocation next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 12));
    assertEquals(time(10, 12), next.getScheduledTime());
    assertEquals(800, next.getDistanceAlongBlock(), 0.0);
    assertEquals(1, next.getStopTimeIndex());
    next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 17));
    assertEquals(time(10, 17), next.getScheduledTime());
    assertEquals(960, next.getDistanceAlongBlock(), 0.0);
    assertEquals(2, next.getStopTimeIndex());
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) Test(org.junit.Test)

Aggregations

ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)35 Test (org.junit.Test)15 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)13 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)10 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)10 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)9 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)9 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)8 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)7 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)6 Date (java.util.Date)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 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)5 PointAndOrientation (org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation)4 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)4 ArrayList (java.util.ArrayList)3 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)3