Package org.onebusaway.realtime.api

Examples of org.onebusaway.realtime.api.VehicleLocationRecord


      BlockConfigurationEntry blockConfig = blockInstance.getBlock();
      BlockEntry block = blockConfig.getBlock();
      AgencyAndId blockId = block.getId();

      VehicleLocationRecord message = new VehicleLocationRecord();

      message.setBlockId(blockId);

      message.setServiceDate(blockInstance.getServiceDate());
      message.setTimeOfRecord(record.getTime() * 1000);
      message.setTimeOfLocationUpdate(message.getTimeOfRecord());
     
      // In Orbcad, +scheduleDeviation means the bus is early and -schedule
      // deviation means bus is late, which is opposite the
      // ScheduleAdherenceRecord convention
      message.setScheduleDeviation(-record.getScheduleDeviation());

      message.setVehicleId(new AgencyAndId(blockId.getAgencyId(),
          Integer.toString(record.getVehicleId())));

      if (record.hasLat() && record.hasLon()) {
        message.setCurrentLocationLat(record.getLat());
        message.setCurrentLocationLon(record.getLon());
      }

      int effectiveScheduleTime = (int) (record.getTime() - blockInstance.getServiceDate() / 1000);
      int adjustedScheduleTime = effectiveScheduleTime
          - record.getScheduleDeviation();

      ScheduledBlockLocation location = _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(
          blockConfig, adjustedScheduleTime);

      if (location != null) {
        message.setDistanceAlongBlock(location.getDistanceAlongBlock());

        BlockTripEntry activeTrip = location.getActiveTrip();
        if (activeTrip != null) {
          message.setTripId(activeTrip.getTrip().getId());
          _currentResult.addMatchedTripId(activeTrip.getTrip().getId().toString());
        } else {
          _log.error("invalid trip for location=" + location);
          _currentResult.addUnmatchedTripId(blockId.toString()); // this isn't exactly right
        }
        // Are we at the start of the block?
        if (location.getDistanceAlongBlock() == 0) {

          VehicleLocationRecord lastRecord = _lastRecordByVehicleId.get(message.getVehicleId());
          boolean inMotion = true;
          if (lastRecord != null && lastRecord.isCurrentLocationSet()
              && message.isCurrentLocationSet()) {
            double d = SphericalGeometryLibrary.distance(
                lastRecord.getCurrentLocationLat(),
                lastRecord.getCurrentLocationLon(),
                message.getCurrentLocationLat(),
                message.getCurrentLocationLon());
            inMotion = d > _motionThreshold;
          }

View Full Code Here


      if (instances.size() != 1)
        continue;

      BlockInstance instance = instances.get(0);

      VehicleLocationRecord r = new VehicleLocationRecord();
      r.setTimeOfRecord(time.getTime());
      r.setServiceDate(instance.getServiceDate());
      r.setBlockId(block.getId());

      String agencyId = block.getId().getAgencyId();
      r.setVehicleId(new AgencyAndId(agencyId, vehicleRef.getValue()));

      r.setScheduleDeviation(delay.getTimeInMillis(now) / 1000);

      LocationStructure location = mvj.getVehicleLocation();
      if (location != null) {
        r.setCurrentLocationLat(location.getLatitude().doubleValue());
        r.setCurrentLocationLon(location.getLongitude().doubleValue());
      }

      records.add(r);
    }
View Full Code Here

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

    }
  }

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

   *
   ****/

  private VehicleStatusBean getStatusAsBean(VehicleStatus status, long time) {

    VehicleLocationRecord record = status.getRecord();

    VehicleStatusBean bean = new VehicleStatusBean();
    bean.setLastUpdateTime(record.getTimeOfRecord());
    bean.setLastLocationUpdateTime(record.getTimeOfLocationUpdate());

    EVehiclePhase phase = record.getPhase();
    if (phase != null)
      bean.setPhase(phase.toLabel());

    bean.setStatus(record.getStatus());

    if (record.isCurrentLocationSet())
      bean.setLocation(new CoordinatePoint(record.getCurrentLocationLat(),
          record.getCurrentLocationLon()));

    bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));

    TripDetailsBean details = _tripDetailsBeanService.getTripForVehicle(
        record.getVehicleId(), time, new TripDetailsInclusionBean(true, false,
            true));
    if (details != null && details.getStatus() != null) {
      bean.setTrip(details.getTrip());
      bean.setTripStatus(details.getStatus());
    }
View Full Code Here

    long timeTo = t + 30 * 60 * 1000;

    List<VehicleLocationRecord> records = new ArrayList<VehicleLocationRecord>();

    for (List<TimepointPrediction> recordsForBlock : predictionsByBlockId.values()) {
      VehicleLocationRecord record = getBestScheduleAdherenceRecord(recordsForBlock);
      List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(
          record.getBlockId(), timeFrom, timeTo);
      // TODO : We currently assume that a block won't overlap with itself
      if (instances.size() != 1)
        continue;

      BlockInstance instance = instances.get(0);
      record.setServiceDate(instance.getServiceDate());

      records.add(record);
    }

    _vehicleLocationListener.handleVehicleLocationRecords(records);
View Full Code Here

  private VehicleLocationRecord getBestScheduleAdherenceRecord(
      List<TimepointPrediction> recordsForBlock) {

    TimepointPrediction best = getBestTimepointPrediction(recordsForBlock);

    VehicleLocationRecord r = new VehicleLocationRecord();
    r.setBlockId(best.getBlockId());
    r.setTimeOfRecord(System.currentTimeMillis());
    r.setTimeOfLocationUpdate(r.getTimeOfRecord());
    r.setScheduleDeviation(best.getScheduleDeviation());

    if (_includeTimepointPredictionRecords) {
      TimepointPredictionRecord tpr = new TimepointPredictionRecord();
      tpr.setTimepointId(best.getTimepointId());
      tpr.setTimepointPredictedTime(best.getTimepointPredictedTime());
      tpr.setTimepointScheduledTime(best.getTimepointScheduledTime());
      r.setTimepointPredictions(Arrays.asList(tpr));
    }

    r.setTripId(best.getTripId());
    r.setVehicleId(best.getVehicleId());
    return r;
  }
View Full Code Here

  }

  @Override
  public void submitVehicleLocation(VehicleLocationRecordBean bean) {

    VehicleLocationRecord r = new VehicleLocationRecord();
    r.setTimeOfRecord(bean.getTimeOfRecord());
    r.setTimeOfLocationUpdate(bean.getTimeOfLocationUpdate());
    r.setServiceDate(bean.getServiceDate());

    r.setBlockId(AgencyAndIdLibrary.convertFromString(bean.getBlockId()));
    r.setTripId(AgencyAndIdLibrary.convertFromString(bean.getTripId()));
    r.setVehicleId(AgencyAndIdLibrary.convertFromString(bean.getVehicleId()));

    if (bean.getPhase() != null)
      r.setPhase(EVehiclePhase.valueOf(bean.getPhase().toUpperCase()));
    r.setStatus(bean.getStatus());

    CoordinatePoint p = bean.getCurrentLocation();
    if (p != null) {
      r.setCurrentLocationLat(p.getLat());
      r.setCurrentLocationLon(p.getLon());
    }

    if (bean.isCurrentOrientationSet())
      r.setCurrentOrientation(bean.getCurrentOrientation());
    if (bean.isDistanceAlongBlockSet())
      r.setDistanceAlongBlock(bean.getDistanceAlongBlock());
    if (bean.isScheduleDeviationSet())
      r.setScheduleDeviation(bean.getScheduleDeviation());

    _vehicleLocationListener.handleVehicleLocationRecord(r);
  }
View Full Code Here

      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");
  }
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.