67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
#include <eqpalg/algs/bound_alg.h>
|
|
#include <eqpalg/feature_extraction/daa.h>
|
|
#include <eqpalg/utility/build_alarm_info.h>
|
|
#include <shm/RuleStatShm.h>
|
|
|
|
BoundAlg::BoundAlg(const std::string& name, const mix_cc::json& rule_json,
|
|
const std::string& ruleId, size_t exp_type)
|
|
: ExpBase(name, rule_json, ruleId, exp_type) {
|
|
logger_.reset(new LOG("BoundAlg:" + rule_name_, AUTO_CATCH_PID));
|
|
}
|
|
|
|
BoundAlg::~BoundAlg() = default;
|
|
|
|
int BoundAlg::init() {
|
|
int ret = ExpBase::init();
|
|
if (ret == 0) {
|
|
exp_is_wrong_ = false;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void BoundAlg::doInitExtend() {
|
|
// BoundAlg 额外的初始化:上下限
|
|
reload_config_up_down();
|
|
reload_ci_dist();
|
|
last_load_time_ = std::chrono::system_clock::now();
|
|
stat_collector_.configure(rule_id_, rule_name_, dist_mode_, is_learning_);
|
|
}
|
|
|
|
bool BoundAlg::checkFilter() {
|
|
if (!expr_engine_->hasExpression("feedback")) {
|
|
return true; // 无筛选表达式,所有数据参与
|
|
}
|
|
try {
|
|
return expr_engine_->evaluateBool("feedback");
|
|
} catch (...) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
AlarmInfo BoundAlg::doMonProc() {
|
|
double result_value = expr_engine_->evaluate("act");
|
|
filter_flag_ = false;
|
|
|
|
// 数据筛选
|
|
filter_flag_ = checkFilter();
|
|
|
|
// 自学习统计
|
|
if (is_learning_ && filter_flag_) {
|
|
rule_stat_.current_value = result_value;
|
|
SingletonTemp<EqpStat>::GetInstance().add_stat_values(rule_id_, result_value);
|
|
}
|
|
|
|
// 超限检测
|
|
if (filter_flag_ && bound_checker_.isOutOfBounds(result_value)) {
|
|
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();
|
|
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
|
|
"EXP2", msg, get_alarm_time());
|
|
}
|
|
return AlarmInfo{};
|
|
}
|