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_) {