fix: 清理 ExpBase 子类中的 exp_act_/exp_feedback_/exp_result_ 残留引用
将 exp_bound、exp_times、exp_sample2D 中对已删除成员的引用替换为 expr_engine_->evaluate()/evaluateBool() 调用。 exp_sample2D 中原来绑定 exp_feedback_ 和 exp_result_ 的 sample_X/sample_Y 表达式现在通过 expr_engine_->registerExpression() 注册。
This commit is contained in:
parent
38d0942a6c
commit
3f8d281596
@ -52,13 +52,13 @@ ExpBound::~ExpBound() {
|
|||||||
|
|
||||||
AlarmInfo ExpBound::mon_proc() {
|
AlarmInfo ExpBound::mon_proc() {
|
||||||
|
|
||||||
if ((bool)exp_feedback_->evaluate() == false) {
|
if (expr_engine_->evaluateBool("feedback") == false) {
|
||||||
logger_->Debug() << "前提条件不满足!" << std::endl;
|
logger_->Debug() << "前提条件不满足!" << std::endl;
|
||||||
return AlarmInfo{};
|
return AlarmInfo{};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*最新数据*/
|
/*最新数据*/
|
||||||
double now_value = exp_act_->evaluate();
|
double now_value = expr_engine_->evaluate("act");
|
||||||
|
|
||||||
rule_stat_.current_value = now_value;
|
rule_stat_.current_value = now_value;
|
||||||
/*报警检查*/
|
/*报警检查*/
|
||||||
|
|||||||
@ -48,7 +48,7 @@ AlarmInfo ExpSample2D::mon_proc() {
|
|||||||
} else {
|
} else {
|
||||||
switch (exp_type_) {
|
switch (exp_type_) {
|
||||||
case ExpType::PolyFit:
|
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;
|
this->rule_stat_.alarm_value = this->rule_stat_.current_value;
|
||||||
auto msg = rule_name_ + this->error_str_ + " Y表达式当前值:" +
|
auto msg = rule_name_ + this->error_str_ + " Y表达式当前值:" +
|
||||||
DAA::double2str(this->rule_stat_.current_value) +
|
DAA::double2str(this->rule_stat_.current_value) +
|
||||||
@ -95,38 +95,26 @@ AlarmInfo ExpSample2D::mon_proc() {
|
|||||||
|
|
||||||
int ExpSample2D::reload_samples() {
|
int ExpSample2D::reload_samples() {
|
||||||
/*
|
/*
|
||||||
sample_X绑定 exp_feedback_
|
sample_X绑定 expr_engine_->evaluate("sample_X")
|
||||||
sample_Y绑定 exp_result_
|
sample_Y绑定 expr_engine_->evaluate("sample_Y")
|
||||||
*/
|
*/
|
||||||
auto tmp_exp =
|
auto tmp_exp =
|
||||||
rule_json_.at("function").at("sample_X").at("value").get<std::string>();
|
rule_json_.at("function").at("sample_X").at("value").get<std::string>();
|
||||||
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
||||||
if (exp_feedback_ == nullptr && exp_str_ != "") {
|
if (exp_str_ != "") {
|
||||||
try {
|
int ret = expr_engine_->registerExpression("sample_X", exp_str_);
|
||||||
exp_feedback_ =
|
if (ret != 0) return -1;
|
||||||
std::make_unique<mix_cc::matheval::Expression>(exp_str_, &mm_vars);
|
|
||||||
logger_->Debug() << "sample_X:" << exp_str_ << "="
|
logger_->Debug() << "sample_X:" << exp_str_ << "="
|
||||||
<< exp_feedback_->evaluate() << endl;
|
<< expr_engine_->evaluate("sample_X") << endl;
|
||||||
} catch (const std::exception &e) {
|
|
||||||
logger_->Error() << "sample_X:" << exp_str_ << "计算出错:" << e.what()
|
|
||||||
<< ",location:" << BOOST_CURRENT_LOCATION << endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tmp_exp =
|
tmp_exp =
|
||||||
rule_json_.at("function").at("sample_Y").at("value").get<std::string>();
|
rule_json_.at("function").at("sample_Y").at("value").get<std::string>();
|
||||||
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
||||||
if (exp_result_ == nullptr && exp_str_ != "") {
|
if (exp_str_ != "") {
|
||||||
try {
|
int ret = expr_engine_->registerExpression("sample_Y", exp_str_);
|
||||||
exp_result_ =
|
if (ret != 0) return -1;
|
||||||
std::make_unique<mix_cc::matheval::Expression>(exp_str_, &mm_vars);
|
|
||||||
logger_->Debug() << "sample_Y:" << exp_str_ << "="
|
logger_->Debug() << "sample_Y:" << exp_str_ << "="
|
||||||
<< exp_result_->evaluate() << endl;
|
<< expr_engine_->evaluate("sample_Y") << endl;
|
||||||
} catch (const std::exception &e) {
|
|
||||||
logger_->Error() << "sample_Y:" << exp_str_ << "计算出错:" << e.what()
|
|
||||||
<< ",location:" << BOOST_CURRENT_LOCATION << endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_exp = rule_json_.at("function")
|
tmp_exp = rule_json_.at("function")
|
||||||
@ -173,8 +161,8 @@ int ExpSample2D::reload_samples() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ExpSample2D::check_polyFit() {
|
bool ExpSample2D::check_polyFit() {
|
||||||
double X = exp_feedback_->evaluate(); /* SampleX*/
|
double X = expr_engine_->evaluate("sample_X"); /* SampleX*/
|
||||||
double Y = exp_result_->evaluate(); /* SampleY*/
|
double Y = expr_engine_->evaluate("sample_Y"); /* SampleY*/
|
||||||
double Y_Fit = PolyFitValue(X, this->fit_coefs_, this->orders_);
|
double Y_Fit = PolyFitValue(X, this->fit_coefs_, this->orders_);
|
||||||
limit_down_ = Y_Fit - abs(Y_Fit) * scale_;
|
limit_down_ = Y_Fit - abs(Y_Fit) * scale_;
|
||||||
limit_up_ = 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<double> &fit_coefs,
|
|||||||
|
|
||||||
bool ExpSample2D::check_pear() {
|
bool ExpSample2D::check_pear() {
|
||||||
if (this->data_len_ < min_len_) {
|
if (this->data_len_ < min_len_) {
|
||||||
if (exp_act_->evaluate()) {
|
if (expr_engine_->evaluateBool("act")) {
|
||||||
SampleX_.push_back(exp_feedback_->evaluate());
|
SampleX_.push_back(expr_engine_->evaluate("sample_X"));
|
||||||
SampleY_.push_back(exp_result_->evaluate());
|
SampleY_.push_back(expr_engine_->evaluate("sample_Y"));
|
||||||
data_len_ = SampleX_.size();
|
data_len_ = SampleX_.size();
|
||||||
} else {
|
} else {
|
||||||
reset_SampleXY();
|
reset_SampleXY();
|
||||||
@ -431,9 +419,9 @@ void ExpSample2D::task_mon_pro() {
|
|||||||
for (auto i = 0; i < queried_data_.rows(); i++) {
|
for (auto i = 0; i < queried_data_.rows(); i++) {
|
||||||
refresh_exp_vars_ihd(i);
|
refresh_exp_vars_ihd(i);
|
||||||
if (data_len_ < MAX_STORAGE_SIZE) {
|
if (data_len_ < MAX_STORAGE_SIZE) {
|
||||||
if (exp_act_->evaluate()) {
|
if (expr_engine_->evaluateBool("act")) {
|
||||||
SampleX_.push_back(exp_feedback_->evaluate());
|
SampleX_.push_back(expr_engine_->evaluate("sample_X"));
|
||||||
SampleY_.push_back(exp_result_->evaluate());
|
SampleY_.push_back(expr_engine_->evaluate("sample_Y"));
|
||||||
data_len_ = SampleX_.size();
|
data_len_ = SampleX_.size();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -198,7 +198,7 @@ int ExpTimes::update_times() {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->act_triggered_ = this->exp_act_->evaluate();
|
this->act_triggered_ = expr_engine_->evaluateBool("act");
|
||||||
/*出现次数累计*/
|
/*出现次数累计*/
|
||||||
if (this->exp_type_ == ExpType::OccTimesAcc) {
|
if (this->exp_type_ == ExpType::OccTimesAcc) {
|
||||||
if (this->act_triggered_) {
|
if (this->act_triggered_) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user