package edu.cwru.sicu_sms;

import java.util.*;

/**
 * This class is used to represent a set of temporal (time-domain) EKG data, used to calculate the patient Stress Index
 *  *
 * @since December 6, 2016
 * @author Ted Frohlich <ttf10@case.edu>
 * @author Abby Walker <amw138@case.edu>
 */

public class EKGTemporalData extends StressIndexData {

    public static final int THRESHOLD = 800;

    /*The list of data points currently being analyzed to compute the stress index.
    5 minutes of data are stored at a time*/
    private ObservableList<T> dataList;
    private double[] data;

    //The sampling frequency
    private int Fs;

    //The current stress index component calculated from this data set alone
    private double stressIndex;


    public EKGTemporalData(ObservableList<T> dataList, int Fs)
    {
        super(dataList, Fs);
        data = new double[MAXSIZE];
    }

    public void setArray()
    {
        data = dataList.toArray();
    }

    public void addDataPoint(/*type to use*/ newPoint)
    {
        dataList.add(newPoint);
        if (dataList.size() > MAXSIZE)
        {
            dataList.remove(0);
        }
        setArray();
    }

    public double stressIndex()
    {
        ArrayList<Double> RtagInts = new ArrayList<Double>(MAXSIZE/2);
        for (int i = 1; i < MAXSIZE; i++)
        {
            time = (1/Fs)*i;
            if (data[i-1] < THRESHOLD && data[i] >= THRESHOLD)
                RtagInts.add(time);
        }

        for(int i = 1; i < RtagInts.size(); i++)
        {
            RtagInts.set(i-1, RtagInts.get(i)-RtagInts.get(i-1));
        }
        RtagInts.remove(RtagInts.size()-1); //final Rtag time will not be replaced by an interval time, so remove it from the list

        double AAD = calculateAAD(RtagInts);
        return 1/(1+AAD);

    }

    private double calculateAAD(ArrayList RRintervals)
    {
        double intervalSum = 0;
        for (int i = 0; i < RRintervals.size(); i++)
        {
            intervalSum += RRintervals.get(i);
        }
        return intervalSum/RRintervals.size();
    }
}

@@ -1,8 +1,534 @@
+/*                                                                      *%5C%0A**                    SICU Stress Measurement System                    **%0A**                      Project P04  %7C  C380 Team A                     **%0A**          EBME 380: Biomedical Engineering Design Experience          **%0A**                    Case Western Reserve University                   **%0A**                          2016 Fall Semester                          **%0A%5C*                                                                      */%0A%0A
 package 
@@ -691,20 +691,18 @@
 ss Index
+.
 %0A
- * 
  *%0A * @s
@@ -809,17 +809,16 @@
 du%3E%0A */%0A
-%0A
 public c
@@ -917,19 +917,32 @@
 %0A%0A    /*
-The
+*%0A     * Current
  list of
@@ -957,18 +957,9 @@
 ints
- currently
+,
  bei
@@ -1002,16 +1002,31 @@
 dex.%0A   
+  * %3Cp%3E%3Ci%3ENote:
  5 minut
@@ -1056,16 +1056,23 @@
 t a time
+.%0A     
 */%0A    p
@@ -1135,25 +1135,27 @@
 data;%0A%0A    /
-/
+** 
 The sampling
@@ -1164,16 +1164,30 @@
 requency
+, in hertz. */
 %0A    pri
@@ -1205,17 +1205,19 @@
 ;%0A%0A    /
-/
+** 
 The curr
@@ -1278,16 +1278,20 @@
 et alone
+. */
 %0A    pri
@@ -1316,16 +1316,254 @@
 Index;%0A%0A
+    /**%0A     * Constructs an %3Ccode%3EEKGTemporalData%3C/code%3E object given a list of data along with its sampling frequency.%0A     *%0A     * @param dataList the list of data points%0A     * @param Fs       the sampling frequency, in hertz%0A     */
 %0A    pub
@@ -1688,32 +1688,48 @@
 AXSIZE%5D;%0A    %7D%0A%0A
+    /** TODO */%0A
     public void 
@@ -1778,32 +1778,52 @@
 oArray();%0A    %7D%0A
+    %0A    /** TODO */
 %0A    public void
@@ -1838,16 +1838,23 @@
 Point(/*
+ TODO: 
 type to 
@@ -1856,16 +1856,17 @@
 e to use
+ 
 */ newPo
@@ -2022,24 +2022,115 @@
 y();%0A    %7D%0A%0A
+    /**%0A     * Calculates the stress index.%0A     *%0A     * @return the stress index%0A     */%0A
     public d
@@ -2206,22 +2206,16 @@
 rayList%3C
-Double
 %3E(MAXSIZ
@@ -2422,16 +2422,17 @@
      for
+ 
 (int i =
@@ -2594,11 +2594,13 @@
 -1);
+ 
  //
+ 
 fina
@@ -2752,24 +2752,53 @@
 1+AAD);%0A
-%0A
     %7D%0A%0A
+    /** Calculates... TODO */%0A
     priv

Revise style, insert 'todo' comments