Package org.onebusaway.realtime.api

Examples of org.onebusaway.realtime.api.VehicleLocationRecord


      List<CombinedTripUpdatesAndVehiclePosition> updates) {

    Set<AgencyAndId> seenVehicles = new HashSet<AgencyAndId>();

    for (CombinedTripUpdatesAndVehiclePosition update : updates) {
      VehicleLocationRecord record = _tripsLibrary.createVehicleLocationRecordForUpdate(result, update);
      if (record != null) {
        if (record.getTripId() != null) {
          result.addUnmatchedTripId(record.getTripId().toString());
        }
        AgencyAndId vehicleId = record.getVehicleId();
        seenVehicles.add(vehicleId);
        Date timestamp = new Date(record.getTimeOfRecord());
        Date prev = _lastVehicleUpdate.get(vehicleId);
        if (prev == null || prev.before(timestamp)) {
          _vehicleLocationListener.handleVehicleLocationRecord(record);
          _lastVehicleUpdate.put(vehicleId, timestamp);
        }
View Full Code Here


   
    public VehicleLocationRecord createVehicleLocationRecordForUpdate(MonitoredResult result,
        CombinedTripUpdatesAndVehiclePosition update) {


    VehicleLocationRecord record = new VehicleLocationRecord();
    record.setTimeOfRecord(currentTime());

    BlockDescriptor blockDescriptor = update.block;

    record.setBlockId(blockDescriptor.getBlockEntry().getId());

    applyTripUpdatesToRecord(result, blockDescriptor, update.tripUpdates, record);

    if (update.vehiclePosition != null) {
      applyVehiclePositionToRecord(update.vehiclePosition, record);
    }

    /**
     * By default, we use the block id as the vehicle id
     */
    record.setVehicleId(record.getBlockId());

    if (result != null) {
      if (record.getTripId() != null) {
        result.addMatchedTripId(record.getTripId().toString());
      } else {
        // we don't have a tripId, use the BlockId instead
        result.addMatchedTripId(record.getBlockId().toString());
      }
    }
   
    if (blockDescriptor.getVehicleId() != null) {
      String agencyId = record.getBlockId().getAgencyId();
      record.setVehicleId(new AgencyAndId(agencyId,
          blockDescriptor.getVehicleId()));
    }

    return record;
  }
View Full Code Here

    FeedMessage.Builder feedMessage = createFeedWithDefaultHeader();

    List<VehicleStatus> statuses = _vehicleStatusService.getAllVehicleStatuses();
    for (VehicleStatus status : statuses) {

      VehicleLocationRecord record = status.getRecord();
      VehiclePosition.Builder vehiclePosition = VehiclePosition.newBuilder();

      if (record.isCurrentLocationSet()) {
        Position.Builder position = Position.newBuilder();
        position.setLatitude((float) record.getCurrentLocationLat());
        position.setLongitude((float) record.getCurrentLocationLon());
        vehiclePosition.setPosition(position);
      }

      VehicleDescriptor.Builder vehicleDescriptor = VehicleDescriptor.newBuilder();
      vehicleDescriptor.setId(AgencyAndId.convertToString(record.getVehicleId()));
      vehiclePosition.setVehicle(vehicleDescriptor);

      if (record.getTimeOfLocationUpdate() != 0)
        vehiclePosition.setTimestamp(record.getTimeOfLocationUpdate() / 1000);
      else
        vehiclePosition.setTimestamp(record.getTimeOfRecord() / 1000);

      /**
       * TODO: Block? Trip?
       */

 
View Full Code Here

    if (cacheElements != null)
      cacheElement = cacheElements.getElementForTimestamp(targetTime);

    if (cacheElement != null) {

      VehicleLocationRecord record = cacheElement.getRecord();

      if (scheduledLocation == null)
        scheduledLocation = getScheduledBlockLocationForVehicleLocationCacheRecord(
            blockInstance, cacheElement, targetTime);

      if (scheduledLocation != null) {
        location.setEffectiveScheduleTime(scheduledLocation.getScheduledTime());
        location.setDistanceAlongBlock(scheduledLocation.getDistanceAlongBlock());

      }

      location.setPredicted(true);
      location.setLastUpdateTime(record.getTimeOfRecord());
      location.setLastLocationUpdateTime(record.getTimeOfLocationUpdate());
      location.setScheduleDeviation(record.getScheduleDeviation());
      location.setScheduleDeviations(cacheElement.getScheduleDeviations());

      if (record.isCurrentLocationSet()) {
        CoordinatePoint p = new CoordinatePoint(record.getCurrentLocationLat(),
            record.getCurrentLocationLon());
        location.setLastKnownLocation(p);
      }
      location.setOrientation(record.getCurrentOrientation());
      location.setPhase(record.getPhase());
      location.setStatus(record.getStatus());
      location.setVehicleId(record.getVehicleId());

      List<TimepointPredictionRecord> timepointPredictions = record.getTimepointPredictions();
      if (timepointPredictions != null && !timepointPredictions.isEmpty()) {

        SortedMap<Integer, Double> scheduleDeviations = new TreeMap<Integer, Double>();

        BlockConfigurationEntry blockConfig = blockInstance.getBlock();
View Full Code Here

  private ScheduledBlockLocation getScheduledBlockLocationForVehicleLocationCacheRecord(
      BlockInstance blockInstance, VehicleLocationCacheElement cacheElement,
      long targetTime) {

    VehicleLocationRecord record = cacheElement.getRecord();
    ScheduledBlockLocation scheduledBlockLocation = cacheElement.getScheduledBlockLocation();

    BlockConfigurationEntry blockConfig = blockInstance.getBlock();
    long serviceDate = blockInstance.getServiceDate();

    int scheduledTime = (int) ((targetTime - serviceDate) / 1000);

    /**
     * If location interpolation has been turned off, then we assume the vehicle
     * is at its last known location, so we return that if it's been stored with
     * the cache element.
     */
    if (!_locationInterpolation && scheduledBlockLocation != null) {
      return scheduledBlockLocation;
    }

    if (record.isScheduleDeviationSet()) {

      /**
       * Effective scheduled time is the point that a transit vehicle is at on
       * its schedule, with schedule deviation taken into account. So if it's
       * 100 minutes into the current service date and the bus is running 10
       * minutes late, it's actually at the 90 minute point in its scheduled
       * operation.
       */
      int effectiveScheduledTime = (int) (scheduledTime - record.getScheduleDeviation());

      if (scheduledBlockLocation != null
          && scheduledBlockLocation.getScheduledTime() <= effectiveScheduledTime) {

        return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
            scheduledBlockLocation, effectiveScheduledTime);
      }

      return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
          blockConfig, effectiveScheduledTime);
    }

    if (record.isDistanceAlongBlockSet()) {

      if ((_locationInterpolation || _distanceAlongBlockLocationInterpolation)
          && scheduledBlockLocation != null
          && scheduledBlockLocation.getDistanceAlongBlock() <= record.getDistanceAlongBlock()) {

        int ellapsedTime = (int) ((targetTime - record.getTimeOfRecord()) / 1000);

        if (ellapsedTime >= 0) {

          int effectiveScheduledTime = scheduledBlockLocation.getScheduledTime()
              + ellapsedTime;

          return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
              blockConfig, effectiveScheduledTime);
        }

        return _scheduledBlockLocationService.getScheduledBlockLocationFromDistanceAlongBlock(
            scheduledBlockLocation, record.getDistanceAlongBlock());
      }

      return _scheduledBlockLocationService.getScheduledBlockLocationFromDistanceAlongBlock(
          blockConfig, record.getDistanceAlongBlock());
    }

    return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
        blockConfig, scheduledTime);
  }
View Full Code Here

      for (int i = 0; i < 100; i++) {

        if (i % 10 == 0)
          _cache.clearRecordsForVehicleId(_vehicleId);

        VehicleLocationRecord r = new VehicleLocationRecord();
        r.setBlockId(_blockInstance.getBlock().getBlock().getId());
        r.setServiceDate(_blockInstance.getServiceDate());
        r.setVehicleId(_vehicleId);
        r.setDistanceAlongBlock(i * 100);
        r.setTimeOfRecord(i * 1000);

        _cache.addRecord(_blockInstance, r, null, null);

        List<VehicleLocationCacheElements> records = _cache.getRecordsForBlockInstance(_blockInstance);
        VehicleLocationCacheElements cacheRecord = getCollectionForVehicleId(records);
        if (cacheRecord == null)
          fail();

        VehicleLocationRecord record = cacheRecord.getLastElement().getRecord();

        assertEquals(i * 1000L, record.getTimeOfRecord());
        assertEquals(_blockInstance, cacheRecord.getBlockInstance());
        assertEquals(_vehicleId, record.getVehicleId());

        Thread.yield();
      }
    }
View Full Code Here

      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);
View Full Code Here

    tripUpdate = group.tripUpdates.get(0);
    assertEquals("tripC", tripUpdate.getTrip().getTripId());
    tripUpdate = group.tripUpdates.get(1);
    assertEquals("tripD", tripUpdate.getTrip().getTripId());

    VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(groups.get(0));
    assertEquals(blockA.getId(), record.getBlockId());
    assertEquals(120, record.getScheduleDeviation(), 0.0);
    assertEquals(0L, record.getServiceDate());
    assertEquals(blockA.getId(), record.getVehicleId());

    record = _library.createVehicleLocationRecordForUpdate(groups.get(1));
    assertEquals(blockB.getId(), record.getBlockId());
    assertEquals(30, record.getScheduleDeviation(), 0.0);
    assertEquals(0L, record.getServiceDate());
    assertEquals(blockB.getId(), record.getVehicleId());
  }
View Full Code Here

    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);
  }
View Full Code Here

   ****/

  @Override
  public VehicleStatus getVehicleStatusForId(AgencyAndId vehicleId) {

    VehicleLocationRecord record = _vehicleRecordsById.get(vehicleId);
    if (record == null)
      return null;

    List<VehicleLocationRecord> records = new ArrayList<VehicleLocationRecord>();
    VehicleLocationCacheElements elements = _vehicleLocationRecordCache.getRecordForVehicleId(vehicleId);
View Full Code Here

TOP

Related Classes of org.onebusaway.realtime.api.VehicleLocationRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.