#ifndef dtGPOnline_HH
#define dtGPOnline_HH

/****************************************************************************
 * GP threshold 
 * Jnaneshwar Das jnaneshd@usc.edu
 ****************************************************************************/

#include "DecisionTool.hh"
#include "SmartSamplerData.hh"
#include "GPOLogger.hh"
#include <vector>
#include <stdio.h>


#define NUM_TRAIN_DATA  87
#define NUM_TRAIN_DIM  2
#define AuvDirNameEnv "AUV"

class dtGPOnline : public DecisionTool{
public:
    dtGPOnline(char *nameIn);
    ~dtGPOnline();
    
    void loadConfig(char *cfgname,SmartSamplerData *ssdIn);
    bool update();
    void reset();
    void readArrays();
    
    
private:
    typedef struct{
        SmartSamplerData::ssd_measurement_t type;
        double initthresh;
        double thresh;
    }STData_t;
    char *name;
    double ell,sf2,org_abun_thresh_high,org_abun_thresh_low,org_abun_thresh_high_override;
    int gulpCount;
    double totalTicks,numberOfWindows;

    SmartSamplerData *ssd;
    long double trainVector[NUM_TRAIN_DATA][NUM_TRAIN_DIM];
    double alphaVector[NUM_TRAIN_DATA];
    
    double meanSensorVector[NUM_TRAIN_DIM];
    double stdevSensorVector[NUM_TRAIN_DIM];
    double aug_vector_y_scaling;
    double depth_thresh;
    long double gulpsTakenData[11][NUM_TRAIN_DIM+2];
    long double gulpsTakenInWindowData[11][NUM_TRAIN_DIM+2];
    
    double spikeFilterSigma;
    char trainMatrixFilenameFullpath[512];
    char alphaVectorFilenameFullpath[512];
    double noGulpers;
    double resultHistory[6];
    double meanOfVector(double resultHistory_[]);
    bool okToGulp;
    double resultFilterAllowance;
    bool statsSet;
    double salRange, salStd, tempRange ,tempStd, chlRange, chlStd;
    double tempMin,salMin,chlMin,tempMax,salMax,chlMax;
    double distCutoff;
    bool haveGulpsForWindow;
    char meanSensorFilenameFullpath[512];
    char stdSensorFilenameFullpath[512];
    
      double stdScaling,stdScalingDefault;
    
    double windowDivisor;
    
    double skipCorrFlag;
    long double optimumCorrThreshold;
    double correlationThreshold;
    long int tickCounter; // two ticks per second
    long int tickLastFired;
    long int eWindowPreviousInd;
    int windowCtr;
    double gulpsPerWindow;
    double maxScore;
    double eWINDOW_TICKS_LENGTH;
    double gulpWindowLength;
    int gulpInWindowCtr;

    
    double tickFireThreshold;
    double minTickWaitTimeThreshold;
    
    GPOLogger log;
    typedef std::vector<STData_t>::iterator di_t;
    std::vector<STData_t> cfg;
    long double sq_dist(long double vec1[], long double vec[], int);
    bool sensorReadingsWithinRange(long double sensorReadingVector[]);
    long double minCorrelationWithExistingDataPoints(long double vec1[]);
    void loadDataFiles();
    std::string popToken(std::string&, const std::string&);
     long double maxDistanceWithExistingDataPoints(long double vec1[]);
     double envSpaceDistance(long double vec1[],long double vec2[]);
    
}; // dtGPOnline

#endif // dtGPOnline_HH
