eis/eqpalg/algs/exp_base.h
Huamonarch 224c2c45c4 Remove irrelevant comments from eqpalg source files
Cleaned 66 files across all eqpalg subdirectories:
- Removed commented-out dead code
- Removed redundant Chinese inline comments that restate variable/function names
- Removed trailing ///< annotations on self-explanatory fields
- Removed namespace closing comments
- Preserved all file headers, Doxygen documentation, and logic explanations
- No code changes — only comment removal
2026-05-09 13:30:09 +08:00

371 lines
8.3 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_base.h
* @brief 表达式类
* 覆盖算法号12345
* exp_type_
* 表达式类型1-逻辑判断2-变量上下限3-动作反馈-逻辑判断4-动作反馈-上下限5-上下限-保持时间
* 算法号24,5的cron累积样本保存至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),n——tag的序号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_;
size_t task_data_size = 0;
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();
};