use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.
the class SiriLikeRealtimeSourceTest method testParseRoute2Multi.
// @Test
public void testParseRoute2Multi() throws Exception {
URL url = getClass().getResource("SiriLike_2_multi.xml").toURI().toURL();
NodesAndTimestamp vehicles = source.parseVehicles(url);
assertNotNull(vehicles);
assertEquals(4, vehicles.getNodes().size());
// as we don't have predictions, there isn't much we can do with this
VehicleLocationRecord vlr = source.parse(vehicles.getNodes().get(0), 0);
assertNotNull(vlr);
assertEquals("UTA", vlr.getTripId().getAgencyId());
assertEquals("2726063", vlr.getTripId().getId());
assertNull(vlr.getBlockId());
assertEquals(1470204000000l, vlr.getServiceDate());
assertEquals("13034", vlr.getVehicleId().getId());
assertEquals(40.76492, vlr.getCurrentLocationLat(), 0.0001);
assertEquals(-111.8756, vlr.getCurrentLocationLon(), 0.0001);
assertEquals(-2.0, vlr.getScheduleDeviation(), 0.01);
}
use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.
the class VehicleLocationRecordCacheImplTest method testSimpleOperations.
@Test
public void testSimpleOperations() {
long serviceDate = System.currentTimeMillis();
BlockEntryImpl block = block("blockA");
TripEntryImpl trip = trip("tripA", "serviceId");
stopTime(0, null, trip, time(9, 00), 0);
BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
VehicleLocationRecordCacheImpl cache = new VehicleLocationRecordCacheImpl();
cache.setBlockLocationRecordCacheWindowSize(20);
List<VehicleLocationCacheElements> records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(0, records.size());
VehicleLocationCacheElements cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
assertNull(cacheRecord);
cache.addRecord(blockInstance, record(20, "blockA", serviceDate, "vehicleA", 10.0), null, null);
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
cacheRecord = records.get(0);
VehicleLocationRecord record = cacheRecord.getLastElement().getRecord();
assertEquals(20, record.getTimeOfRecord());
assertEquals(blockInstance, cacheRecord.getBlockInstance());
assertEquals(aid("vehicleA"), record.getVehicleId());
VehicleLocationCacheElements cacheRecord2 = cache.getRecordForVehicleId(aid("vehicleA"));
assertSame(cacheRecord, cacheRecord2);
cache.addRecord(blockInstance, record(30, "blockA", serviceDate, "vehicleA", 20.0), null, null);
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
cacheRecord = records.get(0);
record = cacheRecord.getLastElement().getRecord();
assertEquals(30, record.getTimeOfRecord());
assertEquals(blockInstance, cacheRecord.getBlockInstance());
assertEquals(aid("vehicleA"), record.getVehicleId());
cacheRecord2 = cache.getRecordForVehicleId(aid("vehicleA"));
assertSame(cacheRecord, cacheRecord2);
cache.addRecord(blockInstance, record(40, "blockA", serviceDate, "vehicleB", 5.0), null, null);
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(2, records.size());
cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
record = cacheRecord.getLastElement().getRecord();
assertEquals(30, record.getTimeOfRecord());
assertEquals(blockInstance, cacheRecord.getBlockInstance());
assertEquals(aid("vehicleA"), record.getVehicleId());
cacheRecord = cache.getRecordForVehicleId(aid("vehicleB"));
record = cacheRecord.getLastElement().getRecord();
assertEquals(40, record.getTimeOfRecord());
assertEquals(blockInstance, cacheRecord.getBlockInstance());
assertEquals(aid("vehicleB"), record.getVehicleId());
cache.clearRecordsForVehicleId(aid("vehicleA"));
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
assertNull(cacheRecord);
cacheRecord = cache.getRecordForVehicleId(aid("vehicleB"));
assertEquals(aid("vehicleB"), cacheRecord.getLastElement().getRecord().getVehicleId());
}
use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.
the class VehicleLocationRecordCacheImplTest method record.
private VehicleLocationRecord record(long t, String blockId, long serviceDate, String vehicleId, double distanceAlongBlock) {
VehicleLocationRecord r = new VehicleLocationRecord();
r.setBlockId(new AgencyAndId("1", blockId));
r.setServiceDate(serviceDate);
r.setVehicleId(new AgencyAndId("1", vehicleId));
r.setDistanceAlongBlock(distanceAlongBlock);
r.setTimeOfRecord(t);
return r;
}
use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.
the class VehicleLocationCacheElements method getElementForTimestamp.
public VehicleLocationCacheElement getElementForTimestamp(long targetTime) {
if (_elements.isEmpty())
return null;
for (int i = _elements.size() - 1; i > 0; i--) {
VehicleLocationCacheElement element = _elements.get(i);
VehicleLocationRecord record = element.getRecord();
if (record.getTimeOfRecord() <= targetTime)
return element;
}
return _elements.get(0);
}
use of org.onebusaway.realtime.api.VehicleLocationRecord in project onebusaway-application-modules by camsys.
the class VehicleLocationRecordController method submit.
@RequestMapping("/vehicle-location-record!submit.action")
public ModelAndView submit(@RequestParam() String time, @RequestParam() String serviceDate, @RequestParam() String blockId, @RequestParam() String vehicleId, int scheduleDeviation) throws ParseException {
long t = convertTime(time);
long sd = convertTime(serviceDate);
VehicleLocationRecord record = new VehicleLocationRecord();
record.setTimeOfRecord(t);
record.setTimeOfLocationUpdate(t);
record.setServiceDate(sd);
record.setBlockId(AgencyAndIdLibrary.convertFromString(blockId));
record.setVehicleId(AgencyAndIdLibrary.convertFromString(vehicleId));
record.setScheduleDeviation(scheduleDeviation);
_vehicleLocationListener.handleVehicleLocationRecord(record);
return new ModelAndView("redirect:/vehicle-location-record.action");
}
Aggregations