/****************************************************************************************************************** * Action instruction algorithm * * arg[0] action expression * arg[1] feedback expression * arg[2] expression of judgment result * * 1.0 2020-12-17 zoufuzhou ******************************************************************************************************************/ #include #include #include extern std::map glob_items; int AlgExpDelay::init() { LOG d("AlgExpDelay::init", AUTO_CATCH_PID); int ret = 0; try { } catch (const std::exception &e) { d.Error() << mix_cc::get_nested_exception(e) << std::endl; ret = -1; } return ret; } AlgExpDelay::AlgExpDelay(const string &name, const Json::Value &rulejson, const string &ruleId) : AlgExp(name, rulejson, ruleId), AlgBase(name, rulejson, ruleId) { LOG d("AlgExpDelay::AlgExpDelay", AUTO_CATCH_PID); try { act_feedback_time_ = m_json_alarm["action_condition"]["time_interval"][1].asInt(); d.Debug() << "Test1.1" << std::endl; this->init(); m_expstr = string(m_json_param["action_condition"]["action_start"][1].asString()); exp_act__ = new MathExpression(m_expstr.c_str(), mm_vars); d.Debug() << m_expstr << ":" << exp_act__->evaluate() << endl; this->SetHDTime(&query_time_region_.right, this->mstime()); } catch (const std::exception &e) { d.Error() << mix_cc::get_nested_exception(e) << endl; } } AlgExpDelay::~AlgExpDelay() { delete exp_act__; } int AlgExpDelay::calculate(string &outjson) { LOG d("AlgExpDelay::calculate|" + rule_name_, AUTO_CATCH_PID); d.Debug() << "test calc" << std::endl; int ret = 0; outjson = ""; d.Debug() << "test calc1" << std::endl; try { this->malloc_ihd_mem(); this->SetHDTime(&query_time_region_.left, &query_time_region_.right); ret = this->QueryDB3Record(); d.Debug() << "test calc1.1" << std::endl; if (ret != NULL) { return 0; } d.Debug() << "test calc2" << std::endl; for (int i = 0; i < tag_count_; i++) { for (int j = 0; j < m_tags.size(); j++) { mm_vars["p" + std::to_string(i + 1)] = mm_vars["tag" + std::to_string(i + 1)]; mm_vars["tag" + std::to_string(j + 1)] = records_queried_[j][i].NumberValue(); } ret = this->mon_proc(outjson); if (ret == NULL && outjson != "") { break; } } d.Debug() << "test calc3" << std::endl; if (this->m_btime == 0) { this->SetHDTime(&query_time_region_.right, this->mstime()); } this->free_ihd_mem(); } catch (const std::exception &e) { d.Error() << mix_cc::get_nested_exception(e) << std::endl; ret = -1; } // d.Debug() << "test calc done" << std::endl; return ret; } int AlgExpDelay::mon_proc(string &outjson) { LOG d("AlgExpDelay::mon_proc|" + rule_name_, AUTO_CATCH_PID); d.Debug() << "test calc once" << std::endl; int ret = 0; outjson = ""; bool act_triggered_ = false; long long timediff = 0; try { prev_calc_result_ = result_exp_act__; result_exp_act__ = (bool)exp_act__->evaluate(); // d.Debug() << "result_exp_act__:" << setw(2) << result_exp_act__ << endl; if (result_exp_act__) { // update one calc result if (begin_time_ == 0) { begin_time_ = mstime(); } } else { // begin time = 0 begin_time_ = 0; } if (mstime() - begin_time_ >= act_feedback_time_) { query_time_region_.left.nSec = begin_time_ / 100; query_time_region_.right.nSec = time(0); // update end time // report event msg = rule_name_ + " " + m_json_param["alarm_option"]["error"][1].asString(); msg = this->build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_, "EXPDELAY", msg, query_time_region_); d.Debug() << "Warning Delceared" << std::endl; // resert begin time to 0 } d.Debug() << "calc done once" << std::endl; } catch (const std::exception &e) { d.Error() << mix_cc::get_nested_exception(e) << std::endl; ret = -1; } return ret; }