eis/eqpalg/feature_extraction/STA.h

229 lines
4.8 KiB
C
Raw Normal View History

#pragma once
/**
* @file STA.h
* @brief
* @author your name (you@domain.com)
* @version 0.1
* @date 2024-01-09
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#include <cmath>
#include <dlib/statistics.h>
#include <eqpalg/define/public.h>
#include <eqpalg/feature_extraction/distribution.h>
#include <log4cplus/LOG.h>
#include <map>
#include <memory>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
namespace DAA {
using RSD = dlib::running_stats<double>;
using std::map;
using std::string;
using std::unordered_map;
using std::vector;
const int STA_SIZE_MIN = 50;
string double2str(double data, int precision = 2);
/**
* @brief limit 32768
* @param data My Param doc
* @param precision My Param doc
* @return string
*/
string double2strLimit(double data, int precision = 2);
/**
* @brief
* @param data
* @param precision 2
* @return double
*/
double limit_precision(double data, int precision = 2);
int64_t double2int64_t(double data, bool is_need = true);
double int64_t2double(int64_t data, bool is_need = true);
/**
* @brief
* eg a0,a0+range,a0+2range,,an
* data对应的 an
* @param a0
* @param range
* @param data
* @return double an
*/
double arith_seq(double a0, double range, double data);
struct FreqDistData {
double X1;
size_t Count;
};
/**
* @brief [min,max]
* @param _min My Param doc
* @param _max My Param doc
* @return double
*/
double RandMinMax(double _min, double _max);
/**
* @brief
*/
class STA {
public:
STA(const string &ruleid, const string &rulename);
~STA();
/**
* @brief
* @param data My Param doc
*/
void dist_add(double data);
/**
* @brief T_RULE_SAMPLE_1D_INFO
* @return true
* @return false
*/
bool is_init();
/**
* @brief T_RULE_SAMPLE_1D_INFO
* @param range My Param doc
* @param init_value My Param doc
* @return true
* @return false
*/
bool init(double range, double init_value);
/**
* @brief T_RULE_SAMPLE_1D数据
* @return true
* @return false
*/
bool store_db2();
/**
* @brief T_SAMPLE_STAT数据
* @return true
* @return false
*/
bool task_store_db2(string sampleid);
size_t size();
/**
* @brief mon接口
* @return mix_cc::float_range_t
*/
static mix_cc::float_range_t select_from_t_rule_feature(std::string ruleid);
/**
* @brief mon接口
* @return mix_cc::float_range_t
*/
static mix_cc::float_range_t select_from_t_sample_mag(std::string ruleid);
/**
* @brief ruleid对应的统计信息
* T_RULE_SAMPLE_1D,
* T_RULE_SAMPLE_1D_INFO,
* T_SAMPLE_RECORD
* T_RULE_SAMPLE_FEATURE
* @param ruleid My Param doc
* @return int
*/
static int delete_statistics_data(std::string ruleid);
/**
* @brief cron接口
* @return int
*/
int update_ci_dist();
/**
* @brief
* 1.
* @return true
* @return false
*/
bool reset_data();
/**
* @brief task接口
* @return int
*/
int task_update_ci_dist();
/**
* @brief task接口
* jsonT_SAMPLE_MAG
* cron内部接口
* T_SAMPLE_RECORD
* @return string
*/
string get_sample_stat_str();
void running_stat_add(double data);
private:
string rule_id_;
RSD running_stat_;
bool is_init_ = false;
std::unique_ptr<LOG> logger_;
Dist dist_1d_;
bool is_need_ = true;
double range_;
double init_value_;
map<int64_t, int64_t> dist_data_;
double scale_;
static constexpr size_t k_dest_dump_size = 10000;
vector<FreqDistData> sample_1d_data_;
mix_cc::float_range_t dist_range_ci_;
bool is_task_ = false;
SampleStat sample_stat_;
int seq_ = 0;
private:
/**
* @brief
*/
void init();
/**
* @brief running_stat_
* @return int
*/
int update_running_stat();
/**
* @brief t_rule_sample_feature
* @return int
*/
int update_t_rule_sample_feature();
/**
* @brief t_sample_record
* @return int
*/
int update_t_sample_record();
/**
* @brief sample_stat_
* json
*
* @return int
*/
int update_t_sample_mag();
bool reset_data(double range, double init_value);
/**
* @brief Get the seq object
* @return int
*/
int get_seq();
};
} // namespace DAA