From 38d0942a6cbf35f1cde3f05dcd4fd35aa8e9b30d Mon Sep 17 00:00:00 2001 From: Huamonarch Date: Fri, 15 May 2026 13:08:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=9D=9E=20ExpBase=20=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E9=80=82=E9=85=8D=20ExpressionEngine=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eqpalg/algs/glitch_detection.cpp | 10 ++++++---- eqpalg/algs/roller3.cpp | 32 +++++++++----------------------- eqpalg/algs/trend_slope2.cpp | 4 ++-- eqpalg/algs/trend_slope3.cpp | 4 ++-- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/eqpalg/algs/glitch_detection.cpp b/eqpalg/algs/glitch_detection.cpp index a3925f7..6cf21cf 100644 --- a/eqpalg/algs/glitch_detection.cpp +++ b/eqpalg/algs/glitch_detection.cpp @@ -78,7 +78,7 @@ AlarmInfo GlitchDetection::exec_mon() { data_index_ = 0; 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_++; return out_alarm; } @@ -117,7 +117,7 @@ int GlitchDetection::load_exp() { auto tmp_exp = rule_json_.at("function").at("dataX").at("value").get(); 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") .at("dataX") @@ -137,8 +137,10 @@ int GlitchDetection::load_exp() { } bool GlitchDetection::get_prr() { if (this->prr_ == 1) { - exp_mpdule_ptr_->update(); - bool prr_result = (bool)exp_mpdule_ptr_->get_value("pre_result"); + this->refresh_now_time(); + 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; logger_->Debug() << "ruleid:" << this->rule_id_ << ",rulename:" << this->rule_name_ diff --git a/eqpalg/algs/roller3.cpp b/eqpalg/algs/roller3.cpp index 35512ed..5bb39f5 100644 --- a/eqpalg/algs/roller3.cpp +++ b/eqpalg/algs/roller3.cpp @@ -71,7 +71,7 @@ Roller3::~Roller3() { AlarmInfo Roller3::mon_proc() { - if ((bool)exp_act_->evaluate() == false) { + if (!expr_engine_->evaluateBool("act")) { logger_->Debug() << "前提条件不满足!" << std::endl; return AlarmInfo{}; } @@ -227,9 +227,7 @@ int Roller3::init_X_exp() { exp_str_ = get_macro_replaced_exp(tmp_exp); res += init_hold_exp_str(exp_str_); - auto fun_res = fun_vars_.add_exp_str(exp_str_, &mm_vars); - res += fun_res.first ? 0 : -1; - exp_str_ = fun_res.second; + // ExpressionEngine::registerExpression() now handles FunVars processing internally. feedback_mode_ = false; auto messy_code = exp_messy_code_check(exp_str_); if (messy_code == -1) { @@ -305,31 +303,19 @@ int Roller3::init_X_exp() { } } value_num_ = tag_seq_.size(); - if (exp_act_ == nullptr && exp_str_ != "") { - try { - exp_act_ = - std::make_unique(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; + if (exp_str_ != "") { + int reg_ret = expr_engine_->registerExpression("act", exp_str_); + if (reg_ret != 0) { this->error_code_list_.push_back( {ErrorType::CalError, ErrorLocation::ActExp}); return -1; } } - if (exp_result_ == nullptr && tags_exp_ != "") { - try { - exp_result_ = - std::make_unique(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; + if (tags_exp_ != "") { + int reg_ret = expr_engine_->registerExpression("result", tags_exp_); + if (reg_ret != 0) { this->error_code_list_.push_back( - {ErrorType::CalError, ErrorLocation::ActExp}); + {ErrorType::CalError, ErrorLocation::ResultExp}); return -1; } } diff --git a/eqpalg/algs/trend_slope2.cpp b/eqpalg/algs/trend_slope2.cpp index 7efe6c6..8e4b2ce 100644 --- a/eqpalg/algs/trend_slope2.cpp +++ b/eqpalg/algs/trend_slope2.cpp @@ -182,8 +182,8 @@ std::vector TrendSlope2::exec_task(mix_cc::time_range_t time_range) { bool TrendSlope2::get_prr2() { if (this->prr_ == 1) { - exp_mpdule_ptr_->update(queried_data_, queried_time_); - bool prr_result = (bool)exp_mpdule_ptr_->get_value("pre_result"); + expr_engine_->refreshFromIhdRow(0, queried_data_, queried_time_, now_time_, query_time_range_); + bool prr_result = expr_engine_->evaluateBool("pre_result"); this->now_prr_ = prr_result; logger_->Debug() << "ruleid:" << this->rule_id_ << ",rulename:" << this->rule_name_ diff --git a/eqpalg/algs/trend_slope3.cpp b/eqpalg/algs/trend_slope3.cpp index 02211a9..401874b 100644 --- a/eqpalg/algs/trend_slope3.cpp +++ b/eqpalg/algs/trend_slope3.cpp @@ -190,8 +190,8 @@ std::vector TrendSlope3::exec_task(mix_cc::time_range_t time_range) { bool TrendSlope3::get_prr2() { if (this->prr_ == 1) { - exp_mpdule_ptr_->update(queried_data_, queried_time_); - bool prr_result = (bool)exp_mpdule_ptr_->get_value("pre_result"); + expr_engine_->refreshFromIhdRow(0, queried_data_, queried_time_, now_time_, query_time_range_); + bool prr_result = expr_engine_->evaluateBool("pre_result"); this->now_prr_ = prr_result; logger_->Debug() << "ruleid:" << this->rule_id_ << ",rulename:" << this->rule_name_