143 lines
4.9 KiB
C++
143 lines
4.9 KiB
C++
#include <mix_cc/ihyper_db/set_record.h>
|
||
#include <eqpalg/algs/br_temp_fit.h>
|
||
#include <eqpalg/utility/build_alarm_info.h>
|
||
#include <vector>
|
||
#include <string>
|
||
|
||
int BrTempFit::init() {
|
||
int ret = 0;
|
||
try {
|
||
this->data_source_ = DataSource::IHDB;
|
||
} catch (const std::exception& e) {
|
||
std::throw_with_nested(
|
||
mix_cc::Exception(-1, "load error", BOOST_CURRENT_LOCATION));
|
||
ret = -1;
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
std::vector<AlarmInfo> BrTempFit::exec_task(mix_cc::time_range_t time_range) {
|
||
std::vector<AlarmInfo> out_alarms;
|
||
try {
|
||
for (auto now_time = time_range.get_left();
|
||
now_time <= time_range.get_right(); now_time += delay_time_) {
|
||
// logger_->Debug() << "start:"
|
||
// << mix_cc::mix_time_t(now_time).to_formatted_time()
|
||
// << std::endl;
|
||
this->now_time_ = now_time;
|
||
this->query_time_range_.set_range(now_time_, now_time_ + delay_time_);
|
||
auto alarm = exec_mon();
|
||
out_alarms.push_back(alarm);
|
||
}
|
||
} catch (const std::exception& e) {
|
||
std::throw_with_nested(
|
||
mix_cc::Exception(-1, "calc_once error", BOOST_CURRENT_LOCATION));
|
||
}
|
||
return out_alarms;
|
||
}
|
||
|
||
BrTempFit::BrTempFit(const string name, const mix_cc::json& rule_json,
|
||
const string ruleId)
|
||
: AlgBase(name, rule_json, ruleId) {
|
||
logger_.reset(new LOG("BrTempFit:" + rule_name_, AUTO_CATCH_PID));
|
||
try {
|
||
this->init();
|
||
} catch (const std::exception& e) {
|
||
std::throw_with_nested(
|
||
mix_cc::Exception(-1, "load error", BOOST_CURRENT_LOCATION));
|
||
}
|
||
}
|
||
|
||
BrTempFit::~BrTempFit() {}
|
||
|
||
AlarmInfo BrTempFit::exec_mon() {
|
||
try {
|
||
this->refresh_now_time();
|
||
this->refresh_ihd_cache();
|
||
// logger_->Debug() << "read tag count:" << this->queried_data_.rows() <<
|
||
// endl;
|
||
for (int i = 0; i < this->queried_data_.rows(); i++) {
|
||
if (queried_data_(i, 0) <= 10.f) {
|
||
continue;
|
||
}
|
||
if (queried_data_(i, 0) <= 10.f) {
|
||
continue;
|
||
}
|
||
if (queried_data_(i, 2) <= 210.f) {
|
||
continue;
|
||
}
|
||
m_sum += queried_data_(i, 3);
|
||
mq_slide.push(queried_data_(i, 3));
|
||
if (mq_slide.size() > CS_SLIDE_AVG_SIZE) {
|
||
m_sum -= mq_slide.front();
|
||
mq_slide.pop();
|
||
float tempfit =
|
||
this->DriveTempCal1(m_sum / mq_slide.size(), 42.42f, 39.0f);
|
||
string tag = "MODFIT_" + m_tags[4];
|
||
mix_cc::ihd::set_record(tag, queried_time_[i], tempfit);
|
||
logger_->Debug() << "actaul:" << queried_data_(i, 4)
|
||
<< " fit:" << tempfit << endl;
|
||
if (queried_data_(i, 4) - tempfit >
|
||
rule_json_.at("limit_alarm").at("diff").at(1).get<double>()) {
|
||
string msg =
|
||
rule_name_ +
|
||
rule_json_.at("limit_alarm").at("name").at(1).get<std::string>() +
|
||
rule_json_.at("limit_alarm")
|
||
.at("content")
|
||
.at(1)
|
||
.get<std::string>() +
|
||
" 实际:" + std::to_string(queried_data_(i, 4)) +
|
||
" 拟合:" + std::to_string(tempfit);
|
||
|
||
return utility::build_alarm_info(MsgLevel::WARN, rule_id_,
|
||
rule_name_, "BR", msg,
|
||
query_time_range_);
|
||
} else if (queried_data_(i, 4) - tempfit > rule_json_.at("limit_error")
|
||
.at("diff")
|
||
.at(1)
|
||
.get<double>()) {
|
||
string msg =
|
||
rule_name_ +
|
||
rule_json_.at("limit_error").at("name").at(1).get<std::string>() +
|
||
rule_json_.at("limit_error")
|
||
.at("content")
|
||
.at(1)
|
||
.get<std::string>() +
|
||
" 实际:" + std::to_string(queried_data_(i, 4)) +
|
||
" 拟合:" + std::to_string(tempfit);
|
||
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_,
|
||
rule_name_, "BR", msg,
|
||
query_time_range_);
|
||
}
|
||
}
|
||
}
|
||
} catch (const std::exception& e) {
|
||
std::throw_with_nested(
|
||
mix_cc::Exception(-1, "calc_once error", BOOST_CURRENT_LOCATION));
|
||
}
|
||
return AlarmInfo{};
|
||
}
|
||
|
||
float BrTempFit::DriveTempCal1(float xi, float xmax, float ymax) {
|
||
float y = 0.0f;
|
||
double m_dwk = 0.0f;
|
||
|
||
double a[6] = {
|
||
0., -4556.1786839, 7132.58229315, -4958.68419167, 1292.01117165, 0.};
|
||
double b = 1091.27820069;
|
||
|
||
if (xi < 37.0f) {
|
||
xi = 37.0f;
|
||
}
|
||
// if( xi > xmax ) { xi = xmax; }
|
||
double x = (xi / xmax);
|
||
|
||
m_dwk = b + a[1] * x + a[2] * x * x + a[3] * x * x * x +
|
||
a[4] * x * x * x * x + a[5] * x * x * x * x * x;
|
||
y = m_dwk * static_cast<double>(ymax);
|
||
|
||
// logger_->Debug("xi=%f,xmax=%f,ymax=%f, x=%f, m_dwk=%f, y=%f",
|
||
// xi, xmax, ymax, x, m_dwk, y);
|
||
return y;
|
||
}
|