#include #include #include #include extern std::mapglob_items; int AlgWasteGas::init() { LOG d("AlgWasteGas::init",AUTO_CATCH_PID); int ret = 0; try { }catch (const std::exception &e) { d.Error() < mod1("ZONE0",1); // gb_data = mod1(); this->init(); m_start = -1; this->set_cycle_time(max(50,m_json_param["interval"]["time"][1].asInt())); } AlgWasteGas::~AlgWasteGas(){ } int AlgWasteGas::calculate(string &outjson) { LOG d("AlgWasteGas::calculate",AUTO_CATCH_PID); outjson = ""; int ret = 0; try { // m_tags[0] : 废气风机启动命令 // m_tags[1] : 废气管道负压值 if(m_start > 0){ time_t m_curr = this->mstime(); HD3TimeRegion timeRegion; timeRegion.left.nSec = m_start / 1000; timeRegion.left.nSec = m_curr / 1000; if(m_curr - m_start < m_json_param["time"]["delay"].asInt() * 60 * 1000 + m_json_param["time"]["check"].asInt() * 1000){ return 0; } time_t start = m_start + m_json_param["time"]["delay"].asInt() * 60 * 1000; double m_max = ihd_tools_->StatsTag(m_tags[1], start, m_curr, HD3_STATS_TYPE_MAX); double m_min = ihd_tools_->StatsTag(m_tags[1], start, m_curr, HD3_STATS_TYPE_MIN); if(m_max - m_min > m_json_param["limit_alarm"]["value"][1].asDouble()){ string msg = m_json_param["limit_alarm"]["content"][1].asString() + " 当前管道负压波动值为" + std::to_string(m_max - m_min); string tmp = this->build_alarm_info(MsgLevel::WARN, rule_id_, rule_name_, "WASTE_GAS", msg, timeRegion); if(!tmp.empty()) outjson = tmp; } else if(m_max - m_min > m_json_param["limit_error"]["value"][1].asDouble()){ string msg = m_json_param["limit_error"]["content"][1].asString() + " 当前管道负压波动值为" + std::to_string(m_max - m_min); string tmp = this->build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_, "WASTE_GAS", msg, timeRegion); if(!tmp.empty()) outjson = tmp; } else{ //d.Debug() << rule_name_ << " 数据正常! " << endl; } m_start = -1; } else{ if(glob_items[m_tags[0]].valueold == 0 && glob_items[m_tags[0]].value == 1){ m_start = this->mstime(); } } }catch(const std::exception &e) { d.Error() <