calculateDecelerations method

int calculateDecelerations()

A deceleration is defined as a decrease in FHR below the baseline that lasts for lasts for longer than 30 seconds and has a maximum excursion below the baseline of greater than 20 beats/min or lasts for longer than 60 seconds and has a maximum excursion below the baseline of greater than 10 beats/min

Implementation

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

  /** first criteria **/
  for (int i = 0; i < size; i++) {
    MarkerIndices deceleration = MarkerIndices();
    if (millisecondsEpochBpm[i] == 0) continue;
    int difference = baselineEpochBpm[i]! - millisecondsEpochBpm[i]!;

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

      /*if (counter1 >= 15 && !isDeceleration) { // 60 seconds = 16 samples
                  isDeceleration = true;
                  //n++;
              }*/
      if (counter1 >= 4 && !isDeceleration) {
        isDeceleration = true;
      }
    } else {
      if (maxExcursion >= 10)
      //Log.i("maxExcursion dec 1", counter1 + " - " + maxExcursion + " - " + ((i * 4) / 60));

      if (counter1 >= 4 && maxExcursion >= 10) {   // change from couter1 >= 15 to couter >= 4
        deceleration = MarkerIndices();
        deceleration.setFrom(((i - counter1) * FACTOR));
        deceleration.setTo(((i) * FACTOR));
        decelerations.add(deceleration);
        n++;
      }else{
        deceleration = MarkerIndices()
          ..setFrom((i - counter1).toInt() * FACTOR)
          ..setTo((i).toInt() * FACTOR);
        decelerations.add(deceleration);
        n++;
      }
      counter1 = 0;
      isDeceleration = false;
      maxExcursion = 0;
    }
  }
  //isDeceleration = false;
  maxExcursion = 0;

  /** second criteria **/
  /*for (int i = 0; i < size; i++) {
    int difference = baselineEpochBpm[i]! - millisecondsEpochBpm[i]!;

    if (difference > 1) {
      counter2++;

      if (maxExcursion < difference) maxExcursion = difference;

      *//*if (counter2 > 8 && counter2 < 15 && !isDeceleration) {// 60 seconds = 16 samples
                  isDeceleration = true;
                  //n++;
              }*//*
    } else {
      if (maxExcursion >= 10)
      //Log.i("maxExcursion dec 2", counter2 + " - " + maxExcursion + " - " + ((i * 4) / 60));

      if (counter2 >= 2 && counter2 < 4 && maxExcursion >= 20) {  // change from counter2 >= 8 && counter2 < 15 to counter2 >= 2 && counter2 < 4
        MarkerIndices deceleration = new MarkerIndices();
        deceleration.setFrom(((i - counter2) * FACTOR));
        deceleration.setTo(((i) * FACTOR));
        decelerations.add(deceleration);
        n++;
      }
      counter2 = 0;
      //isDeceleration = false;
      maxExcursion = 0;
    }
  }*/

  decelerationsList = decelerations;
  return n;
}