eis/eqpalg/.do_not_use/alg_to_transfer/AlgTorque.cpp

86 lines
2.7 KiB
C++

#include <T_TIME_SET.h>
#include <base/BitTool.h>
#include <eqpalg/algs/AlgTorque.h>
#include <utility/StringHelper.h>
// std::map<std::string,int> event_no_of_item;
int AlgTorque::init() {
LOG d("AlgTorque::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;
}
AlgTorque::AlgTorque(const string name, const Json::Value rulejson,
const string ruleId)
: AlgBase(name, rulejson, ruleId) {
this->init();
m_curr = this->mstime();
int dltime = m_json_param["interval"]["time"][1].asInt();
m_start = m_curr - dltime;
m_end = m_curr - dltime;
this->set_cycle_time(max(50, m_json_param["interval"]["time"][1].asInt() / 2));
}
AlgTorque::~AlgTorque() {}
int AlgTorque::calculate(string &outjson) {
LOG d("AlgTorque::calculate", AUTO_CATCH_PID);
outjson = "";
int ret = 0;
try {
m_curr = this->mstime();
int dltime = m_json_param["interval"]["time"][1].asInt();
if (m_curr - m_end < dltime) {
// d.Debug() << " 时间间隔太小! " << endl;
return 0;
} else {
m_start = m_end;
m_end = m_curr;
}
HD3TimeRegion timeRegion;
timeRegion.left.nSec = m_start / 1000;
timeRegion.left.nSec = m_end / 1000;
bool m_flag = true;
double m_min = 0.0, m_max = 0.0;
for (unsigned int i = 0; i < m_tags.size() - 1; i++) {
m_max = ihd_tools_->StatsTag(m_tags[i], m_start, m_end, HD3_STATS_TYPE_MAX);
m_min = ihd_tools_->StatsTag(m_tags[i], m_start, m_end, HD3_STATS_TYPE_MIN);
if (m_max - m_min >= 5) {
m_flag = false;
break;
}
}
if (m_flag) {
m_max = ihd_tools_->StatsTag(m_tags[2], m_start, m_end, HD3_STATS_TYPE_MAX);
m_min = ihd_tools_->StatsTag(m_tags[2], m_start, m_end, HD3_STATS_TYPE_MIN);
// d.Debug() << " max : " << m_max << " min : " << m_min << endl;
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) + ",阈值为" +
std::to_string(m_json_param["limit_error"]["value"][1].asDouble());
d.Debug() << msg << endl;
string tmp = this->build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
"TORQUE", msg, timeRegion);
if (!tmp.empty())
outjson = tmp;
}
// else d.Debug() << rule_name_ << " 数据正常! " << endl;
} else {
// d.Debug() << rule_name_ << " 数据正常! " << endl;
}
} catch (const std::exception &e) {
d.Error() << mix_cc::get_nested_exception(e) << std::endl;
ret = -1;
}
return ret;
}