eis/eqpalg/algs/bound_hold_alg.cpp

63 lines
2.3 KiB
C++
Raw Permalink Normal View History

#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{};
}