eis/eqpalg/algs/exp_bound.cpp

147 lines
4.5 KiB
C++
Raw Normal View History

#include "mix_cc/ihyper_db.h"
#include <algorithm>
#include <base/BitTool.h>
#include <eqpalg/algs/exp_bound.h>>
#include <eqpalg/exp_macro/get_macro_replaced_exp.h>
#include <eqpalg/feature_extraction/daa.h>
#include <eqpalg/utility/build_alarm_info.h>
#include <limits>
#include <string>
#include <utility>
#include <vector>
int ExpBound::init() {
int res = 0;
try {
res += AlgBase::init();
this->con_monitor_.setThreshold(100);
logger_->Debug() << "res:" << res << std::endl;
if (res != 0) {
this->exp_is_wrong_ = true;
return -1;
}
res += this->reload_config_data_source(); /*3.数据源*/
logger_->Debug() << "数据来源,0:iHyperDB,1:memory" << this->data_source_
<< ",单位unit_" << unit_ << std::endl;
res += this->first_fill_mm_vars(); /*4.数据项*/
res += init_X_exp();
rule_stat_.unit = unit_;
rule_stat_.limit_down = -32768;
limit_down_ = -32768;
limit_up_ = limit_warn_;
rule_stat_.limit_up = limit_warn_;
print_load_content();
} catch (const std::exception &e) {
std::throw_with_nested(
mix_cc::Exception(-1, "load error", BOOST_CURRENT_LOCATION));
}
if (res == 0 || limit_warn_ > limit_error_) {
this->exp_is_wrong_ = false;
}
return res;
}
ExpBound::ExpBound(const string &name, const mix_cc::json &rule_json,
const string &ruleId, size_t exp_type)
: ExpBase(name, rule_json, ruleId, exp_type) {
logger_.reset(new LOG("ExpBound:" + rule_name_, AUTO_CATCH_PID));
}
ExpBound::~ExpBound() {
}
AlarmInfo ExpBound::doMonProc() {
return AlarmInfo{}; // 此类重写 mon_proc(),不使用 doMonProc()
}
AlarmInfo ExpBound::mon_proc() {
if (expr_engine_->evaluateBool("feedback") == false) {
logger_->Debug() << "前提条件不满足!" << std::endl;
return AlarmInfo{};
}
/*最新数据*/
double now_value = expr_engine_->evaluate("act");
rule_stat_.current_value = now_value;
/*报警检查*/
if (now_value > limit_warn_) {
std::string msg = "";
msg = error_str_ + ",当前值:" + DAA::double2str(now_value) + unit_ + ",超";
auto alarm_time = get_alarm_time();
print_exp_vars();
if (now_value > limit_error_) {
msg += "报警值:" + DAA::double2str(limit_error_) + unit_;
logger_->Debug() << msg << endl;
return utility::build_alarm_info("ERROR", rule_id_, rule_name_, "EXP17",
msg, alarm_time);
}
msg += "警告值:" + DAA::double2str(limit_warn_) + unit_;
logger_->Debug() << msg << endl;
return utility::build_alarm_info("WARN", rule_id_, rule_name_, "EXP17", msg,
alarm_time);
}
return AlarmInfo{};
}
std::vector<AlarmInfo> ExpBound::exec_task(mix_cc::time_range_t time_range) {
std::vector<AlarmInfo> result;
for (auto now_time = time_range.get_left();
now_time <= time_range.get_right(); now_time += delay_time_) {
this->now_time_ = now_time;
auto rr1 = this->exec_mon();
result.push_back(rr1);
}
return result;
}
void ExpBound::print_load_content() {
logger_->Debug() << "limit_warn_:" << limit_warn_ << ",limit_error_"
<< limit_error_ << ",exp_str_:" << exp_str_
<< ",value_exp_str_:" << value_exp_str_ << std::endl;
}
int ExpBound::init_X_exp() {
int res = 0;
res = +ExpBase::reload_config_exp_act();
if (rule_json_.at("function")
.at("result")
.at("param")
.contains("limit_error")) {
limit_error_ = std::stod(rule_json_.at("function")
.at("result")
.at("param")
.at("limit_error")
.at("value")
.get<std::string>());
}
if (rule_json_.at("function")
.at("result")
.at("param")
.contains("limit_warn")) {
limit_warn_ = std::stod(rule_json_.at("function")
.at("result")
.at("param")
.at("limit_warn")
.at("value")
.get<std::string>());
}
if (rule_json_.at("function").at("result").at("param").contains("unit")) {
unit_ = rule_json_.at("function")
.at("result")
.at("param")
.at("unit")
.at("value")
.get<std::string>();
}
return res;
}