eis/eqpalg/algs/exp_sample2D.h

134 lines
3.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
/**
* @file exp_sample2D.h
* @brief 二维样本拟合/线性相关性
* 覆盖算法号12 13
* exp_type_
* 表达式类型: 12-多项式拟合;13-皮尔逊相关系数监控
* task进程 选时间段 获取样本 生成拟合系数/相关性系数
* mon进程 执行监控
* @author your name (you@domain.com)
* @version 0.1
* @date 2023-12-13
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#include <eqpalg/algs/exp_base.h>
class ExpSample2D : public ExpBase {
public:
ExpSample2D(const string& name, const mix_cc::json& rule_json,
const string& ruleId, size_t exp_type);
~ExpSample2D() override;
virtual int init() override;
/**
* @brief 最小的执行单元
* @return AlarmInfo
*/
virtual AlarmInfo mon_proc() override;
/**
* @brief 单次执行
* @param time_range My Param doc
* @return std::vector<AlarmInfo>
*/
std::vector<AlarmInfo> exec_task(mix_cc::time_range_t time_range) override;
protected:
/**
* @brief 载入样本X Y表达式
* @return int
*/
int reload_samples();
/**
* @brief 检测拟合是否报警
* @return true 报警
* @return false 不报警
*/
bool check_polyFit();
/**
* @brief 检测相关性系数是否报警
* @return true 报警
* @return false 不报警
*/
bool check_pear();
/**
* @brief 拟合 计算值
* @param x My Param doc
* @param fit_coefs My Param doc
* @param orders My Param doc
* @return double
*/
double PolyFitValue(double x, std::vector<double>& fit_coefs, size_t orders);
/**
* @brief 相关性系数 计算值
* @param X My Param doc
* @param Y My Param doc
* @return double
*/
double PearValue(std::vector<double>& X, std::vector<double>& Y);
/**
* @brief 从数据库载入拟合/相关性系数
* @return int
*/
int reload_param();
/**
* @brief 插入样本信息 表T_SAMPLE_MAG
* @param sample_id My Param doc
* @return int
*/
int insert_mag(std::string sample_id);
/**
* @brief 插入样本数据 表T_SAMPLE_FIT
* @param sample_id My Param doc
* @param X My Param doc
* @param Y My Param doc
* @return int
*/
int insert_fit(std::string sample_id, double X, double Y, int seq);
// /**
// * @brief 生成样本id
// * 弃用移至ExpBase
// * @return string
// */
// string get_id();
private:
int orders_; ///< 拟合次数
std::vector<double> fit_coefs_; ///<多项式系数
double pear_coefs_; ///<相关系数
double scale_; ///<报警系数
mix_cc::json sample_param_; ///<样本结果
const string SampleType_ = "T_SAMPLE_FIT"; ///样本类型
int data_len_ = 0; ///<运行当前的样本数量
int min_len_ = 1000; ///<相关性 数据最小长度要求
std::vector<double> SampleX_; ///<样本X
std::vector<double> SampleY_; ///<样本Y
std::unique_ptr<DAA::LSM> lsm_ptr_; ///<拟合/相关性 处理类
private:
/**
* @brief 重置样本
*/
void reset_SampleXY();
protected:
// /**
// * @brief 从ihd查询数据
// * 弃用 继承 ExpBase
// */
// void query_ihd_data();
/**
* @brief task执行函数
*
*/
void task_mon_pro();
};