将 ExpBase::mon_proc() 中的 exp_type_ 分支逻辑提取为 4 个子类,通过 doMonProc() 虚函数实现多态分发: - LogicAlg (exp_type 1):实时逻辑判断 - BoundAlg (exp_type 2):监控变量上下限检测 - BoundHoldAlg (exp_type 5):持续超限检测(继承 BoundAlg) - FeedbackAlg (exp_type 3/4):动作反馈处理 ExpBase 新增纯虚函数 doMonProc() 和钩子函数 doInitExtend(), init() 和 mon_proc() 中所有类型分支替换为虚函数委托调用。
63 lines
2.3 KiB
C++
63 lines
2.3 KiB
C++
#include <eqpalg/algs/bound_hold_alg.h>
|
|
#include <eqpalg/feature_extraction/daa.h>
|
|
#include <eqpalg/utility/build_alarm_info.h>
|
|
|
|
BoundHoldAlg::BoundHoldAlg(const std::string& name, const mix_cc::json& rule_json,
|
|
const std::string& ruleId)
|
|
: BoundAlg(name, rule_json, ruleId, ExpType::BoundHoldTime) {
|
|
logger_.reset(new LOG("BoundHoldAlg:" + rule_name_, AUTO_CATCH_PID));
|
|
}
|
|
|
|
BoundHoldAlg::~BoundHoldAlg() = default;
|
|
|
|
int BoundHoldAlg::init() {
|
|
int ret = BoundAlg::init();
|
|
if (ret == 0) {
|
|
reload_config_up_down_hold_time();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
AlarmInfo BoundHoldAlg::doMonProc() {
|
|
double result_value = expr_engine_->evaluate("act");
|
|
filter_flag_ = checkFilter();
|
|
|
|
if (is_learning_ && filter_flag_) {
|
|
rule_stat_.current_value = result_value;
|
|
SingletonTemp<EqpStat>::GetInstance().add_stat_values(rule_id_, result_value);
|
|
}
|
|
|
|
bool is_over = bound_checker_.isOutOfBounds(result_value);
|
|
|
|
if (!filter_flag_) {
|
|
act_start_time_ = now_time_;
|
|
act_started_ = false;
|
|
} else {
|
|
if (is_over) {
|
|
if (!act_started_) {
|
|
act_started_ = true;
|
|
act_start_time_ = now_time_;
|
|
}
|
|
if ((hold_time_ <= delay_time_) ||
|
|
(now_time_ - act_start_time_ > hold_time_)) {
|
|
rule_stat_.alarm_value = result_value;
|
|
auto msg = error_str_ + ":" + DAA::double2str(result_value) + unit_ +
|
|
",合理区间:[" + DAA::double2strLimit(bound_checker_.limitDown()) +
|
|
"," + DAA::double2strLimit(bound_checker_.limitUp()) + "]" + unit_;
|
|
query_time_range_.set_left(query_time_range_.get_right() - delay_time_);
|
|
expr_engine_->markFunVarsNeedReset();
|
|
act_start_time_ = now_time_;
|
|
act_started_ = false;
|
|
return utility::build_alarm_info(
|
|
utility::get_msg_level(bound_checker_.limitDown(),
|
|
bound_checker_.limitUp(), result_value),
|
|
rule_id_, rule_name_, "EXP5", msg, get_alarm_time());
|
|
}
|
|
} else {
|
|
act_start_time_ = now_time_;
|
|
act_started_ = false;
|
|
}
|
|
}
|
|
return AlarmInfo{};
|
|
}
|