Search in sources :

Example 16 with VehicleLocationRecord

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);
}
Also used : VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) URL(java.net.URL) NodesAndTimestamp(org.onebusaway.transit_data_federation.impl.realtime.SiriLikeRealtimeSource.NodesAndTimestamp)

Example 17 with VehicleLocationRecord

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());
}
Also used : VehicleLocationCacheElements(org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElements) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) 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 18 with VehicleLocationRecord

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord)

Example 19 with VehicleLocationRecord

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

Example 20 with VehicleLocationRecord

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");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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