138 lines
4.4 KiB
C
138 lines
4.4 KiB
C
|
|
#pragma once
|
|||
|
|
/**
|
|||
|
|
* @file exp_sample_multi_dim.h
|
|||
|
|
* @brief 多维样本 高斯拟合
|
|||
|
|
* @author your name (you@domain.com)
|
|||
|
|
* @version 0.1
|
|||
|
|
* @date 2023-12-22
|
|||
|
|
*
|
|||
|
|
* Copyright: Baosight Co. Ltd.
|
|||
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
#include <eqpalg/algs/exp_sample.h>
|
|||
|
|
#include <memory>
|
|||
|
|
#include <string>
|
|||
|
|
#include <vector>
|
|||
|
|
|
|||
|
|
using namespace nlohmann;
|
|||
|
|
/**
|
|||
|
|
* @brief 表达式-多维样本类的实现
|
|||
|
|
* @tparam dims
|
|||
|
|
*/
|
|||
|
|
class ExpSampleMultiDim : public ExpSample {
|
|||
|
|
public:
|
|||
|
|
ExpSampleMultiDim(const string& name, const mix_cc::json& rule_json,
|
|||
|
|
const string& ruleId, size_t dims, double padding_low,
|
|||
|
|
double padding_up)
|
|||
|
|
: ExpSample(name, rule_json, ruleId, dims, padding_low, padding_up) {}
|
|||
|
|
~ExpSampleMultiDim() {}
|
|||
|
|
|
|||
|
|
int init() override;
|
|||
|
|
|
|||
|
|
int reload_config_xyz();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 基本过程,用来组成高级过程
|
|||
|
|
* @tparam T
|
|||
|
|
* @tparam ReturnType
|
|||
|
|
* @return ReturnType
|
|||
|
|
*/
|
|||
|
|
template <typename T, typename ReturnType>
|
|||
|
|
ReturnType base_proc() {
|
|||
|
|
try {
|
|||
|
|
act_triggered_ = static_cast<bool>(exp_act_->evaluate());
|
|||
|
|
if (act_triggered_) {
|
|||
|
|
double x1, x2, x3 = 1;
|
|||
|
|
if (dims_ > 0) {
|
|||
|
|
x1 = exp_xs_[0]->evaluate();
|
|||
|
|
}
|
|||
|
|
if (dims_ > 1) {
|
|||
|
|
x2 = exp_xs_[1]->evaluate();
|
|||
|
|
}
|
|||
|
|
if (dims_ > 2) {
|
|||
|
|
x3 = exp_xs_[2]->evaluate();
|
|||
|
|
}
|
|||
|
|
if ((!std::isnan(x1) && !std::isnan(x2) && !std::isnan(x2)) &&
|
|||
|
|
(x1 != 0 || x2 != 0 || x3 != 0)) {
|
|||
|
|
if constexpr (is_same_v<T, exec_mon_t>) {
|
|||
|
|
if (dims_ == 1) {
|
|||
|
|
auto alarm_info = sample_stat_->auto_detect_and_save(
|
|||
|
|
SamplePoint{x1}, now_time_);
|
|||
|
|
// !IMPORTANT@ NEED TO MODIFY LATTER
|
|||
|
|
if (alarm_info) {
|
|||
|
|
return utility::build_alarm_info(
|
|||
|
|
MsgLevel::ERROR, rule_id_, rule_name_, "POLYFIT",
|
|||
|
|
error_str_ + alarm_info.alarm_str, alarm_info.value,
|
|||
|
|
alarm_info.range, query_time_range_);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (dims_ == 2) {
|
|||
|
|
auto alarm_info = sample_stat_->auto_detect_and_save(
|
|||
|
|
SamplePoint{x1, x2}, now_time_);
|
|||
|
|
// !IMPORTANT@ NEED TO MODIFY LATTER
|
|||
|
|
if (alarm_info) {
|
|||
|
|
return utility::build_alarm_info(
|
|||
|
|
MsgLevel::ERROR, rule_id_, rule_name_, "POLYFIT",
|
|||
|
|
error_str_ + alarm_info.alarm_str, alarm_info.value,
|
|||
|
|
alarm_info.range, query_time_range_);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (dims_ == 3) {
|
|||
|
|
auto alarm_info = sample_stat_->auto_detect_and_save(
|
|||
|
|
SamplePoint{x1, x2, x3}, now_time_);
|
|||
|
|
// !IMPORTANT@ NEED TO MODIFY LATTER
|
|||
|
|
if (alarm_info) {
|
|||
|
|
return utility::build_alarm_info(
|
|||
|
|
MsgLevel::ERROR, rule_id_, rule_name_, "POLYFIT",
|
|||
|
|
error_str_ + alarm_info.alarm_str, alarm_info.value,
|
|||
|
|
alarm_info.range, query_time_range_);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else if constexpr (is_same_v<T, exec_cron_t>) {
|
|||
|
|
if (dims_ == 1) {
|
|||
|
|
return std::make_optional(SamplePoint{x1});
|
|||
|
|
}
|
|||
|
|
if (dims_ == 2) {
|
|||
|
|
return std::make_optional(SamplePoint{x1, x2});
|
|||
|
|
}
|
|||
|
|
if (dims_ == 3) {
|
|||
|
|
return std::make_optional(SamplePoint{x1, x2, x3});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} catch (const std::exception& e) {
|
|||
|
|
std::throw_with_nested(
|
|||
|
|
mix_cc::Exception(-1, "calc_once error", BOOST_CURRENT_LOCATION));
|
|||
|
|
}
|
|||
|
|
if constexpr (is_same_v<T, exec_mon_t>) {
|
|||
|
|
return AlarmInfo{};
|
|||
|
|
} else if constexpr (is_same_v<T, exec_cron_t>) {
|
|||
|
|
return std::nullopt;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 监控过程
|
|||
|
|
* @return AlarmInfo
|
|||
|
|
*/
|
|||
|
|
AlarmInfo mon_proc() override { return base_proc<exec_mon_t, AlarmInfo>(); }
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 定期采样过程
|
|||
|
|
* @return std::optional<std::array<double, 3>>
|
|||
|
|
*/
|
|||
|
|
std::optional<SamplePoint> cron_proc_sample() override {
|
|||
|
|
return base_proc<exec_cron_t, std::optional<SamplePoint>>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected:
|
|||
|
|
std::vector<std::unique_ptr<mix_cc::matheval::Expression>>
|
|||
|
|
exp_xs_; ///< 样本表达式数组
|
|||
|
|
|
|||
|
|
std::string sample_tag_x1_str_; ///< x1 样本表达式字符串
|
|||
|
|
std::string sample_tag_x2_str_; ///< x2 样本表达式字符串
|
|||
|
|
std::string sample_tag_x3_str_; ///< x3 样本表达式字符串
|
|||
|
|
};
|