private VehicleActivity createActivity(VehicleStatusBean vehicleStatus, boolean onwardCalls) {

    if (vehicleStatus.getPhase().equals("DEADHEAD_AFTER")
        || vehicleStatus.getPhase().equals("DEADHEAD_BEFORE")
        || vehicleStatus.getPhase().equals("DEADHEAD_DURING")) {
      return null;
    }
    VehicleActivity activity = new VehicleActivity();

    Calendar time = Calendar.getInstance();
    time.setTime(new Date(vehicleStatus.getLastUpdateTime()));

    activity.RecordedAtTime = time;
    TripBean tripBean = vehicleStatus.getTrip();
    if (tripBean != null) {
      TripDetailsQueryBean query = new TripDetailsQueryBean();
      query.setTime(time.getTimeInMillis());
      query.setTripId(tripBean.getId());
      query.setVehicleId(vehicleStatus.getVehicleId());
      query.getInclusion().setIncludeTripStatus(true);
      TripStatusBean tripStatus = vehicleStatus.getTripStatus();
      query.setServiceDate(tripStatus.getServiceDate());
      TripDetailsBean tripDetails = _transitDataService.getSingleTripDetails(query);
      activity.MonitoredVehicleJourney =
          SiriUtils.getMonitoredVehicleJourney(
              tripDetails, new Date(tripStatus.getServiceDate()), vehicleStatus.getVehicleId());

      if (onwardCalls) {

        List<TripStopTimeBean> stopTimes = tripDetails.getSchedule().getStopTimes();

        long serviceDateMillis = tripStatus.getServiceDate();
        double distance = tripStatus.getDistanceAlongTrip();
        if (Double.isNaN(distance)) {
          distance = tripStatus.getScheduledDistanceAlongTrip();
        }
        activity.MonitoredVehicleJourney.OnwardCalls =
            SiriUtils.getOnwardCalls(
                stopTimes, serviceDateMillis, distance, tripStatus.getNextStop());
      }
    } else {
      activity.MonitoredVehicleJourney = new MonitoredVehicleJourney();
    }
    activity.MonitoredVehicleJourney.Monitored = true;

    activity.MonitoredVehicleJourney.VehicleRef = vehicleStatus.getVehicleId();

    activity.MonitoredVehicleJourney.ProgressRate =
        SiriUtils.getProgressRateForStatus(vehicleStatus.getStatus());

    VehicleLocation location = new VehicleLocation();
    location.Latitude = vehicleStatus.getLocation().getLat();
    location.Longitude = vehicleStatus.getLocation().getLon();

    activity.MonitoredVehicleJourney.VehicleLocation = location;
    return activity;
  }
Пример #2
0
  public VehicleStatusV2Bean getVehicleStatus(VehicleStatusBean vehicleStatus) {

    VehicleStatusV2Bean bean = new VehicleStatusV2Bean();

    bean.setLastUpdateTime(vehicleStatus.getLastUpdateTime());
    if (vehicleStatus.getLastLocationUpdateTime() > 0)
      bean.setLastLocationUpdateTime(vehicleStatus.getLastLocationUpdateTime());
    bean.setLocation(vehicleStatus.getLocation());
    bean.setPhase(vehicleStatus.getPhase());
    bean.setStatus(vehicleStatus.getStatus());
    bean.setVehicleId(vehicleStatus.getVehicleId());

    TripBean trip = vehicleStatus.getTrip();
    if (trip != null) {
      bean.setTripId(trip.getId());
      addToReferences(trip);
    }

    return bean;
  }