93 lines
2.5 KiB
C
93 lines
2.5 KiB
C
|
|
#pragma once
|
|||
|
|
/**
|
|||
|
|
* @file roller3.h
|
|||
|
|
* @brief 多变量,离群检测
|
|||
|
|
* @author your name (you@domain.com)
|
|||
|
|
* @version 0.1
|
|||
|
|
* @date 2026-01-12
|
|||
|
|
*
|
|||
|
|
* Copyright: Baosight Co. Ltd.
|
|||
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
#include <array>
|
|||
|
|
#include <eqpalg/algs/exp_base.h>
|
|||
|
|
#include <eqpalg/define/public.h>
|
|||
|
|
#include <map>
|
|||
|
|
#include <utility>
|
|||
|
|
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(); ///<上次记录时间
|
|||
|
|
AlarmState last_alarm_tate =
|
|||
|
|
AlarmState::None; ///<报警状态 未报警,超下限,超上限
|
|||
|
|
AlarmType alarm_type = AlarmType::Error; ///<报警类型
|
|||
|
|
};
|
|||
|
|
} // namespace HoldState
|
|||
|
|
|
|||
|
|
using std::string;
|
|||
|
|
class Roller3 : public ExpBase {
|
|||
|
|
public:
|
|||
|
|
Roller3(const string &name, const mix_cc::json &rule_json,
|
|||
|
|
const string &ruleId, size_t exp_type);
|
|||
|
|
|
|||
|
|
virtual ~Roller3();
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
int init() override;
|
|||
|
|
virtual AlarmInfo mon_proc() override;
|
|||
|
|
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序号
|
|||
|
|
string tags_exp_;
|
|||
|
|
int value_num_ = 0; ///<对比的数据项个数
|
|||
|
|
vector<int>
|
|||
|
|
is_zero_list_; ///<数据是否为0的标记(0-否,1-是),需要剔除为0的数据项
|
|||
|
|
std::map<int, HoldState::StateInfo> state_info_map_; ///<各个数据项的报警情况跟踪
|
|||
|
|
private:
|
|||
|
|
int init_X_exp();
|
|||
|
|
void print_load_content();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief
|
|||
|
|
* @param expr My Param doc
|
|||
|
|
* @return vector<int>
|
|||
|
|
*/
|
|||
|
|
vector<int> extractTagNumbers(const string &expr);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 计算数组的中位数
|
|||
|
|
* @param data My Param doc
|
|||
|
|
* @return double
|
|||
|
|
*/
|
|||
|
|
double calculateMedian(std::vector<double> data);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 计算数组的max,返回max数据的下标和值
|
|||
|
|
*/
|
|||
|
|
std::pair<int, double> findMaxWithIndex(const std::vector<double> &vec);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Get the up down object
|
|||
|
|
* @param value My Param doc
|
|||
|
|
* @param is_up 是否区间上限
|
|||
|
|
* @return double
|
|||
|
|
*/
|
|||
|
|
double get_up_down(const double &value, bool is_up);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 检测数据超阈值情况
|
|||
|
|
* @param value 数据值
|
|||
|
|
* @return AlarmState None = 0, DownLower, median_
|
|||
|
|
*/
|
|||
|
|
HoldState::AlarmState detect_up_down(const double &value);
|
|||
|
|
};
|