eis/eqpalg/algs/exp_base.h

270 lines
5.9 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 <eqpalg/utility/bound_checker.h>
#include <eqpalg/utility/stat_collector.h>
#include <eqpalg/utility/fb_state_machine.h>
#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----
* stat_collector_(stat_collector_.reset())
*/
virtual void reset_dev_data() override;
bool get_prr() override;
protected:
/**
* @brief
* @return AlarmInfo
*/
virtual AlarmInfo doMonProc() = 0;
/**
* @brief
*/
virtual void doInitExtend() {}
/**
* @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();
/**
* @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:
string exp_str_;
string error_str_;
string unit_;
protected:
const size_t
exp_type_;
TimeDur time_out_;
TimePoint act_start_time_;
bool act_started_ =
false;
FbStateMachine fb_fsm_;
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;
StatCollector stat_collector_;
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_;
DetectMode detect_mode_ = DetectMode::Default;
BoundChecker bound_checker_;
bool filter_flag_ = false;
protected:
/**
* @brief ihd查询数据--task用
*/
void query_ihd_data();
/**
* @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);
};