eis/eqpalg/algs/exp_base.h

369 lines
8.2 KiB
C
Raw Normal View History

#pragma once
/**
* @file exp_base.h
* @brief
* 12345
* exp_type_
* 1-2-3--4--5--
* 24,5cron累积样本db2 T_RULE_SAMPLE_1D
* @author your name (you@domain.com)
* @version 0.1
* @date 2023-12-22
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#include <eqpalg/alg_base.h>
#include <eqpalg/define/public.h>
#include <eqpalg/feature_extraction/daa.h>
#include <eqpalg/gb_item_memory.h>
#include <eqpalg/utility/HoldTime.h>
#include <eqpalg/utility/StatExp.hpp>
#include <eqpalg/utility/item2chinese.hpp>
#include <glob/SingletonTemplate.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
/**
* @brief
*/
class ExpBase : public AlgBase {
public:
ExpBase(const string &name, const mix_cc::json &rule_json,
const string &ruleId, size_t exp_type);
~ExpBase() override;
public:
/**
* @brief
* @return int
*/
virtual int init() override;
/**
* @brief
* @return std::string
*/
AlarmInfo exec_mon() override;
/**
* @brief Set the last alarm time object
* unpause时mm_vars
* @param time_point My Param doc
*/
virtual void
set_last_alarm_time(TimePoint time_point = system_clock::now()) override;
/**
* @brief Set the usable object
* set_usable mm_vars
* @param usable My Param doc
*/
virtual void set_usable(bool usable) override;
/**
* @brief ihdb中获取历史数据
* TAG点的历史数据确实存储在了IHDB中
* @param time_range
* @return AlarmInfo
*/
std::vector<AlarmInfo> exec_task(mix_cc::time_range_t time_range) override;
/**
* @brief / start end
*/
void save_rule_norm_data() override;
/**
* @brief mon
* @return AlarmInfo
*/
virtual AlarmInfo mon_proc();
virtual mix_cc::json exec_cron();
/**
* @brief cron
* @return AlarmInfo
*/
virtual int cron_proc();
/**
* @brief
* mon----
*
* (T_RULE_SAMPLE_1D,T_RULE_SAMPLE_1D_INFO,T_SAMPLE_RECORDT_SAMPLE_RECORDT_RULE_SAMPLE_FEATURE)rule_id_对应数据
* cron----
* sta_ptr_(sta_ptr_.reset())
*/
virtual void reset_dev_data() override;
bool get_prr() override;
protected:
/**
* @brief
* @return int
*/
int reload_config_data_source();
/**
* @brief
* @return int
*/
int reload_config_exp_act();
/**
* @brief Get the cycled cron object
* @return true
* @return false
*/
bool get_cycled_cron();
private:
/**
* @brief
* @return int
*/
int reload_config_up_down();
/**
* @brief载入上
* @return int
*/
int reload_config_up_down_hold_time();
private:
/**
* @brief
* @return int
*/
int reload_config_exp_feedback();
protected:
/**
* @brief
* @return int
*/
int refresh_exp_vars_mem();
/**
* @brief ihyperDB查询到的数据载入到表达式变量中
* @param row
* @return int
*/
int refresh_exp_vars_ihd(int row);
/**
* @brief map
* @return int
*/
int first_fill_mm_vars();
/**
* @brief hold变量hold变量有hold(n,T)
* hold(n,T),ntag的序号T
* @return int
*/
int refresh_hold_var();
protected:
/**
* @brief
* @param expstr My Param doc
*/
void print_exp_vars(const string &expstr = "");
protected:
string exp_str_;
string error_str_;
bool feedback_done_ = false;
string unit_;
/**
* @brief
* KeepT , ///< 保持时间
* KeepC, ///<出现次数
* RiseEdge, ///<上升沿出现次数
* Detect ///<为真检测次数
*/
StatExp::FunVars fun_vars_;
std::unique_ptr<mix_cc::matheval::Expression> exp_act_;
std::unique_ptr<mix_cc::matheval::Expression> exp_feedback_;
std::unique_ptr<mix_cc::matheval::Expression> exp_result_;
protected:
const size_t
exp_type_;
TimeDur time_out_;
TimePoint act_start_time_;
bool act_triggered_ = false;
bool act_started_ =
false;
bool feedback_triggered_ = false;
bool m_timemode = false;
int refresh_counts_ = 0;
protected:
bool feedback_mode_ = false;
bool keep_mode_ = false;
double limit_up_ = 0;
double limit_down_ = 0;
TimeDur hold_time_ = 0ms;
std::unique_ptr<DAA::STA> sta_ptr_;
std::map<std::string, std::unique_ptr<HoldTime>>
hold_times_;
bool exp_is_wrong_ = true;
bool exp_wrong_is_alarmed_ = false;
int dist_mode_;
bool is_learning_ = true;
TimePoint last_load_time_;
int64_t CronUpdateDelay = StatConst::CronUpdateDelay;
std::string sample_type_ = SampleType::T_SAMPLE_STAT;
std::string sample_id_;
std::string sample_result_;
int detect_mode_ = DetectMode::Default;
bool filter_flag_ = false;
bool is_fun_vars_need_reset_ = false;
protected:
/**
* @brief
* s{tagN}
* 使
* @return true
* @return false
*/
bool act_start_done();
/**
* @brief
* 使退
* @return true
* @return false
*/
bool act_not_hold();
/**
* @brief
*
* @return true
* @return false
*/
bool act_done();
/**
* @brief
* 使
* @return true
* @return false
*/
bool act_timeout();
protected:
/**
* @brief ihd查询数据--task用
*/
void query_ihd_data();
/**
* @brief
* @return AlarmInfo
*/
AlarmInfo get_timeout_alarm();
/**
* @brief hold(n,T)hold变量map初始化
* @param exp_str My Param doc
* @return int
*/
int init_hold_exp_str(const std::string &exp_str);
/**
* @brief
* @param exp_str My Param doc
* @return int
*/
int exp_messy_code_check(const std::string &exp_str);
/**
* @brief
* @return int
*/
int reload_ci_dist();
/**
* @brief task执行函数
*/
virtual void task_mon_pro();
/**
* @brief id
* ruleid(3,21)_starttime_endtime
* @return string
*/
string get_id(mix_cc::time_range_t time_range);
/**
* @brief task
* 2--
* 4--
* 5---
* @return TaskReturnType
*/
TaskReturnType task_base_proc();
/**
* @brief
* @param vlid
* @return int
*/
int update_t_sample_mag(bool vlid);
/**
* @brief
* @param value My Param doc
* @return true false
*/
bool detect_up_down(const double &value);
/**
* @brief task进程接口
* @param i My Param doc
* @return true
* @return false
*/
bool task_prr(int row);
/**
* @brief fun_vars_
* fun_vars_替换
*/
void fun_vars_init();
/**
* @brief
* is_fun_vars_need_reset_
*/
void auto_fun_vars_reset();
};