115 lines
2.4 KiB
C
115 lines
2.4 KiB
C
|
|
#pragma once
|
|||
|
|
/**
|
|||
|
|
* @file rs_mgr.h
|
|||
|
|
* @brief rs即dlib的running state
|
|||
|
|
* 其中包含均值、方差、数量、标准差
|
|||
|
|
* 超值峰度、偏度等信息
|
|||
|
|
* @author Cat (null.null.null@qq.com)
|
|||
|
|
* @version 0.1
|
|||
|
|
* @date 2021-09-10
|
|||
|
|
*
|
|||
|
|
* Copyright: Baosight Co. Ltd.
|
|||
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
#include <dlib/statistics.h>
|
|||
|
|
#include <log4cplus/LOG.h>
|
|||
|
|
#include <eqpalg/data_handler/rs_tools.h>
|
|||
|
|
#include <eqpalg/define/dlib.h>
|
|||
|
|
#include <boost/date_time.hpp>
|
|||
|
|
|
|||
|
|
#include <memory>
|
|||
|
|
#include <string>
|
|||
|
|
#include <filesystem>
|
|||
|
|
#include <fstream>
|
|||
|
|
#include <functional>
|
|||
|
|
#include <optional>
|
|||
|
|
#include "mix_cc/json.h"
|
|||
|
|
|
|||
|
|
namespace data_handler {
|
|||
|
|
|
|||
|
|
using namespace boost::posix_time;
|
|||
|
|
using namespace boost::gregorian;
|
|||
|
|
/**
|
|||
|
|
* @brief dlib::RunningState的管理器
|
|||
|
|
* @tparam dims
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
class RsMgr {
|
|||
|
|
public:
|
|||
|
|
using RunningStats = Rs; ///< small_vector<dlib::running_stats<double>, 3>
|
|||
|
|
|
|||
|
|
protected:
|
|||
|
|
const std::unique_ptr<LOG> logger_; // Logger类
|
|||
|
|
|
|||
|
|
const std::string rule_id_; // 规则ID
|
|||
|
|
|
|||
|
|
const size_t dims_;
|
|||
|
|
|
|||
|
|
RunningStats running_stats_; ///< 整体数据的统计特征
|
|||
|
|
RunningStats weekly_running_stats_; ///< 本周运行统计
|
|||
|
|
|
|||
|
|
bool is_first_sampling_ = true;
|
|||
|
|
|
|||
|
|
size_t rs_count_ = 0;
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
RsMgr(std::string rule_id_, size_t dims);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 载入running state信息,在此之前要检测是否是第一次采样
|
|||
|
|
* @return true
|
|||
|
|
* @return false
|
|||
|
|
*/
|
|||
|
|
bool load();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 第一次采样函数,data_load为第一次采样中,cron进程累积的数据
|
|||
|
|
* @param data_load My Param doc
|
|||
|
|
* @return int
|
|||
|
|
*/
|
|||
|
|
int first_sampling(const SampleWindow& data_load);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 是否是第一次采样,如果是,则需要执行first_sampling()函数
|
|||
|
|
* @return true
|
|||
|
|
* @return false
|
|||
|
|
*/
|
|||
|
|
bool is_first_sampling();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Get the running stats object
|
|||
|
|
* @return RunningStats
|
|||
|
|
*/
|
|||
|
|
RunningStats get_running_stats();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 把mon进程中满足条件的单个周期的数据存在其中
|
|||
|
|
* @param value My Param doc
|
|||
|
|
* @return true
|
|||
|
|
* @return false
|
|||
|
|
*/
|
|||
|
|
bool store(const SamplePoint& value);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 把数据变更写入磁盘
|
|||
|
|
* @return true
|
|||
|
|
* @return false
|
|||
|
|
*/
|
|||
|
|
bool commit();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 每周组织报告数据
|
|||
|
|
* @return int
|
|||
|
|
*/
|
|||
|
|
// int weekly_organize_data();
|
|||
|
|
|
|||
|
|
protected:
|
|||
|
|
/**
|
|||
|
|
* @brief 正态偏移检验
|
|||
|
|
* @return int
|
|||
|
|
*/
|
|||
|
|
int normal_dist_shift_alarm();
|
|||
|
|
};
|
|||
|
|
} // namespace data_handler
|