eis/eqpalg/.do_not_use/alg_to_transfer/AlgFFTComp.cpp

132 lines
3.7 KiB
C++
Raw Normal View History

/******************************************************************************************************************
* Action instruction algorithm(study sample data online,compare with sample
*data)
*
* arg[0] action expression
* arg[1] feedback expression
* arg[2] expression of judgment result
*
* feedback expression
* arg[2] expression of judgment result
*
* 1.0 2020-12-17 zoufuzhou
* 1.1 2021-3 c@t add DTW
******************************************************************************************************************/
#include <base/BitTool.h>
#include <dao/DBMag.h>
#include <eqpalg/algs/AlgFFTComp.h>
#include <utility/StringHelper.h>
// add static modules
extern std::map<std::string, ITEM> glob_items;
int AlgFFTComp::init() {
LOG d("AlgFFTComp::init", AUTO_CATCH_PID);
int ret = 0;
m_btime = 0;
try {
} catch (const std::exception &e) {
d.Error() << mix_cc::get_nested_exception(e) << std::endl;
ret = -1;
}
return ret;
}
AlgFFTComp::AlgFFTComp(const string &name, const Json::Value &rulejson,
const string &ruleId)
: AlgBase(name, rulejson, ruleId) {
LOG d("AlgFFTComp::AlgFFTComp", AUTO_CATCH_PID);
m_sampletag_freq = m_json_param["alarm_option"]["tag_freq"][1].asString();
m_sampletag_data = m_json_param["alarm_option"]["tag_data"][1].asString();
max_diff_ = m_json_alarm["alarm_option"]["max_diff"][1].asDouble();
StringHelper::Trim(m_sampletag_freq);
StringHelper::Trim(m_sampletag_data);
this->init();
this->fft_stat_ = std::move(std::unique_ptr<FFTStat>(new FFTStat(rule_id_)));
d.Debug() << "Init Success" << std::endl;
}
AlgFFTComp::~AlgFFTComp() {}
int AlgFFTComp::calculate(string &outjson) {
LOG d("AlgFFTComp::calculate|" + rule_name_, AUTO_CATCH_PID);
int ret = 0;
outjson = "";
// d.Debug()<<rule_name_<<" datasource:"<<data_source_<<endl;
try {
ret = this->mon_proc(outjson);
} catch (const std::exception &e) {
d.Error() << mix_cc::get_nested_exception(e) << std::endl;
ret = -1;
}
return ret;
}
int AlgFFTComp::mon_proc(string &outjson) {
LOG d("AlgFFTComp::mon_proc|" + rule_name_, AUTO_CATCH_PID);
int ret = 0;
outjson = "";
try {
if (query_time_region_.right.nSec < query_time_region_.left.nSec) {
std::swap(query_time_region_.right.nSec, query_time_region_.left.nSec);
d.Error() << "Time Range is Error !" << std::endl;
}
// 得到查询的结果
auto sample_data =
hd_com
.GetQueryBatch(m_tags[atoi(m_sampletag_data.substr(3).c_str()) - 1],
query_time_region_)
.QueryRemainingAll();
auto sample_freq =
hd_com
.GetQueryBatch(m_tags[atoi(m_sampletag_freq.substr(3).c_str()) - 1],
query_time_region_)
.QueryRemainingAll();
d.Debug() << "Size1 :" << sample_data.size()
<< " Size2:" << sample_freq.size() << std::endl;
fft_stat_->ParseData(sample_data, sample_freq);
auto val = fft_stat_->GetComparevalue(fft_stat_->GetMaxMagnitudeIndex());
d.Debug() << "Value:" << val << std::endl;
fft_stat_->StorageToDB2(val);
// delete
// ret = this->GetHDTrend(m_expstr);
if (ret == NULL) {
if (false) {
msg = rule_name_ + " " + m_json_param["alarm_option"]["error"][1].asString();
d.Debug() << msg << endl;
msg = this->build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
"TREND_SMP", msg, query_time_region_);
if (!msg.empty())
outjson = msg;
}
}
m_btime = 0;
} catch (const std::exception &e) {
d.Error() << mix_cc::get_nested_exception(e) << std::endl;
ret = -1;
}
return ret;
}