From 3f8d281596472ca7d06db7d49acfb504148a2ff7 Mon Sep 17 00:00:00 2001 From: Huamonarch Date: Fri, 15 May 2026 13:14:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B8=85=E7=90=86=20ExpBase=20=E5=AD=90?= =?UTF-8?q?=E7=B1=BB=E4=B8=AD=E7=9A=84=20exp=5Fact=5F/exp=5Ffeedback=5F/ex?= =?UTF-8?q?p=5Fresult=5F=20=E6=AE=8B=E7=95=99=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 exp_bound、exp_times、exp_sample2D 中对已删除成员的引用替换为 expr_engine_->evaluate()/evaluateBool() 调用。 exp_sample2D 中原来绑定 exp_feedback_ 和 exp_result_ 的 sample_X/sample_Y 表达式现在通过 expr_engine_->registerExpression() 注册。 --- eqpalg/algs/exp_bound.cpp | 4 +-- eqpalg/algs/exp_sample2D.cc | 54 +++++++++++++++---------------------- eqpalg/algs/exp_times.cc | 2 +- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/eqpalg/algs/exp_bound.cpp b/eqpalg/algs/exp_bound.cpp index 46c5000..00d2cf2 100644 --- a/eqpalg/algs/exp_bound.cpp +++ b/eqpalg/algs/exp_bound.cpp @@ -52,13 +52,13 @@ ExpBound::~ExpBound() { AlarmInfo ExpBound::mon_proc() { - if ((bool)exp_feedback_->evaluate() == false) { + if (expr_engine_->evaluateBool("feedback") == false) { logger_->Debug() << "前提条件不满足!" << std::endl; return AlarmInfo{}; } /*最新数据*/ - double now_value = exp_act_->evaluate(); + double now_value = expr_engine_->evaluate("act"); rule_stat_.current_value = now_value; /*报警检查*/ diff --git a/eqpalg/algs/exp_sample2D.cc b/eqpalg/algs/exp_sample2D.cc index 921c148..218cd12 100644 --- a/eqpalg/algs/exp_sample2D.cc +++ b/eqpalg/algs/exp_sample2D.cc @@ -48,7 +48,7 @@ AlarmInfo ExpSample2D::mon_proc() { } else { switch (exp_type_) { case ExpType::PolyFit: - if (exp_act_->evaluate() && check_polyFit()) { + if (expr_engine_->evaluateBool("act") && check_polyFit()) { this->rule_stat_.alarm_value = this->rule_stat_.current_value; auto msg = rule_name_ + this->error_str_ + " Y表达式当前值:" + DAA::double2str(this->rule_stat_.current_value) + @@ -95,38 +95,26 @@ AlarmInfo ExpSample2D::mon_proc() { int ExpSample2D::reload_samples() { /* - sample_X绑定 exp_feedback_ - sample_Y绑定 exp_result_ + sample_X绑定 expr_engine_->evaluate("sample_X") + sample_Y绑定 expr_engine_->evaluate("sample_Y") */ auto tmp_exp = rule_json_.at("function").at("sample_X").at("value").get(); exp_str_ = get_macro_replaced_exp(tmp_exp); - if (exp_feedback_ == nullptr && exp_str_ != "") { - try { - exp_feedback_ = - std::make_unique(exp_str_, &mm_vars); - logger_->Debug() << "sample_X:" << exp_str_ << "=" - << exp_feedback_->evaluate() << endl; - } catch (const std::exception &e) { - logger_->Error() << "sample_X:" << exp_str_ << "计算出错:" << e.what() - << ",location:" << BOOST_CURRENT_LOCATION << endl; - return -1; - } + if (exp_str_ != "") { + int ret = expr_engine_->registerExpression("sample_X", exp_str_); + if (ret != 0) return -1; + logger_->Debug() << "sample_X:" << exp_str_ << "=" + << expr_engine_->evaluate("sample_X") << endl; } tmp_exp = rule_json_.at("function").at("sample_Y").at("value").get(); exp_str_ = get_macro_replaced_exp(tmp_exp); - if (exp_result_ == nullptr && exp_str_ != "") { - try { - exp_result_ = - std::make_unique(exp_str_, &mm_vars); - logger_->Debug() << "sample_Y:" << exp_str_ << "=" - << exp_result_->evaluate() << endl; - } catch (const std::exception &e) { - logger_->Error() << "sample_Y:" << exp_str_ << "计算出错:" << e.what() - << ",location:" << BOOST_CURRENT_LOCATION << endl; - return -1; - } + if (exp_str_ != "") { + int ret = expr_engine_->registerExpression("sample_Y", exp_str_); + if (ret != 0) return -1; + logger_->Debug() << "sample_Y:" << exp_str_ << "=" + << expr_engine_->evaluate("sample_Y") << endl; } tmp_exp = rule_json_.at("function") @@ -173,8 +161,8 @@ int ExpSample2D::reload_samples() { } bool ExpSample2D::check_polyFit() { - double X = exp_feedback_->evaluate(); /* SampleX*/ - double Y = exp_result_->evaluate(); /* SampleY*/ + double X = expr_engine_->evaluate("sample_X"); /* SampleX*/ + double Y = expr_engine_->evaluate("sample_Y"); /* SampleY*/ double Y_Fit = PolyFitValue(X, this->fit_coefs_, this->orders_); limit_down_ = Y_Fit - abs(Y_Fit) * scale_; limit_up_ = Y_Fit + abs(Y_Fit) * scale_; @@ -207,9 +195,9 @@ double ExpSample2D::PolyFitValue(double x, std::vector &fit_coefs, bool ExpSample2D::check_pear() { if (this->data_len_ < min_len_) { - if (exp_act_->evaluate()) { - SampleX_.push_back(exp_feedback_->evaluate()); - SampleY_.push_back(exp_result_->evaluate()); + if (expr_engine_->evaluateBool("act")) { + SampleX_.push_back(expr_engine_->evaluate("sample_X")); + SampleY_.push_back(expr_engine_->evaluate("sample_Y")); data_len_ = SampleX_.size(); } else { reset_SampleXY(); @@ -431,9 +419,9 @@ void ExpSample2D::task_mon_pro() { for (auto i = 0; i < queried_data_.rows(); i++) { refresh_exp_vars_ihd(i); if (data_len_ < MAX_STORAGE_SIZE) { - if (exp_act_->evaluate()) { - SampleX_.push_back(exp_feedback_->evaluate()); - SampleY_.push_back(exp_result_->evaluate()); + if (expr_engine_->evaluateBool("act")) { + SampleX_.push_back(expr_engine_->evaluate("sample_X")); + SampleY_.push_back(expr_engine_->evaluate("sample_Y")); data_len_ = SampleX_.size(); } } else { diff --git a/eqpalg/algs/exp_times.cc b/eqpalg/algs/exp_times.cc index a94025f..064f8ae 100644 --- a/eqpalg/algs/exp_times.cc +++ b/eqpalg/algs/exp_times.cc @@ -198,7 +198,7 @@ int ExpTimes::update_times() { return -1; } - this->act_triggered_ = this->exp_act_->evaluate(); + this->act_triggered_ = expr_engine_->evaluateBool("act"); /*出现次数累计*/ if (this->exp_type_ == ExpType::OccTimesAcc) { if (this->act_triggered_) {