Remove irrelevant comments from eqpalg source files
Cleaned 66 files across all eqpalg subdirectories: - Removed commented-out dead code - Removed redundant Chinese inline comments that restate variable/function names - Removed trailing ///< annotations on self-explanatory fields - Removed namespace closing comments - Preserved all file headers, Doxygen documentation, and logic explanations - No code changes — only comment removal
This commit is contained in:
parent
ef6612d2ea
commit
224c2c45c4
@ -18,7 +18,6 @@ AlgBase::AlgBase(const string &name, const mix_cc::json &rule_json,
|
||||
: rule_id_(ruleId), rule_name_(name), rule_json_(rule_json),
|
||||
gb_logger_(std::make_unique<GbLogger>("Logger:" + name)),
|
||||
logger_(std::make_unique<LOG>("AlgBase", AUTO_CATCH_PID)),
|
||||
// last_alarm_time_(system_clock::now()), ///< 屏蔽启动时的报警信息
|
||||
last_alarm_time_(
|
||||
system_clock::now() -
|
||||
(minutes(std::max(5, CMemVar::Const()->AlarmIntervalHours * 60) - 1) +
|
||||
@ -26,8 +25,6 @@ AlgBase::AlgBase(const string &name, const mix_cc::json &rule_json,
|
||||
con_monitor_(1), delay_time_(50ms) {}
|
||||
|
||||
AlgBase::~AlgBase() {
|
||||
// this->is_usable_ = false;
|
||||
// SingletonTemp<EqpStat>::release();
|
||||
}
|
||||
void AlgBase::logReset(int task_seq) {
|
||||
task_seq = task_seq;
|
||||
@ -81,7 +78,6 @@ int AlgBase::init() {
|
||||
try {
|
||||
res += this->reload_config_tag();
|
||||
data_info_.init(m_tags);
|
||||
// int ms = rule_json_.at("interval").at("time").at(1).get<int64_t>();
|
||||
try {
|
||||
int ms =
|
||||
std::stoi(rule_json_.at("trigger").at("value").get<std::string>());
|
||||
@ -122,8 +118,6 @@ int AlgBase::init() {
|
||||
last_run_start_time_ = system_clock::now() - this->delay_time_;
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
// std::throw_with_nested(
|
||||
// mix_cc::Exception(-1, "init error", BOOST_CURRENT_LOCATION));
|
||||
logger_->Error() << e.what() << "location:" << BOOST_CURRENT_LOCATION
|
||||
<< endl;
|
||||
res += -1;
|
||||
@ -132,12 +126,11 @@ int AlgBase::init() {
|
||||
<< ",last_alarm_time_:"
|
||||
<< mix_cc::mix_time_t(last_alarm_time_).to_formatted_time()
|
||||
<< std::endl;
|
||||
// is_usable_ = true;
|
||||
this->rule_stat_.limit_down = 0;
|
||||
this->rule_stat_.limit_up = 0;
|
||||
this->rule_stat_.current_value = 0;
|
||||
if (glob_process_type == ProcessType::kMon) {
|
||||
this->update_map_rule(); ///<测试
|
||||
this->update_map_rule();
|
||||
}
|
||||
logger_->Debug() << "|" << rule_id_ << "|alg init 完成! " << std::endl;
|
||||
return res;
|
||||
@ -164,7 +157,6 @@ int AlgBase::reload_config_tag() {
|
||||
m_tags.resize(tag_dict.size());
|
||||
this->rule_stat_.items.resize(tag_dict.size());
|
||||
for (auto x : tag_dict.items()) {
|
||||
// debug
|
||||
int item_index = stoi(x.key().substr(3));
|
||||
logger_->Debug() << "item_index:" << item_index << ",x.key():" << x.key()
|
||||
<< std::endl;
|
||||
@ -177,12 +169,9 @@ int AlgBase::reload_config_tag() {
|
||||
}
|
||||
auto itemi = x.value().at("value").get<std::string>();
|
||||
logger_->Debug() << "tag" << item_index << ":" << itemi << std::endl;
|
||||
/*有机组号前缀*/
|
||||
m_tags[item_index - 1] = string(CMemVar::Const()->UnitNo) + "_" + itemi;
|
||||
/*无机组号前缀*/
|
||||
// m_tags[item_index - 1] = itemi;
|
||||
|
||||
this->rule_stat_.items[item_index - 1] = itemi; ///<提供给页面的
|
||||
this->rule_stat_.items[item_index - 1] = itemi;
|
||||
}
|
||||
var_cache_.init(m_tags.size(), pv_num_);
|
||||
if (m_tags.empty()) {
|
||||
@ -206,27 +195,18 @@ void AlgBase::exec_mon_call() {
|
||||
if (this->get_cycled()) {
|
||||
if (this->get_usable() && get_prr()) {
|
||||
auto alarm = this->exec_mon();
|
||||
this->con_monitor_.update(alarm.alarmed); ///<更新状态
|
||||
this->con_monitor_.update(alarm.alarmed);
|
||||
if (alarm.alarmed) {
|
||||
logger_->Debug() << alarm.content << endl;
|
||||
alarm_poster_.alarm(alarm, &last_alarm_time_);
|
||||
exp_mpdule_ptr_->fun_reset();
|
||||
} else {
|
||||
// auto runs_t1 = std::chrono::steady_clock::now();
|
||||
if (get_save_data_cycled()) {
|
||||
this->save_rule_norm_data();
|
||||
}
|
||||
|
||||
// auto runs_t2 = std::chrono::steady_clock::now();
|
||||
// int64_t costs_time =
|
||||
// std::chrono::duration_cast<std::chrono::nanoseconds>(runs_t2 -
|
||||
// runs_t1)
|
||||
// .count();
|
||||
// gb_logger_->log_info(rule_name_ + "|save_rule_norm_data,cost:" +
|
||||
// std::to_string(costs_time));
|
||||
}
|
||||
} else {
|
||||
this->con_monitor_.update(true); ///<更新状态,不满足前提条件,重置
|
||||
this->con_monitor_.update(true);
|
||||
}
|
||||
if (get_update_rule_stat_cycled()) {
|
||||
this->update_map_rule();
|
||||
@ -268,23 +248,11 @@ void AlgBase::exec_normal_task_call(const mix_cc::time_range_t &time_range) {
|
||||
}
|
||||
void AlgBase::exec_cron_call() { this->exec_cron(); }
|
||||
|
||||
// void AlgBase::exec_cron_call() {
|
||||
// if (!this->is_cron_run) {
|
||||
// this->exec_cron();
|
||||
// this->is_cron_run = true;
|
||||
// } else {
|
||||
// this->logger_->Debug() << this->rule_name_ << ":" << this->rule_id_
|
||||
// << "cron执行完成" << std::endl;
|
||||
// }
|
||||
// }
|
||||
|
||||
// 设置是否可用
|
||||
void AlgBase::set_usable(bool usable) {
|
||||
is_usable_ = usable;
|
||||
logger_->Debug() << rule_name_ << " usable:" << usable << endl;
|
||||
}
|
||||
|
||||
// 单次执行
|
||||
mix_cc::json AlgBase::exec_cron() { return mix_cc::json{}; }
|
||||
|
||||
// 刷新ihyperDB缓存,把ihyperDB中的数据转移到当前程序缓存中
|
||||
@ -403,9 +371,6 @@ bool AlgBase::get_prr() {
|
||||
exp_mpdule_ptr_->update();
|
||||
bool prr_result = (bool)exp_mpdule_ptr_->get_value("pre_result");
|
||||
this->now_prr_ = prr_result;
|
||||
// logger_->Debug() << "ruleid:" << this->rule_id_
|
||||
// << ",rulename:" << this->rule_name_
|
||||
// << " get_prr():" << prr_result << std::endl;
|
||||
return prr_result;
|
||||
}
|
||||
now_prr_ = true;
|
||||
@ -413,7 +378,6 @@ bool AlgBase::get_prr() {
|
||||
}
|
||||
|
||||
int AlgBase::ihd_get_by_tag(string tag, mix_cc::time_range_t time_range) {
|
||||
// 进行查询
|
||||
std::vector<std::string> tags;
|
||||
tags.push_back(tag);
|
||||
try {
|
||||
@ -493,10 +457,6 @@ void AlgBase::update_limit_alarm(double lb, double ub, double va, int64_t stime,
|
||||
std::chrono::milliseconds>(
|
||||
std::chrono::milliseconds(etime)));
|
||||
}
|
||||
// logger_->Debug() << "update_limit_alarm|"
|
||||
// << "lb:" << lb << ",ub:" << ub << ",va:" << va
|
||||
// << ",stime:" << stime << ",etime:" << etime <<
|
||||
// std::endl;
|
||||
} catch (const std::exception &e) {
|
||||
logger_->Error() << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@ -44,86 +44,75 @@ using TimeDur = milliseconds;
|
||||
*/
|
||||
class AlgBase {
|
||||
protected:
|
||||
std::map<std::string, double> mm_vars; ///< 表达式系统变量map
|
||||
std::map<std::string, double> mm_vars;
|
||||
const size_t pv_num_ = 6;
|
||||
VarsCache var_cache_; ///< mmvar_变量明 预分配
|
||||
VarsCache var_cache_;
|
||||
|
||||
const string rule_id_; ///< 算法实例id,在AlgBase基类内部初始化
|
||||
const string rule_id_;
|
||||
|
||||
const string rule_name_; ///< 算法实例名称,在AlgBase内部初始化
|
||||
const string rule_name_;
|
||||
|
||||
const mix_cc::json rule_json_; ///< 规则json对象,在AlgBase基类内部初始化
|
||||
const mix_cc::json rule_json_;
|
||||
|
||||
std::unique_ptr<GbLogger> gb_logger_; ///< 全局logger指针
|
||||
std::unique_ptr<GbLogger> gb_logger_;
|
||||
|
||||
std::unique_ptr<LOG>
|
||||
logger_; ///< 基类的logger指针,子类需要使用使用reset方法重置为子类的指针
|
||||
logger_;
|
||||
|
||||
TimePoint last_run_start_time_; ///< 上次运行的开始时间
|
||||
TimePoint last_run_start_time_;
|
||||
|
||||
TimePoint last_save_start_time_; ///< 上次调用保存数据函数的开始时间
|
||||
TimePoint last_save_start_time_;
|
||||
TimePoint
|
||||
last_rule_state_updae_start_time_; ///< 上次调用保存数据函数的开始时间
|
||||
TimePoint last_heart_beat_start_time_; ///< 上次规则运行 活跃 心跳检测日志
|
||||
last_rule_state_updae_start_time_;
|
||||
TimePoint last_heart_beat_start_time_;
|
||||
|
||||
TimePoint this_run_start_time_; ///< 本次运行的开始时间
|
||||
TimePoint this_run_start_time_;
|
||||
|
||||
TimePoint now_time_; ///< 当前正在执行时的时间
|
||||
TimePoint now_time_;
|
||||
|
||||
int data_source_ = 1; ///< 数据来源,0:iHyperDB,1:memory
|
||||
int data_source_ = 1;
|
||||
|
||||
TimePoint last_alarm_time_; ///< 上次报警的时间,用于外部类使用
|
||||
TimePoint last_alarm_time_;
|
||||
|
||||
TimeDur delay_time_; ///< 每次执行的时间间隔,在AlgBase内部初始化
|
||||
TimeDur delay_time_;
|
||||
|
||||
TimeDur query_interval_time_ = hours(
|
||||
CMemVar::Const()->eis_qihd_interval_time); ///< cron task 查询最大时间区间
|
||||
CMemVar::Const()->eis_qihd_interval_time);
|
||||
|
||||
// TimeDur ihd_min_time_particles_ = 50ms; ///<
|
||||
// iHyperDB数据查询最小时间颗粒
|
||||
TimeDur ihd_min_time_particles_ = 20ms; ///< iHyperDB数据查询最小时间颗粒
|
||||
TimeDur ihd_min_time_particles_ = 20ms;
|
||||
|
||||
vector<string> m_tags; ///< 保存的tag点名
|
||||
vector<string> m_tags;
|
||||
|
||||
bool is_usable_; ///< 算法是否可用
|
||||
bool is_usable_;
|
||||
|
||||
// bool is_cron_run = false; ///< cron是否已经完成
|
||||
bool is_running_ = true;
|
||||
|
||||
bool is_running_ = true; ///< 算法是否正在执行
|
||||
|
||||
// int smooth_type_ = 0; ///<
|
||||
// 数据平滑方式,0为不更改,1为高斯,此部分暂时未完成
|
||||
|
||||
utility::AlarmPoster alarm_poster_; ///< 发送报警信息
|
||||
utility::AlarmPoster alarm_poster_;
|
||||
|
||||
string remark_ =
|
||||
"0"; ///<通知方式 0-不通知,1-短信+语音单次通知 2-短信单次+语音多次
|
||||
"0";
|
||||
|
||||
std::mutex lm;
|
||||
RuleStatShm::RuleStat rule_stat_; ///<规则的统计参数,给页面
|
||||
RuleStatShm::RuleStat rule_stat_;
|
||||
|
||||
std::string error_message_str_; ///<参数错误提示语
|
||||
std::string error_message_str_;
|
||||
|
||||
std::vector<ErrorCodeType> error_code_list_; ///<错误码{错误类型,错误位置}
|
||||
std::vector<ErrorCodeType> error_code_list_;
|
||||
|
||||
int prr_ = PRR::None; ///<规则运行前提条件
|
||||
// int spd_th_ = 1; ///<规则运行前提条件
|
||||
// bool need_prr_ = false; ///<是否需要规则执行的前提条件
|
||||
// std::string pre_item_; ///<前提条件 item
|
||||
// double pre_min_ = 0; ///<前提条件最小值
|
||||
std::unique_ptr<ExpModule> exp_mpdule_ptr_; ///<表达式模块
|
||||
int prr_ = PRR::None;
|
||||
std::unique_ptr<ExpModule> exp_mpdule_ptr_;
|
||||
|
||||
DataInfo data_info_; ///<运行数据保存信息 保存正常数据
|
||||
DataInfo data_info_;
|
||||
|
||||
ConditionMonitor con_monitor_; ///<保存正常数据 是否保存判断
|
||||
ConditionMonitor con_monitor_;
|
||||
|
||||
bool now_prr_ = false; ///<前提条件是否满足
|
||||
bool now_prr_ = false;
|
||||
|
||||
bool is_exp_alg_ = false; ///<是否是表达式类算法
|
||||
bool is_exp_alg_ = false;
|
||||
|
||||
int task_seq = 0; ///< task线程 线程id
|
||||
TimeDur save_interval_ms_ = 5000ms; ///< 正常数据保存 间隔时间
|
||||
TimeDur rule_state_update_interval_ms_ = 500ms; ///< 页面数据更新 间隔时间
|
||||
int task_seq = 0;
|
||||
TimeDur save_interval_ms_ = 5000ms;
|
||||
TimeDur rule_state_update_interval_ms_ = 500ms;
|
||||
public:
|
||||
void logReset(int task_seq);
|
||||
/**
|
||||
@ -275,14 +264,14 @@ public:
|
||||
// bool get_is_cron_run(){return this->is_cron_run};
|
||||
|
||||
protected:
|
||||
mix_cc::time_range_t query_time_range_; ///< ihdb查询的时间周期
|
||||
mix_cc::time_range_t query_time_range_;
|
||||
|
||||
mix_cc::time_range_t task_time_range_; ////<task进程的时间范围
|
||||
mix_cc::time_range_t task_time_range_;
|
||||
|
||||
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
|
||||
queried_data_; ///< ihd查询后的数据缓存
|
||||
queried_data_;
|
||||
|
||||
std::vector<TimePoint> queried_time_; ///< ihdb查询后的时间缓存
|
||||
std::vector<TimePoint> queried_time_;
|
||||
|
||||
protected:
|
||||
/**
|
||||
@ -337,12 +326,6 @@ public:
|
||||
* 供类 ExpTimes用
|
||||
*/
|
||||
virtual void reset_dev_data(){};
|
||||
/**
|
||||
* @brief 更新 通知方式
|
||||
* 适用于太钢硅钢 弃用
|
||||
* @return int
|
||||
*/
|
||||
// int update_remark();
|
||||
/**
|
||||
* @brief
|
||||
* @param lb 下限
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
extern ProcessType glob_process_type;
|
||||
// extern CreateModels glob_create_models;
|
||||
|
||||
using namespace mix_cc::sql;
|
||||
/**
|
||||
@ -52,7 +51,7 @@ AlgorithmManager::AlgorithmManager() {
|
||||
x.flag, x.paddingDown, x.paddingUp, x.TaskSeq);
|
||||
|
||||
if (glob_process_type == ProcessType::kMon) {
|
||||
this->update_rule_start_time(x.ruleId); //< 更新算法实例启动时间
|
||||
this->update_rule_start_time(x.ruleId);
|
||||
logger_->Info() << x.ruleName << "update rule start time done"
|
||||
<< endl;
|
||||
}
|
||||
@ -87,12 +86,11 @@ void AlgorithmManager::dispose(int event_no, const ::Ice::ByteSeq &seq) {
|
||||
event_no = json_value.at("eventNo").get<int64_t>();
|
||||
if (event_no == -1) {
|
||||
logger_->Debug() << "eqpalg 重启" << endl;
|
||||
// system("rleqpm");
|
||||
sleep(1);
|
||||
exit(0);
|
||||
}
|
||||
ruleId = json_value.at("ruleId").get<std::string>();
|
||||
int task_seq = 0; ///<线程序号,默认0
|
||||
int task_seq = 0;
|
||||
if (event_no == EventCase::kExec) {
|
||||
time_start =
|
||||
TimePoint(milliseconds(json_value.at("startTime").get<int64_t>()));
|
||||
@ -122,8 +120,6 @@ void AlgorithmManager::dispose(int event_no, const ::Ice::ByteSeq &seq) {
|
||||
switch (event_no) {
|
||||
/*-------1---*/
|
||||
case EventCase::kCreate: {
|
||||
// glob_create_models.create_new_models = true; ///<添加模型标记位
|
||||
// 创建新实例的操作
|
||||
thread_manager_.storage(ruleId, algId, rule_name, param_info, usable, 0,
|
||||
0, task_seq);
|
||||
thread_manager_.attach(ruleId);
|
||||
@ -164,7 +160,7 @@ void AlgorithmManager::dispose(int event_no, const ::Ice::ByteSeq &seq) {
|
||||
if (ProcessType::kMon == glob_process_type) {
|
||||
thread_manager_.enable(ruleId, usable);
|
||||
if (usable) {
|
||||
this->update_rule_start_time(ruleId); //< 更新算法实例启动时间
|
||||
this->update_rule_start_time(ruleId);
|
||||
logger_->Info() << rule_name << "update rule start time done" << endl;
|
||||
}
|
||||
}
|
||||
@ -183,7 +179,7 @@ void AlgorithmManager::dispose(int event_no, const ::Ice::ByteSeq &seq) {
|
||||
if (ProcessType::kMon == glob_process_type) {
|
||||
this->update_rule_modify_time(ruleId);
|
||||
logger_->Info() << rule_name << "update rule modify time done" << endl;
|
||||
this->update_rule_start_time(ruleId); //< 更新算法实例启动时间
|
||||
this->update_rule_start_time(ruleId);
|
||||
logger_->Info() << rule_name << "update rule start time done" << endl;
|
||||
}
|
||||
logger_->Info() << "update done" << endl;
|
||||
@ -232,7 +228,6 @@ void AlgorithmManager::dispose(int event_no, const ::Ice::ByteSeq &seq) {
|
||||
|
||||
int AlgorithmManager::cache_data() {
|
||||
return SingletonTemplate<GlobaltemSharedMemory>::GetInstance().cache_data();
|
||||
// return 0;
|
||||
}
|
||||
|
||||
int AlgorithmManager::update_rule_start_time(std::string ruleId) {
|
||||
@ -248,12 +243,6 @@ int AlgorithmManager::update_rule_start_time(std::string ruleId) {
|
||||
auto &info = info_maybe.unsafe_get_just();
|
||||
if (info.empty()) // trrt中没有该ruleid的记录
|
||||
{
|
||||
// 插入cfg中的toc
|
||||
// 1.查询cfg的toc
|
||||
// T_RULE_CFG t_cfg;
|
||||
// auto cfg_toc = exec<db2_t, T_RULE_CFG>(
|
||||
// select(t_cfg.toc()).from(t_cfg).where(t_cfg.ruleId() == ruleId));
|
||||
// auto& cfg_toc_info = cfg_toc.unsafe_get_just();
|
||||
// 2.插入toc 插入tos为now time
|
||||
auto time_insert_ret = exec<db2_t, size_t>(insert_into(trrt).set(
|
||||
trrt.ruleId() = ruleId,
|
||||
|
||||
@ -80,7 +80,7 @@ public:
|
||||
int get_thread_size();
|
||||
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_; ///< logger类
|
||||
std::unique_ptr<LOG> logger_;
|
||||
|
||||
threads::Manager thread_manager_; ///< 任务线程
|
||||
threads::Manager thread_manager_;
|
||||
};
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
#include <eqpalg/exp_macro/get_macro_replaced_exp.h>
|
||||
#include <eqpalg/table_struct/t_sample_mag.h>
|
||||
#include <eqpalg/utility/build_alarm_info.h>
|
||||
// #include <eqpalg/utility/entCentExit.h> ///<弃用
|
||||
// #include <eqpalg/utility/instance_lock.h> ///<弃用
|
||||
#include <float.h>
|
||||
#include <memory>
|
||||
#include <mix_cc/ihyper_db/utility.h>
|
||||
@ -24,7 +22,6 @@ ExpBase::ExpBase(const string &name, const mix_cc::json &rule_json,
|
||||
AUTO_CATCH_PID));
|
||||
}
|
||||
ExpBase::~ExpBase() {
|
||||
// AlgBase::~AlgBase();
|
||||
}
|
||||
|
||||
int ExpBase::init() {
|
||||
@ -60,8 +57,6 @@ int ExpBase::init() {
|
||||
} catch (const std::exception &e) {
|
||||
logger_->Debug() << e.what() << ".location:" << BOOST_CURRENT_LOCATION
|
||||
<< endl;
|
||||
// std::throw_with_nested(
|
||||
// mix_cc::Exception(-1, "load error", BOOST_CURRENT_LOCATION));
|
||||
}
|
||||
if (ret == 0) {
|
||||
this->exp_is_wrong_ = false;
|
||||
@ -93,7 +88,6 @@ AlarmInfo ExpBase::exec_mon() {
|
||||
if (alarm_task.alarmed) {
|
||||
last_alarm_time_ -= minutes(5);
|
||||
alarm_poster_.alarm(alarm_task, &last_alarm_time_);
|
||||
// logger_->Info() << rule_name_ << " alarm_task.alarmed " << std::endl;
|
||||
}
|
||||
exp_wrong_is_alarmed_ = true;
|
||||
}
|
||||
@ -154,14 +148,9 @@ AlarmInfo ExpBase::exec_mon() {
|
||||
return out_alarm;
|
||||
}
|
||||
|
||||
// 单次执行
|
||||
std::vector<AlarmInfo> ExpBase::exec_task(mix_cc::time_range_t time_range) {
|
||||
task_data_size = 0;
|
||||
|
||||
// string ss0 = "rm -rf /users/dsc/shm/TaskData_boost.mmap";
|
||||
// system(ss0.c_str());
|
||||
// logger_->Debug() << "rm -rf /users/dsc/shm/TaskData_boost.mmap" <<
|
||||
// std::endl;
|
||||
std::vector<AlarmInfo> out_alarms;
|
||||
/*统计类,需要单独处理数据*/
|
||||
if (this->exp_type_ == ExpType::Bound ||
|
||||
@ -187,25 +176,6 @@ std::vector<AlarmInfo> ExpBase::exec_task(mix_cc::time_range_t time_range) {
|
||||
sta_ptr_ = std::make_unique<DAA::STA>(rule_id_, rule_name_);
|
||||
}
|
||||
|
||||
// TaskShm::TimeRecordPtr.get()->data_size = 0;
|
||||
// TaskShm::TimeRecordPtr.get()->stime =
|
||||
// mix_cc::mix_time_t(time_range.get_left()).to_milliseconds();
|
||||
// TaskShm::TimeRecordPtr.get()->etime =
|
||||
// mix_cc::mix_time_t(time_range.get_right()).to_milliseconds();
|
||||
// TaskShm::TimeRecordPtr.get()
|
||||
// ->
|
||||
// operator[](exp_type_ * 1000 + task_seq)
|
||||
// .data_size = 0;
|
||||
// TaskShm::TimeRecordPtr.get()
|
||||
// ->
|
||||
// operator[](exp_type_ * 1000 + task_seq)
|
||||
// .stime =
|
||||
// mix_cc::mix_time_t(time_range.get_left()).to_milliseconds();
|
||||
// TaskShm::TimeRecordPtr.get()
|
||||
// ->
|
||||
// operator[](exp_type_ * 1000 + task_seq)
|
||||
// .etime =
|
||||
// mix_cc::mix_time_t(time_range.get_right()).to_milliseconds();
|
||||
logger_->Debug() << "reset_data()------1" << endl;
|
||||
if ((time_range.get_right() - time_range.get_left()) <
|
||||
this->query_interval_time_) {
|
||||
@ -227,47 +197,17 @@ std::vector<AlarmInfo> ExpBase::exec_task(mix_cc::time_range_t time_range) {
|
||||
this->sta_ptr_->reset_data(); /*参数重置*/
|
||||
logger_->Debug() << "reset_data()------2" << endl;
|
||||
logger_->Debug() << "task_seq:" << task_seq << std::endl;
|
||||
// size_t dataSize = TaskShm::TimeRecordPtr.get()
|
||||
// ->
|
||||
// operator[](exp_type_ * 1000 + task_seq)
|
||||
// .data_size;
|
||||
logger_->Debug() << "dataSize:" << task_data_size << std::endl;
|
||||
for (size_t j = 0; j < task_data_size; j++) {
|
||||
double dataJ = TaskShm::TaskRecordPtr.get()
|
||||
->
|
||||
operator[](exp_type_ * 1000 + task_seq)
|
||||
.data_record[j];
|
||||
// logger_->Debug() << "dataJ:" << dataJ << endl;
|
||||
this->sta_ptr_->dist_add(dataJ);
|
||||
}
|
||||
logger_->Debug() << "reset_data()------3" << endl;
|
||||
auto store_res = this->sta_ptr_->task_store_db2(sample_id);
|
||||
logger_->Debug() << "reset_data()------4" << endl;
|
||||
// if (this->sta_ptr_->task_update_ci_dist() == 0) {
|
||||
|
||||
// if (store_res == 0) {
|
||||
// this->sample_result_ = this->sta_ptr_->get_sample_stat_str();
|
||||
// /*存数据 T_SAMPLE_MAG*/
|
||||
// T_SAMPLE_MAG tsm;
|
||||
// auto inset_ret = exec<db2_t, size_t>(insert_into(tsm).set(
|
||||
// tsm.ruleId() = this->rule_id_, tsm.result() = stat_result,
|
||||
// tsm.type() = SampleType::T_SAMPLE_STAT, tsm.sampleid() =
|
||||
// sample_id, tsm.usable() = 0, tsm.starttime() =
|
||||
// mix_cc::mix_time_t(this->query_time_range_.get_left()),
|
||||
// tsm.endtime() =
|
||||
// mix_cc::mix_time_t(query_time_range_.get_right())));
|
||||
// if (inset_ret.is_nothing()) {
|
||||
// std::string error_msg =
|
||||
// "ruleid size:" + std::to_string(rule_id_.size()) +
|
||||
// ",result:" + stat_result + ",type:" + SampleType::T_SAMPLE_STAT
|
||||
// + "smpleid size:" + std::to_string(sample_id.size());
|
||||
// gb_logger_->log_info("T_SAMPLE_MAG 表插入失败:" + rule_name_ + ","
|
||||
// +
|
||||
// error_msg);
|
||||
// return out_alarms;
|
||||
// }
|
||||
// return out_alarms;
|
||||
// }
|
||||
this->sample_result_ = this->sta_ptr_->get_sample_stat_str();
|
||||
this->update_t_sample_mag(store_res);
|
||||
this->alarm_poster_.zmqp_send(912, this->sample_result_);
|
||||
@ -309,15 +249,12 @@ std::vector<AlarmInfo> ExpBase::exec_task(mix_cc::time_range_t time_range) {
|
||||
}
|
||||
for (auto i = 0; i < queried_data_.rows(); i++) {
|
||||
refresh_exp_vars_ihd(i);
|
||||
// gb_logger_->log_info(this->rule_name_+":测试");
|
||||
auto tmp = mon_proc();
|
||||
if (tmp.alarmed) {
|
||||
// gb_logger_->log_info(this->rule_name_+"满足报警");
|
||||
out_alarms.push_back(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
// utility::unlock_file(rule_id_);
|
||||
gb_logger_->log_info("本次测试报警数量:" +
|
||||
std::to_string(out_alarms.size()));
|
||||
auto msg =
|
||||
@ -336,11 +273,11 @@ std::vector<AlarmInfo> ExpBase::exec_task(mix_cc::time_range_t time_range) {
|
||||
AlarmInfo ExpBase::mon_proc() {
|
||||
// 监控基本过程
|
||||
double result_value;
|
||||
filter_flag_ = false; ///<数据筛选结果 每次执行 初始化为 false
|
||||
filter_flag_ = false;
|
||||
auto_fun_vars_reset();
|
||||
try {
|
||||
// 获得是否满足前提条件表达式
|
||||
result_value = exp_act_->evaluate(); ///< 2/5用于 非反馈 上下限
|
||||
result_value = exp_act_->evaluate();
|
||||
if (exp_type_ == ExpType::Bound || exp_type_ == ExpType::BoundHoldTime) {
|
||||
if (exp_feedback_ != nullptr) {
|
||||
/*有数据筛选*/
|
||||
@ -357,7 +294,7 @@ AlarmInfo ExpBase::mon_proc() {
|
||||
filter_flag_ = true;
|
||||
}
|
||||
if (is_learning_ && filter_flag_ == true) {
|
||||
rule_stat_.current_value = result_value; ///<共享内存
|
||||
rule_stat_.current_value = result_value;
|
||||
SingletonTemp<EqpStat>::GetInstance().add_stat_values(this->rule_id_,
|
||||
result_value);
|
||||
}
|
||||
@ -389,28 +326,25 @@ AlarmInfo ExpBase::mon_proc() {
|
||||
feedback_done_ = true;
|
||||
this->query_time_range_.set_left(
|
||||
query_time_range_.get_right() -
|
||||
milliseconds(int(mm_vars["time"]))); ///<报警开始时间-动作开始时间
|
||||
milliseconds(int(mm_vars["time"])));
|
||||
result_value = exp_result_->evaluate();
|
||||
is_fun_vars_need_reset_ = true; ///<取了最后的结果,就可以重置了
|
||||
is_fun_vars_need_reset_ = true;
|
||||
this->rule_stat_.limit_down = limit_down_;
|
||||
this->rule_stat_.limit_up = limit_up_;
|
||||
rule_stat_.current_value = result_value; ///<共享内存
|
||||
rule_stat_.current_value = result_value;
|
||||
print_exp_vars();
|
||||
logger_->Debug() << " action end:"
|
||||
<< mix_cc::mix_time_t(query_time_range_.get_right())
|
||||
.to_formatted_time()
|
||||
<< " timediff:" << mm_vars["time"]
|
||||
<< " exp:" << exp_str_ << "=" << result_value << endl;
|
||||
///<动作反馈-变量 上下限----4
|
||||
if (exp_type_ == ExpType::CondBound) {
|
||||
if (this->is_learning_) {
|
||||
SingletonTemp<EqpStat>::GetInstance().add_stat_values(
|
||||
this->rule_id_, result_value);
|
||||
}
|
||||
if (this->detect_up_down(result_value)) {
|
||||
///<共享内存
|
||||
rule_stat_.alarm_value = result_value;
|
||||
///<报警
|
||||
std::string msg = "";
|
||||
if (m_timemode) {
|
||||
/*动作时间类*/
|
||||
@ -425,13 +359,11 @@ AlarmInfo ExpBase::mon_proc() {
|
||||
<< "报警!!!!" << msg << ",last_alarm_time_:"
|
||||
<< mix_cc::mix_time_t(last_alarm_time_).to_formatted_time()
|
||||
<< endl;
|
||||
// is_fun_vars_need_reset_ = true;
|
||||
return utility::build_alarm_info(
|
||||
utility::get_msg_level(limit_down_, limit_up_, result_value),
|
||||
rule_id_, rule_name_, "EXP4", msg, this->get_alarm_time());
|
||||
}
|
||||
}
|
||||
///<逻辑条件
|
||||
else {
|
||||
if (result_value) {
|
||||
rule_stat_.alarm_value = result_value;
|
||||
@ -441,7 +373,6 @@ AlarmInfo ExpBase::mon_proc() {
|
||||
<< "报警!!!!" << msg << ",last_alarm_time_:"
|
||||
<< mix_cc::mix_time_t(last_alarm_time_).to_formatted_time()
|
||||
<< endl;
|
||||
// is_fun_vars_need_reset_ = true;
|
||||
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_,
|
||||
rule_name_, "EXP3", msg,
|
||||
this->get_alarm_time());
|
||||
@ -456,34 +387,29 @@ AlarmInfo ExpBase::mon_proc() {
|
||||
}
|
||||
// 不是动作反馈
|
||||
else {
|
||||
// print_exp_vars();
|
||||
///< 变量-上下限-----2
|
||||
if (exp_type_ == ExpType::Bound) {
|
||||
if (filter_flag_ == true && this->detect_up_down(result_value)) {
|
||||
///<共享内存
|
||||
rule_stat_.alarm_value = result_value;
|
||||
///<报警
|
||||
auto msg = error_str_ + ":" + DAA::double2str(result_value) + unit_ +
|
||||
",合理区间:[" + DAA::double2strLimit(limit_down_) + "," +
|
||||
DAA::double2strLimit(limit_up_) + "]" + unit_;
|
||||
logger_->Debug() << msg << endl;
|
||||
this->query_time_range_.set_left(query_time_range_.get_right() -
|
||||
delay_time_); //
|
||||
delay_time_);
|
||||
is_fun_vars_need_reset_ = true;
|
||||
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_,
|
||||
rule_name_, "EXP2", msg,
|
||||
this->get_alarm_time());
|
||||
}
|
||||
}
|
||||
///< 上下限 保持时间-------5
|
||||
else if (exp_type_ == ExpType::BoundHoldTime) {
|
||||
|
||||
bool is_over_up_down =
|
||||
this->detect_up_down(result_value); ///<当前数据是否超范围
|
||||
this->detect_up_down(result_value);
|
||||
if (!filter_flag_) {
|
||||
/*前提条件不满足*/
|
||||
act_start_time_ = this->now_time_; ///<重置开始时间 用于计算保持时间
|
||||
act_started_ = false; ///<不满足 状态
|
||||
act_start_time_ = this->now_time_;
|
||||
act_started_ = false;
|
||||
} else {
|
||||
/*前提条件满足*/
|
||||
/*检查范围*/
|
||||
@ -497,31 +423,28 @@ AlarmInfo ExpBase::mon_proc() {
|
||||
/*检查时间*/
|
||||
if ((hold_time_ <= delay_time_) ||
|
||||
(now_time_ - act_start_time_ > hold_time_)) {
|
||||
///<共享内存
|
||||
rule_stat_.alarm_value = result_value;
|
||||
///<报警
|
||||
auto msg = error_str_ + ":" + DAA::double2str(result_value) +
|
||||
unit_ + ",合理区间:[" +
|
||||
DAA::double2strLimit(limit_down_) + "," +
|
||||
DAA::double2strLimit(limit_up_) + "]" + unit_;
|
||||
print_exp_vars();
|
||||
this->query_time_range_.set_left(query_time_range_.get_right() -
|
||||
delay_time_); //
|
||||
delay_time_);
|
||||
is_fun_vars_need_reset_ = true;
|
||||
act_start_time_ =
|
||||
this->now_time_; ///<重置开始时间 用于计算保持时间
|
||||
this->now_time_;
|
||||
act_started_ = false;
|
||||
return utility::build_alarm_info(
|
||||
utility::get_msg_level(limit_down_, limit_up_, result_value),
|
||||
rule_id_, rule_name_, "EXP5", msg, this->get_alarm_time());
|
||||
}
|
||||
} else {
|
||||
act_start_time_ = this->now_time_; ///<重置开始时间 用于计算保持时间
|
||||
act_start_time_ = this->now_time_;
|
||||
act_started_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
///<实时逻辑
|
||||
else {
|
||||
if (act_triggered_) {
|
||||
rule_stat_.alarm_value = act_triggered_;
|
||||
@ -529,7 +452,7 @@ AlarmInfo ExpBase::mon_proc() {
|
||||
auto msg = rule_name_ + " " + error_str_;
|
||||
logger_->Debug() << msg << endl;
|
||||
this->query_time_range_.set_left(query_time_range_.get_right() -
|
||||
delay_time_); //
|
||||
delay_time_);
|
||||
is_fun_vars_need_reset_ = true;
|
||||
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_,
|
||||
rule_name_, "EXP1", msg,
|
||||
@ -538,8 +461,6 @@ AlarmInfo ExpBase::mon_proc() {
|
||||
}
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
// std::throw_with_nested(
|
||||
// mix_cc::Exception(-1, "mon_proc error", BOOST_CURRENT_LOCATION));
|
||||
gb_logger_->log_error("rule_name:" + rule_name_ + ",error:" + e.what());
|
||||
return AlarmInfo{};
|
||||
}
|
||||
@ -587,10 +508,6 @@ bool ExpBase::act_start_done() {
|
||||
mm_vars["tag" + std::to_string(i + 1)];
|
||||
mm_vars["mi_tag" + std::to_string(i + 1)] =
|
||||
mm_vars["tag" + std::to_string(i + 1)];
|
||||
// mm_vars["mx_p" + std::to_string(i + 1)] =
|
||||
// mm_vars["p" + std::to_string(i + 1)];
|
||||
// mm_vars["mi_p" + std::to_string(i + 1)] =
|
||||
// mm_vars["p" + std::to_string(i + 1)];
|
||||
mm_vars["up_tag" + std::to_string(i + 1)] = 0;
|
||||
mm_vars["dw_tag" + std::to_string(i + 1)] = 0;
|
||||
mm_vars["mv2_tag" + std::to_string(i + 1)] = 0;
|
||||
@ -701,12 +618,6 @@ bool ExpBase::act_done() {
|
||||
mm_vars["mi_tag" + std::to_string(i + 1)] =
|
||||
std::min(mm_vars["tag" + std::to_string(i + 1)],
|
||||
mm_vars["mi_tag" + std::to_string(i + 1)]);
|
||||
// mm_vars["mx_p" + std::to_string(i + 1)] =
|
||||
// std::max(mm_vars["p" + std::to_string(i + 1)],
|
||||
// mm_vars["mx_p" + std::to_string(i + 1)]);
|
||||
// mm_vars["mi_p" + std::to_string(i + 1)] =
|
||||
// std::min(mm_vars["p" + std::to_string(i + 1)],
|
||||
// mm_vars["mi_p" + std::to_string(i + 1)]);
|
||||
if (mm_vars["tag" + std::to_string(i + 1)] == 1) {
|
||||
mm_vars["mv2_tag" + std::to_string(i + 1)] += 1;
|
||||
}
|
||||
@ -729,7 +640,6 @@ bool ExpBase::act_done() {
|
||||
if (act_started_ && feedback_triggered_) {
|
||||
// 则记录下结束时间
|
||||
mm_vars["etime"] = mm_vars["now"];
|
||||
// mm_vars["time"] = mm_vars["etime"] - mm_vars["stime"];
|
||||
act_started_ = false;
|
||||
return true;
|
||||
}
|
||||
@ -888,7 +798,7 @@ int ExpBase::reload_config_exp_feedback() {
|
||||
if (exp_str_.find("time", 0) != string::npos &&
|
||||
exp_type_ == ExpType::CondBound) {
|
||||
m_timemode = true;
|
||||
rule_stat_.unit = "ms"; ///<时间的单位是 ms
|
||||
rule_stat_.unit = "ms";
|
||||
} else {
|
||||
m_timemode = false;
|
||||
}
|
||||
@ -910,24 +820,6 @@ int ExpBase::refresh_exp_vars_mem() {
|
||||
}
|
||||
mm_vars[var_cache_.pv_keys[i][0]] = current;
|
||||
|
||||
// mm_vars["p" + std::to_string(i + 1)] =
|
||||
// mm_vars["tag" + std::to_string(i + 1)];
|
||||
// mm_vars["tag" + std::to_string(i + 1)] =
|
||||
// SingletonTemplate<GlobaltemSharedMemory>::GetInstance()[m_tags[i]];
|
||||
|
||||
// auto pv_str = "pv" + std::to_string(i + 1);
|
||||
|
||||
// // mm_vars[pv_str + "_10"] = mm_vars[pv_str + "_9"];
|
||||
// // mm_vars[pv_str + "_9"] = mm_vars[pv_str + "_8"];
|
||||
// // mm_vars[pv_str + "_8"] = mm_vars[pv_str + "_7"];
|
||||
// // mm_vars[pv_str + "_7"] = mm_vars[pv_str + "_6"];
|
||||
// // mm_vars[pv_str + "_6"] = mm_vars[pv_str + "_5"];
|
||||
// mm_vars[pv_str + "_5"] = mm_vars[pv_str + "_4"];
|
||||
// mm_vars[pv_str + "_4"] = mm_vars[pv_str + "_3"];
|
||||
// mm_vars[pv_str + "_3"] = mm_vars[pv_str + "_2"];
|
||||
// mm_vars[pv_str + "_2"] = mm_vars[pv_str + "_1"];
|
||||
// mm_vars[pv_str + "_1"] = mm_vars[pv_str + "_0"];
|
||||
// mm_vars[pv_str + "_0"] = mm_vars["tag" + std::to_string(i + 1)];
|
||||
}
|
||||
mm_vars["now"] =
|
||||
duration_cast<milliseconds>(now_time_.time_since_epoch()).count();
|
||||
@ -991,11 +883,6 @@ int ExpBase::refresh_exp_vars_ihd(int row) {
|
||||
mm_vars["tag" + std::to_string(i + 1)];
|
||||
mm_vars["tag" + std::to_string(i + 1)] = queried_data_(row, i);
|
||||
auto pv_str = "pv" + std::to_string(i + 1);
|
||||
// mm_vars[pv_str + "_10"] = mm_vars[pv_str + "_9"];
|
||||
// mm_vars[pv_str + "_9"] = mm_vars[pv_str + "_8"];
|
||||
// mm_vars[pv_str + "_8"] = mm_vars[pv_str + "_7"];
|
||||
// mm_vars[pv_str + "_7"] = mm_vars[pv_str + "_6"];
|
||||
// mm_vars[pv_str + "_6"] = mm_vars[pv_str + "_5"];
|
||||
mm_vars[pv_str + "_5"] = mm_vars[pv_str + "_4"];
|
||||
mm_vars[pv_str + "_4"] = mm_vars[pv_str + "_3"];
|
||||
mm_vars[pv_str + "_3"] = mm_vars[pv_str + "_2"];
|
||||
@ -1009,13 +896,6 @@ int ExpBase::refresh_exp_vars_ihd(int row) {
|
||||
// 当前时间 == 上次执行的结束时间
|
||||
this->now_time_ = queried_time_[row];
|
||||
}
|
||||
/*-----太钢硅钢 -----弃用------*/
|
||||
// mm_vars["isEntOK"] =
|
||||
// SingletonTemplate<entCentExit>::GetInstance().isEntOK_ihd();
|
||||
// mm_vars["isCentOK"] =
|
||||
// SingletonTemplate<entCentExit>::GetInstance().isCentOK_ihd();
|
||||
// mm_vars["isExitOK"] =
|
||||
// SingletonTemplate<entCentExit>::GetInstance().isExitOK_ihd();
|
||||
this->fun_vars_.refresh_fun_vars(false, &mm_vars);
|
||||
refresh_hold_var();
|
||||
return 0;
|
||||
@ -1028,10 +908,6 @@ int ExpBase::first_fill_mm_vars() {
|
||||
logger_->Debug() << "-first_fill_mm_vars()-----mm_vars,size:"
|
||||
<< mm_vars.size() << ",mm_vars..empty():" << mm_vars.empty()
|
||||
<< std::endl;
|
||||
// if (!mm_vars.empty()) {
|
||||
// logger_->Debug() << " mm_vars.begin()->first:" << mm_vars.begin()->first
|
||||
// << endl;
|
||||
// }
|
||||
this->act_started_ = false;
|
||||
this->act_triggered_ = false;
|
||||
this->feedback_triggered_ = false;
|
||||
@ -1076,13 +952,6 @@ int ExpBase::first_fill_mm_vars() {
|
||||
mm_vars[pv_str + "_3"] = value;
|
||||
mm_vars[pv_str + "_4"] = value;
|
||||
mm_vars[pv_str + "_5"] = value;
|
||||
// mm_vars[pv_str + "_6"] = value;
|
||||
// mm_vars[pv_str + "_7"] = value;
|
||||
// mm_vars[pv_str + "_8"] = value;
|
||||
// mm_vars[pv_str + "_9"] = value;
|
||||
// mm_vars[pv_str + "_10"] = value;
|
||||
|
||||
// if (this->rule_id_ == "fba8df61-8a16-4a0e-80de-6e25aaf3d037") {
|
||||
if (this->exp_type_ == -1) {
|
||||
logger_->Debug() << "m_tags[" << i << "]:" << m_tags[i]
|
||||
<< ",m_tags.size():" << m_tags.size() << "-----3-----"
|
||||
@ -1095,8 +964,8 @@ int ExpBase::first_fill_mm_vars() {
|
||||
mm_vars["time"] = 0;
|
||||
} else if (data_source_ == DataSource::IHDB) {
|
||||
this->refresh_now_time();
|
||||
query_time_range_.set_left(now_time_ - 10s); ///<防止间隔时间太短查不到数据
|
||||
query_time_range_.set_right(now_time_ - 5s); ///<防止间隔时间太短查不到数据
|
||||
query_time_range_.set_left(now_time_ - 10s);
|
||||
query_time_range_.set_right(now_time_ - 5s);
|
||||
this->refresh_ihd_cache();
|
||||
if (queried_data_.rows() == 0) {
|
||||
logger_->Debug() << "time:"
|
||||
@ -1118,9 +987,6 @@ int ExpBase::first_fill_mm_vars() {
|
||||
{ErrorType::Empty, ErrorLocation::DataValue});
|
||||
return -1;
|
||||
}
|
||||
// mm_vars["isEntOK"] = false;
|
||||
// mm_vars["isCentOK"] = false;
|
||||
// mm_vars["isExitOK"] = false;
|
||||
for (unsigned int i = 0; i < m_tags.size(); i++) {
|
||||
auto pv_str = "pv" + std::to_string(i + 1);
|
||||
auto rows = queried_data_.rows() - 1;
|
||||
@ -1136,22 +1002,12 @@ int ExpBase::first_fill_mm_vars() {
|
||||
mm_vars["tag" + std::to_string(i + 1)];
|
||||
mm_vars["mi_tag" + std::to_string(i + 1)] =
|
||||
mm_vars["tag" + std::to_string(i + 1)];
|
||||
// mm_vars["mx_p" + std::to_string(i + 1)] =
|
||||
// mm_vars["p" + std::to_string(i + 1)];
|
||||
// mm_vars["mi_p" + std::to_string(i + 1)] =
|
||||
// mm_vars["p" + std::to_string(i + 1)];
|
||||
mm_vars[pv_str + "_0"] = tmp_val;
|
||||
mm_vars[pv_str + "_1"] = tmp_val;
|
||||
mm_vars[pv_str + "_2"] = tmp_val;
|
||||
mm_vars[pv_str + "_3"] = tmp_val;
|
||||
mm_vars[pv_str + "_4"] = tmp_val;
|
||||
mm_vars[pv_str + "_5"] = tmp_val;
|
||||
// mm_vars[pv_str + "_6"] = tmp_val;
|
||||
// mm_vars[pv_str + "_7"] = tmp_val;
|
||||
// mm_vars[pv_str + "_8"] = tmp_val;
|
||||
// mm_vars[pv_str + "_9"] = tmp_val;
|
||||
// mm_vars[pv_str + "_10"] = tmp_val;
|
||||
|
||||
mm_vars["stime"] = 0;
|
||||
mm_vars["now"] = 0;
|
||||
mm_vars["etime"] = 0;
|
||||
@ -1364,19 +1220,15 @@ void ExpBase::print_exp_vars(const string &expstr) {
|
||||
void ExpBase::set_last_alarm_time(TimePoint time_point) {
|
||||
this->refresh_counts_ = 0;
|
||||
if (this->is_usable_) {
|
||||
this->first_fill_mm_vars(); ///<打破原动作状态
|
||||
this->first_fill_mm_vars();
|
||||
}
|
||||
AlgBase::set_last_alarm_time(time_point);
|
||||
}
|
||||
|
||||
void ExpBase::set_usable(bool usable) {
|
||||
// if (rule_id_ == "ded572f3-0572-40f8-a86c-fca82e9497dd") {
|
||||
// logger_->Debug() << "------test--------" << BOOST_CURRENT_FUNCTION <<
|
||||
// endl;
|
||||
// }
|
||||
this->refresh_counts_ = 0;
|
||||
if (this->is_usable_) {
|
||||
this->first_fill_mm_vars(); ///<打破原动作状态
|
||||
this->first_fill_mm_vars();
|
||||
}
|
||||
AlgBase::set_usable(usable);
|
||||
}
|
||||
@ -1464,7 +1316,7 @@ int ExpBase::reload_ci_dist() {
|
||||
this->rule_stat_.limit_down = limit_down_;
|
||||
this->rule_stat_.limit_up = limit_up_;
|
||||
this->rule_stat_.current_value =
|
||||
(this->limit_down_ + this->limit_up_) / 2; ///<页面展示
|
||||
(this->limit_down_ + this->limit_up_) / 2;
|
||||
logger_->Info()
|
||||
<< "更新置信区间,[" << dist_range.get_left() << ","
|
||||
<< dist_range.get_right() << "]"
|
||||
@ -1476,31 +1328,6 @@ int ExpBase::reload_ci_dist() {
|
||||
|
||||
void ExpBase::query_ihd_data() {
|
||||
vector<string> ihd_tags = m_tags;
|
||||
// if (this->prr_ > 0) {
|
||||
// switch (this->prr_) {
|
||||
// case PRR::None:
|
||||
// break;
|
||||
// case PRR::EntRunning:
|
||||
// ihd_tags.push_back(string(CMemVar::Const()->UnitNo) + "_" +
|
||||
// string(CMemVar::Const()->ent_run_state));
|
||||
// break;
|
||||
// case PRR::ACDRunning:
|
||||
// ihd_tags.push_back(string(CMemVar::Const()->UnitNo) + "_" +
|
||||
// string(CMemVar::Const()->acd_run_state));
|
||||
// break;
|
||||
// case PRR::AXTRunning:
|
||||
// ihd_tags.push_back(string(CMemVar::Const()->UnitNo) + "_" +
|
||||
// string(CMemVar::Const()->axt_run_state));
|
||||
|
||||
// break;
|
||||
// case PRR::TCMRunning:
|
||||
// ihd_tags.push_back(string(CMemVar::Const()->UnitNo) + "_" +
|
||||
// string(CMemVar::Const()->tcm_run_state));
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
auto queried_batch_maybe = mix_cc::ihd::make_query_batch_maybe(
|
||||
ihd_tags, query_time_range_, this->ihd_min_time_particles_);
|
||||
if (queried_batch_maybe.is_nothing()) {
|
||||
@ -1534,13 +1361,6 @@ void ExpBase::task_mon_pro() {
|
||||
} else {
|
||||
auto res = task_base_proc();
|
||||
if (res.is_valid && this->task_prr(i)) {
|
||||
// TaskShm::TaskRecordPtr.get()
|
||||
// ->
|
||||
// operator[](exp_type_ * 1000 + task_seq)
|
||||
// .data_record[TaskShm::TimeRecordPtr.get()
|
||||
// ->
|
||||
// operator[](exp_type_ * 1000 + task_seq)
|
||||
// .data_size++] = res.value;
|
||||
TaskShm::TaskRecordPtr.get()
|
||||
->
|
||||
operator[](exp_type_ * 1000 + task_seq)
|
||||
@ -1551,10 +1371,6 @@ void ExpBase::task_mon_pro() {
|
||||
}
|
||||
}
|
||||
string ExpBase::get_id(mix_cc::time_range_t time_range) {
|
||||
// return this->rule_id_.substr(3, 9) + "_" +
|
||||
// std::to_string(time_range.get_left().time_since_epoch().count()) +
|
||||
// "_" +
|
||||
// std::to_string(time_range.get_right().time_since_epoch().count());
|
||||
this->sample_id_ =
|
||||
this->rule_id_.substr(3, 21) + "_" +
|
||||
std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
@ -1570,10 +1386,9 @@ string ExpBase::get_id(mix_cc::time_range_t time_range) {
|
||||
TaskReturnType ExpBase::task_base_proc() {
|
||||
TaskReturnType task_return_data;
|
||||
double result_value = 0;
|
||||
// logger_->Debug() << "task_base_proc()---1" << endl;
|
||||
try {
|
||||
// 获得是否满足前提条件表达式
|
||||
result_value = exp_act_->evaluate(); ///< 2/5用于 非反馈 上下限
|
||||
result_value = exp_act_->evaluate();
|
||||
act_triggered_ = static_cast<bool>(result_value);
|
||||
// 检测是否是表达式-反馈模式
|
||||
if (feedback_mode_) {
|
||||
@ -1581,8 +1396,6 @@ TaskReturnType ExpBase::task_base_proc() {
|
||||
if (act_start_done() || act_not_hold()) {
|
||||
return task_return_data;
|
||||
}
|
||||
// feedback_triggered_ = static_cast<bool>(exp_feedback_->evaluate());
|
||||
// 如果所有前提动作和条件均满足
|
||||
if (act_done()) {
|
||||
result_value = exp_result_->evaluate();
|
||||
print_exp_vars();
|
||||
@ -1593,7 +1406,6 @@ TaskReturnType ExpBase::task_base_proc() {
|
||||
return task_return_data;
|
||||
}
|
||||
} else if (act_timeout()) {
|
||||
// 如果超时,则返回
|
||||
return task_return_data;
|
||||
}
|
||||
}
|
||||
@ -1695,7 +1507,6 @@ void ExpBase::reset_dev_data() {
|
||||
if (glob_process_type == ProcessType::kMon) {
|
||||
if (exp_type_ == ExpType::Bound || exp_type_ == ExpType::CondBound ||
|
||||
exp_type_ == ExpType::BoundHoldTime) {
|
||||
// logger_->Debug() << "reset_dev_data()---1" << endl;
|
||||
int res = DAA::STA::delete_statistics_data(this->rule_id_);
|
||||
if (res != 0) {
|
||||
logger_->Debug() << "DAA::STA::delete_statistics_data(this->rule_id_) "
|
||||
|
||||
@ -169,15 +169,13 @@ protected:
|
||||
void print_exp_vars(const string &expstr = "");
|
||||
|
||||
protected:
|
||||
// std::map<std::string, double> mm_vars; ///< 表达式系统变量map
|
||||
string exp_str_;
|
||||
|
||||
string exp_str_; ///< 表达式字符串
|
||||
string error_str_;
|
||||
|
||||
string error_str_; ///< 错误字符串
|
||||
bool feedback_done_ = false;
|
||||
|
||||
bool feedback_done_ = false; ///<动作反馈完成
|
||||
|
||||
string unit_; ///<单位
|
||||
string unit_;
|
||||
/**
|
||||
* @brief 自定义带状态函数
|
||||
* KeepT , ///< 保持时间
|
||||
@ -187,76 +185,71 @@ protected:
|
||||
*/
|
||||
StatExp::FunVars fun_vars_;
|
||||
|
||||
std::unique_ptr<mix_cc::matheval::Expression> exp_act_; ///< 动作表达式
|
||||
std::unique_ptr<mix_cc::matheval::Expression> exp_act_;
|
||||
|
||||
std::unique_ptr<mix_cc::matheval::Expression> exp_feedback_; ///< 反馈表达式
|
||||
std::unique_ptr<mix_cc::matheval::Expression> exp_feedback_;
|
||||
|
||||
std::unique_ptr<mix_cc::matheval::Expression> exp_result_; ///< 数值表达式
|
||||
std::unique_ptr<mix_cc::matheval::Expression> exp_result_;
|
||||
|
||||
size_t task_data_size = 0;
|
||||
|
||||
protected:
|
||||
const size_t
|
||||
exp_type_; ///< 表达式类型:1-实时逻辑判断;2-变量上下限;3-动作反馈;4-动作反馈-上下限
|
||||
exp_type_;
|
||||
|
||||
TimeDur time_out_; ///< 反馈限制超时时间
|
||||
TimeDur time_out_;
|
||||
|
||||
TimePoint act_start_time_; ///<动作开始时间
|
||||
TimePoint act_start_time_;
|
||||
|
||||
bool act_triggered_ = false; ///< 开始动作是否触发
|
||||
bool act_triggered_ = false;
|
||||
|
||||
bool act_started_ =
|
||||
false; ///< 动作是否开始(即使之前触发过,但是也可能由于超时、未保持而停止)
|
||||
false;
|
||||
|
||||
bool feedback_triggered_ = false; ///< 反馈是否触发
|
||||
bool feedback_triggered_ = false;
|
||||
|
||||
bool m_timemode = false; ///< 执行的时间模式
|
||||
bool m_timemode = false;
|
||||
|
||||
int refresh_counts_ = 0; ///< 当数据源是共享内存时开机保证前4次 mm_vars有值
|
||||
int refresh_counts_ = 0;
|
||||
protected:
|
||||
bool feedback_mode_ = false; ///< 有反馈的表达式模式
|
||||
bool feedback_mode_ = false;
|
||||
|
||||
bool keep_mode_ = false; ///< 开始动作是否需要保持
|
||||
bool keep_mode_ = false;
|
||||
|
||||
double limit_up_ = 0; ///<上限
|
||||
double limit_up_ = 0;
|
||||
|
||||
double limit_down_ = 0; ///<下限
|
||||
double limit_down_ = 0;
|
||||
|
||||
TimeDur hold_time_ = 0ms; ///< 超范围 保持时间
|
||||
TimeDur hold_time_ = 0ms;
|
||||
|
||||
std::unique_ptr<DAA::STA> sta_ptr_; ///< 统计类
|
||||
std::unique_ptr<DAA::STA> sta_ptr_;
|
||||
|
||||
std::map<std::string, std::unique_ptr<HoldTime>>
|
||||
hold_times_; ///< hold变量保存类
|
||||
hold_times_;
|
||||
|
||||
bool exp_is_wrong_ = true; ///<表达式是否错误:true 是错误 false 没有错
|
||||
bool exp_is_wrong_ = true;
|
||||
|
||||
bool exp_wrong_is_alarmed_ = false; ///<加载错误是否已报警
|
||||
bool exp_wrong_is_alarmed_ = false;
|
||||
|
||||
// bool is_auto_ = true;
|
||||
// ///<区间是否采用自动学习的区间;true-自动;false-手动 弃用
|
||||
int dist_mode_; ///<区间模式
|
||||
///< 0-手动设置的区间;1-在线更新的区间;2-离线分析的区间
|
||||
int dist_mode_;
|
||||
|
||||
bool is_learning_ = true; ///<是否自学习;true-自学习;false-不学习
|
||||
bool is_learning_ = true;
|
||||
|
||||
TimePoint last_load_time_; ///< 上一次重载置信区间的时间
|
||||
TimePoint last_load_time_;
|
||||
|
||||
// mix_cc::json sample_param_; ///<样本结果
|
||||
int64_t CronUpdateDelay = StatConst::CronUpdateDelay;
|
||||
|
||||
int64_t CronUpdateDelay = StatConst::CronUpdateDelay; ///<更新周期
|
||||
std::string sample_type_ = SampleType::T_SAMPLE_STAT;
|
||||
|
||||
std::string sample_type_ = SampleType::T_SAMPLE_STAT; ///< task进程 样本类型
|
||||
std::string sample_id_;
|
||||
|
||||
std::string sample_id_; ///< task进程 样本id
|
||||
std::string sample_result_;
|
||||
|
||||
std::string sample_result_; ///<样本结果
|
||||
int detect_mode_ = DetectMode::Default;
|
||||
|
||||
int detect_mode_ = DetectMode::Default; ///<检测模式
|
||||
bool filter_flag_ = false;
|
||||
|
||||
bool filter_flag_ = false; ///< 数据筛选结果
|
||||
|
||||
bool is_fun_vars_need_reset_ = false; ///<自定义带状态函数 状态重置标记
|
||||
bool is_fun_vars_need_reset_ = false;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -26,7 +26,7 @@ int ExpBound::init() {
|
||||
res += this->first_fill_mm_vars(); /*4.数据项*/
|
||||
res += init_X_exp();
|
||||
rule_stat_.unit = unit_;
|
||||
rule_stat_.limit_down = -32768; ///<下限 无限制
|
||||
rule_stat_.limit_down = -32768;
|
||||
limit_down_ = -32768;
|
||||
limit_up_ = limit_warn_;
|
||||
rule_stat_.limit_up = limit_warn_;
|
||||
@ -48,7 +48,6 @@ ExpBound::ExpBound(const string &name, const mix_cc::json &rule_json,
|
||||
}
|
||||
|
||||
ExpBound::~ExpBound() {
|
||||
// AlgBase::~AlgBase();
|
||||
}
|
||||
|
||||
AlarmInfo ExpBound::mon_proc() {
|
||||
@ -65,9 +64,6 @@ AlarmInfo ExpBound::mon_proc() {
|
||||
/*报警检查*/
|
||||
if (now_value > limit_warn_) {
|
||||
std::string msg = "";
|
||||
// msg = error_str_ + ",当前值:" + DAA::double2str(now_value) + unit_ +
|
||||
// ",合理区间:[" + DAA::double2strLimit(limit_down_) + "," +
|
||||
// DAA::double2strLimit(limit_up_) + "] " + unit_;
|
||||
msg = error_str_ + ",当前值:" + DAA::double2str(now_value) + unit_ + ",超";
|
||||
auto alarm_time = get_alarm_time();
|
||||
print_exp_vars();
|
||||
|
||||
@ -29,9 +29,9 @@ public:
|
||||
std::vector<AlarmInfo> exec_task(mix_cc::time_range_t time_range) override;
|
||||
|
||||
private:
|
||||
double limit_error_; ///<报警限幅
|
||||
double limit_warn_;///<警告限幅
|
||||
string value_exp_str_;///<监控变量表达式
|
||||
double limit_error_;
|
||||
double limit_warn_;
|
||||
string value_exp_str_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@ -20,7 +20,6 @@ ExpSample2D::ExpSample2D(const string &name, const mix_cc::json &rule_json,
|
||||
}
|
||||
|
||||
ExpSample2D::~ExpSample2D() {
|
||||
// ExpBase::~ExpBase();
|
||||
}
|
||||
|
||||
int ExpSample2D::init() {
|
||||
@ -29,9 +28,7 @@ int ExpSample2D::init() {
|
||||
// 重新载入数据源配置信息
|
||||
ret += this->reload_config_data_source();
|
||||
// 在载入数据源信息完成后,载入表达式配置之前,必须刷新变量,把变量信息初始化到mm_vars内
|
||||
// if (glob_process_type == ProcessType::kMon) {
|
||||
ret += this->first_fill_mm_vars(); /*4.数据项*/
|
||||
// }
|
||||
ret += this->first_fill_mm_vars();
|
||||
// 必须在刷新变量后,才可以初始化表达式
|
||||
ret += this->reload_config_exp_act();
|
||||
ret += this->reload_samples();
|
||||
@ -342,12 +339,6 @@ int ExpSample2D::insert_mag(std::string sample_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*移至ExpBase*/
|
||||
// string ExpSample2D::get_id() {
|
||||
// return this->rule_id_.substr(0, 30) + "_" +
|
||||
// std::to_string(system_clock::now().time_since_epoch().count());
|
||||
// }
|
||||
|
||||
std::vector<AlarmInfo> ExpSample2D::exec_task(mix_cc::time_range_t time_range) {
|
||||
/**
|
||||
* 1.查数据,生成SampleX_、SampleY_
|
||||
@ -433,27 +424,6 @@ void ExpSample2D::reset_SampleXY() {
|
||||
data_len_ = 0;
|
||||
}
|
||||
|
||||
/*弃用 继承 ExpBase*/
|
||||
// void ExpSample2D::query_ihd_data() {
|
||||
// auto queried_batch_maybe = mix_cc::ihd::make_query_batch_maybe(
|
||||
// m_tags, query_time_range_, this->ihd_min_time_particles_);
|
||||
// if (queried_batch_maybe.is_nothing()) {
|
||||
// queried_time_.clear();
|
||||
// queried_data_ = typename decltype(queried_batch_maybe)::type::Mat2d{};
|
||||
// gb_logger_->log_error("Tag点没有查到相应的信息");
|
||||
// return;
|
||||
// }
|
||||
// auto queried_bath = queried_batch_maybe.unsafe_get_just();
|
||||
// auto result_maybe = mix_cc::ihd::read_data_with_time_maybe(&queried_bath);
|
||||
// if (result_maybe.is_nothing()) {
|
||||
// queried_time_.clear();
|
||||
// queried_data_ = typename decltype(queried_batch_maybe)::type::Mat2d{};
|
||||
// gb_logger_->log_error("Tag点没有查到相应的数据");
|
||||
// return;
|
||||
// }
|
||||
// std::tie(queried_time_, queried_data_) = result_maybe.unsafe_get_just();
|
||||
// }
|
||||
|
||||
void ExpSample2D::task_mon_pro() {
|
||||
if (data_len_ > MAX_STORAGE_SIZE) {
|
||||
return;
|
||||
|
||||
@ -93,25 +93,18 @@ class ExpSample2D : public ExpBase {
|
||||
*/
|
||||
int insert_fit(std::string sample_id, double X, double Y, int seq);
|
||||
|
||||
// /**
|
||||
// * @brief 生成样本id
|
||||
// * 弃用移至ExpBase
|
||||
// * @return string
|
||||
// */
|
||||
// string get_id();
|
||||
|
||||
private:
|
||||
int orders_; ///< 拟合次数
|
||||
std::vector<double> fit_coefs_; ///<多项式系数
|
||||
double pear_coefs_; ///<相关系数
|
||||
double scale_; ///<报警系数
|
||||
mix_cc::json sample_param_; ///<样本结果
|
||||
const string SampleType_ = "T_SAMPLE_FIT"; ///样本类型
|
||||
int data_len_ = 0; ///<运行当前的样本数量
|
||||
int min_len_ = 1000; ///<相关性 数据最小长度要求
|
||||
std::vector<double> SampleX_; ///<样本X
|
||||
std::vector<double> SampleY_; ///<样本Y
|
||||
std::unique_ptr<DAA::LSM> lsm_ptr_; ///<拟合/相关性 处理类
|
||||
int orders_;
|
||||
std::vector<double> fit_coefs_;
|
||||
double pear_coefs_;
|
||||
double scale_;
|
||||
mix_cc::json sample_param_;
|
||||
const string SampleType_ = "T_SAMPLE_FIT";
|
||||
int data_len_ = 0;
|
||||
int min_len_ = 1000;
|
||||
std::vector<double> SampleX_;
|
||||
std::vector<double> SampleY_;
|
||||
std::unique_ptr<DAA::LSM> lsm_ptr_;
|
||||
|
||||
private:
|
||||
/**
|
||||
@ -120,15 +113,8 @@ class ExpSample2D : public ExpBase {
|
||||
void reset_SampleXY();
|
||||
|
||||
protected:
|
||||
// /**
|
||||
// * @brief 从ihd查询数据
|
||||
// * 弃用 继承 ExpBase
|
||||
// */
|
||||
// void query_ihd_data();
|
||||
|
||||
/**
|
||||
* @brief task执行函数
|
||||
*
|
||||
*/
|
||||
void task_mon_pro();
|
||||
};
|
||||
@ -14,7 +14,6 @@ ExpTimes::ExpTimes(const string &name, const mix_cc::json &rule_json,
|
||||
}
|
||||
|
||||
ExpTimes::~ExpTimes() {
|
||||
// ExpBase::~ExpBase();
|
||||
this->wait_flag_ = 0;
|
||||
}
|
||||
|
||||
@ -92,16 +91,6 @@ int ExpTimes::reload_params() {
|
||||
|
||||
AlarmInfo ExpTimes::mon_proc() {
|
||||
AlarmInfo out_alarm{};
|
||||
/*首次运行等待 防止上次运行未析构*/
|
||||
// if (this->wait_flag_ < 2) {
|
||||
// this->wait_flag_++;
|
||||
// logger_->Debug() << "等待,当前等待次数:" << this->wait_flag_ << endl;
|
||||
// if (this->get_history_times() == -1) {
|
||||
// this->exp_is_wrong_ = true;
|
||||
// }
|
||||
// return out_alarm;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 1.检查存写周期,满足则存db2
|
||||
* 2.运行累计
|
||||
@ -141,8 +130,6 @@ AlarmInfo ExpTimes::mon_proc() {
|
||||
this->rule_stat_.current_value),
|
||||
rule_id_, rule_name_, "ExpTimes", msg, query_time_range_);
|
||||
|
||||
// return utility::build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
|
||||
// "ExpTimes", msg, query_time_range_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,9 +286,6 @@ int ExpTimes::update_history_times() {
|
||||
}
|
||||
this->rule_stat_.shear_times = now_times;
|
||||
this->rule_stat_.running_time = now_used_time;
|
||||
// SingletonTemp<EqpStat>::GetInstance().update_static(this->rule_id_,
|
||||
// this->rule_stat_,
|
||||
// true);
|
||||
SingletonTemp<EqpStat>::GetInstance().update_static(this->rule_id_, true);
|
||||
return 0;
|
||||
}
|
||||
@ -325,16 +309,10 @@ int ExpTimes::insert_history_times(int64_t now_times, double now_used_time) {
|
||||
|
||||
void ExpTimes::reset_dev_data() {
|
||||
// T_RULE_SAMPLE_1D trs1a;
|
||||
last_load_time_ = now_time_; ///<防止刷新数据
|
||||
// exec<db2_t, size_t>(update(trs1a)
|
||||
// .set(trs1a.Count() = 0, trs1a.X1() = 0)
|
||||
// .where(trs1a.RuleId() == this->rule_id_));
|
||||
last_load_time_ = now_time_;
|
||||
this->rule_stat_.shear_times = 0;
|
||||
this->rule_stat_.running_time = 0;
|
||||
this->update_history_times();
|
||||
// SingletonTemp<EqpStat>::GetInstance().update_static(this->rule_id_,
|
||||
// this->rule_stat_,
|
||||
// true);
|
||||
SingletonTemp<EqpStat>::GetInstance().update_static(this->rule_id_, true);
|
||||
logger_->Debug() << rule_name_ << ":ExpTimes::reset_dev_data()" << endl;
|
||||
this->wait_flag_ = 0;
|
||||
|
||||
@ -28,10 +28,10 @@ class ExpTimes : public ExpBase {
|
||||
virtual void reset_dev_data() override;
|
||||
|
||||
protected:
|
||||
double max_time_ = 0; ///<最大累积的运行时间
|
||||
int64_t max_times_ = 0; ///<最大出现次数
|
||||
int rw_time_ = 10; ///<读写时间间隔 min
|
||||
int wait_flag_ = 0; ///<首次读取db2 等待1次运行
|
||||
double max_time_ = 0;
|
||||
int64_t max_times_ = 0;
|
||||
int rw_time_ = 10;
|
||||
int wait_flag_ = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
||||
@ -11,7 +11,6 @@ FaultCode::FaultCode(const string name, const mix_cc::json& rule_json,
|
||||
logger_.reset(new LOG("FaultCode:" + rule_name_, AUTO_CATCH_PID));
|
||||
}
|
||||
FaultCode::~FaultCode() {
|
||||
// AlgBase::~AlgBase();
|
||||
}
|
||||
|
||||
int FaultCode::init() {
|
||||
@ -41,7 +40,7 @@ AlarmInfo FaultCode::exec_mon() {
|
||||
/*故障代码解析*/
|
||||
int fault_code_now =
|
||||
int(SingletonTemplate<GlobaltemSharedMemory>::GetInstance()[m_tags[0]]);
|
||||
this->rule_stat_.current_value = fault_code_now; ///<页面展示
|
||||
this->rule_stat_.current_value = fault_code_now;
|
||||
query_time_range_.set_right(now_time_);
|
||||
query_time_range_.set_left(now_time_ - this->delay_time_);
|
||||
if (fault_code_now != 0) {
|
||||
|
||||
@ -55,13 +55,13 @@ class FaultCode : public AlgBase {
|
||||
int select_t_lov_fcode();
|
||||
|
||||
protected:
|
||||
const size_t code_type_; ///< 故障代码解析类型:0-整体解析;1-按位解析
|
||||
const size_t code_type_;
|
||||
struct FaultCodeInfo {
|
||||
bool is_usable = false;
|
||||
std::string name;
|
||||
std::string content;
|
||||
};
|
||||
std::map<int, FaultCodeInfo> map2fcode_; ///<故障代码对应表
|
||||
std::string alarm_content_; ///<报警内容
|
||||
bool is_valid_ = false; ///<配置参数是否合法
|
||||
std::map<int, FaultCodeInfo> map2fcode_;
|
||||
std::string alarm_content_;
|
||||
bool is_valid_ = false;
|
||||
};
|
||||
@ -11,7 +11,6 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
// 炉辊组算法无需额外的算法初始化步骤
|
||||
int GlitchDetection::init() {
|
||||
data_index_ = 0;
|
||||
int ret = 0;
|
||||
@ -32,7 +31,7 @@ int GlitchDetection::init() {
|
||||
py_param_["name"] = this->rule_name_;
|
||||
py_param_["glitch_per"] = this->glitch_per_;
|
||||
run_time_range_.set_left(this->now_time_);
|
||||
this->data_ = {0}; ///<初始化
|
||||
this->data_ = {0};
|
||||
logger_->Debug() << rule_name_ << "--init 完成!" << std::endl;
|
||||
return ret;
|
||||
}
|
||||
@ -45,7 +44,6 @@ GlitchDetection::GlitchDetection(const string name,
|
||||
}
|
||||
|
||||
GlitchDetection::~GlitchDetection() {
|
||||
// AlgBase::~AlgBase();
|
||||
}
|
||||
|
||||
AlarmInfo GlitchDetection::exec_mon() {
|
||||
@ -120,16 +118,6 @@ int GlitchDetection::load_exp() {
|
||||
rule_json_.at("function").at("dataX").at("value").get<std::string>();
|
||||
exp_str_ = get_macro_replaced_exp(tmp_exp);
|
||||
exp_mpdule_ptr_->add_exp("dataX", exp_str_);
|
||||
// res += init_hold_exp_str(exp_str_);
|
||||
// feedback_mode_ = true;
|
||||
// auto messy_code = exp_messy_code_check(exp_str_);
|
||||
// if (messy_code == -1) {
|
||||
// this->error_code_list_.push_back(
|
||||
// {ErrorType::EnCodeError, ErrorLocation::ActExp});
|
||||
// res += messy_code;
|
||||
// } else {
|
||||
// exp_mpdule_ptr_->add_exp("dataX", exp_str_);
|
||||
// }
|
||||
/*数据长度*/
|
||||
auto tmp_data_size = rule_json_.at("function")
|
||||
.at("dataX")
|
||||
@ -141,15 +129,7 @@ int GlitchDetection::load_exp() {
|
||||
if (data_size_ < 100 || data_size_ > MAXLEN) {
|
||||
data_size_ = MAXLEN - 2;
|
||||
}
|
||||
/*数据报警阈值*/
|
||||
// auto tmp_scale = rule_json_.at("function")
|
||||
// .at("dataX")
|
||||
// .at("param")
|
||||
// .at("scale")
|
||||
// .at("value")
|
||||
// .get<std::string>();
|
||||
// glitch_per_ = std::stod(tmp_scale); ///<毛刺比例
|
||||
glitch_per_ = 0.1; ///<毛刺比例
|
||||
glitch_per_ = 0.1;
|
||||
logger_->Debug() << "exp_str:" << exp_str_ << ",data_size_:" << data_size_
|
||||
<< ",glitch_per_:" << glitch_per_ << std::endl;
|
||||
return res;
|
||||
|
||||
@ -22,14 +22,14 @@ public:
|
||||
bool get_prr() override;
|
||||
|
||||
private:
|
||||
std::array<double, MAXLEN> data_; ///<被检测的数据
|
||||
int data_index_ = 0; ///<当前数据个数
|
||||
int data_size_ = 0; ///<数据长度
|
||||
double glitch_per_ = 0.1; ///<毛刺比例
|
||||
std::array<double, MAXLEN> data_;
|
||||
int data_index_ = 0;
|
||||
int data_size_ = 0;
|
||||
double glitch_per_ = 0.1;
|
||||
mix_cc::time_range_t run_time_range_;
|
||||
string exp_str_; ///< 表达式字符串
|
||||
mix_cc::json py_param_; ///< send 2 py params
|
||||
std::string error_content_; ///<报警内容
|
||||
string exp_str_;
|
||||
mix_cc::json py_param_;
|
||||
std::string error_content_;
|
||||
private:
|
||||
/**
|
||||
* @brief 加载表达式
|
||||
|
||||
@ -47,7 +47,8 @@ Roller::Roller(const string name, const mix_cc::json& rule_json,
|
||||
}
|
||||
|
||||
Roller::~Roller() {
|
||||
// AlgBase::~AlgBase();
|
||||
|
||||
|
||||
}
|
||||
|
||||
AlarmInfo Roller::exec_mon() {
|
||||
@ -140,9 +141,9 @@ int Roller::exec_mon_base() {
|
||||
<< ",sum:" << this->min_max_sum_[2]
|
||||
<< ",n_tag2:" << n_tags << std::endl;
|
||||
if (this->mmean_tags_[*iter] > m_ave) {
|
||||
tags_errors_[*iter] = 0; ///<过大
|
||||
tags_errors_[*iter] = 0;
|
||||
} else {
|
||||
tags_errors_[*iter] = 1; ///<过小
|
||||
tags_errors_[*iter] = 1;
|
||||
}
|
||||
iter = this->comparison_tags_.erase(iter);
|
||||
this->logger_->Debug() << "flag=" << flag << std::endl;
|
||||
|
||||
@ -26,18 +26,18 @@ class Roller :public AlgBase {
|
||||
int init() override;
|
||||
AlarmInfo exec_mon() override;
|
||||
std::vector<AlarmInfo> exec_task(mix_cc::time_range_t time_range) override;
|
||||
const array<string, 2> BIG_SMALL = {"过大", "过小"}; ///<检测异常的结果集
|
||||
const array<string, 2> BIG_SMALL = {"过大", "过小"};
|
||||
|
||||
private:
|
||||
TimeDur interval_time_; ///<查ihd均值的时间长短,默认3分钟
|
||||
std::string error_content_; ///<报警内容
|
||||
double error_diff_; ///<报警阈值,百分比
|
||||
std::string error_name_; ///<报警原因
|
||||
std::map<int, double> mmean_tags_; ///<查询的结果
|
||||
std::vector<int> comparison_tags_; ///<需要查找是否异常的tag
|
||||
std::map<int, int> tags_errors_; ///<异常的tags
|
||||
std::array<double, 3> min_max_sum_; ///最小值 最大值 和
|
||||
int n_tags_; ///< tag的个数
|
||||
TimeDur interval_time_;
|
||||
std::string error_content_;
|
||||
double error_diff_;
|
||||
std::string error_name_;
|
||||
std::map<int, double> mmean_tags_;
|
||||
std::vector<int> comparison_tags_;
|
||||
std::map<int, int> tags_errors_;
|
||||
std::array<double, 3> min_max_sum_;
|
||||
int n_tags_;
|
||||
private:
|
||||
/**
|
||||
* @brief 查询mmean_tags_ 调用ihd均值查询API
|
||||
|
||||
@ -48,7 +48,8 @@ Roller2::Roller2(const string& name, const mix_cc::json& rule_json,
|
||||
}
|
||||
|
||||
Roller2::~Roller2() {
|
||||
// AlgBase::~AlgBase();
|
||||
|
||||
|
||||
}
|
||||
|
||||
AlarmInfo Roller2::mon_proc() {
|
||||
@ -67,7 +68,7 @@ AlarmInfo Roller2::mon_proc() {
|
||||
this->rule_stat_.limit_down = limit_down_;
|
||||
this->rule_stat_.limit_up = limit_up_;
|
||||
for (auto& exp_value : var_Xdouble_) {
|
||||
rule_stat_.current_value = exp_value.second; ///<共享内存
|
||||
rule_stat_.current_value = exp_value.second;
|
||||
logger_->Debug() << var_name_[exp_value.first] + ":" +
|
||||
DAA::double2str(exp_value.second, 3) +
|
||||
",合理区间:[" + DAA::double2str(limit_down_, 3) +
|
||||
@ -81,9 +82,7 @@ AlarmInfo Roller2::mon_proc() {
|
||||
DAA::double2str(limit_down_, 3) + "," +
|
||||
DAA::double2str(limit_up_, 3) + "]";
|
||||
auto alarm_time = query_time_range_;
|
||||
// if (alarm_time.get_right() - alarm_time.get_left() < minutes(2)) {
|
||||
alarm_time.set_left(alarm_time.get_right() - minutes(2));
|
||||
// }
|
||||
return utility::build_alarm_info(
|
||||
utility::get_msg_level(limit_down_, limit_up_, exp_value.second),
|
||||
rule_id_, rule_name_, "EXP9", msg, alarm_time);
|
||||
|
||||
@ -29,16 +29,16 @@ class Roller2 : public ExpBase {
|
||||
int init() override;
|
||||
virtual AlarmInfo mon_proc() override;
|
||||
std::vector<AlarmInfo> exec_task(mix_cc::time_range_t time_range) override;
|
||||
const array<string, 2> BIG_SMALL = {"过大", "过小"}; ///<检测异常的结果集
|
||||
double limit_over_; ///<百分比阈值
|
||||
const array<string, 2> BIG_SMALL = {"过大", "过小"};
|
||||
double limit_over_;
|
||||
private:
|
||||
std::unique_ptr<mix_cc::matheval::Expression> pre_exp_; ///<前提条件
|
||||
std::unique_ptr<mix_cc::matheval::Expression> pre_exp_;
|
||||
map<std::string, std::unique_ptr<mix_cc::matheval::Expression>>
|
||||
var_exp_; ///<监控变量
|
||||
map<std::string, std::string> var_name_; ///<变量名
|
||||
var_exp_;
|
||||
map<std::string, std::string> var_name_;
|
||||
map<std::string, std::string> var_exp_str_;
|
||||
map<std::string, double> var_Xdouble_; ///<监控数据
|
||||
bool pre_exp_flag_; ///<前提条件
|
||||
map<std::string, double> var_Xdouble_;
|
||||
bool pre_exp_flag_;
|
||||
|
||||
private:
|
||||
int init_X_exp();
|
||||
|
||||
@ -66,7 +66,8 @@ Roller3::Roller3(const string &name, const mix_cc::json &rule_json,
|
||||
}
|
||||
|
||||
Roller3::~Roller3() {
|
||||
// AlgBase::~AlgBase();
|
||||
|
||||
|
||||
}
|
||||
|
||||
AlarmInfo Roller3::mon_proc() {
|
||||
@ -108,8 +109,8 @@ AlarmInfo Roller3::mon_proc() {
|
||||
limit_up_ = median_ + deviationWarn;
|
||||
rule_stat_.limit_down = get_up_down(limit_down_, 0);
|
||||
rule_stat_.limit_up = get_up_down(limit_up_, 1);
|
||||
// rule_stat_.current_value =
|
||||
// mm_vars["tag" + std::to_string(maxIndexValue.first + 1)];
|
||||
|
||||
|
||||
rule_stat_.current_value =
|
||||
std::fabs(mm_vars["tag" + std::to_string(maxIndexValue.first + 1)]);
|
||||
|
||||
|
||||
@ -20,12 +20,12 @@ namespace HoldState {
|
||||
enum class AlarmState { None = 0, DownLower, UpHigher };
|
||||
enum class AlarmType { Warn = 0, Error };
|
||||
struct StateInfo {
|
||||
TimePoint last_start_time = std::chrono::system_clock::now(); ///<上次记录时间
|
||||
TimePoint last_start_time = std::chrono::system_clock::now();
|
||||
AlarmState last_alarm_tate =
|
||||
AlarmState::None; ///<报警状态 未报警,超下限,超上限
|
||||
AlarmType alarm_type = AlarmType::Error; ///<报警类型
|
||||
AlarmState::None;
|
||||
AlarmType alarm_type = AlarmType::Error;
|
||||
};
|
||||
} // namespace HoldState
|
||||
}
|
||||
|
||||
using std::string;
|
||||
class Roller3 : public ExpBase {
|
||||
@ -41,17 +41,17 @@ public:
|
||||
std::vector<AlarmInfo> exec_task(mix_cc::time_range_t time_range) override;
|
||||
|
||||
private:
|
||||
double limit_error_; ///<报警限幅
|
||||
double limit_warn_; ///<警告限幅
|
||||
double median_; ///<中位数
|
||||
vector<double> deviations_; ///<偏差
|
||||
vector<double> values_; ///<最新的值
|
||||
vector<int> tag_seq_; ///< tag序号
|
||||
double limit_error_;
|
||||
double limit_warn_;
|
||||
double median_;
|
||||
vector<double> deviations_;
|
||||
vector<double> values_;
|
||||
vector<int> tag_seq_;
|
||||
string tags_exp_;
|
||||
int value_num_ = 0; ///<对比的数据项个数
|
||||
int value_num_ = 0;
|
||||
vector<int>
|
||||
is_zero_list_; ///<数据是否为0的标记(0-否,1-是),需要剔除为0的数据项
|
||||
std::map<int, HoldState::StateInfo> state_info_map_; ///<各个数据项的报警情况跟踪
|
||||
is_zero_list_;
|
||||
std::map<int, HoldState::StateInfo> state_info_map_;
|
||||
private:
|
||||
int init_X_exp();
|
||||
void print_load_content();
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#include "mix_cc/ihyper_db/read_data_stats.h"
|
||||
/*计算次数,采用6次出现连续3次*/
|
||||
#define CS_AVG_SIZE 6
|
||||
const double MAX_SLOPE = 100000000; ///<用于设置单边区间的无用侧
|
||||
const double MAX_SLOPE = 100000000;
|
||||
|
||||
TrendSlope::TrendSlope(const string name, const mix_cc::json& rule_json,
|
||||
const string ruleId)
|
||||
@ -18,7 +18,8 @@ TrendSlope::TrendSlope(const string name, const mix_cc::json& rule_json,
|
||||
}
|
||||
|
||||
TrendSlope::~TrendSlope() {
|
||||
// AlgBase::~AlgBase();
|
||||
|
||||
|
||||
}
|
||||
|
||||
int TrendSlope::init() {
|
||||
@ -40,12 +41,14 @@ int TrendSlope::init() {
|
||||
.at("value")
|
||||
.get<std::string>());
|
||||
if (limit_slope_ > 0) {
|
||||
// this->rule_stat_.limit_down = -MAX_SLOPE;
|
||||
|
||||
|
||||
this->rule_stat_.limit_down = -32768;
|
||||
this->rule_stat_.limit_up = limit_slope_;
|
||||
} else {
|
||||
this->rule_stat_.limit_down = limit_slope_;
|
||||
// this->rule_stat_.limit_up = MAX_SLOPE;
|
||||
|
||||
|
||||
this->rule_stat_.limit_up = -32768;
|
||||
}
|
||||
this->rule_stat_.current_value = 0;
|
||||
@ -73,7 +76,7 @@ AlarmInfo TrendSlope::exec_mon() {
|
||||
this->refresh_ihd_cache();
|
||||
double avg[CS_AVG_SIZE] = {0.0};
|
||||
double f_slope = 0.0;
|
||||
double f_slope_max = 0; ///<斜率最大值
|
||||
double f_slope_max = 0;
|
||||
try {
|
||||
/* before --> now*/
|
||||
// 检查6个周期的时间内数据的斜率是否小于目标斜率
|
||||
@ -124,14 +127,9 @@ AlarmInfo TrendSlope::exec_mon() {
|
||||
}
|
||||
}
|
||||
|
||||
rule_stat_.current_value = f_slope_max; ///<共享内存
|
||||
// if (limit_slope_ > 0) {
|
||||
// rule_stat_.limit_down = 0;
|
||||
// rule_stat_.limit_up = limit_slope_;
|
||||
// } else {
|
||||
// rule_stat_.limit_down = limit_slope_;
|
||||
// rule_stat_.limit_up = 0;
|
||||
// }
|
||||
rule_stat_.current_value = f_slope_max;
|
||||
|
||||
|
||||
|
||||
if (count_error >= 3) {
|
||||
rule_stat_.alarm_value = rule_stat_.current_value;
|
||||
@ -149,7 +147,8 @@ AlarmInfo TrendSlope::exec_mon() {
|
||||
mix_cc::Exception(-1, "calc error", BOOST_CURRENT_LOCATION));
|
||||
}
|
||||
|
||||
// return AlarmInfo{};
|
||||
|
||||
|
||||
return out_alarm;
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ class TrendSlope : public AlgBase {
|
||||
std::vector<AlarmInfo> exec_task(mix_cc::time_range_t time_range) override;
|
||||
|
||||
private:
|
||||
TimeDur limit_time_interval_; ///<查询ihd 均值数据的时间间隔
|
||||
double limit_slope_; ///<斜率
|
||||
std::string error_content_; ///<报警内容
|
||||
TimeDur limit_time_interval_;
|
||||
double limit_slope_;
|
||||
std::string error_content_;
|
||||
};
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <string>
|
||||
#include <utility/StringHelper.h>
|
||||
#include <vector>
|
||||
// const double MAX_SLOPE = 100000000; ///<用于设置单边区间的无用侧
|
||||
|
||||
|
||||
|
||||
TrendSlope2::TrendSlope2(const string name, const mix_cc::json &rule_json,
|
||||
const string ruleId)
|
||||
@ -17,7 +18,8 @@ TrendSlope2::TrendSlope2(const string name, const mix_cc::json &rule_json,
|
||||
}
|
||||
|
||||
TrendSlope2::~TrendSlope2() {
|
||||
// AlgBase::~AlgBase();
|
||||
|
||||
|
||||
}
|
||||
|
||||
int TrendSlope2::init() {
|
||||
@ -30,7 +32,8 @@ int TrendSlope2::init() {
|
||||
.at("interval_time")
|
||||
.at("value")
|
||||
.get<std::string>());
|
||||
// limit_time_interval_ = seconds(int(interval_time * 60));
|
||||
|
||||
|
||||
limit_time_interval_ = seconds(int(interval_time));
|
||||
if (limit_time_interval_ < seconds(1)) {
|
||||
limit_time_interval_ = seconds(1);
|
||||
@ -62,8 +65,8 @@ int TrendSlope2::init() {
|
||||
.at("value")
|
||||
.get<std::string>());
|
||||
|
||||
this->rule_stat_.limit_down = 0; ///<只显示 true/false 无上下限
|
||||
this->rule_stat_.limit_up = 0; ///<只显示 true/false 无上下限
|
||||
this->rule_stat_.limit_down = 0;
|
||||
this->rule_stat_.limit_up = 0;
|
||||
error_content_ =
|
||||
rule_json_.at("output").at("error").at("value").get<std::string>();
|
||||
logger_->Debug() << "查询均值时间[s]:"
|
||||
@ -83,12 +86,13 @@ int TrendSlope2::init() {
|
||||
AlarmInfo TrendSlope2::exec_mon() {
|
||||
AlarmInfo out_alarm{};
|
||||
int count_error = 0;
|
||||
// this->refresh_now_time();
|
||||
|
||||
|
||||
now_time_ =
|
||||
system_clock::now() - 60s; ///<当前时间 往前1分钟,防止查不到ihd数据
|
||||
system_clock::now() - 60s;
|
||||
vector<double> avg;
|
||||
double f_slope = 0.0;
|
||||
double f_slope_max = 0; ///<斜率最大值
|
||||
double f_slope_max = 0;
|
||||
try {
|
||||
/* before --> now*/
|
||||
// 检查6个周期的时间内数据的斜率是否小于目标斜率
|
||||
@ -107,7 +111,8 @@ AlarmInfo TrendSlope2::exec_mon() {
|
||||
<< mix_cc::mix_time_t(query_time_range_.get_right())
|
||||
.to_formatted_time()
|
||||
<< std::endl;
|
||||
// if (ihd_get_by_tag(m_tags[need_tag_seq_], query_time_range_) != 0) {
|
||||
|
||||
|
||||
if (refresh_ihd_cache(query_time_range_) != 0) {
|
||||
logger_->Error() << rule_name_ << ":ihd查询异常!" << std::endl;
|
||||
return out_alarm;
|
||||
|
||||
@ -43,12 +43,12 @@ public:
|
||||
bool get_prr2();
|
||||
|
||||
private:
|
||||
TimeDur limit_time_interval_; ///<查询ihd 均值数据的时间间隔
|
||||
TimeDur limit_time_interval_;
|
||||
TimeDur deltaX_;
|
||||
double limit_slope_; ///<斜率阈值
|
||||
std::string error_content_; ///<报警内容
|
||||
int CS_AVG_SIZE_; ///<连续出现的次数
|
||||
int need_tag_seq_ = 0; ///<监控变量的位置
|
||||
// private:
|
||||
// int ihd_get_by_tag(string tag, mix_cc::time_range_t time_range);
|
||||
double limit_slope_;
|
||||
std::string error_content_;
|
||||
int CS_AVG_SIZE_;
|
||||
int need_tag_seq_ = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
#include <string>
|
||||
#include <utility/StringHelper.h>
|
||||
#include <vector>
|
||||
// const double MAX_SLOPE = 100000000; ///<用于设置单边区间的无用侧
|
||||
|
||||
|
||||
|
||||
TrendSlope3::TrendSlope3(const string name, const mix_cc::json &rule_json,
|
||||
const string ruleId)
|
||||
@ -17,7 +18,8 @@ TrendSlope3::TrendSlope3(const string name, const mix_cc::json &rule_json,
|
||||
}
|
||||
|
||||
TrendSlope3::~TrendSlope3() {
|
||||
// AlgBase::~AlgBase();
|
||||
|
||||
|
||||
}
|
||||
|
||||
int TrendSlope3::init() {
|
||||
@ -30,7 +32,8 @@ int TrendSlope3::init() {
|
||||
.at("interval_time")
|
||||
.at("value")
|
||||
.get<std::string>());
|
||||
// limit_time_interval_ = seconds(int(interval_time * 60));
|
||||
|
||||
|
||||
limit_time_interval_ = seconds(int(interval_time));
|
||||
if (limit_time_interval_ < seconds(1)) {
|
||||
limit_time_interval_ = seconds(1);
|
||||
@ -77,12 +80,13 @@ int TrendSlope3::init() {
|
||||
AlarmInfo TrendSlope3::exec_mon() {
|
||||
AlarmInfo out_alarm{};
|
||||
int count_error = 0;
|
||||
// this->refresh_now_time();
|
||||
|
||||
|
||||
now_time_ =
|
||||
system_clock::now() - 60s; ///<当前时间 往前1分钟,防止查不到ihd数据
|
||||
system_clock::now() - 60s;
|
||||
vector<double> avg;
|
||||
double f_slope = 0.0;
|
||||
double f_slope_max = 0; ///<斜率最大值
|
||||
double f_slope_max = 0;
|
||||
try {
|
||||
/* before --> now*/
|
||||
auto start_time = now_time_ - this->deltaX_ * CS_AVG_SIZE_;
|
||||
@ -119,7 +123,7 @@ AlarmInfo TrendSlope3::exec_mon() {
|
||||
for (int i = 0; i < CS_AVG_SIZE_ + 1; i++) {
|
||||
if (i > 0) {
|
||||
f_slope =
|
||||
static_cast<int>(1000.0 * (avg[i] - avg[i - 1]) + 0.5); /// delta Y
|
||||
static_cast<int>(1000.0 * (avg[i] - avg[i - 1]) + 0.5);
|
||||
f_slope = f_slope / 1000;
|
||||
if (avg[i - 1] == 0) {
|
||||
f_slope_max =
|
||||
@ -145,7 +149,8 @@ AlarmInfo TrendSlope3::exec_mon() {
|
||||
}
|
||||
}
|
||||
|
||||
// rule_stat_.current_value = f_slope_max; ///<共享内存
|
||||
|
||||
|
||||
|
||||
if (count_error == CS_AVG_SIZE_) {
|
||||
rule_stat_.current_value = 1;
|
||||
@ -165,7 +170,8 @@ AlarmInfo TrendSlope3::exec_mon() {
|
||||
mix_cc::Exception(-1, "calc error", BOOST_CURRENT_LOCATION));
|
||||
}
|
||||
|
||||
// return AlarmInfo{};
|
||||
|
||||
|
||||
return out_alarm;
|
||||
}
|
||||
|
||||
|
||||
@ -42,10 +42,10 @@ public:
|
||||
*/
|
||||
bool get_prr2();
|
||||
private:
|
||||
TimeDur limit_time_interval_; ///<查询ihd 均值数据的时间间隔
|
||||
TimeDur limit_time_interval_;
|
||||
TimeDur deltaX_;
|
||||
double limit_slope_; ///<斜率阈值
|
||||
std::string error_content_; ///<报警内容
|
||||
int CS_AVG_SIZE_; ///<连续出现的次数
|
||||
int need_tag_seq_ = 0; ///<监控变量的位置
|
||||
double limit_slope_;
|
||||
std::string error_content_;
|
||||
int CS_AVG_SIZE_;
|
||||
int need_tag_seq_ = 0;
|
||||
};
|
||||
|
||||
@ -1,20 +1,3 @@
|
||||
// #include <eqpalg/algs/exp.h>
|
||||
// #include <eqpalg/algs/exp_cpc.h>
|
||||
// #include <eqpalg/algs/exp_sample.h>
|
||||
// #include <eqpalg/algs/exp_sample_multi_dim.h>
|
||||
// #include <eqpalg/algs/exp_sample_curve.h>
|
||||
// #include <eqpalg/algs/exp_hs.h>
|
||||
// #include <eqpalg/algs/dist_interval_alg.h>
|
||||
// #include <eqpalg/algs/exp_material.h>
|
||||
// #include <eqpalg/algs/exp_wave.h>
|
||||
// #include <eqpalg/algs/sbreak_position.h>
|
||||
// #include <eqpalg/algs/alarm_monitor.h>
|
||||
// #include <eqpalg/algs/exp_cs.h>
|
||||
// #include <eqpalg/algs/meter_bound.h>
|
||||
// #include <eqpalg/algs/meter_static.h>
|
||||
// #include <eqpalg/algs/table_static.h>
|
||||
// #include <eqpalg/algs/times_stastics.h>
|
||||
// #include <eqpalg/algs/times_stastics_cs.h>
|
||||
#include <eqpalg/algs/roller2.h>
|
||||
#include <eqpalg/algs/trend_slope2.h>
|
||||
#include <eqpalg/build_algorithm.h>
|
||||
@ -54,7 +37,6 @@ std::unique_ptr<AlgBase> build_algorithm(int algId, const string &ruleId,
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
/*故障代码解析*/
|
||||
return std::make_unique<FaultCode>(name, rule_json, ruleId, algId - 10);
|
||||
break;
|
||||
case 12:
|
||||
@ -74,112 +56,6 @@ std::unique_ptr<AlgBase> build_algorithm(int algId, const string &ruleId,
|
||||
case 17:
|
||||
return std::make_unique<ExpBound>(name, rule_json, ruleId, algId);
|
||||
break;
|
||||
// case 18:
|
||||
// return std::make_unique<Roller3>(name, rule_json, ruleId, -3);
|
||||
// break;
|
||||
// case 11:
|
||||
// // return std::make_unique<Torque>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 20:
|
||||
// case 21:
|
||||
// case 220:
|
||||
// case 221:
|
||||
// case 111:
|
||||
// return std::make_unique<Exp>(name, rule_json, ruleId, 1);
|
||||
// break;
|
||||
|
||||
// case 23:
|
||||
// return std::make_unique<ExpMaterial>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 22:
|
||||
// case 25:
|
||||
// case 27:
|
||||
// case 28:
|
||||
// return std::make_unique<ExpSample>(name, rule_json, ruleId, 1,
|
||||
// padding_low, padding_up);
|
||||
// break;
|
||||
// case 30:
|
||||
// // case 230:
|
||||
// return std::make_unique<TrendSlope>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 32:
|
||||
// // return std::make_unique<ExpSampleCurve>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 33: {
|
||||
// int dim = 0;
|
||||
// auto tag1 =
|
||||
// rule_json.at("sample").at("tag_x1").at(1).get<std::string>(); if (tag1
|
||||
// != "null" && !tag1.empty()) {
|
||||
// dim++;
|
||||
// }
|
||||
// auto tag2 =
|
||||
// rule_json.at("sample").at("tag_x2").at(1).get<std::string>(); if (tag2
|
||||
// != "null" && !tag2.empty()) {
|
||||
// dim++;
|
||||
// }
|
||||
// auto tag3 =
|
||||
// rule_json.at("sample").at("tag_x3").at(1).get<std::string>(); if (tag3
|
||||
// != "null" && !tag3.empty()) {
|
||||
// dim++;
|
||||
// }
|
||||
// if (dim == 1) {
|
||||
// return std::make_unique<ExpSampleMultiDim>(name, rule_json, ruleId,
|
||||
// 1,
|
||||
// padding_low, padding_up);
|
||||
// }
|
||||
// if (dim == 2) {
|
||||
// return std::make_unique<ExpSampleMultiDim>(name, rule_json, ruleId,
|
||||
// 2,
|
||||
// padding_low, padding_up);
|
||||
// }
|
||||
// if (dim == 3) {
|
||||
// return std::make_unique<ExpSampleMultiDim>(name, rule_json, ruleId,
|
||||
// 3,
|
||||
// padding_low, padding_up);
|
||||
// }
|
||||
// } break;
|
||||
// case 34:
|
||||
// return std::make_unique<ExpWave>(name, rule_json, ruleId, padding_low,
|
||||
// padding_up);
|
||||
// break;
|
||||
// case 40:
|
||||
// // return std::make_unique<ExpRunStatic>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 50:
|
||||
// return std::make_unique<ExpCpc>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 61:
|
||||
// // return std::make_unique<ExpSampleCurve>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 71:
|
||||
// return std::make_unique<DistInterval>(name, rule_json, ruleId, 1,
|
||||
// padding_low, padding_up);
|
||||
// break;
|
||||
// // case 100:
|
||||
// // return std::make_unique<SBreakPosition>(name, rule_json, ruleId);
|
||||
// // break;
|
||||
// case 113:
|
||||
// return std::make_unique<TimesStastics>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 112:
|
||||
// return std::make_unique<TableStatic>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// case 114:
|
||||
// return std::make_unique<MeterStatic>(name, rule_json, ruleId);
|
||||
// break;
|
||||
// // case 120:
|
||||
// // case 121:
|
||||
// // return std::make_unique<ExpCS>(name, rule_json, ruleId, 1);
|
||||
// // break;
|
||||
// // case 122:
|
||||
// // return std::make_unique<TimesStasticsCS>(name, rule_json, ruleId);
|
||||
// // break;
|
||||
// case 131:
|
||||
// return std::make_unique<MeterBound>(name, rule_json, ruleId, 1);
|
||||
// break;
|
||||
// case 132:
|
||||
// return std::make_unique<AlarmMonitor>(name, rule_json, ruleId, 1);
|
||||
// break;
|
||||
default:
|
||||
d.Warn() << "undefined algorithm" << endl;
|
||||
return std::make_unique<Null>(name, rule_json, ruleId);
|
||||
|
||||
@ -5,23 +5,23 @@ using std::string;
|
||||
using std::vector;
|
||||
enum class ErrorType {
|
||||
Success = 0,
|
||||
Empty = 1, ///<为空
|
||||
EnCodeError = 2, ///<表达式中文或其它字符
|
||||
EqualError = 3, ///<相等应使用"=="而非其他
|
||||
NotEqualError = 4, ///<不等应使用"!="而非其他
|
||||
CalError = 5, ///<计算错误,比如除数是0
|
||||
Empty = 1,
|
||||
EnCodeError = 2,
|
||||
EqualError = 3,
|
||||
NotEqualError = 4,
|
||||
CalError = 5,
|
||||
};
|
||||
enum class ErrorLocation {
|
||||
Success = 0,
|
||||
Tags = 1, ///< tag点异常
|
||||
ExeCyc = 2, ///<执行周期
|
||||
DataSource = 3, ///<数据源
|
||||
DataValue = 4, ///<数据项
|
||||
ActExp = 5, ///<动作表达式
|
||||
HoldOn = 6, ///<动作保持
|
||||
FBExp = 7, ///<反馈表达式
|
||||
ResultExp = 8, ///<监控表达式
|
||||
ResultParam = 9, ///<监控表达式
|
||||
Tags = 1,
|
||||
ExeCyc = 2,
|
||||
DataSource = 3,
|
||||
DataValue = 4,
|
||||
ActExp = 5,
|
||||
HoldOn = 6,
|
||||
FBExp = 7,
|
||||
ResultExp = 8,
|
||||
ResultParam = 9,
|
||||
};
|
||||
|
||||
namespace ErrorCode {
|
||||
@ -35,7 +35,7 @@ const vector<string> ErrorTypeDescription = {"正确",
|
||||
const vector<string> ErrorLocationDescription = {
|
||||
"正确", "tag点异常", "执行周期", "数据源", "数据项",
|
||||
"动作表达式", "动作保持", "反馈表达式", "监控表达式","监控表达式参数"};
|
||||
} // namespace ErrorCode
|
||||
}
|
||||
|
||||
struct ErrorCodeType {
|
||||
ErrorType error_type;
|
||||
|
||||
@ -21,10 +21,10 @@
|
||||
* @brief 进程类型
|
||||
*/
|
||||
enum class ProcessType {
|
||||
kNull = 0, ///< 空进程,由错误的初始化方法得到的进程
|
||||
kMon, ///< 监控进程
|
||||
kCron, ///< 定时任务进程
|
||||
kTask ///< 任务进程
|
||||
kNull = 0,
|
||||
kMon,
|
||||
kCron,
|
||||
kTask
|
||||
};
|
||||
/**
|
||||
* @brief 其他算法与机器学习类算法的临界算法号
|
||||
@ -36,62 +36,58 @@ struct AlgId_ML {
|
||||
* @brief 表达式类型
|
||||
*/
|
||||
struct ExpType {
|
||||
static const int Logic = 1; ///< 逻辑判断
|
||||
static const int Bound = 2; ///< 上下限
|
||||
static const int ActionFeedBack = 3; ///< 动作反馈-逻辑判断
|
||||
static const int CondBound = 4; ///< 条件-上下限
|
||||
static const int BoundHoldTime = 5; ///< 上下限-保持时间
|
||||
static const int HoldTimeAcc = 6; ///<保持时间累计
|
||||
static const int OccTimesAcc = 7; ///<出现次数累计
|
||||
static const int PolyFit = 12; ///< 多项式拟合
|
||||
static const int PEAR = 13; ///< 皮尔逊相关系数监控
|
||||
static const int Trend = -1; ///< Trend 趋势监控
|
||||
static const int OuterPer = 16; ///< 离群百分比阈值
|
||||
static const int OuterAct = 18; ///< 离群实际值阈值
|
||||
static const int Logic = 1;
|
||||
static const int Bound = 2;
|
||||
static const int ActionFeedBack = 3;
|
||||
static const int CondBound = 4;
|
||||
static const int BoundHoldTime = 5;
|
||||
static const int HoldTimeAcc = 6;
|
||||
static const int OccTimesAcc = 7;
|
||||
static const int PolyFit = 12;
|
||||
static const int PEAR = 13;
|
||||
static const int Trend = -1;
|
||||
static const int OuterPer = 16;
|
||||
static const int OuterAct = 18;
|
||||
};
|
||||
/**
|
||||
* @brief 区间模式
|
||||
*/
|
||||
struct DistMode {
|
||||
static const int Manual = 0; ///< 手动
|
||||
static const int Online = 1; ///< 在线
|
||||
static const int Offline = 2; ///< 离线
|
||||
static const int Manual = 0;
|
||||
static const int Online = 1;
|
||||
static const int Offline = 2;
|
||||
};
|
||||
/**
|
||||
* @brief 检测模式
|
||||
*/
|
||||
struct DetectMode {
|
||||
static const int Default = 0; ///<默认 双侧
|
||||
static const int OnlyLeft = 1; ///<只检测左区间
|
||||
static const int OnlyRight = 2; //<只检测右区间
|
||||
static const int ErrorMode = 3; ///<错误模式
|
||||
static const int Default = 0;
|
||||
static const int OnlyLeft = 1;
|
||||
static const int OnlyRight = 2;
|
||||
static const int ErrorMode = 3;
|
||||
};
|
||||
/**
|
||||
* @brief 规则运行前提条件
|
||||
*/
|
||||
struct PRR {
|
||||
static const int None = 0; ///<无
|
||||
static const int Exp = 1; ///<表达式
|
||||
// static const int EntRunning = 1; ///< 酸洗入口运行
|
||||
// static const int ACDRunning = 2; ///< 酸洗中央运行
|
||||
// static const int AXTRunning = 3; ///<酸洗出口运行
|
||||
// static const int TCMRunning = 4; ///<轧机段运行
|
||||
static const int None = 0;
|
||||
static const int Exp = 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
struct StatConst {
|
||||
static const int64_t CronUpdateDelay = 24; ///< 更新统计结果的时间间隔
|
||||
static const int StatClassCount = 50; ///< 样本基本组数
|
||||
static const int64_t CronUpdateDelay = 24;
|
||||
static const int StatClassCount = 50;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 样本类型
|
||||
*/
|
||||
struct SampleType {
|
||||
static constexpr char T_SAMPLE_FIT[] = "T_SAMPLE_FIT"; ///< 2D 线性相关性/拟合
|
||||
static constexpr char T_SAMPLE_STAT[] = "T_SAMPLE_STAT"; ///< 1D 统计
|
||||
static constexpr char T_SAMPLE_FIT[] = "T_SAMPLE_FIT";
|
||||
static constexpr char T_SAMPLE_STAT[] = "T_SAMPLE_STAT";
|
||||
};
|
||||
|
||||
/**
|
||||
@ -105,12 +101,12 @@ struct CreateModels {
|
||||
* @brief 对应控制过程的事件号
|
||||
*/
|
||||
struct EventCase {
|
||||
static const int kDelete = 0; ///< 删除任务
|
||||
static const int kCreate = 1; ///< 创建任务
|
||||
static const int kUpdate = 2; ///< 更新任务
|
||||
static const int kEnable = 3; ///< 启用任务
|
||||
static const int kReset = 4; ///< 重置任务
|
||||
static const int kExec = 10; ///< 单次执行任务
|
||||
static const int kDelete = 0;
|
||||
static const int kCreate = 1;
|
||||
static const int kUpdate = 2;
|
||||
static const int kEnable = 3;
|
||||
static const int kReset = 4;
|
||||
static const int kExec = 10;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -118,8 +114,8 @@ struct EventCase {
|
||||
* 包含IHDB和共享内存
|
||||
*/
|
||||
struct DataSource {
|
||||
static const int16_t IHDB = 0; ///< IHDB
|
||||
static const int16_t MEMORY = 1; ///< 共享内存
|
||||
static const int16_t IHDB = 0;
|
||||
static const int16_t MEMORY = 1;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -147,213 +143,23 @@ struct AlarmInfo {
|
||||
|
||||
~AlarmInfo() {}
|
||||
|
||||
bool alarmed; ///< 是否报警
|
||||
mix_cc::json content; ///<报警内容
|
||||
std::chrono::system_clock::time_point alarm_start_time; ///< 报警开始时间
|
||||
std::chrono::system_clock::time_point alarm_end_time; ///< 报警结束时间
|
||||
bool alarmed;
|
||||
mix_cc::json content;
|
||||
std::chrono::system_clock::time_point alarm_start_time;
|
||||
std::chrono::system_clock::time_point alarm_end_time;
|
||||
/**
|
||||
* @brief 规则配置信息
|
||||
*/
|
||||
struct ConfigInfo {
|
||||
std::string id; ///< 规则id
|
||||
std::string name; ///< 规则名
|
||||
std::string group; ///< 规则组
|
||||
std::string remark; ///< 标记
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string group;
|
||||
std::string remark;
|
||||
std::string descName;
|
||||
};
|
||||
ConfigInfo cfg_info;
|
||||
};
|
||||
|
||||
// /**
|
||||
// * @brief 报表数据
|
||||
// * 弃用
|
||||
// */
|
||||
// struct TableData {
|
||||
// std::string group_name_; ///< cfg 分组名
|
||||
// int rule_nums_; ///<规则数量
|
||||
// std::vector<std::string> rule_ids_; ///<报表涉及的模型id 运行时间
|
||||
// std::vector<std::string> rule_names_; ///<模型名
|
||||
// std::vector<double> running_time_; ///<运行时间 0
|
||||
// std::vector<int> alrm_times_; ///<报警次数 2
|
||||
// std::vector<int> fault_times_; ///<故障次数 1
|
||||
// std::vector<unsigned long> used_times_; ///<使用次数 3
|
||||
// /**
|
||||
// * @brief init_id 初始化
|
||||
// * @param rule_ids My Param doc
|
||||
// * @param rule_names My Param doc
|
||||
// */
|
||||
// void init_id(std::vector<std::string> rule_ids,
|
||||
// std::vector<std::string> rule_names) {
|
||||
// this->rule_ids_ = rule_ids;
|
||||
// this->rule_names_ = rule_names;
|
||||
// this->rule_nums_ = this->rule_ids_.size();
|
||||
// std::vector<std::pair<std::string, std::string>> zipped;
|
||||
// for (size_t i = 0; i < this->rule_nums_; i++) {
|
||||
// zipped.push_back(std::make_pair(rule_ids_[i], rule_names_[i]));
|
||||
// } // Sort the vector of pairs
|
||||
// std::sort(zipped.begin(), zipped.end(),
|
||||
// [](std::pair<std::string, std::string> a,
|
||||
// std::pair<std::string, std::string> b) {
|
||||
// return a.second < b.second;
|
||||
// });
|
||||
// for (size_t i = 0; i < this->rule_nums_; i++) {
|
||||
// this->rule_ids_[i] = zipped[i].first;
|
||||
// this->rule_names_[i] = zipped[i].second;
|
||||
// }
|
||||
// this->running_time_ = std::vector<double>(rule_ids_.size(), 0);
|
||||
// this->alrm_times_ = std::vector<int>(rule_ids_.size(), 0);
|
||||
// this->fault_times_ = std::vector<int>(rule_ids_.size(), 0);
|
||||
// this->used_times_ = std::vector<unsigned long>(rule_ids_.size(), 0);
|
||||
// }
|
||||
|
||||
// void clear_running_time() {
|
||||
// if (!running_time_.empty()) {
|
||||
// running_time_.clear();
|
||||
// }
|
||||
// }
|
||||
// void clear_alrm_times() {
|
||||
// if (!alrm_times_.empty()) {
|
||||
// alrm_times_.clear();
|
||||
// }
|
||||
// }
|
||||
// void clear_fault_times() {
|
||||
// if (!fault_times_.empty()) {
|
||||
// fault_times_.clear();
|
||||
// }
|
||||
// }
|
||||
// void clear_used_times() {
|
||||
// if (!used_times_.empty()) {
|
||||
// used_times_.clear();
|
||||
// }
|
||||
// }
|
||||
// nlohmann::json invert2json() {
|
||||
// nlohmann::json js1;
|
||||
// js1["rule_ids"] = rule_ids_;
|
||||
// js1["rule_names"] = rule_names_;
|
||||
// if (!running_time_.empty()) {
|
||||
// js1["running_time"] = running_time_;
|
||||
// }
|
||||
// if (!alrm_times_.empty()) {
|
||||
// js1["alarm_times"] = alrm_times_;
|
||||
// }
|
||||
// if (!fault_times_.empty()) {
|
||||
// js1["fault_times"] = fault_times_;
|
||||
// }
|
||||
// if (!used_times_.empty()) {
|
||||
// js1["fault_times"] = fault_times_;
|
||||
// }
|
||||
|
||||
// return js1;
|
||||
// }
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * @brief 仪表数据项
|
||||
// *弃用
|
||||
// */
|
||||
// struct MeterData {
|
||||
// std::string group_name_; ///< cfg 分组名
|
||||
// int rule_nums_; ///<规则数量
|
||||
// std::vector<std::string> rule_ids_; ///<报表涉及的模型id 运行时间
|
||||
// std::vector<std::string> rule_names_; ///<模型名
|
||||
// std::vector<double> upL_; ///<报警上限
|
||||
// std::vector<double> downL_; ///<报警下限
|
||||
// std::vector<std::string> latest_alarm_time_; ///<最新一次报警时间
|
||||
|
||||
// /**
|
||||
// * @brief init_id 初始化
|
||||
// * @param rule_ids My Param doc
|
||||
// * @param rule_names My Param doc
|
||||
// */
|
||||
// void init_sort_by_name() {
|
||||
// this->rule_nums_ = this->rule_ids_.size();
|
||||
// std::vector<std::pair<std::string, std::string>> zipped;
|
||||
// for (size_t i = 0; i < this->rule_nums_; i++) {
|
||||
// zipped.push_back(std::make_pair(rule_ids_[i], rule_names_[i]));
|
||||
// } // Sort the vector of pairs
|
||||
// std::sort(zipped.begin(), zipped.end(),
|
||||
// [](std::pair<std::string, std::string> a,
|
||||
// std::pair<std::string, std::string> b) {
|
||||
// return a.second < b.second;
|
||||
// });
|
||||
// for (size_t i = 0; i < this->rule_nums_; i++) {
|
||||
// this->rule_ids_[i] = zipped[i].first;
|
||||
// this->rule_names_[i] = zipped[i].second;
|
||||
// }
|
||||
// this->upL_ = std::vector<double>(rule_ids_.size(), 0);
|
||||
// this->downL_ = std::vector<double>(rule_ids_.size(), 0);
|
||||
// this->latest_alarm_time_ =
|
||||
// std::vector<std::string>(rule_ids_.size(), "无报警");
|
||||
// }
|
||||
|
||||
// void clear_upL() {
|
||||
// if (!this->upL_.empty()) {
|
||||
// this->upL_.clear();
|
||||
// }
|
||||
// }
|
||||
// void clear_downL() {
|
||||
// if (!this->downL_.empty()) {
|
||||
// this->downL_.clear();
|
||||
// }
|
||||
// }
|
||||
// void clear_latest_alarm_time() {
|
||||
// if (!this->latest_alarm_time_.empty()) {
|
||||
// this->latest_alarm_time_.clear();
|
||||
// }
|
||||
// }
|
||||
|
||||
// nlohmann::json invert2json() {
|
||||
// nlohmann::json js1;
|
||||
// js1["rule_ids"] = rule_ids_;
|
||||
// js1["rule_names"] = rule_names_;
|
||||
// if (!upL_.empty()) {
|
||||
// js1["upL"] = upL_;
|
||||
// }
|
||||
// if (!downL_.empty()) {
|
||||
// js1["downL"] = downL_;
|
||||
// }
|
||||
// if (!latest_alarm_time_.empty()) {
|
||||
// js1["latest_alarm_time"] = latest_alarm_time_;
|
||||
// }
|
||||
// return js1;
|
||||
// }
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * @brief RuleStat 内存版
|
||||
// * 弃用
|
||||
// */
|
||||
// struct RuleStat {
|
||||
// double alarm_value;
|
||||
// double limit_up;
|
||||
// double limit_down;
|
||||
// double running_time;
|
||||
// double running_time_th;
|
||||
// double motion_time;
|
||||
// double motion_time_th;
|
||||
// int64_t shear_times;
|
||||
// int64_t alarm_times;
|
||||
// int64_t last_alarm_time;
|
||||
// std::vector<std::string> items;
|
||||
// std::string dev_coder;
|
||||
// nlohmann::json invert2json() {
|
||||
// nlohmann::json js1;
|
||||
// js1["alarm_value"] = alarm_value; ///<实时报警值
|
||||
// js1["limit_up"] = limit_up; ///<上限阈值
|
||||
// js1["limit_down"] = limit_down; ///<下限阈值
|
||||
// js1["running_time"] = running_time; ///<统计的运行时间
|
||||
// js1["running_time_th"] = running_time_th; ///<运行时间阈值
|
||||
// js1["motion_time"] = motion_time; ///<动作时间
|
||||
// js1["motion_time_th"] = motion_time_th; ///<动作时间阈值
|
||||
// js1["shear_times"] = shear_times; ///<剪切次数
|
||||
// js1["alarm_times"] = alarm_times; ///<报警次数
|
||||
// js1["last_alarm_time"] = last_alarm_time; ///<上次报警时间
|
||||
// js1["items"] = items; ///< tag点
|
||||
// js1["dev_coder"] = dev_coder; ///<九位码
|
||||
// return js1;
|
||||
// }
|
||||
// };
|
||||
|
||||
/**
|
||||
* @brief sample2D二维数据 数据结构
|
||||
*
|
||||
|
||||
@ -26,6 +26,5 @@ typedef system_clock::time_point TimePoint;
|
||||
#define TWO_DIM_MIN_FIT_SIZE 100
|
||||
#define THREE_DIM_MIN_FIT_SIZE 240
|
||||
|
||||
// #define MAX_STORAGE_SIZE 10000
|
||||
#define MAX_STORAGE_SIZE 2000
|
||||
#define MIN_STORAGE_SIZE 1000
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
using namespace baosight;
|
||||
|
||||
ProcessType glob_process_type;
|
||||
// CreateModels glob_create_models;
|
||||
|
||||
MIX_CC_TEST_DEBUG_MODE
|
||||
|
||||
@ -53,5 +52,4 @@ int eqpalg::start() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PACE_SERVER_INSTALL(eqpalg) //应用程序主入口,传入参数为定义的类名
|
||||
PACE_PLATFORM_SERVER_INSTALL(eqpalg, APPVERSION);
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
*
|
||||
*/
|
||||
#include <eqpalg/eqpalg_icei.h>
|
||||
// #include <eqpalg/utility/segvCatch.h>///<测试
|
||||
#include <glob/ConnectionMag.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <pace/Component.h>
|
||||
@ -44,8 +43,8 @@ class eqpalg : public Component {
|
||||
virtual int start();
|
||||
|
||||
private:
|
||||
MessageICEPtr eqpalg_server; ///< Ice通信模块
|
||||
std::shared_ptr<ConnectionMag> con_mag_; ///< DB2连接管理器,邹师傅的模块需要
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
MessageICEPtr eqpalg_server;
|
||||
std::shared_ptr<ConnectionMag> con_mag_;
|
||||
std::unique_ptr<LOG> logger_;
|
||||
};
|
||||
};
|
||||
}; // namespace baosight
|
||||
|
||||
@ -36,13 +36,11 @@ EqpAlgICEI::EqpAlgICEI() {
|
||||
if (glob_process_type == ProcessType::kMon) {
|
||||
this->m_proxy2cron = ProxyMag::GetAppICEPrx("baosight/eqpalg-cron");
|
||||
this->m_proxy2dsm = ProxyMag::GetAppICEPrx("baosight/dsm");
|
||||
// this->m_proxy2task = ProxyMag::GetAppICEPrx("baosight/eqpalg-task");
|
||||
logger_->Debug() << "向其cron进程发送ice" << endl;
|
||||
}
|
||||
|
||||
this->is_running_ = true;
|
||||
alg_mgr_ = std::make_unique<AlgorithmManager>(); ///< threads::manager
|
||||
///< 构造,eqpalg程序入口
|
||||
alg_mgr_ = std::make_unique<AlgorithmManager>();
|
||||
if (glob_process_type == ProcessType::kMon) {
|
||||
up_date_data_ptr_ = std::make_unique<UpDateData>();
|
||||
|
||||
@ -50,8 +48,6 @@ EqpAlgICEI::EqpAlgICEI() {
|
||||
// 使用单调时钟
|
||||
auto next_wake_time = std::chrono::steady_clock::now();
|
||||
while (is_running_) {
|
||||
// this->logger_->Debug() << "Test mem_cached_thread_ "
|
||||
// <<binary_tele.size()<< endl;
|
||||
auto t1 = MonotonicClock::now();
|
||||
const auto time_start = system_clock::now();
|
||||
const auto time_starts = std::chrono::steady_clock::now();
|
||||
@ -59,8 +55,6 @@ EqpAlgICEI::EqpAlgICEI() {
|
||||
if (res != 0) {
|
||||
this->logger_->Debug() << "cache_data() return :" << res << endl;
|
||||
}
|
||||
// SingletonTemplate<GlobaltemSharedMemory>::GetInstance().memcache_data(
|
||||
// 2000); ///<随机数测试
|
||||
auto t2 = MonotonicClock::now();
|
||||
const auto time_end = system_clock::now();
|
||||
const auto time_ends = std::chrono::steady_clock::now();
|
||||
@ -86,7 +80,6 @@ EqpAlgICEI::EqpAlgICEI() {
|
||||
// 计算下一次唤醒时间
|
||||
next_wake_time += CACHE_OUTTIME;
|
||||
std::this_thread::sleep_until(next_wake_time);
|
||||
// std::this_thread::sleep_for(CACHE_OUTTIME - time_cost);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -114,7 +107,6 @@ void baosight::EqpAlgICEI::SendDataShort(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq &seq,
|
||||
::Ice::Int length,
|
||||
const Ice::Current ¤t) {
|
||||
// logger_->Info() << "event no:" << eventNo << endl; /* ALARM! */
|
||||
|
||||
// 根据电文号调用,执行分派任务操作
|
||||
switch (eventNo) {
|
||||
@ -123,22 +115,18 @@ void baosight::EqpAlgICEI::SendDataShort(::Ice::Int eventNo,
|
||||
if (glob_process_type == ProcessType::kMon) {
|
||||
logger_->Debug() << "向 baosight/eqpalg-cron进程发送消息" << endl;
|
||||
this->m_proxy2cron->SendDataShort(99999, seq, seq.size());
|
||||
// logger_->Debug() << "向 baosight/eqpalg-task进程发送消息" << endl;
|
||||
// this->m_proxy2task->SendDataShort(99999, seq, seq.size());
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* eventNo=11111 报警信息 */
|
||||
case 11111: {
|
||||
string str(seq.begin(), seq.end());
|
||||
// logger_->Debug() << "seq:" << str << std::endl;
|
||||
alarm_poster_.alarm(str);
|
||||
break;
|
||||
}
|
||||
/* eventNo=22222 规则状态更新 */
|
||||
case 22222: {
|
||||
string str(seq.begin(), seq.end());
|
||||
// logger_->Debug() << "seq:" << str << std::endl;
|
||||
alg_mgr_->rule_handelr(str);
|
||||
break;
|
||||
}
|
||||
@ -158,12 +146,11 @@ void baosight::EqpAlgICEI::TimeNotify(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq &seq,
|
||||
const Ice::Current ¤t) {
|
||||
if (eventNo == 1) {
|
||||
// up_date_data_ptr_->update_item_data(); ///< fdaaitem数据更新
|
||||
up_date_data_ptr_->update_eqp_status(); ///<设备运行状态更新
|
||||
up_date_data_ptr_->update_eqp_status();
|
||||
|
||||
} else if (eventNo == 2 && !is_rule_stat_data_updating_) {
|
||||
is_rule_stat_data_updating_ = true;
|
||||
up_date_data_ptr_->update_rule_stat_data(); ///< rule_stat 规则shm数据
|
||||
up_date_data_ptr_->update_rule_stat_data();
|
||||
is_rule_stat_data_updating_ = false;
|
||||
}
|
||||
if (eventNo == 5) {
|
||||
@ -173,7 +160,6 @@ void baosight::EqpAlgICEI::TimeNotify(::Ice::Int eventNo,
|
||||
(unsigned char *)Jvalue.c_str() +
|
||||
Jvalue.length());
|
||||
this->m_proxy2dsm->SendDataShort(99999, seq, Jvalue.length());
|
||||
// logger_->Debug() << "send data to dsm" << std::endl;
|
||||
logger_->Info() << "data size:"
|
||||
<< SingletonTemplate<GlobaltemSharedMemory>::GetInstance()
|
||||
.get_data_size()
|
||||
@ -184,6 +170,4 @@ void baosight::EqpAlgICEI::TimeNotify(::Ice::Int eventNo,
|
||||
logger_->Error() << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// logger_->Debug() << eventNo << "----Test----" << endl;
|
||||
}
|
||||
|
||||
@ -15,12 +15,10 @@
|
||||
#include <eqpalg/algorithm_manager.h>
|
||||
#include <eqpalg/utility/update_data.h>
|
||||
#include <proxy/MessageICE.h>
|
||||
// #include <shm/RuleStatShm.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
/* Equipment object .h file define here */
|
||||
#include <eqpalg/alg_base.h>
|
||||
#include<eqpalg/utility/alarm_poster.h>
|
||||
namespace baosight {
|
||||
@ -56,17 +54,16 @@ public:
|
||||
const Ice::Current &);
|
||||
|
||||
private:
|
||||
std::unique_ptr<AlgorithmManager> alg_mgr_; ///< 算法管理器
|
||||
std::unique_ptr<std::thread> mem_cached_thread_; ///< 更新共享内存的线程
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
bool is_running_; ///< 程序是否在运行
|
||||
std::unique_ptr<UpDateData> up_date_data_ptr_; ///<更新数据
|
||||
MessageICEPrx m_proxy2cron; ///< mon 向cron发送
|
||||
MessageICEPrx m_proxy2dsm; ///< mon 向dsm发送最新的ruleid
|
||||
std::unique_ptr<AlgorithmManager> alg_mgr_;
|
||||
std::unique_ptr<std::thread> mem_cached_thread_;
|
||||
std::unique_ptr<LOG> logger_;
|
||||
bool is_running_;
|
||||
std::unique_ptr<UpDateData> up_date_data_ptr_;
|
||||
MessageICEPrx m_proxy2cron;
|
||||
MessageICEPrx m_proxy2dsm;
|
||||
bool is_rule_stat_data_updating_ =
|
||||
false; ///< update_rule_stat_data 是否更新中
|
||||
// MessageICEPrx m_proxy2task; ///< mon 向task发送
|
||||
utility::AlarmPoster alarm_poster_; ///< 发送报警信息
|
||||
false;
|
||||
utility::AlarmPoster alarm_poster_;
|
||||
};
|
||||
|
||||
} // namespace baosight
|
||||
}
|
||||
|
||||
@ -97,4 +97,4 @@ int LSM::get_order_best() {
|
||||
return this->order_best;
|
||||
}
|
||||
|
||||
}; // namespace DAA
|
||||
};
|
||||
|
||||
@ -63,4 +63,4 @@ class LSM {
|
||||
int order_best = 1;
|
||||
};
|
||||
|
||||
}; // namespace DAA
|
||||
};
|
||||
|
||||
@ -30,12 +30,9 @@ double limit_precision(double data, int precision) {
|
||||
return std::round(data * factor) / factor;
|
||||
}
|
||||
int64_t double2int64_t(double data, bool is_need) {
|
||||
// return is_need ? int64_t(limit_precision(data) * 100) :
|
||||
// int64_t(limit_precision(data));
|
||||
return int64_t(100 * limit_precision(data));
|
||||
}
|
||||
double int64_t2double(int64_t data, bool is_need) {
|
||||
// return is_need ? (limit_precision(double(data) / 100.00)) : double(data);
|
||||
return (limit_precision(double(data) / 100.00));
|
||||
}
|
||||
|
||||
@ -58,7 +55,7 @@ STA::STA(const string &ruleid, const string &rulename) : rule_id_(ruleid) {
|
||||
logger_ = std::make_unique<LOG>("STA:" + rulename);
|
||||
this->running_stat_.clear();
|
||||
init();
|
||||
this->get_seq(); ///< seq_初始化
|
||||
this->get_seq();
|
||||
logger_->Debug() << "is_init_:" << is_init_ << endl;
|
||||
}
|
||||
|
||||
@ -69,7 +66,6 @@ size_t STA::size() { return dist_data_.size(); }
|
||||
bool STA::init(double range, double init_value) {
|
||||
range_ = limit_precision(range, 1);
|
||||
init_value_ = limit_precision(init_value);
|
||||
// is_need_ = (range_ > 1) ? false : true;
|
||||
is_need_ = true;
|
||||
is_init_ = true;
|
||||
T_RULE_SAMPLE_1D_INFO tci;
|
||||
@ -156,9 +152,6 @@ void STA::init() {
|
||||
limit_precision(arith_seq(init_value_, range_, info2[i].X1)),
|
||||
is_need_);
|
||||
dist_data_[map_key] = info2[i].Count;
|
||||
// logger_->Debug() << "data:" << info2[i].X1 << ",key:" << map_key
|
||||
// << ",a0:" << init_value_ << ",range:" << range_
|
||||
// << endl;
|
||||
}
|
||||
} else {
|
||||
logger_->Info() << "STA::init(),T_RULE_SAMPLE_1D 为空!" << endl;
|
||||
@ -220,23 +213,23 @@ int STA::update_ci_dist() {
|
||||
double dump_size = this->running_stat_.current_n();
|
||||
if (dump_size > 3) {
|
||||
this->scale_ = (double)this->k_dest_dump_size / dump_size;
|
||||
vector<double> data_value; ///<解压缩后的数据
|
||||
vector<double> data_value;
|
||||
for (auto item : this->sample_1d_data_) {
|
||||
int count_now = std::ceil(
|
||||
scale_ * item.Count); //根据该条记录的频次 得到解压到数据个数
|
||||
scale_ * item.Count);
|
||||
for (int i = 0; i < count_now; i++) {
|
||||
data_value.push_back(
|
||||
RandMinMax(item.X1 - range_, item.X1 + range_));
|
||||
}
|
||||
}
|
||||
std::sort(data_value.begin(), data_value.end()); ///< 从小到大排序
|
||||
std::sort(data_value.begin(), data_value.end());
|
||||
logger_->Debug() << "解压后数据量:" << data_value.size() << endl;
|
||||
this->dist_1d_.auto_test(this->running_stat_, data_value);
|
||||
if (this->dist_1d_.valid()) {
|
||||
dist_range_ci_ = this->dist_1d_.get_range();
|
||||
res +=
|
||||
this->update_t_rule_sample_feature(); ///< 更新T_RULE_SAMPLE_FEATURE
|
||||
res += this->update_t_sample_record(); ///<更新 T_SAMPLE_RECORD
|
||||
this->update_t_rule_sample_feature();
|
||||
res += this->update_t_sample_record();
|
||||
} else {
|
||||
logger_->Debug() << "区间不合法!" << endl;
|
||||
res = -1;
|
||||
@ -299,14 +292,14 @@ int STA::update_t_rule_sample_feature() {
|
||||
|
||||
int STA::update_t_sample_record() {
|
||||
try {
|
||||
this->update_t_sample_mag(); ///<更新 json
|
||||
this->update_t_sample_mag();
|
||||
this->sample_stat_.init_value = this->init_value_;
|
||||
this->sample_stat_.range = this->range_;
|
||||
auto js1 = this->sample_stat_.invert2json();
|
||||
this->seq_++;
|
||||
js1["seq"] = this->seq_;
|
||||
int seq = this->seq_ % 30;
|
||||
string reSult = js1.dump(); ///< result字段内容
|
||||
string reSult = js1.dump();
|
||||
T_SAMPLE_RECORD tsr;
|
||||
auto res = exec<db2_t, size_t>(
|
||||
update(tsr)
|
||||
|
||||
@ -22,17 +22,14 @@ struct DoubleBufferArrays {
|
||||
read_array.resize(size);
|
||||
write_array.resize(size);
|
||||
}
|
||||
// 交换缓冲区
|
||||
void swap_buffers() { std::swap(read_array, write_array); }
|
||||
|
||||
// 安全获取当前写入map的引用
|
||||
std::vector<double>& get_write_array() { return write_array; }
|
||||
};
|
||||
bool data_updated = false;
|
||||
DoubleBufferArrays buffer_arrays;
|
||||
std::unordered_map<std::string, size_t> index_map;
|
||||
std::shared_mutex buffer_mutex; // 保护缓冲区交换的互斥锁
|
||||
} // namespace
|
||||
}
|
||||
|
||||
// 在类外定义并初始化静态成员变量(必须)
|
||||
int GlobaltemSharedMemory::instanceCount = 0;
|
||||
@ -68,7 +65,7 @@ GlobaltemSharedMemory::GlobaltemSharedMemory() {
|
||||
double GlobaltemSharedMemory::operator[](std::string tag_name) {
|
||||
// 直接读取前端缓冲区,无需加锁
|
||||
if (!data_updated) {
|
||||
return 0.0; // 或者返回默认值
|
||||
return 0.0;
|
||||
}
|
||||
const auto& read_array = buffer_arrays.read_array;
|
||||
auto it = index_map.find(tag_name);
|
||||
@ -76,13 +73,12 @@ double GlobaltemSharedMemory::operator[](std::string tag_name) {
|
||||
size_t index_value = it->second;
|
||||
return index_value < data_size_ ? read_array[index_value] : 0;
|
||||
}
|
||||
return 0.0; // 或者返回默认值
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// 从共享内存缓存数据到写入缓冲区
|
||||
int GlobaltemSharedMemory::cache_data() {
|
||||
try {
|
||||
// 获取写入缓冲区的引用
|
||||
auto& write_array = buffer_arrays.get_write_array();
|
||||
// 为共享内存中的数据添加机组号前缀
|
||||
size_t index_value = 0;
|
||||
|
||||
@ -13,8 +13,6 @@
|
||||
#include <eqpalg/define/public.h>
|
||||
#include <glob/BinaryTele.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
// #include <shm/RuleStatShm.h>
|
||||
// #include <zlib/MemCachedClient.h>
|
||||
#include <zlib/MemVar.h>
|
||||
#include <zlib/zoneDef.h>
|
||||
#include <array>
|
||||
@ -53,7 +51,7 @@ struct GlobaltemSharedMemory {
|
||||
int get_data_size();
|
||||
|
||||
private:
|
||||
static int instanceCount; // 声明静态成员变量
|
||||
static int instanceCount;
|
||||
|
||||
public:
|
||||
static int get_instanceCount();
|
||||
@ -68,6 +66,6 @@ struct GlobaltemSharedMemory {
|
||||
|
||||
BinaryTele binary_tele{CMemVar::Const()->event_eis_start, "T_LOV_FDAAITEM"};
|
||||
map<int, CMemFix<PLC_DATA>*> m_mapfix;
|
||||
size_t data_size_ = 0; ///<数据点个数
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
size_t data_size_ = 0;
|
||||
std::unique_ptr<LOG> logger_;
|
||||
};
|
||||
|
||||
@ -23,11 +23,11 @@
|
||||
*/
|
||||
class GbLogger {
|
||||
private:
|
||||
std::unique_ptr<LOG> gb_logger_; // 全局logger
|
||||
std::unique_ptr<LOG> local_logger_; // 本地logger
|
||||
std::unique_ptr<LOG> gb_logger_;
|
||||
std::unique_ptr<LOG> local_logger_;
|
||||
|
||||
std::string rule_id_; ///<规则id
|
||||
std::string rule_name_; ///<规则名
|
||||
std::string rule_id_;
|
||||
std::string rule_name_;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// #include <eqpalg/gb_item_memory.h>
|
||||
#include "mix_cc/exception.h"
|
||||
#include <eqpalg/threads/handler_exec.h>
|
||||
#include <regex>
|
||||
@ -6,16 +5,12 @@
|
||||
#include <zlib/MemVar.h>
|
||||
#define MON_CALL_MAX_COST 20ms
|
||||
extern ProcessType glob_process_type;
|
||||
// const std::vector<int> do_not_stop_alg = {1111, 1110}; ///<不停机算法号
|
||||
namespace threads {
|
||||
// 在类外定义并初始化静态成员变量(必须)
|
||||
int HandlerExec::instanceCount = 0;
|
||||
HandlerExec::HandlerExec(const string &alg_name) {
|
||||
++instanceCount;
|
||||
// 创建logger
|
||||
this->logger_ = std::make_unique<LOG>(string("HandlerExec") + alg_name);
|
||||
this->thread_name_ = "alg_" + alg_name;
|
||||
// 如果是单次执行,
|
||||
if (glob_process_type == ProcessType::kTask) {
|
||||
this->thread_name_ += "_task";
|
||||
} else if (glob_process_type == ProcessType::kCron) {
|
||||
@ -24,10 +19,6 @@ HandlerExec::HandlerExec(const string &alg_name) {
|
||||
this->alg_id_ = stoi(alg_name);
|
||||
logger_->Debug() << "alg_name:" << alg_name << ",alg_id:" << alg_id_ << endl;
|
||||
is_running_ = true;
|
||||
// is_line_stop_ = true; ///< 初始化机组状态为停机状态
|
||||
// if (this->alg_id_ > 1110) {
|
||||
// is_line_stop_ = false; ///< 初始化机组状态为开机机状态
|
||||
// }
|
||||
}
|
||||
|
||||
HandlerExec::~HandlerExec() {
|
||||
@ -37,20 +28,6 @@ HandlerExec::~HandlerExec() {
|
||||
r_thread_->join();
|
||||
}
|
||||
logger_->Debug() << "HandlerExec::~HandlerExec()" << endl;
|
||||
// if (glob_process_type == ProcessType::kCron) {
|
||||
// if (this->alg_id_ == 221 || this->alg_id_ == 220 || this->alg_id_ == 251
|
||||
// ||
|
||||
// this->alg_id_ == 250 || this->alg_id_ == 331 || this->alg_id_ == 330)
|
||||
// {
|
||||
// if (r_thread_->joinable()) {
|
||||
// r_thread_->join();
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (r_thread_->joinable()) {
|
||||
// r_thread_->join();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
std::thread::id HandlerExec::run_thread() {
|
||||
@ -68,7 +45,6 @@ std::thread::id HandlerExec::run_thread() {
|
||||
try {
|
||||
this->event_handler();
|
||||
{
|
||||
// task 进程
|
||||
if (glob_process_type == ProcessType::kTask) {
|
||||
for (auto &x : this->rule_pointers_) {
|
||||
x.second->logReset(task_seq * 10 + x.second->get_data_source());
|
||||
@ -81,7 +57,6 @@ std::thread::id HandlerExec::run_thread() {
|
||||
this->rule_pointers_.erase(x.first);
|
||||
}
|
||||
}
|
||||
// this->is_running_ = false;
|
||||
}
|
||||
if (glob_process_type == ProcessType::kCron) {
|
||||
for (auto &x : this->rule_pointers_) {
|
||||
@ -117,8 +92,6 @@ std::thread::id HandlerExec::run_thread() {
|
||||
}
|
||||
}
|
||||
if (glob_process_type == ProcessType::kMon) {
|
||||
// std::this_thread::sleep_for(1ms);//
|
||||
// 极短的sleep,兼顾响应性和CPU占用
|
||||
if (std::chrono::milliseconds(cost_time) > MON_CALL_MAX_COST) {
|
||||
next_wake_time = std::chrono::steady_clock::now();
|
||||
} else {
|
||||
@ -138,49 +111,11 @@ std::thread::id HandlerExec::run_thread() {
|
||||
this->logger_->Error() << "未知异常" << std::endl;
|
||||
}
|
||||
}
|
||||
this->rule_pointers_.clear(); // is_running_ = false 跳出循环,准备析构
|
||||
this->rule_pointers_.clear();
|
||||
});
|
||||
return r_thread_->get_id();
|
||||
}
|
||||
|
||||
// bool HandlerExec::look_is_cron_run() { return this->is_cron_run_; }
|
||||
// void HandlerExec::set_is_cron_run(bool is_cron_run) {
|
||||
// this->is_cron_run_ = is_cron_run;
|
||||
// }
|
||||
// bool HandlerExec::look_is_cron_run() {
|
||||
// bool all_is_run = true;
|
||||
// if (!this->rule_pointers_.empty()) {
|
||||
// for (auto& x : this->rule_pointers_) {
|
||||
// all_is_run = all_is_run && (x.second->get_is_cron_run());
|
||||
// }
|
||||
// return all_is_run;
|
||||
// } else {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// bool HandlerExec::look_is_pause() { return this->is_line_stop_; }
|
||||
// int HandlerExec::pause() {
|
||||
// // if (std::find(do_not_stop_alg.cbegin(), do_not_stop_alg.cend(),
|
||||
// // this->alg_id_) == do_not_stop_alg.cend()) {
|
||||
// // this->is_line_stop_ = true;
|
||||
// // }
|
||||
// this->is_line_stop_ = true;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// int HandlerExec::unpause() {
|
||||
// // 重置上次报警时间 屏蔽开机前几分钟的报警
|
||||
// std::lock_guard<std::mutex> guard(mutex_);
|
||||
// if (!this->rule_pointers_.empty() && this->is_line_stop_) {
|
||||
// for (auto& x : this->rule_pointers_) {
|
||||
// x.second->set_last_alarm_time(system_clock::now());
|
||||
// }
|
||||
// }
|
||||
// this->is_line_stop_ = false;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
std::vector<std::string> HandlerExec::get_rule_ids() {
|
||||
std::vector<std::string> ret;
|
||||
for (auto &x : rule_pointers_) {
|
||||
@ -254,24 +189,10 @@ int HandlerExec::event_handler() {
|
||||
logger_->Info() << "删除算法:" << detach_rule_id << std::endl;
|
||||
detach_queue_.pop();
|
||||
rule_pointers_.erase(detach_rule_id);
|
||||
// 删除统计的样本rs(数字特征,包括均值方差标准差等)--已弃用
|
||||
// try {
|
||||
// string ss0 = "rm /users/dsc/stat_data/" + detach_rule_id + "_0.dat";
|
||||
// system(ss0.c_str());
|
||||
// string ss1 = "rm /users/dsc/stat_data/" + detach_rule_id + "_1.dat";
|
||||
// system(ss1.c_str());
|
||||
// string ss2 = "rm /users/dsc/stat_data/" + detach_rule_id + "_2.dat";
|
||||
// system(ss2.c_str());
|
||||
// } catch (...) {
|
||||
// this->logger_->Debug() << "system(ss.c_str()) 失败!" << std::endl;
|
||||
// }
|
||||
|
||||
logger_->Info() << "删除算法完成" << detach_rule_id << std::endl;
|
||||
}
|
||||
while (!attach_queue_.empty()) {
|
||||
// if (attach_queue_.front()->get_usable()) {
|
||||
// attach_queue_.front()->init();
|
||||
// }
|
||||
auto pointer = std::move(attach_queue_.front());
|
||||
attach_queue_.pop();
|
||||
auto rule_id = pointer->get_rule_id();
|
||||
@ -280,7 +201,6 @@ int HandlerExec::event_handler() {
|
||||
rule_pointers_.emplace(std::make_pair(rule_id, std::move(pointer)));
|
||||
logger_->Info() << "添加算法完成" << std::endl;
|
||||
} else {
|
||||
// rule_pointers_.erase(rule_id);
|
||||
logger_->Info() << "更新算法:" << pointer->get_rule_name() << std::endl;
|
||||
rule_pointers_[rule_id] = std::move(pointer);
|
||||
}
|
||||
@ -295,7 +215,6 @@ int HandlerExec::event_handler() {
|
||||
} else {
|
||||
logger_->Info() << "停用算法:" << rule_id << std::endl;
|
||||
}
|
||||
// logger_->Info() << "启用算法:" << rule_id << std::endl;
|
||||
rule_pointers_[std::get<0>(usable_q)]->set_usable(std::get<1>(usable_q));
|
||||
logger_->Info() << "algbase的is_usable_:"
|
||||
<< rule_pointers_[std::get<0>(usable_q)]->get_usable()
|
||||
@ -333,7 +252,6 @@ void HandlerExec::update_limit_alarm(std::string ruleid, double lb, double ub,
|
||||
}
|
||||
|
||||
int HandlerExec::extractCTaskNumberRegexGeneric(std::string input) {
|
||||
// 匹配任意位置的数字部分,但通过贪婪匹配获取最后一个
|
||||
std::regex pattern(R"((\d+))");
|
||||
std::sregex_iterator begin(input.begin(), input.end(), pattern);
|
||||
std::sregex_iterator end;
|
||||
@ -354,4 +272,5 @@ int HandlerExec::extractCTaskNumberRegexGeneric(std::string input) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace threads
|
||||
}
|
||||
|
||||
|
||||
@ -162,28 +162,25 @@ public:
|
||||
private:
|
||||
static int instanceCount; // 声明静态成员变量
|
||||
private:
|
||||
int alg_id_; ///< 算法id
|
||||
bool is_running_; ///< 当前线程是否运行
|
||||
string thread_name_; ///< 当前线程名称
|
||||
// std::map<string, std::unique_ptr<AlgBase>>
|
||||
// rule_pointers_; ///< 规则指针,同一个[algid+数据源]下的所有算法
|
||||
int alg_id_;
|
||||
bool is_running_;
|
||||
string thread_name_;
|
||||
std::unordered_map<string, std::unique_ptr<AlgBase>>
|
||||
rule_pointers_; ///< 规则指针,同一个[algid+数据源]下的所有算法
|
||||
rule_pointers_;
|
||||
std::map<string, mix_cc::time_range_t>
|
||||
time_ranges_; ///< task保存的时间范围信息
|
||||
std::mutex mutex_; ///< mutex
|
||||
// 用来执行各种操作的的队列
|
||||
std::queue<std::unique_ptr<AlgBase>> attach_queue_; ///< 新增算法的队列
|
||||
std::queue<std::string> detach_queue_; ///< 删除算法的队列
|
||||
std::queue<std::string> reset_queue_; ///< 重置统计数的算法的队列
|
||||
time_ranges_;
|
||||
std::mutex mutex_;
|
||||
std::queue<std::unique_ptr<AlgBase>> attach_queue_;
|
||||
std::queue<std::string> detach_queue_;
|
||||
std::queue<std::string> reset_queue_;
|
||||
std::queue<std::tuple<std::string, bool>>
|
||||
usable_queue_; ///< 设置算法可用性的队列
|
||||
usable_queue_;
|
||||
std::queue<std::tuple<std::unique_ptr<AlgBase>, mix_cc::time_range_t>>
|
||||
once_exec_queue_; ///< task单次执行的队列
|
||||
once_exec_queue_;
|
||||
|
||||
TimePoint run_t1; //
|
||||
TimePoint run_t1;
|
||||
TimePoint run_t2;
|
||||
int64_t cost_time = 0;
|
||||
};
|
||||
|
||||
} // namespace threads
|
||||
}
|
||||
|
||||
@ -10,13 +10,12 @@ namespace threads {
|
||||
* 只读
|
||||
*/
|
||||
namespace {
|
||||
const int AlarmLen = 4000; ///<报警信息的最大长度
|
||||
const int AlarmMaxSize = 10000; ///<报警信息队列容量
|
||||
const int AlarmLen = 4000;
|
||||
const int AlarmMaxSize = 10000;
|
||||
typedef char AlarmJsonData[AlarmLen];
|
||||
// CMemQueue<AlarmJsonData> alarm_json_data_ = CMemQueue<AlarmJsonData>("2012");
|
||||
CMemQueue<AlarmJsonData> alarm_json_data_ = CMemQueue<AlarmJsonData>("ZONE0");
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
Manager::Manager()
|
||||
: is_running_(true), is_start_(false),
|
||||
@ -133,7 +132,7 @@ int Manager::start() {
|
||||
x.first)); //运行具体的算法线程
|
||||
}
|
||||
}
|
||||
this->is_start_ = true; ///<算法线程已启动标记
|
||||
this->is_start_ = true;
|
||||
thread_num_ = this->handles_.size();
|
||||
return res;
|
||||
}
|
||||
@ -167,21 +166,15 @@ int Manager::reset(const string &ruleId) {
|
||||
}
|
||||
|
||||
int Manager::detach(const string &ruleId) {
|
||||
// std::lock_guard<std::mutex> guard(r_mutex_); //有修改操作 2022-1-18
|
||||
try {
|
||||
// 找到算法id对应的线程名
|
||||
auto alg_thread_name = rule_alg_id_mapping_[ruleId];
|
||||
auto iter = handles_.find(alg_thread_name);
|
||||
// 如果找的到对应的算法
|
||||
if (iter != handles_.end()) {
|
||||
// detach对应的算法
|
||||
iter->second->detach(ruleId);
|
||||
if (iter->second->size() == 0) {
|
||||
// 如果当前线程算法实例数量为0,则结束当前线程
|
||||
this->detach_full_alg(alg_thread_name);
|
||||
}
|
||||
}
|
||||
// 抹除对应关系
|
||||
rule_alg_id_mapping_.erase(alg_thread_name);
|
||||
logger_->Debug() << "detach instance complete" << endl;
|
||||
} catch (const std::exception &e) {
|
||||
@ -199,12 +192,10 @@ int Manager::exec_task(std::string ruleId, TimePoint time_start,
|
||||
padding_up);
|
||||
ptr->init();
|
||||
|
||||
/*线程号:算法号_数据源_线程序号*/
|
||||
auto alg_thread_name = std::to_string(alg_id) + "_" +
|
||||
std::to_string(ptr->get_data_source()) + "_" +
|
||||
std::to_string(task_seq); ///<添加 task_seq
|
||||
std::to_string(task_seq);
|
||||
logger_->Debug() << "线程id:" << alg_thread_name << endl;
|
||||
// 如果找不到对应算法的线程,则新建线程
|
||||
std::unique_lock write_lock(handles_mutex);
|
||||
if (handles_.find(alg_thread_name) == handles_.end()) {
|
||||
logger_->Debug() << "线程id:" << alg_thread_name << " not found,to create!"
|
||||
@ -216,18 +207,13 @@ int Manager::exec_task(std::string ruleId, TimePoint time_start,
|
||||
}
|
||||
handles_[alg_thread_name]->submit(std::move(ptr), time_start, time_end);
|
||||
logger_->Info() << "exec submit done" << endl;
|
||||
// logger_->Info() << "handles_.clear()" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Manager::enable(std::string ruleId, bool usable) {
|
||||
// std::lock_guard<std::mutex> guard(r_mutex_); //有修改操作 2022-1-18
|
||||
// 找到对应算法的线程,启用/停用对应的算法
|
||||
auto alg_id_iter = rule_alg_id_mapping_.find(ruleId);
|
||||
// 如果找得到对应的算法线程,在线程中寻找对应的实例
|
||||
if (alg_id_iter != rule_alg_id_mapping_.end()) {
|
||||
auto handle_iter = this->handles_.find(alg_id_iter->second);
|
||||
// 如果找得到对应的实例
|
||||
if (handle_iter != this->handles_.end()) {
|
||||
handle_iter->second->set_usable(ruleId, usable);
|
||||
}
|
||||
@ -257,7 +243,6 @@ int Manager::delete_instance(std::string ruleId) {
|
||||
}
|
||||
|
||||
int Manager::build_alg_to_handle(const string &ruleId) {
|
||||
// 构建算法
|
||||
auto[algId, name, rule_json, usable, padding_low, padding_up, task_seq] =
|
||||
stored_cfg_data_.find(ruleId)->second;
|
||||
int data_source = 0;
|
||||
@ -275,34 +260,28 @@ int Manager::build_alg_to_handle(const string &ruleId) {
|
||||
if (usable) {
|
||||
ptr->init();
|
||||
} else {
|
||||
ptr->AlgBase::init(); ///<提供页面数据(items)
|
||||
ptr->AlgBase::init();
|
||||
}
|
||||
ptr->set_usable(usable);
|
||||
|
||||
/*线程号:算法号_数据源_线程序号*/
|
||||
auto alg_thread_name = std::to_string(algId) + "_" +
|
||||
std::to_string(data_source) + "_" +
|
||||
std::to_string(task_seq); ///<添加task_seq
|
||||
// 查找
|
||||
std::to_string(task_seq);
|
||||
auto iter = handles_.find(alg_thread_name);
|
||||
if (iter == handles_.end()) {
|
||||
// 如果找不到对应的算法句柄,新建
|
||||
auto exec_handler = std::make_unique<HandlerExec>(alg_thread_name);
|
||||
exec_handler->attach(std::move(ptr));
|
||||
if (this->is_start_) {
|
||||
tid_2_thread_name_.push_back(
|
||||
std::make_tuple(exec_handler->run_thread(),
|
||||
alg_thread_name)); //运行具体的算法线程
|
||||
alg_thread_name));
|
||||
this->logger_->Debug() << "开启新线程:" << alg_thread_name << std::endl;
|
||||
}
|
||||
handles_.emplace(make_pair(alg_thread_name, std::move(exec_handler)));
|
||||
} else {
|
||||
// 否则向已有的算法句柄中插入
|
||||
iter->second->attach(std::move(ptr));
|
||||
}
|
||||
// 将算法句柄的对应关系插入到对应关系map中
|
||||
rule_alg_id_mapping_.insert(make_pair(ruleId, alg_thread_name));
|
||||
// }
|
||||
thread_num_ = this->handles_.size();
|
||||
return 0;
|
||||
}
|
||||
@ -310,11 +289,8 @@ int Manager::build_alg_to_handle(const string &ruleId) {
|
||||
int Manager::detach_full_alg(std::string alg_thread_name) {
|
||||
try {
|
||||
auto iter = handles_.find(alg_thread_name);
|
||||
// 如果存在该线程
|
||||
if (iter != handles_.end()) {
|
||||
// 调用取消
|
||||
iter->second->destroy();
|
||||
// 设置active为false
|
||||
handles_.erase(alg_thread_name);
|
||||
}
|
||||
logger_->Debug() << "detach full alg complete" << endl;
|
||||
@ -345,4 +321,4 @@ void Manager::update_limit_alarm(std::string ruleid, double lb, double ub,
|
||||
|
||||
int Manager::get_thread_size() { return thread_num_; }
|
||||
|
||||
} // namespace threads
|
||||
}
|
||||
|
||||
@ -38,25 +38,25 @@ public:
|
||||
protected:
|
||||
std::map<std::string, std::tuple<int, std::string, mix_cc::json, bool, double,
|
||||
double, int>>
|
||||
stored_cfg_data_; ///< 存储的配置信息,用于初始化单次执行信息和重新载入算法时组织信息
|
||||
stored_cfg_data_;
|
||||
|
||||
std::vector<std::tuple<std::thread::id, std::string>>
|
||||
tid_2_thread_name_; ///< 进程id到进程名的关系
|
||||
tid_2_thread_name_;
|
||||
|
||||
bool is_running_; ///< 是否正在运行
|
||||
bool is_start_; ///< 是否调用了start
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
std::unique_ptr<LOG> alarm_logger_; ///< 本地alarm_logger_
|
||||
map<string, string> rule_alg_id_mapping_; ///< id和规则的对应关系
|
||||
std::shared_mutex handles_mutex; // 针对handles_的互斥锁
|
||||
bool is_running_;
|
||||
bool is_start_;
|
||||
std::unique_ptr<LOG> logger_;
|
||||
std::unique_ptr<LOG> alarm_logger_;
|
||||
map<string, string> rule_alg_id_mapping_;
|
||||
std::shared_mutex handles_mutex;
|
||||
map<std::string, std::unique_ptr<HandlerExec>>
|
||||
handles_; ///< 监控程序的handles,每个alg_id_datasource_seq一个handle
|
||||
handles_;
|
||||
|
||||
std::unique_ptr<std::thread> r_thread_; ///< 检测工厂运行状态的线程
|
||||
std::unique_ptr<std::thread> r_thread_;
|
||||
|
||||
std::unique_ptr<AlarmHandler> alarm_handler_ptr_;
|
||||
|
||||
int thread_num_ = 0; ///<规则 线程数
|
||||
int thread_num_ = 0;
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -170,4 +170,4 @@ public:
|
||||
int get_thread_size();
|
||||
};
|
||||
|
||||
} // namespace threads
|
||||
}
|
||||
|
||||
@ -55,8 +55,6 @@ void ExpModule::refresh_exp_ihd_mem(
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < m_tags.size(); i++) {
|
||||
// s[n] 表示tag[n]在动作开始时刻的起始值
|
||||
// p[n] 表示tag[n]在上一个动作周期的数值
|
||||
if (row >= queried_data.rows() || i >= (unsigned int)queried_data.cols()) {
|
||||
continue;
|
||||
}
|
||||
@ -66,11 +64,6 @@ void ExpModule::refresh_exp_ihd_mem(
|
||||
mm_vars["now"] = mix_cc::mix_time_t(queried_time[row]).to_milliseconds();
|
||||
auto pv_str = "pv" + std::to_string(i + 1);
|
||||
|
||||
// mm_vars[pv_str + "_10"] = mm_vars[pv_str + "_9"];
|
||||
// mm_vars[pv_str + "_9"] = mm_vars[pv_str + "_8"];
|
||||
// mm_vars[pv_str + "_8"] = mm_vars[pv_str + "_7"];
|
||||
// mm_vars[pv_str + "_7"] = mm_vars[pv_str + "_6"];
|
||||
// mm_vars[pv_str + "_6"] = mm_vars[pv_str + "_5"];
|
||||
mm_vars[pv_str + "_5"] = mm_vars[pv_str + "_4"];
|
||||
mm_vars[pv_str + "_4"] = mm_vars[pv_str + "_3"];
|
||||
mm_vars[pv_str + "_3"] = mm_vars[pv_str + "_2"];
|
||||
@ -83,18 +76,11 @@ void ExpModule::refresh_exp_ihd_mem(
|
||||
void ExpModule::refresh_exp_vars_mem() {
|
||||
this->now_time_ = std::chrono::system_clock::now();
|
||||
for (unsigned int i = 0; i < m_tags.size(); i++) {
|
||||
// s[n] 表示tag[n]在动作开始时刻的起始值
|
||||
// p[n] 表示tag[n]在上一个动作周期的数值
|
||||
mm_vars["p" + std::to_string(i + 1)] =
|
||||
mm_vars["tag" + std::to_string(i + 1)];
|
||||
mm_vars["tag" + std::to_string(i + 1)] =
|
||||
SingletonTemplate<GlobaltemSharedMemory>::GetInstance()[m_tags[i]];
|
||||
auto pv_str = "pv" + std::to_string(i + 1);
|
||||
// mm_vars[pv_str + "_10"] = mm_vars[pv_str + "_9"];
|
||||
// mm_vars[pv_str + "_9"] = mm_vars[pv_str + "_8"];
|
||||
// mm_vars[pv_str + "_8"] = mm_vars[pv_str + "_7"];
|
||||
// mm_vars[pv_str + "_7"] = mm_vars[pv_str + "_6"];
|
||||
// mm_vars[pv_str + "_6"] = mm_vars[pv_str + "_5"];
|
||||
mm_vars[pv_str + "_5"] = mm_vars[pv_str + "_4"];
|
||||
mm_vars[pv_str + "_4"] = mm_vars[pv_str + "_3"];
|
||||
mm_vars[pv_str + "_3"] = mm_vars[pv_str + "_2"];
|
||||
@ -110,7 +96,6 @@ void ExpModule::init() {
|
||||
for (unsigned int i = 0; i < m_tags.size(); i++) {
|
||||
double value =
|
||||
SingletonTemplate<GlobaltemSharedMemory>::GetInstance()[m_tags[i]];
|
||||
// p[n] 表示tag[n]在上一个动作周期的数值
|
||||
mm_vars["p" + std::to_string(i + 1)] = value;
|
||||
mm_vars["tag" + std::to_string(i + 1)] = value;
|
||||
|
||||
@ -124,11 +109,6 @@ void ExpModule::init() {
|
||||
mm_vars[pv_str + "_3"] = value;
|
||||
mm_vars[pv_str + "_4"] = value;
|
||||
mm_vars[pv_str + "_5"] = value;
|
||||
// mm_vars[pv_str + "_6"] = value;
|
||||
// mm_vars[pv_str + "_7"] = value;
|
||||
// mm_vars[pv_str + "_8"] = value;
|
||||
// mm_vars[pv_str + "_9"] = value;
|
||||
// mm_vars[pv_str + "_10"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -97,20 +97,16 @@ private:
|
||||
std::vector<TimePoint> queried_time, int row);
|
||||
|
||||
private:
|
||||
map<string, double> &mm_vars; ///< 表达式系统变量map
|
||||
map<string, double> exp_result_; ///<表达式计算结果
|
||||
map<string, std::unique_ptr<MExp>> exp_ptr_; ///表达式名称-表达式
|
||||
map<string, string> exp_str_; ///<表达式名称-表达式字符串
|
||||
vector<string> &m_tags; ///< 保存的tag点名
|
||||
std::unique_ptr<LOG> logger_; ///<日志
|
||||
TimePoint now_time_; ///< 当前正在执行时的时间
|
||||
map<string, double> &mm_vars;
|
||||
map<string, double> exp_result_;
|
||||
map<string, std::unique_ptr<MExp>> exp_ptr_;
|
||||
map<string, string> exp_str_;
|
||||
vector<string> &m_tags;
|
||||
std::unique_ptr<LOG> logger_;
|
||||
TimePoint now_time_;
|
||||
/**
|
||||
* @brief 自定义带状态函数
|
||||
* KeepT , ///< 保持时间
|
||||
* KeepC, ///<出现次数
|
||||
* RiseEdge, ///<上升沿出现次数
|
||||
* Detect ///<为真检测次数
|
||||
*/
|
||||
StatExp::FunVars fun_vars_;
|
||||
bool &is_exp_alg_; ///<是否是表达式ExpBase对象
|
||||
bool &is_exp_alg_;
|
||||
};
|
||||
|
||||
@ -68,10 +68,10 @@ class HoldTime {
|
||||
inline bool get_value(void) const { return value; }
|
||||
|
||||
private:
|
||||
double last_value; ///<上次tag数据值
|
||||
double hold_time; ///<保持时间
|
||||
bool value; ///<保持状态量
|
||||
std::chrono::system_clock::time_point last_time; ///<上次为保持时间点
|
||||
double last_value;
|
||||
double hold_time;
|
||||
bool value;
|
||||
std::chrono::system_clock::time_point last_time;
|
||||
private:
|
||||
/**
|
||||
* @brief static函数 从源字符串中查找子字符串
|
||||
|
||||
@ -40,9 +40,9 @@ struct KeepT {
|
||||
}
|
||||
|
||||
private:
|
||||
int64_t keep_time = 0; ///<当前保持时间 ms
|
||||
int64_t keep_time = 0;
|
||||
std::chrono::system_clock::time_point t1 =
|
||||
std::chrono::system_clock::now(); ///<起始时间点
|
||||
std::chrono::system_clock::now();
|
||||
};
|
||||
/**
|
||||
* @brief KeepC 保持次数仿函数
|
||||
@ -130,27 +130,26 @@ private:
|
||||
* @brief
|
||||
*/
|
||||
struct DelayT {
|
||||
using Clock = std::chrono::steady_clock; // 使用steady_clock
|
||||
using Clock = std::chrono::steady_clock;
|
||||
using Milliseconds = std::chrono::milliseconds;
|
||||
|
||||
int operator()(bool data, bool is_reset) { // 参数类型更改为bool
|
||||
int operator()(bool data, bool is_reset) {
|
||||
if (is_reset) {
|
||||
accumulated_time = 0;
|
||||
last_data = false;
|
||||
counting = false;
|
||||
return 0;
|
||||
}
|
||||
if (!last_data && data) { // 上升沿
|
||||
// accumulated_time = 0; ///<不多次累积
|
||||
if (!last_data && data) {
|
||||
start_time = Clock::now();
|
||||
counting = true;
|
||||
} else if (last_data && !data) { // 下降沿
|
||||
} else if (last_data && !data) {
|
||||
if (counting) {
|
||||
auto current_time = Clock::now();
|
||||
accumulated_time +=
|
||||
std::chrono::duration_cast<Milliseconds>(current_time - start_time)
|
||||
.count();
|
||||
counting = false; // 计时结束
|
||||
counting = false;
|
||||
}
|
||||
}
|
||||
last_data = data;
|
||||
@ -159,8 +158,7 @@ struct DelayT {
|
||||
int current_duration =
|
||||
std::chrono::duration_cast<Milliseconds>(current_time - start_time)
|
||||
.count();
|
||||
return accumulated_time +
|
||||
current_duration; // 实时计算当前周期时长,不依赖成员变量
|
||||
return accumulated_time + current_duration;
|
||||
} else {
|
||||
return accumulated_time;
|
||||
}
|
||||
@ -170,16 +168,16 @@ private:
|
||||
int accumulated_time = 0;
|
||||
bool last_data = false;
|
||||
bool counting = false;
|
||||
Clock::time_point start_time{}; // 确保初始化
|
||||
Clock::time_point start_time{};
|
||||
};
|
||||
|
||||
using FIDD = std::function<int(double, double)>;
|
||||
|
||||
enum class FiddType {
|
||||
KeepT = 0, ///< 保持时间
|
||||
KeepC, ///<出现次数
|
||||
RiseEdge, ///<上升沿出现次数
|
||||
Detect ///<为真检测次数
|
||||
KeepT = 0,
|
||||
KeepC,
|
||||
RiseEdge,
|
||||
Detect
|
||||
};
|
||||
|
||||
const std::map<std::string, FiddType> Fidd2M = {
|
||||
@ -274,8 +272,8 @@ struct BinaryF {
|
||||
|
||||
FIDD Fun;
|
||||
FiddType ftype;
|
||||
std::unique_ptr<mix_cc::matheval::Expression> var1; ///<参数1 表达式
|
||||
std::unique_ptr<mix_cc::matheval::Expression> var2; ///<参数2 表达式
|
||||
std::unique_ptr<mix_cc::matheval::Expression> var1;
|
||||
std::unique_ptr<mix_cc::matheval::Expression> var2;
|
||||
inline double operator()() {
|
||||
if (var1 != nullptr && var2 != nullptr) {
|
||||
switch (ftype) {
|
||||
@ -362,10 +360,10 @@ public:
|
||||
inline bool empty() { return exp2fvar.empty(); }
|
||||
|
||||
private:
|
||||
const std::string pre_var = "fun"; ///<函数变量 fun[index]的前缀
|
||||
int index = 0; ///<函数变量 fun[index]的序号
|
||||
std::map<std::string, BinaryF> exp2binayF; ///<表达式-二元函数
|
||||
std::map<std::string, std::string> exp2fvar; ///<表达式-函数变量
|
||||
std::map<std::string, FiddType> exp2ftype; ///<表达式-函数类型
|
||||
}; // namespace StatExp
|
||||
} // namespace StatExp
|
||||
const std::string pre_var = "fun";
|
||||
int index = 0;
|
||||
std::map<std::string, BinaryF> exp2binayF;
|
||||
std::map<std::string, std::string> exp2fvar;
|
||||
std::map<std::string, FiddType> exp2ftype;
|
||||
};
|
||||
}
|
||||
@ -9,10 +9,9 @@ public:
|
||||
m_tags = tags;
|
||||
tag_num = tags.size();
|
||||
pv_num = _pv_num;
|
||||
// 预分配所有 key
|
||||
p_keys.resize(tag_num);
|
||||
tag_keys.resize(tag_num);
|
||||
pv_keys.resize(tag_num); // 每个元素是 pv_num 个 key 的数组
|
||||
pv_keys.resize(tag_num);
|
||||
|
||||
for (size_t i = 0; i < tag_num; ++i) {
|
||||
auto &x = tags[i];
|
||||
@ -20,7 +19,6 @@ public:
|
||||
p_keys[i] = "p" + std::to_string(item_index);
|
||||
tag_keys[i] = "tag" + std::to_string(item_index);
|
||||
|
||||
// 预分配 pv 滑动窗口的 key
|
||||
pv_keys[i].resize(pv_num);
|
||||
for (int j = 0; j < pv_num; ++j) {
|
||||
pv_keys[i][j] =
|
||||
@ -32,10 +30,9 @@ public:
|
||||
|
||||
tag_num = _tag_num;
|
||||
pv_num = _pv_num;
|
||||
// 预分配所有 key
|
||||
p_keys.resize(tag_num);
|
||||
tag_keys.resize(tag_num);
|
||||
pv_keys.resize(tag_num); // 每个元素是 pv_num 个 key 的数组
|
||||
pv_keys.resize(tag_num);
|
||||
m_tags.resize(tag_num);
|
||||
for (size_t i = 0; i < tag_num; ++i) {
|
||||
|
||||
@ -44,7 +41,6 @@ public:
|
||||
p_keys[i] = "p" + std::to_string(item_index);
|
||||
tag_keys[i] = "tag" + std::to_string(item_index);
|
||||
|
||||
// 预分配 pv 滑动窗口的 key
|
||||
pv_keys[i].resize(pv_num);
|
||||
for (int j = 0; j < pv_num; ++j) {
|
||||
pv_keys[i][j] =
|
||||
|
||||
@ -24,8 +24,8 @@
|
||||
#include <mix_cc/type/mix_time.h>
|
||||
class AlarmHandler {
|
||||
private:
|
||||
MessageICEPrx message_queue_proxy_; ///< 给消息队列发消息的Ice代理
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
MessageICEPrx message_queue_proxy_;
|
||||
std::unique_ptr<LOG> logger_;
|
||||
public:
|
||||
AlarmHandler() {
|
||||
logger_ = std::make_unique<LOG>("AlarmHandler");
|
||||
@ -34,7 +34,6 @@ public:
|
||||
~AlarmHandler() {}
|
||||
int store_alarm(const string &alarm_info) {
|
||||
mix_cc::json js1 = mix_cc::json::parse(alarm_info);
|
||||
//从 t_rule_record_time 中查询 模型修改时间 模型启动时间
|
||||
mix_cc::mix_time_t rule_lmt;
|
||||
mix_cc::mix_time_t rule_lst;
|
||||
string ruleid = js1.at("rule").at("id").get<string>();
|
||||
@ -86,12 +85,8 @@ public:
|
||||
|
||||
T_RULE_RESULT rr;
|
||||
|
||||
/*报警等及
|
||||
ERROR---1
|
||||
WARN----0*/
|
||||
int rank =
|
||||
js1.at("result")[0].at("key").get<std::string>() == "ERROR" ? 1 : 0;
|
||||
// 向表中插入
|
||||
if (is_200_status) {
|
||||
short status = 200;
|
||||
auto num = exec<db2_t, size_t>(insert_into(rr).set(
|
||||
|
||||
@ -15,14 +15,13 @@ namespace utility {
|
||||
* 只写
|
||||
*/
|
||||
namespace {
|
||||
// std::mutex local_mutext{}; ///<共享锁
|
||||
const int AlarmLen = 4000; ///<报警信息的最大长度
|
||||
const int AlarmMaxSize = 10000; ///<报警信息队列容量
|
||||
const int AlarmLen = 4000;
|
||||
const int AlarmMaxSize = 10000;
|
||||
typedef char AlarmJsonData[AlarmLen];
|
||||
AlarmJsonData alarm_json_data_char;
|
||||
CMemQueue<AlarmJsonData> alarm_json_data_queue =
|
||||
CMemQueue<AlarmJsonData>("ZONE0", AlarmMaxSize);
|
||||
} // namespace
|
||||
}
|
||||
|
||||
AlarmPoster::AlarmPoster()
|
||||
: gb_logger_(std::make_unique<GbLogger>("AlarmPoster")) {
|
||||
@ -36,69 +35,14 @@ AlarmPoster::~AlarmPoster() {}
|
||||
int AlarmPoster::alarm(
|
||||
const AlarmInfo &alarm_info,
|
||||
std::chrono::system_clock::time_point *const prev_alarm_time) {
|
||||
// 2021-10-27 报警间隔时间
|
||||
int minutesTh = std::max(5, CMemVar::Const()->AlarmIntervalHours * 60);
|
||||
if (alarm_info.alarm_end_time - *prev_alarm_time > minutes(minutesTh)) {
|
||||
*prev_alarm_time = alarm_info.alarm_end_time;
|
||||
// std::lock_guard<std::mutex> guard(local_mutext);
|
||||
auto alarm_json1 = build_json_from_alarm_Info(alarm_info);
|
||||
strcpy(alarm_json_data_char, alarm_json1.c_str());
|
||||
alarm_json_data_queue.push(&alarm_json_data_char);
|
||||
gb_logger_->log_info("alarm_json1:"+alarm_json1);
|
||||
}
|
||||
|
||||
// //从 t_rule_record_time 中查询 模型修改时间 模型启动时间
|
||||
// mix_cc::mix_time_t rule_lmt;
|
||||
// mix_cc::mix_time_t rule_lst;
|
||||
// T_RULE_RECORD_TIME t_rule_record_time;
|
||||
// auto select_statement =
|
||||
// select(t_rule_record_time.tos(), t_rule_record_time.rule_tom())
|
||||
// .from(t_rule_record_time)
|
||||
// .where(t_rule_record_time.ruleId() = alarm_info.cfg_info.id);
|
||||
|
||||
// auto tos_tom_maybe =
|
||||
// mix_cc::sql::exec<db2_t, T_RULE_RECORD_TIME>(select_statement);
|
||||
// if (tos_tom_maybe.is_just()) {
|
||||
// auto tos_tom = tos_tom_maybe.unsafe_get_just();
|
||||
// if (tos_tom.size() == 0) {
|
||||
// gb_logger_->log_error("t_rule_record_time表格无记录");
|
||||
// rule_lmt = mix_cc::mix_time_t(std::chrono::system_clock::now());
|
||||
// rule_lst = mix_cc::mix_time_t(std::chrono::system_clock::now());
|
||||
// } else {
|
||||
// rule_lmt = tos_tom[0].rule_tom;
|
||||
// rule_lst = tos_tom[0].tos;
|
||||
// }
|
||||
|
||||
// } else {
|
||||
// gb_logger_->log_error("t_rule_record_time表格查询失败");
|
||||
// }
|
||||
|
||||
// T_RULE_RESULT rr;
|
||||
// // 向表中插入
|
||||
// auto num = exec<db2_t, size_t>(insert_into(rr).set(
|
||||
// rr.ruleId() = alarm_info.cfg_info.id,
|
||||
// rr.ruleName() = alarm_info.cfg_info.name,
|
||||
// rr.ruleGroup() = alarm_info.cfg_info.group,
|
||||
// rr.ruleBtime() = mix_cc::mix_time_t(alarm_info.alarm_start_time),
|
||||
// rr.ruleEtime() = mix_cc::mix_time_t(alarm_info.alarm_end_time),
|
||||
// rr.dealResult() = 0,
|
||||
// rr.result() = mix_cc::to_string(alarm_info.content),
|
||||
// rr.ruleLastMTime() = rule_lmt, rr.ruleLastSTime() = rule_lst));
|
||||
// auto alarm_json = build_json_from_alarm_Info(alarm_info);
|
||||
// gb_logger_->log_info(alarm_json.c_str());
|
||||
// if (num.is_nothing()) {
|
||||
// this->gb_logger_->log_error("数据库存储异常");
|
||||
// }
|
||||
// try {
|
||||
// std::vector<unsigned char> seq(
|
||||
// (unsigned char*)alarm_json.c_str(),
|
||||
// (unsigned char*)alarm_json.c_str() + alarm_json.length());
|
||||
// message_queue_proxy_->SendDataShort(911, seq, alarm_json.length());
|
||||
// } catch (::Ice::LocalException& e) {
|
||||
// gb_logger_->log_error(std::string("消息队列发送失败,请检查消息") +
|
||||
// e.what());
|
||||
// }
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -135,7 +79,6 @@ int AlarmPoster::alarm(const AlarmInfo &alarm_info,
|
||||
string remark) {
|
||||
if (alarm_info.alarm_end_time - *prev_alarm_time > minutes(5)) {
|
||||
*prev_alarm_time = alarm_info.alarm_end_time;
|
||||
//从 t_rule_record_time 中查询 模型修改时间 模型启动时间
|
||||
mix_cc::mix_time_t rule_lmt;
|
||||
mix_cc::mix_time_t rule_lst;
|
||||
T_RULE_RECORD_TIME t_rule_record_time;
|
||||
@ -155,7 +98,6 @@ int AlarmPoster::alarm(const AlarmInfo &alarm_info,
|
||||
}
|
||||
|
||||
T_RULE_RESULT rr;
|
||||
// 向表中插入
|
||||
auto num = exec<db2_t, size_t>(insert_into(rr).set(
|
||||
rr.ruleId() = alarm_info.cfg_info.id,
|
||||
rr.ruleName() = alarm_info.cfg_info.name,
|
||||
@ -195,4 +137,4 @@ bool AlarmPoster::zmqp_send(int event_no, const string &content) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace utility
|
||||
}
|
||||
@ -23,9 +23,8 @@ namespace utility {
|
||||
*/
|
||||
class AlarmPoster {
|
||||
private:
|
||||
MessageICEPrx message_queue_proxy_; ///< 给消息队列发消息的Ice代理
|
||||
// GbLogger logger_; ///< 内部的打印logger
|
||||
std::unique_ptr<GbLogger> gb_logger_; ///< 全局logger指针
|
||||
MessageICEPrx message_queue_proxy_;
|
||||
std::unique_ptr<GbLogger> gb_logger_;
|
||||
|
||||
public:
|
||||
AlarmPoster();
|
||||
@ -73,4 +72,4 @@ public:
|
||||
bool zmqp_send(int event_no, const string &content);
|
||||
};
|
||||
|
||||
} // namespace utility
|
||||
}
|
||||
@ -10,15 +10,13 @@ AlarmInfo build_alarm_info(const string &alarm_level, const string &ruleId,
|
||||
const std::string &alarm_content,
|
||||
const mix_cc::time_range_t &time_range) {
|
||||
AlarmInfo ret;
|
||||
// 设置 key - result
|
||||
ret.content[0]["key"] = alarm_level;
|
||||
ret.content[0]["result"] = alarm_content;
|
||||
ret.content[0]["alarm_time"] =
|
||||
mix_cc::mix_time_t(time_range.get_right()).to_milliseconds();
|
||||
// 设置报警基本信息
|
||||
ret.alarmed = true;
|
||||
ret.alarm_start_time = time_range.get_left();
|
||||
ret.alarm_end_time = time_range.get_right(); // 2021-10-27
|
||||
ret.alarm_end_time = time_range.get_right();
|
||||
ret.cfg_info.id = ruleId;
|
||||
ret.cfg_info.name = name;
|
||||
ret.cfg_info.group = group;
|
||||
@ -34,14 +32,12 @@ build_alarm_info(const string &alarm_level, const string &ruleId,
|
||||
const std::vector<double> &value,
|
||||
const std::vector<mix_cc::float_range_t> &desire_range,
|
||||
const mix_cc::time_range_t &time_range) {
|
||||
// 设置原始报警信息
|
||||
auto ret = build_alarm_info(alarm_level, ruleId, name, group, alarm_content,
|
||||
time_range);
|
||||
auto dr_array = mix_cc::json::array();
|
||||
for (const auto &x : desire_range) {
|
||||
dr_array.push_back(x.to_array());
|
||||
}
|
||||
// 为原始报警信息添加更多信息
|
||||
ret.content[0]["value"] = value;
|
||||
ret.content[0]["desire_range"] = dr_array;
|
||||
return ret;
|
||||
@ -56,4 +52,4 @@ string get_msg_level(double limit_down, double limit_up, double value) {
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
} // namespace utility
|
||||
}
|
||||
|
||||
@ -63,4 +63,4 @@ AlarmInfo build_alarm_info(
|
||||
* "ERROR"---异常 偏差大于等于极限的30%
|
||||
*/
|
||||
string get_msg_level(double limit_down, double limit_up, double value);
|
||||
} // namespace utility
|
||||
}
|
||||
|
||||
@ -4,38 +4,32 @@
|
||||
|
||||
std::string build_json_from_alarm_Info(const AlarmInfo &alarm_info) {
|
||||
mix_cc::json json_alarm;
|
||||
// 设置报警显示信息
|
||||
json_alarm["result"] = alarm_info.content;
|
||||
json_alarm["rule"]["id"] = alarm_info.cfg_info.id;
|
||||
json_alarm["rule"]["name"] = alarm_info.cfg_info.name; // which name
|
||||
json_alarm["rule"]["group"] = alarm_info.cfg_info.group; // Gruop
|
||||
json_alarm["rule"]["name"] = alarm_info.cfg_info.name;
|
||||
json_alarm["rule"]["group"] = alarm_info.cfg_info.group;
|
||||
json_alarm["rule"]["remark"] = alarm_info.cfg_info.remark;
|
||||
json_alarm["rule"]["descName"] = alarm_info.cfg_info.descName;
|
||||
json_alarm["rule"]["rulebtime"] =
|
||||
mix_cc::mix_time_t(alarm_info.alarm_start_time).to_milliseconds();
|
||||
// mix_cc::mix_time_t(alarm_info.alarm_start_time).to_time_t();
|
||||
json_alarm["rule"]["ruleetime"] =
|
||||
mix_cc::mix_time_t(alarm_info.alarm_end_time).to_milliseconds();
|
||||
// mix_cc::mix_time_t(alarm_info.alarm_end_time).to_time_t();
|
||||
// 导出不带格式化信息的json字符串
|
||||
return json_alarm.dump();
|
||||
}
|
||||
|
||||
std::string build_json_from_alarm_Info(const AlarmInfo &alarm_info,
|
||||
std::string remark) {
|
||||
mix_cc::json json_alarm;
|
||||
// 设置报警显示信息
|
||||
json_alarm["result"] = alarm_info.content;
|
||||
json_alarm["remark"] = remark;
|
||||
json_alarm["rule"]["id"] = alarm_info.cfg_info.id;
|
||||
json_alarm["rule"]["name"] = alarm_info.cfg_info.name; // which name
|
||||
json_alarm["rule"]["group"] = alarm_info.cfg_info.group; // Gruop
|
||||
json_alarm["rule"]["name"] = alarm_info.cfg_info.name;
|
||||
json_alarm["rule"]["group"] = alarm_info.cfg_info.group;
|
||||
json_alarm["rule"]["remark"] = alarm_info.cfg_info.remark;
|
||||
json_alarm["rule"]["descName"] = alarm_info.cfg_info.descName;
|
||||
json_alarm["rule"]["rulebtime"] =
|
||||
mix_cc::mix_time_t(alarm_info.alarm_start_time).to_time_t();
|
||||
json_alarm["rule"]["ruleetime"] =
|
||||
mix_cc::mix_time_t(alarm_info.alarm_end_time).to_time_t();
|
||||
// 导出不带格式化信息的json字符串
|
||||
return json_alarm.dump();
|
||||
}
|
||||
@ -29,14 +29,12 @@ public:
|
||||
if (!condition_a) {
|
||||
consecutive_count_++;
|
||||
|
||||
// 检查是否达到阈值且本轮尚未触发
|
||||
if (consecutive_count_ >= threshold_n_ && !is_triggered_) {
|
||||
resetCount();
|
||||
is_triggered_ = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// 条件满足,重置状态
|
||||
resetCount();
|
||||
is_triggered_ = false;
|
||||
}
|
||||
@ -44,13 +42,10 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
/// 清空计数器
|
||||
void resetCount() { consecutive_count_ = 0; }
|
||||
|
||||
/// 获取当前连续不满足条件的计数
|
||||
int getCurrentCount() const { return consecutive_count_; }
|
||||
|
||||
/// 获取阈值
|
||||
int getThreshold() const { return threshold_n_; }
|
||||
/**
|
||||
* @brief Set the Threshold object
|
||||
@ -69,7 +64,7 @@ public:
|
||||
bool getCurrentState() const { return is_triggered_; }
|
||||
|
||||
private:
|
||||
int threshold_n_; // 阈值N
|
||||
int consecutive_count_; // 连续不满足计数
|
||||
bool is_triggered_; // 防止重复触发的标志
|
||||
int threshold_n_;
|
||||
int consecutive_count_;
|
||||
bool is_triggered_;
|
||||
};
|
||||
@ -8,10 +8,10 @@
|
||||
#include <mutex>
|
||||
/*mapRuleStat 单例*/
|
||||
namespace {
|
||||
std::mutex up_mutex{}; ///<共享锁
|
||||
std::mutex up_mutex{};
|
||||
RuleStatShm::MapRuleStat mapRuleStat;
|
||||
RuleStatShm::RuleStat rule_stat;
|
||||
}; // namespace
|
||||
};
|
||||
|
||||
EqpStat::EqpStat() {
|
||||
logger_ = std::make_unique<LOG>("EqpStat");
|
||||
|
||||
@ -42,19 +42,6 @@ class EqpStat {
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
// bool update_static(std::string ruleid,
|
||||
// const RuleStatShm::RuleStat& rule_stat);
|
||||
/**
|
||||
* @brief 更新指定key的shear_times/running_time 弃用
|
||||
* @param ruleid 规则id
|
||||
* @param rule_stat RuleStatShm::RuleStat数据 引用
|
||||
* @param is_times 是否为运行时间
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
// bool update_static(std::string ruleid, const RuleStatShm::RuleStat&
|
||||
// rule_stat,
|
||||
// bool is_times);
|
||||
/**
|
||||
* @brief 更新指定key的 静态数据
|
||||
* 内含当前变量 rule_stat_statstic_
|
||||
@ -131,11 +118,9 @@ class EqpStat {
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_;
|
||||
std::vector<string> cfg_rules_;
|
||||
// RuleStatShm::RuleStat rule_stat_; ///<当前数据 供循环用
|
||||
// RuleStatShm::RuleStat rule_stat_statstic_; ///<当前数据 统计类调用函数
|
||||
bool cfg_flag = false; ///<查询
|
||||
bool cfg_flag = false;
|
||||
chrono::system_clock::time_point
|
||||
last_update_static_time_; ///<上次刷新静态数据的时间
|
||||
last_update_static_time_;
|
||||
/**
|
||||
* @brief 运行时间
|
||||
* @param ruleid My Param doc
|
||||
|
||||
@ -5,12 +5,10 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
namespace {
|
||||
std::unordered_map<std::string, bool> eqp_status; ///<设备id,运行状态
|
||||
std::unordered_map<std::string, std::string> eqpid2item; ///<设备id,item
|
||||
// std::unordered_map<std::string, std::vector<std::string> >
|
||||
// eqpid2items_or; ///<设备id,items 或
|
||||
std::vector<std::string> eqp_ids; ///<设备编号
|
||||
} // namespace
|
||||
std::unordered_map<std::string, bool> eqp_status;
|
||||
std::unordered_map<std::string, std::string> eqpid2item;
|
||||
std::vector<std::string> eqp_ids;
|
||||
}
|
||||
|
||||
EqpStatus::EqpStatus() {
|
||||
logger_ = std::make_unique<LOG>("EqpStatus");
|
||||
@ -22,28 +20,11 @@ EqpStatus::EqpStatus() {
|
||||
const auto size = binary_tele.size();
|
||||
for (int j = 0; j < size; j++) {
|
||||
string flag = binary_tele[j].flag;
|
||||
// logger_->Debug() << "item:" << binary_tele[j].item
|
||||
// << ",flag:" << binary_tele[j].flag << endl;
|
||||
if (flag[1] == 'E') {
|
||||
string eqp_id = binary_tele[j].tables[0];
|
||||
// string epq_id2 = binary_tele[j].tables[1];
|
||||
std::string name_without_plant_code = binary_tele[j].item;
|
||||
eqpid2item[eqp_id] = prefix + name_without_plant_code;
|
||||
// if (!epq_id2.empty()) {
|
||||
// logger_->Debug() << "epq_id:" << eqp_id << ",eqp_id2:" << eqp_id2
|
||||
// << ",item:" << name_without_plant_code << endl;
|
||||
// eqpid2items_or[eqp_id2].push_back(prefix +
|
||||
// name_without_plant_code);
|
||||
// }
|
||||
|
||||
// logger_->Debug() << "eqp_id:" << eqp_id
|
||||
// << ",item:" << name_without_plant_code << endl;
|
||||
}
|
||||
// else if (flag[1] == 'D') {
|
||||
// string eqp_id = binary_tele[j].tables[0];
|
||||
// std::string name_without_plant_code = binary_tele[j].item;
|
||||
// eqpid2items_or[eqp_id].push_back(prefix + name_without_plant_code);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -62,26 +43,7 @@ int EqpStatus::update_status() {
|
||||
if (eqpid2item.find(eqp_ids[i]) != eqpid2item.end()) {
|
||||
eqp_status[eqp_ids[i]] = SingletonTemplate<
|
||||
GlobaltemSharedMemory>::GetInstance()[eqpid2item[eqp_ids[i]]];
|
||||
// logger_->Debug()
|
||||
// << "epqid:" << eqp_ids[i] << ",item:" << eqpid2item[eqp_ids[i]]
|
||||
// << ",data:"
|
||||
// << SingletonTemplate<
|
||||
// GlobaltemSharedMemory>::GetInstance()[eqpid2item[eqp_ids[i]]]
|
||||
// << endl;
|
||||
}
|
||||
// else if (eqpid2items_or.find(eqp_ids[i]) != eqpid2items_or.end()) {
|
||||
// if (!eqpid2items_or[eqp_ids[i]].empty()) {
|
||||
// eqp_status[eqp_ids[i]] = false;
|
||||
// for (auto items : eqpid2items_or[eqp_ids[i]]) {
|
||||
// eqp_status[eqp_ids[i]] =
|
||||
// eqp_status[eqp_ids[i]] ||
|
||||
// SingletonTemplate<GlobaltemSharedMemory>::GetInstance()[items];
|
||||
// }
|
||||
// } else {
|
||||
// eqp_status[eqp_ids[i]] = true;
|
||||
// }
|
||||
|
||||
// }
|
||||
else {
|
||||
eqp_status[eqp_ids[i]] = true;
|
||||
}
|
||||
|
||||
@ -43,9 +43,9 @@ public:
|
||||
std::string operator()(const std::string &item) const {
|
||||
auto it = data_.find(item);
|
||||
if (it != data_.end()) {
|
||||
return it->second; // 返回找到的翻译副本
|
||||
return it->second;
|
||||
}
|
||||
return item; // 安全地返回传入项的副本
|
||||
return item;
|
||||
}
|
||||
|
||||
Item2Chines() { select_fdaaitem(); }
|
||||
|
||||
@ -18,15 +18,9 @@ bool ProxPy::insert(std::string ruleid, std::array<double, 2000> datax,
|
||||
<< ",ruleid_CMemMap_->operator[](ruleid) return false!"
|
||||
<< std::endl;
|
||||
}
|
||||
// else {
|
||||
// logger_->Info() << "data size:" << (*res).data_szie << std::endl;
|
||||
// }
|
||||
|
||||
GlithData now_data;
|
||||
now_data.update(datax, dataSize);
|
||||
// logger_->Debug() << "GlithData,size of:" << sizeof(GlithData)
|
||||
// << ",data size:" << now_data.data_szie << std::endl;
|
||||
// ruleid_CMemMap_->clear();
|
||||
ruleid_CMemMap_->insert(ruleid, &now_data);
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
@ -51,7 +45,6 @@ bool ProxPy::send2py(std::string module_name, string content) {
|
||||
void ProxPy::add_module(std::string module_name) {
|
||||
try {
|
||||
if (prox_py_ptrs_.find(module_name) != prox_py_ptrs_.end()) {
|
||||
// logger_->Debug() << module_name << " 已存在" << std::endl;
|
||||
return;
|
||||
}
|
||||
string pre_name = "baosight/";
|
||||
|
||||
@ -20,9 +20,8 @@
|
||||
#include <zlib/MemMap.hpp>
|
||||
|
||||
struct ProxPyMapConfig {
|
||||
static inline constexpr char TableName[] = "ZONE20"; ///<表名
|
||||
static constexpr int MapMaxSize =
|
||||
499; ///< map 最大容量 sizof 8000000 499*16008=7987992
|
||||
static inline constexpr char TableName[] = "ZONE20";
|
||||
static constexpr int MapMaxSize = 499;
|
||||
static constexpr int dataMaxLen = 2000;
|
||||
};
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#include <eqpalg/utility/update_data.h>
|
||||
UpDateData::UpDateData(string Jkey_data, string Jkey_rule_stat) {
|
||||
this->Jkey_data_ = unitNo_ + "_" + Jkey_data;
|
||||
// this->Jkey_rule_stat_ = unitNo_ + "_" + Jkey_rule_stat;
|
||||
this->Jkey_rule_stat_ = "EIS_Rule_stat";
|
||||
if (logger_ == nullptr) {
|
||||
logger_ = std::make_unique<LOG>("UpDateData");
|
||||
@ -17,7 +16,6 @@ UpDateData::UpDateData(string Jkey_data, string Jkey_rule_stat) {
|
||||
UpDateData::UpDateData() {
|
||||
this->Jkey_data_ = unitNo_ + "_" + "EIS_itemtag";
|
||||
this->Jkey_rule_stat_ = unitNo_ + "_" + "Rule_stat";
|
||||
// this->Jkey_rule_stat_ = "EIS_Rule_stat";
|
||||
this->Jkey_eqp_state_ = unitNo_ + "_" + "Eqp_status";
|
||||
if (logger_ == nullptr) {
|
||||
logger_ = std::make_unique<LOG>("UpDateData");
|
||||
@ -46,12 +44,7 @@ void UpDateData::update_item_data() {
|
||||
|
||||
void UpDateData::update_rule_stat_data() {
|
||||
SingletonTemp<EqpStat>::GetInstance().init();
|
||||
// auto runs_t1 = std::chrono::steady_clock::now();
|
||||
string Jvalue = SingletonTemp<EqpStat>::GetInstance().get_stat_json();
|
||||
// auto runs_t2 = std::chrono::steady_clock::now();
|
||||
// int64_t cost_time = (runs_t2 - runs_t1).count() / 1000000;
|
||||
// logger_->Debug() << "get_stat_json cost time:" << cost_time << "ms"
|
||||
// << std::endl;
|
||||
auto reSult = m_memclient.Insert(Jkey_rule_stat_.c_str(), Jvalue.c_str());
|
||||
if (1 != reSult) {
|
||||
this->logger_->Debug()
|
||||
|
||||
@ -14,18 +14,18 @@
|
||||
#include <eqpalg/utility/eqp_stat.h>
|
||||
#include <eqpalg/utility/eqp_status.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <zlib/MemCachedClient.h> ///MemCachedClient
|
||||
#include <zlib/MemCachedClient.h>
|
||||
#include <memory>
|
||||
#include <shm/SingletonTemp.hpp>
|
||||
class UpDateData {
|
||||
private:
|
||||
MemCachedClient m_memclient; ///< MemCachedClient
|
||||
string unitNo_ = string(CMemVar::Const()->UnitNo); ///<机组号
|
||||
string Jkey_data_; ///< fdaaitem数据的key
|
||||
string Jkey_rule_stat_; ///<规则shm的key
|
||||
string Jkey_eqp_state_; ///<设备运行状态
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
std::unique_ptr<EqpStatus> eqp_status_ptr_; ///<设备状态
|
||||
MemCachedClient m_memclient;
|
||||
string unitNo_ = string(CMemVar::Const()->UnitNo);
|
||||
string Jkey_data_;
|
||||
string Jkey_rule_stat_;
|
||||
string Jkey_eqp_state_;
|
||||
std::unique_ptr<LOG> logger_;
|
||||
std::unique_ptr<EqpStatus> eqp_status_ptr_;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user