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 TripStopTimesV2Bean getTripStopTimes(TripStopTimesBean tripStopTimes) {

    TripStopTimesV2Bean bean = new TripStopTimesV2Bean();

    bean.setTimeZone(tripStopTimes.getTimeZone());

    List<TripStopTimeV2Bean> instances = new ArrayList<TripStopTimeV2Bean>();
    for (TripStopTimeBean sti : tripStopTimes.getStopTimes()) {

      if (_excludeNonRevenueStops && isNonRevenueStop(sti)) continue;

      TripStopTimeV2Bean stiBean = new TripStopTimeV2Bean();
      stiBean.setArrivalTime(sti.getArrivalTime());
      stiBean.setDepartureTime(sti.getDepartureTime());
      stiBean.setStopHeadsign(sti.getStopHeadsign());
      stiBean.setDistanceAlongTrip(sti.getDistanceAlongTrip());

      stiBean.setStopId(sti.getStop().getId());
      addToReferences(sti.getStop());

      instances.add(stiBean);
    }

    bean.setStopTimes(instances);

    TripBean nextTrip = tripStopTimes.getNextTrip();
    if (nextTrip != null) {
      bean.setNextTripId(nextTrip.getId());
      addToReferences(nextTrip);
    }

    TripBean prevTrip = tripStopTimes.getPreviousTrip();
    if (prevTrip != null) {
      bean.setPreviousTripId(prevTrip.getId());
      addToReferences(prevTrip);
    }

    FrequencyBean freq = tripStopTimes.getFrequency();
    if (freq != null) bean.setFrequency(getFrequency(freq));

    return bean;
  }
示例#3
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;
  }
示例#4
0
  public TripV2Bean getTrip(TripBean trip) {

    TripV2Bean bean = new TripV2Bean();

    bean.setId(trip.getId());

    bean.setRouteId(trip.getRoute().getId());
    addToReferences(trip.getRoute());

    bean.setRouteShortName(trip.getRouteShortName());
    bean.setTripHeadsign(trip.getTripHeadsign());
    bean.setTripShortName(trip.getTripShortName());

    bean.setDirectionId(trip.getDirectionId());
    bean.setServiceId(trip.getServiceId());
    bean.setShapeId(trip.getShapeId());
    bean.setBlockId(trip.getBlockId());

    return bean;
  }
  public TransitLegV2Bean getTransitLeg(TransitLegBean leg) {

    TransitLegV2Bean bean = new TransitLegV2Bean();

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

    bean.setServiceDate(leg.getServiceDate());
    bean.setVehicleId(leg.getVehicleId());

    FrequencyBean frequency = leg.getFrequency();
    if (frequency != null) {
      FrequencyV2Bean freqBean = _factory.getFrequency(frequency);
      bean.setFrequency(freqBean);
    }

    StopBean fromStop = leg.getFromStop();
    if (fromStop != null) {
      bean.setFromStopId(fromStop.getId());
      bean.setFromStopSequence(leg.getFromStopSequence());
      _factory.addToReferences(fromStop);
    }

    bean.setScheduledDepartureTime(leg.getScheduledDepartureTime());
    bean.setPredictedDepartureTime(leg.getPredictedDepartureTime());
    bean.setScheduledDepartureInterval(
        _factory.getTimeInterval(leg.getScheduledDepartureInterval()));
    bean.setPredictedDepartureInterval(
        _factory.getTimeInterval(leg.getPredictedDepartureInterval()));

    StopBean toStop = leg.getToStop();
    if (toStop != null) {
      bean.setToStopId(toStop.getId());
      bean.setToStopSequence(leg.getToStopSequence());
      _factory.addToReferences(toStop);
    }

    bean.setScheduledArrivalTime(leg.getScheduledArrivalTime());
    bean.setPredictedArrivalTime(leg.getPredictedArrivalTime());
    bean.setScheduledArrivalInterval(_factory.getTimeInterval(leg.getScheduledArrivalInterval()));
    bean.setPredictedArrivalInterval(_factory.getTimeInterval(leg.getPredictedArrivalInterval()));

    bean.setRouteShortName(leg.getRouteShortName());
    bean.setRouteLongName(leg.getRouteLongName());
    bean.setTripHeadsign(leg.getTripHeadsign());
    bean.setPath(leg.getPath());

    List<ServiceAlertBean> situations = leg.getSituations();
    if (!CollectionsLibrary.isEmpty(situations)) {
      List<String> situationIds = new ArrayList<String>(situations.size());
      for (ServiceAlertBean situation : situations) {
        situationIds.add(situation.getId());
        _factory.addToReferences(situation);
      }
      bean.setSituationIds(situationIds);
    }

    return bean;
  }
示例#6
0
 public void addToReferences(TripBean trip) {
   if (!shouldAddReferenceWithId(_references.getTrips(), trip.getId())) return;
   TripV2Bean bean = getTrip(trip);
   _references.addTrip(bean);
 }
示例#7
0
  public ArrivalAndDepartureV2Bean getArrivalAndDeparture(ArrivalAndDepartureBean ad) {

    TripBean trip = ad.getTrip();
    RouteBean route = trip.getRoute();
    StopBean stop = ad.getStop();

    ArrivalAndDepartureV2Bean bean = new ArrivalAndDepartureV2Bean();

    bean.setTripId(trip.getId());
    addToReferences(trip);

    bean.setServiceDate(ad.getServiceDate());
    bean.setVehicleId(ad.getVehicleId());
    bean.setStopId(stop.getId());
    addToReferences(stop);
    bean.setStopSequence(ad.getStopSequence());
    bean.setBlockTripSequence(ad.getBlockTripSequence());

    bean.setRouteId(route.getId());
    addToReferences(route);

    String routeShortName = ad.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty())
      routeShortName = trip.getRouteShortName();
    if (routeShortName == null || routeShortName.isEmpty()) routeShortName = route.getShortName();
    bean.setRouteShortName(routeShortName);

    bean.setRouteLongName(route.getLongName());

    String tripHeadsign = ad.getTripHeadsign();
    if (tripHeadsign == null || tripHeadsign.isEmpty()) tripHeadsign = trip.getTripHeadsign();
    bean.setTripHeadsign(tripHeadsign);

    bean.setArrivalEnabled(ad.isArrivalEnabled());
    bean.setDepartureEnabled(ad.isDepartureEnabled());

    bean.setScheduledArrivalTime(ad.getScheduledArrivalTime());
    bean.setScheduledDepartureTime(ad.getScheduledDepartureTime());

    bean.setScheduledArrivalInterval(getTimeInterval(ad.getScheduledArrivalInterval()));
    bean.setScheduledDepartureInterval(getTimeInterval(ad.getScheduledDepartureInterval()));

    if (ad.getFrequency() != null) bean.setFrequency(getFrequency(ad.getFrequency()));

    bean.setStatus(ad.getStatus());

    if (ad.isDistanceFromStopSet()) bean.setDistanceFromStop(ad.getDistanceFromStop());

    bean.setNumberOfStopsAway(ad.getNumberOfStopsAway());

    bean.setPredicted(ad.isPredicted());
    bean.setLastUpdateTime(ad.getLastUpdateTime());

    List<ServiceAlertBean> situations = ad.getSituations();
    if (situations != null && !situations.isEmpty()) {
      List<String> situationIds = new ArrayList<String>();
      for (ServiceAlertBean situation : situations) {
        situationIds.add(situation.getId());
        addToReferences(situation);
      }
      bean.setSituationIds(situationIds);
    }

    return bean;
  }