calculateAccelerations method

int calculateAccelerations()

An acceleration is defined as an increase in FHR above the baseline that lasts for longer than 15 seconds and has a maximum excursion above the baseline of greater than 10 beats/min

Implementation

int calculateAccelerations() {
  List<MarkerIndices> accelerations = [];
  int size = millisecondsEpoch.length;
  int counter1 = 0, counter2 = 0, n = 0;
  int maxExcursion = 0;
  bool isAcceleration = false;

  for (int i = 0; i < size; i++) {
    MarkerIndices acceleration = MarkerIndices();
    int difference = millisecondsEpochBpm[i]! - baselineEpochBpm[i]!;

    /*if (difference <= 0) {
              if (isAcceleration && (maxExcursion> (gestAge<= 32?15:10))) {
                  acceleration = new MarkerIndices();
                  acceleration.setFrom((int) ((i - (gestAge <= 32 ? counter1 : counter2)) * FACTOR));
                  acceleration.setTo((int) ((i) * FACTOR));
                  accelerations.add(acceleration);
                  n++;//adding acc count
              }
              counter1 = 0;
              counter2 = 0;
              maxExcursion = 0;
              isAcceleration = false;
              continue;
          }*/

    if (gestAge < 32) {
      if (difference >= 1) {
        counter1++;

        if (maxExcursion < difference) maxExcursion = difference;

        /*if (counter1 > 3 && !isAcceleration) { // 10 seconds = 3 samples
                      // acceleration detected
                      isAcceleration = true;
                      //n++;
                  }*/
      } else {
        if (counter1 >= 3 && maxExcursion >= 9) {
          // change from counter1 > 3 to counter1 >= 3
          acceleration = MarkerIndices();
          acceleration.setFrom(((i - counter1) * FACTOR));
          acceleration.setTo(((i) * FACTOR));
          accelerations.add(acceleration);
          n++; //adding acc count
        }
        counter1 = 0;
        //isAcceleration = false;
        maxExcursion = 0;
      }
    } else {
      /** gestetional age >=32 weeks **/
      if (difference > 1) {
        counter2++;

        if (maxExcursion < difference) maxExcursion = difference;

        /*if (counter2 >= 4 && !isAcceleration) {// 15 seconds = 4 samples
                      isAcceleration = true;
                      //n++;
                  }*/
      } else if (gestAge >= 32) {
        // change from gestAge > 32 to gestAge >= 32
        if (maxExcursion >= 10)
          //Log.i("maxExcursion", counter2 + " - " + maxExcursion + " - " + ((i * 4) / 60));

          if (counter2 >= 4 && maxExcursion >= 14) {
            // change counter2 > 4 to counter2 >= 4
            acceleration = MarkerIndices();
            acceleration.setFrom(((i - counter2) * FACTOR));
            acceleration.setTo(((i) * FACTOR));
            accelerations.add(acceleration);
            n++; //adding acc count
          }
        counter2 = 0;
        //isAcceleration = false;
        maxExcursion = 0;
      }
    }
  }
  accelerationsList = accelerations;
  return n;
}