eis/inc/eqpalg/stat/SampleTrendAnalysis.h

94 lines
2.5 KiB
C++

/*********************************************************************
*
* 文 件: SampleTrendAnalysis.h
*
* 版权所有: Shanghai Baosight Software Co., Ltd.
* zoufuzhou
*********************************************************************/
#ifndef H_TREND_SAMPLE_H
#define H_TREND_SAMPLE_H
#include "mix_cc/algorithm/fast_dtw/EuclideanDistance.h"
#include "mix_cc/algorithm/fast_dtw/FastDTW.h"
#include <eqpalg/AlgCommonDefine.h>
#include <eqpalg/stat/NormalDistribution.h>
#include <iostream>
#include <memory>
#include <vector>
#include <zhd/hd3Struct.h>
using namespace std;
/*********************************************************************
* 类 名: SampleTrendAnalysis
* 版权所有: Shanghai Baosight Software Co., Ltd.
*********************************************************************/
class SampleTrendAnalysis {
public:
// step 0 init parameter
SampleTrendAnalysis(const string &table = "T_RULE_SAMPLE", int judgemode = 0,
int archive = 0, double probability = 0.9,
std::string tag_name = "DEFAULT_TAG");
virtual ~SampleTrendAnalysis();
// step 1 init parameter
void Init(const string &table = "T_RULE_SAMPLE", int judgemode = 0,
int archive = 0, double probability = 0.9,
std::string tag_name = "DEFAULT_TAG");
void SetRule(const string &ruleid, const string &rulename);
// step2 read sample by db
int Read(const string &dbwhere);
// step3 learning sample store db
int Learning(double value, int covert2samplesize = 5);
int Learning(vector<double> value, int covert2samplesize = 5);
// get current judge mode
int JudgeMode();
// get whether the sampling
bool HaveSample();
// get whether learned
bool IsLearned();
// get sample parameter
const SampleProperty *GetProperty();
public:
bool ShouldReportCurve(const vector<double> &value, double dest);
// get distance of two curves using Dynamic Time Warping Algorthim
double CalcDTWValue(const vector<double> &value);
double CalcDTWValue(HD3Record *record);
private:
int LearningAbsDiff(void);
int LearningNormal(void);
int LearningTrend(vector<double> value);
int ReadAbsDiff(const string &dbwhere);
int ReadNormal(const string &dbwhere, vector<double> &voutdatas);
int ReadJson(const string &dbwhere);
string GetSql(const string &dbwhere);
long GetCount(const string &dbwhere);
int Save(void);
private:
NormalDistribution *mp_normal;
private:
SampleProperty m_sample;
private:
string m_table;
string m_ruleid;
string m_rulename;
};
#endif