eis/eqpalg/.do_not_use/exp_sample_curve.cpp

90 lines
2.8 KiB
C++
Raw Normal View History

/******************************************************************************************************************
* Action instruction algorithm(study sample data online,compare with sample
*data)
*
* arg[0] action expression
* arg[1] feedback expression
* arg[2] expression of judgment result
*
* feedback expression
* arg[2] expression of judgment result
*
* 1.0 2020-12-17 zoufuzhou
* 1.1 2021-3 c@t add DTW
******************************************************************************************************************/
#include <eqpalg/algs/exp_sample_curve.h>
#include <eqpalg/utility/build_alarm_info.h>
#include <vector>
#include <memory>
// add static modules
int ExpSampleCurve::init() {
try {
sample_stat_.load();
} catch (const std::exception& e) {
std::throw_with_nested(
mix_cc::Exception(-1, "init error", BOOST_CURRENT_LOCATION));
}
return 0;
}
ExpSampleCurve::ExpSampleCurve(const string& name,
const mix_cc::json& rule_json,
const string& ruleId)
: ExpSample<s_curve_impl_t>(name, rule_json, ruleId) {
logger_.reset(new LOG("ExpSampleCurve" + name, AUTO_CATCH_PID));
this->init();
}
ExpSampleCurve::~ExpSampleCurve() {}
AlarmInfo ExpSampleCurve::mon_proc() {
try {
std::vector<double> curve_data;
act_triggered_ = static_cast<bool>(exp_act_->evaluate());
if (act_triggered_) {
curve_data.push_back(exp_result_->evaluate());
}
if (feedback_mode_) {
feedback_triggered_ = static_cast<bool>(exp_feedback_->evaluate());
if (act_started_done()) {
return AlarmInfo{};
}
if (act_not_hold()) {
return AlarmInfo{};
}
if (act_done()) {
this->log_action_info(curve_data.back());
auto result =
this->sample_stat_.auto_detect_and_save(curve_data, now_time_);
curve_data.clear();
if (result) {
return utility::build_alarm_info(
MsgLevel::ERROR, rule_id_, rule_name_, "POLYFIT",
error_str_ + result.get_alarm_info(), query_time_range_);
}
} else if (act_timeout()) {
this->get_timeout_alarm();
}
} else {
if (act_started_done()) {
return AlarmInfo{};
} else if (!act_triggered_ && act_started_) {
act_started_ = false;
auto result =
this->sample_stat_.auto_detect_and_save(curve_data, now_time_);
curve_data.clear();
if (result) {
return utility::build_alarm_info(
MsgLevel::ERROR, rule_id_, rule_name_, "POLYFIT",
error_str_ + result.get_alarm_info(), query_time_range_);
}
}
}
} catch (const std::exception& e) {
std::throw_with_nested(
mix_cc::Exception(-1, "calc_once error", BOOST_CURRENT_LOCATION));
}
return AlarmInfo{};
}