759 lines
27 KiB
C++
759 lines
27 KiB
C++
|
|
#include <RICS/RICS_alg.h>
|
|||
|
|
#include <RICS/table_struct/t_rule_cfg.h>
|
|||
|
|
#include <RICS/utility.h>
|
|||
|
|
#include <mix_cc/sql.h>
|
|||
|
|
#include <mix_cc/sql/database/db2_t.h>
|
|||
|
|
RICSAlg::RICSAlg() {
|
|||
|
|
logger_ = std::make_unique<LOG>("RICSAlg");
|
|||
|
|
SingletonTemplate<Item2Chines>::GetInstance()("test");
|
|||
|
|
}
|
|||
|
|
RICSAlg::~RICSAlg() {}
|
|||
|
|
void RICSAlg::alg_handle(int algid) {
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
// 载入T_RULE_CFG表,从其中读取算法
|
|||
|
|
T_RULE_CFG t_rule_cfg;
|
|||
|
|
auto sql_statement =
|
|||
|
|
select(t_rule_cfg.algId(), t_rule_cfg.ruleId(), t_rule_cfg.ruleName(),
|
|||
|
|
t_rule_cfg.remark(), t_rule_cfg.ruleGroup(), t_rule_cfg.eqpid(),
|
|||
|
|
t_rule_cfg.flag(), t_rule_cfg.ruleParam())
|
|||
|
|
.from(t_rule_cfg)
|
|||
|
|
.where(t_rule_cfg.algId() == algid);
|
|||
|
|
auto rule_list_maybe = mix_cc::sql::exec<db2_t, T_RULE_CFG>(sql_statement);
|
|||
|
|
if (rule_list_maybe.is_just()) {
|
|||
|
|
int tagMax = 0;
|
|||
|
|
auto rule_list = rule_list_maybe.unsafe_get_just();
|
|||
|
|
logger_->Info() << "rules in DB:" << rule_list.size() << endl;
|
|||
|
|
CfgRuleInfo cfg_rule_info;
|
|||
|
|
for (auto x : rule_list) {
|
|||
|
|
RuleInfo rule_info;
|
|||
|
|
// logger_->Debug() << "ID:" << x.ruleId << " AlgID:" << x.algId
|
|||
|
|
// << " Name:" << x.ruleName << " Flag:" << x.flag
|
|||
|
|
// << endl;
|
|||
|
|
rule_info.rule_name = x.ruleName;
|
|||
|
|
rule_info.remark = x.remark;
|
|||
|
|
rule_info.eqpid = x.eqpid;
|
|||
|
|
rule_info.rule_group = x.ruleGroup;
|
|||
|
|
auto param_info = mix_cc::json::parse(x.ruleParam);
|
|||
|
|
if (param_info.contains("output")) {
|
|||
|
|
rule_info.alarm_reason =
|
|||
|
|
param_info.at("output").at("reason").at("value").get<string>();
|
|||
|
|
rule_info.alarm_content =
|
|||
|
|
param_info.at("output").at("error").at("value").get<string>();
|
|||
|
|
}
|
|||
|
|
rule_info.pre_condition = param_info.at("before_exec").get<string>();
|
|||
|
|
rule_info.pre_result = param_info.at("function")
|
|||
|
|
.at("pre_result")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
|
|||
|
|
const auto tag_dict = param_info["tags"];
|
|||
|
|
const int tag_size = tag_dict.size();
|
|||
|
|
tagMax = std::max(tagMax, tag_size);
|
|||
|
|
rule_info.tags_item.resize(tag_size);
|
|||
|
|
rule_info.tags_chinese.resize(tag_size);
|
|||
|
|
for (auto y : tag_dict.items()) {
|
|||
|
|
int item_index = stoi(y.key().substr(3));
|
|||
|
|
if (item_index > tag_size) {
|
|||
|
|
logger_->Error()
|
|||
|
|
<< "ruleid:" << x.ruleId << ",rulename:" << x.ruleName
|
|||
|
|
<< ",tag max:" << tag_size << ",now tag index:" << item_index
|
|||
|
|
<< std::endl;
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
auto itemi = y.value().at("value").get<std::string>();
|
|||
|
|
rule_info.tags_item[item_index - 1] = itemi;
|
|||
|
|
rule_info.tags_chinese[item_index - 1] =
|
|||
|
|
SingletonTemplate<Item2Chines>::GetInstance()(itemi);
|
|||
|
|
}
|
|||
|
|
auto fun_json = param_info.at("function");
|
|||
|
|
exp_handle(fun_json, rule_info, algid);
|
|||
|
|
cfg_rule_info[x.ruleId] = rule_info;
|
|||
|
|
}
|
|||
|
|
alg_rule_info_[algid] = cfg_rule_info;
|
|||
|
|
alg_2_tagMax[algid] = tagMax;
|
|||
|
|
logger_->Debug() << "alg_2_tagMax[algid]:" << alg_2_tagMax[algid]
|
|||
|
|
<< std::endl;
|
|||
|
|
} else {
|
|||
|
|
logger_->Debug() << "algid:" << algid << " 无规则" << std::endl;
|
|||
|
|
}
|
|||
|
|
} catch (const std::exception &e) {
|
|||
|
|
logger_->Error() << e.what() << std::endl;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void RICSAlg::timed_task() {
|
|||
|
|
logger_->Debug() << "test" << std::endl;
|
|||
|
|
for (auto item : AlgId) {
|
|||
|
|
logger_->Debug() << "item:" << item << std::endl;
|
|||
|
|
alg_handle(item);
|
|||
|
|
string jvalue = get_json_by_algid(item);
|
|||
|
|
|
|||
|
|
string jkey = unitNo_ + "_Alg_" + std::to_string(item);
|
|||
|
|
write_memcaced(jkey, jvalue);
|
|||
|
|
logger_->Debug() << "jkey:" << jkey
|
|||
|
|
<< ",jvalue size:" << alg_rule_info_[item].size()
|
|||
|
|
<< std::endl;
|
|||
|
|
// logger_->Debug() << "jkey:" << jkey << ",jvalue:" << jvalue << std::endl;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void RICSAlg::dispose(int event_no, const ::Ice::ByteSeq &seq) {
|
|||
|
|
string str(seq.begin(), seq.end());
|
|||
|
|
logger_->Debug() << "seq:" << str << std::endl;
|
|||
|
|
}
|
|||
|
|
void RICSAlg::exp_handle(json &funciton_param, RuleInfo &ruleInfo, int algid) {
|
|||
|
|
|
|||
|
|
switch (algid) {
|
|||
|
|
case 1: {
|
|||
|
|
ruleInfo.exp_str.resize(1);
|
|||
|
|
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
} break;
|
|||
|
|
case 2: {
|
|||
|
|
ruleInfo.exp_str.resize(2);
|
|||
|
|
ruleInfo.exp_str[0] =
|
|||
|
|
funciton_param.at("filter_exp").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[1] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
ruleInfo.limit_down = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_down")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.limit_up = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_up")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
if (funciton_param.at("result").at("param").contains("unit")) {
|
|||
|
|
ruleInfo.unit = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("unit")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 3: {
|
|||
|
|
ruleInfo.exp_str.resize(3);
|
|||
|
|
ruleInfo.exp_str[0] =
|
|||
|
|
funciton_param.at("action_start").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[1] =
|
|||
|
|
funciton_param.at("action_end").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[2] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
ruleInfo.params.resize(2);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("action_start")
|
|||
|
|
.at("param")
|
|||
|
|
.at("hold")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[1] = funciton_param.at("action_end")
|
|||
|
|
.at("param")
|
|||
|
|
.at("timeout")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
} break;
|
|||
|
|
case 4: {
|
|||
|
|
ruleInfo.exp_str.resize(3);
|
|||
|
|
ruleInfo.exp_str[0] =
|
|||
|
|
funciton_param.at("action_start").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[1] =
|
|||
|
|
funciton_param.at("action_end").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[2] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
ruleInfo.params.resize(2);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("action_start")
|
|||
|
|
.at("param")
|
|||
|
|
.at("hold")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[1] = funciton_param.at("action_end")
|
|||
|
|
.at("param")
|
|||
|
|
.at("timeout")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.limit_down = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_down")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.limit_up = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_up")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
if (funciton_param.at("result").at("param").contains("unit")) {
|
|||
|
|
ruleInfo.unit = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("unit")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 5: {
|
|||
|
|
ruleInfo.exp_str.resize(2);
|
|||
|
|
ruleInfo.exp_str[0] =
|
|||
|
|
funciton_param.at("filter_exp").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[1] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
|
|||
|
|
ruleInfo.params.resize(1);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("hold_time")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
|
|||
|
|
ruleInfo.limit_down = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_down")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.limit_up = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_up")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
if (funciton_param.at("result").at("param").contains("unit")) {
|
|||
|
|
ruleInfo.unit = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("unit")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 6: {
|
|||
|
|
ruleInfo.exp_str.resize(1);
|
|||
|
|
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
|
|||
|
|
ruleInfo.params.resize(1);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_time")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 7: {
|
|||
|
|
ruleInfo.exp_str.resize(1);
|
|||
|
|
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
|
|||
|
|
ruleInfo.params.resize(1);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_times")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 8: {
|
|||
|
|
ruleInfo.exp_str.resize(1);
|
|||
|
|
ruleInfo.exp_str[0] =
|
|||
|
|
funciton_param.at("limit_error").at("value").get<string>();
|
|||
|
|
|
|||
|
|
ruleInfo.params.resize(4);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("limit_error")
|
|||
|
|
.at("param")
|
|||
|
|
.at("interval_time")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[1] = funciton_param.at("limit_error")
|
|||
|
|
.at("param")
|
|||
|
|
.at("deltaX")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[2] = funciton_param.at("limit_error")
|
|||
|
|
.at("param")
|
|||
|
|
.at("diff")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[3] = funciton_param.at("limit_error")
|
|||
|
|
.at("param")
|
|||
|
|
.at("CS_AVG_SIZE")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 12: {
|
|||
|
|
ruleInfo.exp_str.resize(3);
|
|||
|
|
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[1] =
|
|||
|
|
funciton_param.at("sample_X").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[2] =
|
|||
|
|
funciton_param.at("sample_Y").at("value").get<string>();
|
|||
|
|
|
|||
|
|
ruleInfo.params.resize(1);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("sample_Y")
|
|||
|
|
.at("param")
|
|||
|
|
.at("scale")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
} break;
|
|||
|
|
case 13: {
|
|||
|
|
ruleInfo.exp_str.resize(3);
|
|||
|
|
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[1] =
|
|||
|
|
funciton_param.at("sample_X").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[2] =
|
|||
|
|
funciton_param.at("sample_Y").at("value").get<string>();
|
|||
|
|
|
|||
|
|
ruleInfo.params.resize(2);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("sample_Y")
|
|||
|
|
.at("param")
|
|||
|
|
.at("scale")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[1] = funciton_param.at("sample_Y")
|
|||
|
|
.at("param")
|
|||
|
|
.at("min_len")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
} break;
|
|||
|
|
case 14: {
|
|||
|
|
ruleInfo.exp_str.resize(1);
|
|||
|
|
ruleInfo.exp_str[0] =
|
|||
|
|
funciton_param.at("limit_error").at("value").get<string>();
|
|||
|
|
|
|||
|
|
ruleInfo.params.resize(4);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("limit_error")
|
|||
|
|
.at("param")
|
|||
|
|
.at("interval_time")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[1] = funciton_param.at("limit_error")
|
|||
|
|
.at("param")
|
|||
|
|
.at("deltaX")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[2] = funciton_param.at("limit_error")
|
|||
|
|
.at("param")
|
|||
|
|
.at("diff")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[3] = funciton_param.at("limit_error")
|
|||
|
|
.at("param")
|
|||
|
|
.at("CS_AVG_SIZE")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 15: {
|
|||
|
|
ruleInfo.exp_str.resize(1);
|
|||
|
|
ruleInfo.exp_str[0] = funciton_param.at("dataX").at("value").get<string>();
|
|||
|
|
ruleInfo.params.resize(1);
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("dataX")
|
|||
|
|
.at("param")
|
|||
|
|
.at("lenth")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
} break;
|
|||
|
|
case 16:
|
|||
|
|
case 18: {
|
|||
|
|
ruleInfo.exp_str.resize(2);
|
|||
|
|
ruleInfo.exp_str[0] =
|
|||
|
|
funciton_param.at("pre_exp").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[1] = funciton_param.at("input").at("value").get<string>();
|
|||
|
|
ruleInfo.params.resize(4);
|
|||
|
|
if (funciton_param.at("input").at("param").contains("unit")) {
|
|||
|
|
ruleInfo.unit = funciton_param.at("input")
|
|||
|
|
.at("param")
|
|||
|
|
.at("unit")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
}
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("input")
|
|||
|
|
.at("param")
|
|||
|
|
.at("detect_mode")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[1] = funciton_param.at("input")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_warn")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[2] = funciton_param.at("input")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_error")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
if (funciton_param.at("input").at("param").contains("hold_time")) {
|
|||
|
|
ruleInfo.params[3] = funciton_param.at("input")
|
|||
|
|
.at("param")
|
|||
|
|
.at("hold_time")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
} else {
|
|||
|
|
ruleInfo.params[3] = "0";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 17: {
|
|||
|
|
ruleInfo.exp_str.resize(2);
|
|||
|
|
ruleInfo.exp_str[0] =
|
|||
|
|
funciton_param.at("filter_exp").at("value").get<string>();
|
|||
|
|
ruleInfo.exp_str[1] = funciton_param.at("result").at("value").get<string>();
|
|||
|
|
ruleInfo.params.resize(3);
|
|||
|
|
if (funciton_param.at("result").at("param").contains("unit")) {
|
|||
|
|
ruleInfo.unit = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("unit")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ruleInfo.params[0] = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_warn")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
ruleInfo.params[1] = funciton_param.at("result")
|
|||
|
|
.at("param")
|
|||
|
|
.at("limit_error")
|
|||
|
|
.at("value")
|
|||
|
|
.get<string>();
|
|||
|
|
} break;
|
|||
|
|
default:
|
|||
|
|
logger_->Debug() << "algid:" << algid << " error!" << std::endl;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
string RICSAlg::get_json_by_algid(int algid) {
|
|||
|
|
nlohmann::json js1;
|
|||
|
|
vector<string> columns_name{
|
|||
|
|
"规则名称", "设备id", "规则分组", "规则描述",
|
|||
|
|
"报警原因", "报警内容", "前置条件", "执行前置条件表达式",
|
|||
|
|
};
|
|||
|
|
vector<vector<string>> data;
|
|||
|
|
const auto &algRuleIfo = alg_rule_info_[algid];
|
|||
|
|
for (int i = 0; i < 8; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (auto &item : algRuleIfo) {
|
|||
|
|
coli_data.push_back(item.second.get_value(i));
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
switch (algid) {
|
|||
|
|
|
|||
|
|
case 1: {
|
|||
|
|
columns_name.push_back("报警条件表达式");
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[0]);
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
} break;
|
|||
|
|
case 2: {
|
|||
|
|
columns_name.push_back("数据筛选表达式");
|
|||
|
|
columns_name.push_back("监控变量表达式");
|
|||
|
|
columns_name.push_back("单位");
|
|||
|
|
columns_name.push_back("下限");
|
|||
|
|
columns_name.push_back("上限");
|
|||
|
|
for (int i = 0; i < 5; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 2) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else if (i == 2) {
|
|||
|
|
coli_data.push_back(item.second.unit);
|
|||
|
|
} else if (i == 3) {
|
|||
|
|
coli_data.push_back(item.second.limit_down);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.limit_up);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 3: {
|
|||
|
|
columns_name.push_back("动作表达式");
|
|||
|
|
columns_name.push_back("反馈表达式");
|
|||
|
|
columns_name.push_back("监控变量表达式");
|
|||
|
|
columns_name.push_back("是否保持");
|
|||
|
|
columns_name.push_back("超时时间");
|
|||
|
|
for (int i = 0; i < 5; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 3) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[i - 3]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 4: {
|
|||
|
|
columns_name.push_back("动作表达式");
|
|||
|
|
columns_name.push_back("反馈表达式");
|
|||
|
|
columns_name.push_back("监控变量条件表达式");
|
|||
|
|
columns_name.push_back("是否保持");
|
|||
|
|
columns_name.push_back("超时时间");
|
|||
|
|
columns_name.push_back("单位");
|
|||
|
|
columns_name.push_back("下限");
|
|||
|
|
columns_name.push_back("上限");
|
|||
|
|
for (int i = 0; i < 8; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 3) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else if (i == 3) {
|
|||
|
|
coli_data.push_back(item.second.params[0]);
|
|||
|
|
} else if (i == 4) {
|
|||
|
|
coli_data.push_back(item.second.params[1]);
|
|||
|
|
} else if (i == 5) {
|
|||
|
|
coli_data.push_back(item.second.unit);
|
|||
|
|
} else if (i == 6) {
|
|||
|
|
coli_data.push_back(item.second.limit_down);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.limit_up);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 5: {
|
|||
|
|
columns_name.push_back("数据筛选表达式");
|
|||
|
|
columns_name.push_back("监控变量表达式");
|
|||
|
|
columns_name.push_back("单位");
|
|||
|
|
columns_name.push_back("下限");
|
|||
|
|
columns_name.push_back("上限");
|
|||
|
|
columns_name.push_back("持续时间[ms]");
|
|||
|
|
for (int i = 0; i < 6; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 2) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else if (i == 2) {
|
|||
|
|
coli_data.push_back(item.second.unit);
|
|||
|
|
} else if (i == 3) {
|
|||
|
|
coli_data.push_back(item.second.limit_down);
|
|||
|
|
} else if (i == 4) {
|
|||
|
|
coli_data.push_back(item.second.limit_up);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[0]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 6: {
|
|||
|
|
columns_name.push_back("检测条件表达式");
|
|||
|
|
columns_name.push_back("最大保持时间[小时]");
|
|||
|
|
for (int i = 0; i < 2; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i == 0) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[0]);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[0]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 7: {
|
|||
|
|
columns_name.push_back("检测条件表达式");
|
|||
|
|
columns_name.push_back("最大出现次数");
|
|||
|
|
for (int i = 0; i < 2; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i == 0) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[0]);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[0]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 8: {
|
|||
|
|
columns_name.push_back("报警条件表达式");
|
|||
|
|
columns_name.push_back("查询均值时间[s]");
|
|||
|
|
columns_name.push_back("单位时间间隔[min]");
|
|||
|
|
columns_name.push_back("监控量斜率(减少为用负值)");
|
|||
|
|
columns_name.push_back("连续出现的次数");
|
|||
|
|
for (int i = 0; i < 5; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i == 0) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[0]);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[i - 1]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 12: {
|
|||
|
|
columns_name.push_back("筛选条件表达式");
|
|||
|
|
columns_name.push_back("X表达式");
|
|||
|
|
columns_name.push_back("Y表达式");
|
|||
|
|
columns_name.push_back("数据误差比(0~1)");
|
|||
|
|
for (int i = 0; i < 4; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 3) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[0]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 13: {
|
|||
|
|
columns_name.push_back("筛选条件表达式");
|
|||
|
|
columns_name.push_back("X表达式");
|
|||
|
|
columns_name.push_back("Y表达式");
|
|||
|
|
columns_name.push_back("数据误差比(0~1)");
|
|||
|
|
columns_name.push_back("相关性计算数据最小长度");
|
|||
|
|
for (int i = 0; i < 5; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 3) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[i - 3]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 14: {
|
|||
|
|
columns_name.push_back("报警条件表达式");
|
|||
|
|
columns_name.push_back("查询均值时间[s]");
|
|||
|
|
columns_name.push_back("单位时间间隔[min]");
|
|||
|
|
columns_name.push_back("监控量变化率[%](减少为用负值)");
|
|||
|
|
columns_name.push_back("连续出现的次数");
|
|||
|
|
for (int i = 0; i < 5; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i == 0) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[0]);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[i - 1]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
} break;
|
|||
|
|
case 15: {
|
|||
|
|
columns_name.push_back("监控变量表达式");
|
|||
|
|
columns_name.push_back("监测窗数据量[100,1000]");
|
|||
|
|
for (int i = 0; i < 2; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i == 0) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[0]);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[0]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 16: {
|
|||
|
|
columns_name.push_back("前提条件表达式");
|
|||
|
|
columns_name.push_back("多变量求和表达式");
|
|||
|
|
columns_name.push_back("单位");
|
|||
|
|
columns_name.push_back("检测模式");
|
|||
|
|
columns_name.push_back("超时警告:离群变量超均值百分比");
|
|||
|
|
columns_name.push_back("报警:离群变量超均值百分比");
|
|||
|
|
columns_name.push_back("持续时间[ms]");
|
|||
|
|
for (int i = 0; i < 7; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 2) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else if (i == 2) {
|
|||
|
|
coli_data.push_back(item.second.unit);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[i - 3]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 17: {
|
|||
|
|
columns_name.push_back("数据筛选表达式");
|
|||
|
|
columns_name.push_back("超限结果表达式");
|
|||
|
|
columns_name.push_back("单位");
|
|||
|
|
columns_name.push_back("警告:限幅");
|
|||
|
|
columns_name.push_back("报警:限幅");
|
|||
|
|
for (int i = 0; i < 5; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 2) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else if (i == 2) {
|
|||
|
|
coli_data.push_back(item.second.unit);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[i - 3]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
case 18: {
|
|||
|
|
columns_name.push_back("前提条件表达式");
|
|||
|
|
columns_name.push_back("多变量求和表达式");
|
|||
|
|
columns_name.push_back("单位");
|
|||
|
|
columns_name.push_back("检测模式");
|
|||
|
|
columns_name.push_back("超时警告:离群变量超均值");
|
|||
|
|
columns_name.push_back("报警:离群变量超均值");
|
|||
|
|
columns_name.push_back("持续时间[ms]");
|
|||
|
|
for (int i = 0; i < 7; i++) {
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
if (i < 2) {
|
|||
|
|
coli_data.push_back(item.second.exp_str[i]);
|
|||
|
|
} else if (i == 2) {
|
|||
|
|
coli_data.push_back(item.second.unit);
|
|||
|
|
} else {
|
|||
|
|
coli_data.push_back(item.second.params[i - 3]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} break;
|
|||
|
|
default:
|
|||
|
|
logger_->Debug() << "algid:" << algid << " error!" << std::endl;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
const int tagMaxNum = alg_2_tagMax[algid];
|
|||
|
|
for (int i = 0; i < tagMaxNum; i++) {
|
|||
|
|
string tagi = "tag" + std::to_string(i + 1);
|
|||
|
|
columns_name.push_back(tagi);
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
coli_data.push_back(item.second.tags_item_get(i));
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (int i = 0; i < tagMaxNum; i++) {
|
|||
|
|
string tagi = "tag" + std::to_string(i + 1) + "中文";
|
|||
|
|
columns_name.push_back(tagi);
|
|||
|
|
vector<string> coli_data;
|
|||
|
|
for (const auto &item : algRuleIfo) {
|
|||
|
|
coli_data.push_back(item.second.tags_chinese_get(i));
|
|||
|
|
}
|
|||
|
|
data.push_back(coli_data);
|
|||
|
|
}
|
|||
|
|
js1["columns"] = columns_name;
|
|||
|
|
js1["data"] = data;
|
|||
|
|
return js1.dump();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool RICSAlg::write_memcaced(string jkey, string jvalue) {
|
|||
|
|
auto reSult = m_memclient.Insert(jkey.c_str(), jvalue.c_str());
|
|||
|
|
if (1 != reSult) {
|
|||
|
|
this->logger_->Debug()
|
|||
|
|
<< "update_eqp_status()"
|
|||
|
|
<< "m_memclient.Insert异常[0,set data fail;-1,key=null or value=null]:"
|
|||
|
|
<< reSult << std::endl;
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|