#pragma once /** * @file eqpalg/define/public.h * @brief eqpalg项目下常用公共定义 * @author Cat (null.null.null@qq.com) * @version 0.1 * @date 2021-07-08 * * Company: Baosight Co. Ltd. * DO NOT COPY/USE WITHOUT PERMISSION * */ #include "mix_cc/json.h" #include #include #define EVENT_NO_MAX 2019 #define EVENT_NO_MIN 2000 #define STASTIC_DAYS 7 /** * @brief 进程类型 */ enum class ProcessType { kNull = 0, kMon, kCron, kTask }; /** * @brief 其他算法与机器学习类算法的临界算法号 */ struct AlgId_ML { static const int AlgIdMLMin = 110; }; /** * @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; 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; }; // DetectMode 已提取至 eqpalg/utility/bound_checker.h(enum class) /** * @brief 规则运行前提条件 */ struct PRR { static const int None = 0; static const int Exp = 1; }; /** * @brief */ struct StatConst { static const int64_t CronUpdateDelay = 24; static const int StatClassCount = 50; }; /** * @brief 样本类型 */ struct SampleType { static constexpr char T_SAMPLE_FIT[] = "T_SAMPLE_FIT"; static constexpr char T_SAMPLE_STAT[] = "T_SAMPLE_STAT"; }; /** * @brief 导入模型标记位 */ struct CreateModels { bool create_new_models = false; }; /** * @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; }; /** * @brief 数据来源 * 包含IHDB和共享内存 */ struct DataSource { static const int16_t IHDB = 0; static const int16_t MEMORY = 1; }; /** * @brief 存储消息类型 */ struct MsgLevel { static constexpr char INFO[] = "INFO"; static constexpr char WARN[] = "WARN"; static constexpr char ERROR[] = "ERROR"; }; /** * @brief 报警信息结构体 */ struct AlarmInfo { /** * @brief Construct a new Alarm Info object */ AlarmInfo() { alarmed = false; auto tmp = std::chrono::system_clock::now(); alarm_start_time = tmp; alarm_end_time = tmp; } ~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; /** * @brief 规则配置信息 */ struct ConfigInfo { std::string id; std::string name; std::string group; std::string remark; std::string descName; }; ConfigInfo cfg_info; }; /** * @brief sample2D二维数据 数据结构 * */ struct sample2D { int orders = 1; std::vector> fit_coefs; std::vector scores; double pear_coefs; std::string method; bool init() { fit_coefs.clear(); scores.clear(); return true; } nlohmann::json invert2json() { nlohmann::json js1; js1["orders"] = orders; js1["fit_coefs"] = fit_coefs; js1["scores"] = scores; js1["pear_coefs"] = pear_coefs; js1["method"] = method; return js1; } }; /** * @brief sample_stat统计数据 数据结构 */ struct SampleStat { double ci_left = 0; double ci_right = 0; double mean = 0; double stddev = 0; double skewness = 0; double kurtosis = 0; double variance = 0; double range = 0; double init_value = 0; double min = 0; double max = 0; nlohmann::json invert2json() { nlohmann::json js1; js1["ci_left"] = limit_precision(ci_left); js1["ci_right"] = limit_precision(ci_right); js1["mean"] = limit_precision(mean, 3); js1["min"] = limit_precision(min, 3); js1["max"] = limit_precision(max, 3); js1["stddev"] = stddev; js1["kurtosis"] = kurtosis; js1["variance"] = variance; js1["skewness"] = skewness; js1["range"] = limit_precision(range, 3); js1["init_value"] = limit_precision(init_value, 3); return js1; } double limit_precision(double data, int precision = 2) { double factor = std::pow(10, precision); return std::round(data * factor) / factor; } }; struct TaskReturnType { bool is_valid = false; double value = 0; };