Exemplo n.º 1
0
  private int[] getExhalation(int[] data, int length) {
    int valleyIndex = 0, peakIndex = 0;

    ArrayList<Integer> list = new ArrayList<Integer>();

    int i = 0;
    int temp = length;
    for (; i < temp; i += 4) {
      // check the starting whether it starts from valley or not. It should be valley
      if ((i == 0) && (data[i + 1] > data[i + 3]))
        continue; // it escaping if first member is a peak. in that case we can not find the
      // inspiration. inspiration always starts from a valley

      // check last element whether it is valley or peak. it should be valley
      if ((i == 0)
          && (data[length - 1]
              > data[length - 3])) // at the beginning the stopping condition is changed
      temp = length - 2;

      if (i + 4 < length) {
        valleyIndex = data[i + 4];
        peakIndex = data[i + 2];
        list.add(new Integer(valleyIndex - peakIndex));
      }
    }
    // converting the ArrayList to array
    int exhalation[] = new int[list.size()];
    for (int j = 0; j < list.size(); j++) {
      exhalation[j] = list.get(j).intValue();
    }

    DebugHelper.dump(TAG, exhalation);

    return exhalation;
  }
Exemplo n.º 2
0
  @Override
  protected void processInput(String name, String type, Object data, int length, long timestamp) {
    if (name.contains("AccelerometerRMSFFT1.0-10.0-1.0")) {
      mFFT1_10 = (double[]) data;
    } else if (name.contains("AccelerometerRMSVariance")) {
      mVariance = (Double) data;
      mIsVarianceNew = true;
    } else if (name.contains("AccelerometerRMSScale310.0FFT1.0-3.0-1.0")) {
      mScaledFFT1_3 = (double[]) data;
    } else if (name.contains("AccelerometerRMSScale310.0Variance")) {
      mScaledVariance = (Double) data;
      mIsScaledVarianceNew = true;
    } else if (name.contains("GPS")) {
      mSpeed = ((double[]) data)[3];
      mIsSpeedNew = true;
    } else {
      throw new UnsupportedOperationException("Unsupported name: " + name);
    }

    int activity = -1;

    if (mIsSpeedNew && mSpeed > 0.29 && mIsScaledVarianceNew && mScaledFFT1_3 != null) {
      activity = classifyActivityWithGPS(mSpeed, mScaledVariance, mScaledFFT1_3);
      mIsSpeedNew = false;
      mIsScaledVarianceNew = false;
      mScaledFFT1_3 = null;
    } else if (mFFT1_10 != null && mIsVarianceNew) {
      activity = classifyActivityWithoutGPS(mVariance, mFFT1_10);
      mIsVarianceNew = false;
      mFFT1_10 = null;
    }

    if (activity != -1) {
      DebugHelper.log(TAG, "activity = " + activity);
      output(SensorType.ACTIVITY_CONTEXT_NAME, DataType.INTEGER, activity, 0, timestamp);
    }
  }