refactor: 非 ExpBase 算法适配 ExpressionEngine API
This commit is contained in:
parent
7c2fe7f7bb
commit
38d0942a6c
@ -78,7 +78,7 @@ AlarmInfo GlitchDetection::exec_mon() {
|
|||||||
data_index_ = 0;
|
data_index_ = 0;
|
||||||
run_time_range_.set_left(this->now_time_);
|
run_time_range_.set_left(this->now_time_);
|
||||||
}
|
}
|
||||||
data_[data_index_] = exp_mpdule_ptr_->get_value("dataX");
|
data_[data_index_] = expr_engine_->evaluate("dataX");
|
||||||
data_index_++;
|
data_index_++;
|
||||||
return out_alarm;
|
return out_alarm;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ int GlitchDetection::load_exp() {
|
|||||||
auto tmp_exp =
|
auto tmp_exp =
|
||||||
rule_json_.at("function").at("dataX").at("value").get<std::string>();
|
rule_json_.at("function").at("dataX").at("value").get<std::string>();
|
||||||
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
||||||
exp_mpdule_ptr_->add_exp("dataX", exp_str_);
|
expr_engine_->registerExpression("dataX", exp_str_);
|
||||||
/*数据长度*/
|
/*数据长度*/
|
||||||
auto tmp_data_size = rule_json_.at("function")
|
auto tmp_data_size = rule_json_.at("function")
|
||||||
.at("dataX")
|
.at("dataX")
|
||||||
@ -137,8 +137,10 @@ int GlitchDetection::load_exp() {
|
|||||||
}
|
}
|
||||||
bool GlitchDetection::get_prr() {
|
bool GlitchDetection::get_prr() {
|
||||||
if (this->prr_ == 1) {
|
if (this->prr_ == 1) {
|
||||||
exp_mpdule_ptr_->update();
|
this->refresh_now_time();
|
||||||
bool prr_result = (bool)exp_mpdule_ptr_->get_value("pre_result");
|
mix_cc::time_range_t dummy_range;
|
||||||
|
expr_engine_->refreshFromMemory(this->now_time_, dummy_range);
|
||||||
|
bool prr_result = expr_engine_->evaluateBool("pre_result");
|
||||||
this->now_prr_ = prr_result;
|
this->now_prr_ = prr_result;
|
||||||
logger_->Debug() << "ruleid:" << this->rule_id_
|
logger_->Debug() << "ruleid:" << this->rule_id_
|
||||||
<< ",rulename:" << this->rule_name_
|
<< ",rulename:" << this->rule_name_
|
||||||
|
|||||||
@ -71,7 +71,7 @@ Roller3::~Roller3() {
|
|||||||
|
|
||||||
AlarmInfo Roller3::mon_proc() {
|
AlarmInfo Roller3::mon_proc() {
|
||||||
|
|
||||||
if ((bool)exp_act_->evaluate() == false) {
|
if (!expr_engine_->evaluateBool("act")) {
|
||||||
logger_->Debug() << "前提条件不满足!" << std::endl;
|
logger_->Debug() << "前提条件不满足!" << std::endl;
|
||||||
return AlarmInfo{};
|
return AlarmInfo{};
|
||||||
}
|
}
|
||||||
@ -227,9 +227,7 @@ int Roller3::init_X_exp() {
|
|||||||
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
||||||
res += init_hold_exp_str(exp_str_);
|
res += init_hold_exp_str(exp_str_);
|
||||||
|
|
||||||
auto fun_res = fun_vars_.add_exp_str(exp_str_, &mm_vars);
|
// ExpressionEngine::registerExpression() now handles FunVars processing internally.
|
||||||
res += fun_res.first ? 0 : -1;
|
|
||||||
exp_str_ = fun_res.second;
|
|
||||||
feedback_mode_ = false;
|
feedback_mode_ = false;
|
||||||
auto messy_code = exp_messy_code_check(exp_str_);
|
auto messy_code = exp_messy_code_check(exp_str_);
|
||||||
if (messy_code == -1) {
|
if (messy_code == -1) {
|
||||||
@ -305,31 +303,19 @@ int Roller3::init_X_exp() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
value_num_ = tag_seq_.size();
|
value_num_ = tag_seq_.size();
|
||||||
if (exp_act_ == nullptr && exp_str_ != "") {
|
if (exp_str_ != "") {
|
||||||
try {
|
int reg_ret = expr_engine_->registerExpression("act", exp_str_);
|
||||||
exp_act_ =
|
if (reg_ret != 0) {
|
||||||
std::make_unique<mix_cc::matheval::Expression>(exp_str_, &mm_vars);
|
|
||||||
logger_->Debug() << "exp_act:" << exp_str_ << "=" << exp_act_->evaluate()
|
|
||||||
<< endl;
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
logger_->Error() << "exp_act:" << exp_str_ << "计算出错:" << e.what()
|
|
||||||
<< ",location:" << BOOST_CURRENT_LOCATION << endl;
|
|
||||||
this->error_code_list_.push_back(
|
this->error_code_list_.push_back(
|
||||||
{ErrorType::CalError, ErrorLocation::ActExp});
|
{ErrorType::CalError, ErrorLocation::ActExp});
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exp_result_ == nullptr && tags_exp_ != "") {
|
if (tags_exp_ != "") {
|
||||||
try {
|
int reg_ret = expr_engine_->registerExpression("result", tags_exp_);
|
||||||
exp_result_ =
|
if (reg_ret != 0) {
|
||||||
std::make_unique<mix_cc::matheval::Expression>(tags_exp_, &mm_vars);
|
|
||||||
logger_->Debug() << "tags_exp_:" << tags_exp_ << "="
|
|
||||||
<< exp_result_->evaluate() << endl;
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
logger_->Error() << "tags_exp_:" << tags_exp_ << "计算出错:" << e.what()
|
|
||||||
<< ",location:" << BOOST_CURRENT_LOCATION << endl;
|
|
||||||
this->error_code_list_.push_back(
|
this->error_code_list_.push_back(
|
||||||
{ErrorType::CalError, ErrorLocation::ActExp});
|
{ErrorType::CalError, ErrorLocation::ResultExp});
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -182,8 +182,8 @@ std::vector<AlarmInfo> TrendSlope2::exec_task(mix_cc::time_range_t time_range) {
|
|||||||
|
|
||||||
bool TrendSlope2::get_prr2() {
|
bool TrendSlope2::get_prr2() {
|
||||||
if (this->prr_ == 1) {
|
if (this->prr_ == 1) {
|
||||||
exp_mpdule_ptr_->update(queried_data_, queried_time_);
|
expr_engine_->refreshFromIhdRow(0, queried_data_, queried_time_, now_time_, query_time_range_);
|
||||||
bool prr_result = (bool)exp_mpdule_ptr_->get_value("pre_result");
|
bool prr_result = expr_engine_->evaluateBool("pre_result");
|
||||||
this->now_prr_ = prr_result;
|
this->now_prr_ = prr_result;
|
||||||
logger_->Debug() << "ruleid:" << this->rule_id_
|
logger_->Debug() << "ruleid:" << this->rule_id_
|
||||||
<< ",rulename:" << this->rule_name_
|
<< ",rulename:" << this->rule_name_
|
||||||
|
|||||||
@ -190,8 +190,8 @@ std::vector<AlarmInfo> TrendSlope3::exec_task(mix_cc::time_range_t time_range) {
|
|||||||
|
|
||||||
bool TrendSlope3::get_prr2() {
|
bool TrendSlope3::get_prr2() {
|
||||||
if (this->prr_ == 1) {
|
if (this->prr_ == 1) {
|
||||||
exp_mpdule_ptr_->update(queried_data_, queried_time_);
|
expr_engine_->refreshFromIhdRow(0, queried_data_, queried_time_, now_time_, query_time_range_);
|
||||||
bool prr_result = (bool)exp_mpdule_ptr_->get_value("pre_result");
|
bool prr_result = expr_engine_->evaluateBool("pre_result");
|
||||||
this->now_prr_ = prr_result;
|
this->now_prr_ = prr_result;
|
||||||
logger_->Debug() << "ruleid:" << this->rule_id_
|
logger_->Debug() << "ruleid:" << this->rule_id_
|
||||||
<< ",rulename:" << this->rule_name_
|
<< ",rulename:" << this->rule_name_
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user