use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.
the class SimulateScheduledVehicleLocationsController method index.
@RequestMapping()
public ModelAndView index(@RequestParam() String blockId, @RequestParam() long serviceDate, @RequestParam(defaultValue = "0") int scheduleDeviation, @RequestParam(defaultValue = "0.0") double noise) {
AgencyAndId bid = AgencyAndIdLibrary.convertFromString(blockId);
BlockInstance blockInstance = _blockCalendarService.getBlockInstance(bid, serviceDate);
CurrentVehicleEstimateQueryBean bean = new CurrentVehicleEstimateQueryBean();
long time = SystemTime.currentTimeMillis();
List<Record> records = new ArrayList<Record>();
for (int i = 0; i < 5 * 60; i += 30) {
int scheduleTime = (int) ((time - blockInstance.getServiceDate()) / 1000 - scheduleDeviation - i);
ScheduledBlockLocation location = _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(blockInstance.getBlock(), scheduleTime);
if (location != null) {
CoordinatePoint p = applyNoiseToLocation(location.getLocation(), noise);
Record r = new Record();
r.setLocation(location.getLocation());
r.setTimestamp(time - i * 1000);
r.setLocation(p);
r.setAccuracy(noise);
records.add(r);
}
}
bean.setRecords(records);
ModelAndView mv = new ModelAndView("simulate-vehicle-locations.jspx");
mv.addObject("time", time);
mv.addObject("query", bean);
return mv;
}
use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord.
/**
* Set up the BlockLocationServiceImpl for the test, using the given
* timepointPredictions
*
* This method creates a loop route with a single trip and two stops in a block
* Stop A is visited twice in the route
*
* stop_id trip_id stop_sequence
* A 1 0
* B 1 1
* A 1 2
*
* @param timepointPredictions real-time predictions to apply to the
* BlockLocationServiceImpl
* @param stop stop_id for this stop is used to call getArrivalsAndDeparturesForStopInTimeRange()
* @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> getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(List<TimepointPredictionRecord> timepointPredictions, StopEntryImpl stop) {
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);
stopTime(2, mStopA, mTrip1, time(13, 55), time(13, 55), 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(2);
// 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(bstAA, blockInstance.getState());
ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
in1.setBlockLocation(blockLocationB);
in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
StopTimeInstance sti2 = new StopTimeInstance(bstAB, blockInstance.getState());
ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
in2.setBlockLocation(blockLocationB);
StopTimeInstance sti3 = new StopTimeInstance(bstBA, blockInstance.getState());
ArrivalAndDepartureInstance in3 = new ArrivalAndDepartureInstance(sti3);
in3.setBlockLocation(blockLocationB);
in3.setPredictedArrivalTime((long) (in3.getScheduledArrivalTime()));
in3.setPredictedDepartureTime((long) (in3.getScheduledDepartureTime()));
Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(stop, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2, sti3));
// 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(stop, target, stopTimeFrom, stopTimeTo);
}
use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImplTest method testHint01.
@Test
public void testHint01() {
ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(_blockConfig, time(10, 05));
try {
_service.getScheduledBlockLocationFromScheduledTime(position, time(9, 58));
fail();
} catch (Throwable ex) {
}
ScheduledBlockLocation next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 05));
assertEquals(time(10, 05), next.getScheduledTime());
assertEquals(500, next.getDistanceAlongBlock(), 0.0);
assertEquals(1, next.getStopTimeIndex());
next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 10));
assertEquals(time(10, 10), 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());
next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 20));
assertEquals(time(10, 20), next.getScheduledTime());
assertEquals(1200, next.getDistanceAlongBlock(), 0.0);
assertEquals(2, next.getStopTimeIndex());
next = _service.getScheduledBlockLocationFromScheduledTime(position, time(10, 25));
assertNull(next);
/**
**
*
***
*/
position = _service.getScheduledBlockLocationFromDistanceAlongBlock(_blockConfig, 500);
try {
_service.getScheduledBlockLocationFromDistanceAlongBlock(position, 400);
fail();
} catch (Throwable ex) {
}
next = _service.getScheduledBlockLocationFromDistanceAlongBlock(position, 680);
assertEquals(time(10, 8), next.getScheduledTime());
assertEquals(680, next.getDistanceAlongBlock(), 0.0);
assertEquals(1, next.getStopTimeIndex());
next = _service.getScheduledBlockLocationFromDistanceAlongBlock(position, 800);
assertEquals(time(10, 10), next.getScheduledTime());
assertEquals(800, next.getDistanceAlongBlock(), 0.0);
assertEquals(1, next.getStopTimeIndex());
next = _service.getScheduledBlockLocationFromDistanceAlongBlock(position, 960);
assertEquals(time(10, 17), next.getScheduledTime());
assertEquals(960, next.getDistanceAlongBlock(), 0.0);
assertEquals(2, next.getStopTimeIndex());
}
use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImplTest method test03.
@Test
public void test03() {
ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(_blockConfig, time(10, 8));
assertEquals(_tripA, position.getActiveTrip());
assertEquals(_stopTimeB, position.getClosestStop());
assertEquals(120, position.getClosestStopTimeOffset());
assertEquals(_stopTimeA, position.getPreviousStop());
assertEquals(_stopTimeB, position.getNextStop());
assertEquals(120, position.getNextStopTimeOffset());
assertEquals(680, position.getDistanceAlongBlock(), 0.0);
assertEquals(47.6666929645559, position.getLocation().getLat(), 1e-6);
assertEquals(-122.38214275139767, position.getLocation().getLon(), 1e-6);
assertEquals(318.3, position.getOrientation(), 0.1);
assertEquals(time(10, 8), position.getScheduledTime());
assertTrue(position.isInService());
assertEquals(1, position.getStopTimeIndex());
position = _service.getScheduledBlockLocationFromDistanceAlongBlock(_blockConfig, 680);
assertEquals(_tripA, position.getActiveTrip());
assertEquals(_stopTimeB, position.getClosestStop());
assertEquals(_stopTimeA, position.getPreviousStop());
assertEquals(_stopTimeB, position.getNextStop());
assertEquals(120, position.getNextStopTimeOffset());
assertEquals(120, position.getClosestStopTimeOffset());
assertEquals(680, position.getDistanceAlongBlock(), 0.0);
assertEquals(47.6666929645559, position.getLocation().getLat(), 1e-6);
assertEquals(-122.38214275139767, position.getLocation().getLon(), 1e-6);
assertEquals(318.3, position.getOrientation(), 0.1);
assertEquals(time(10, 8), position.getScheduledTime());
assertTrue(position.isInService());
assertEquals(1, position.getStopTimeIndex());
}
use of org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImplTest method test01.
@Test
public void test01() {
ScheduledBlockLocation position = _service.getScheduledBlockLocationFromScheduledTime(_blockConfig, time(10, 00));
assertEquals(_tripA, position.getActiveTrip());
assertEquals(_stopTimeA, position.getClosestStop());
assertEquals(0, position.getClosestStopTimeOffset());
assertNull(position.getPreviousStop());
assertEquals(_stopTimeA, position.getNextStop());
assertEquals(0, position.getNextStopTimeOffset());
assertEquals(200.0, position.getDistanceAlongBlock(), 0.0);
assertEquals(_stopA.getStopLat(), position.getLocation().getLat(), 1e-6);
assertEquals(_stopA.getStopLon(), position.getLocation().getLon(), 1e-6);
assertEquals(356.6, position.getOrientation(), 0.1);
assertEquals(time(10, 00), position.getScheduledTime());
assertTrue(position.isInService());
assertEquals(0, position.getStopTimeIndex());
position = _service.getScheduledBlockLocationFromDistanceAlongBlock(_blockConfig, 200.0);
assertEquals(_tripA, position.getActiveTrip());
assertEquals(_stopTimeA, position.getClosestStop());
assertEquals(0, position.getClosestStopTimeOffset());
assertNull(position.getPreviousStop());
assertEquals(_stopTimeA, position.getNextStop());
assertEquals(0, position.getNextStopTimeOffset());
assertEquals(200.0, position.getDistanceAlongBlock(), 0.0);
assertEquals(_stopA.getStopLat(), position.getLocation().getLat(), 1e-6);
assertEquals(_stopA.getStopLon(), position.getLocation().getLon(), 1e-6);
assertEquals(356.6, position.getOrientation(), 0.1);
assertEquals(time(10, 00), position.getScheduledTime());
assertTrue(position.isInService());
assertEquals(0, position.getStopTimeIndex());
}
Aggregations