#pragma once /** * @file exp_base.h * @brief 表达式类 * 覆盖算法号:1,2,3,4,5 * exp_type_ * 表达式类型:1-逻辑判断;2-变量上下限;3-动作反馈-逻辑判断;4-动作反馈-上下限;5-上下限-保持时间 * 算法号2,4,5的cron累积样本,保存至db2 T_RULE_SAMPLE_1D * @author your name (you@domain.com) * @version 0.1 * @date 2023-12-22 * * Copyright: Baosight Co. Ltd. * DO NOT COPY/USE WITHOUT PERMISSION * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /** * @brief 表达式类,可以自动检测是否带有动作反馈 */ class ExpBase : public AlgBase { public: ExpBase(const string &name, const mix_cc::json &rule_json, const string &ruleId, size_t exp_type); ~ExpBase() override; public: /** * @brief 重新载入表达式及其配置 * @return int */ virtual int init() override; /** * @brief 得到所有的计算结果 * @return std::string */ AlarmInfo exec_mon() override; /** * @brief Set the last alarm time object * unpause时,重新刷新mm_vars,屏蔽因长时间的停机再开机的误报 * @param time_point My Param doc */ virtual void set_last_alarm_time(TimePoint time_point = system_clock::now()) override; /** * @brief Set the usable object * set_usable 重新刷新mm_vars,屏蔽因长时间的停用带来的误报 * @param usable My Param doc */ virtual void set_usable(bool usable) override; /** * @brief 得到在指定时间内的单次执行结果,该执行只会从ihdb中获取历史数据 * 所以要确保对应时间和TAG点的历史数据确实存储在了IHDB中 * @param time_range 对应时间的历史数据 * @return AlarmInfo */ std::vector exec_task(mix_cc::time_range_t time_range) override; /** * @brief 保持数据 正常/异常 start end */ void save_rule_norm_data() override; /** * @brief mon 最小的执行单元 * @return AlarmInfo */ virtual AlarmInfo mon_proc(); virtual mix_cc::json exec_cron(); /** * @brief cron 最小执行单元 * @return AlarmInfo */ virtual int cron_proc(); /** * @brief 重置统计信息 * mon---- * 删除 * 四张表(T_RULE_SAMPLE_1D,T_RULE_SAMPLE_1D_INFO,T_SAMPLE_RECORD,T_SAMPLE_RECORD,T_RULE_SAMPLE_FEATURE)rule_id_对应数据 * cron---- * 重置 stat_collector_(stat_collector_.reset()) */ virtual void reset_dev_data() override; bool get_prr() override; protected: /** * @brief 重新载入数据源信息 * @return int */ int reload_config_data_source(); /** * @brief 重新载入表达式(不带反馈)信息,并确定算法是否是带反馈的算法 * @return int */ int reload_config_exp_act(); /** * @brief Get the cycled cron object * @return true * @return false */ bool get_cycled_cron(); private: /** * @brief 载入上下限 * @return int */ int reload_config_up_down(); /** * @brief载入上、下限及保持时间 * @return int */ int reload_config_up_down_hold_time(); private: /** * @brief 重新载入反馈表达式、计算表达式、反馈限制执行时间 * @return int */ int reload_config_exp_feedback(); protected: string exp_str_; string error_str_; string unit_; protected: const size_t exp_type_; TimeDur time_out_; TimePoint act_start_time_; bool act_started_ = false; FbStateMachine fb_fsm_; int refresh_counts_ = 0; protected: bool feedback_mode_ = false; bool keep_mode_ = false; double limit_up_ = 0; double limit_down_ = 0; TimeDur hold_time_ = 0ms; StatCollector stat_collector_; std::map> hold_times_; bool exp_is_wrong_ = true; bool exp_wrong_is_alarmed_ = false; int dist_mode_; bool is_learning_ = true; TimePoint last_load_time_; int64_t CronUpdateDelay = StatConst::CronUpdateDelay; std::string sample_type_ = SampleType::T_SAMPLE_STAT; std::string sample_id_; std::string sample_result_; DetectMode detect_mode_ = DetectMode::Default; BoundChecker bound_checker_; bool filter_flag_ = false; protected: /** * @brief 从ihd查询数据--task用 */ void query_ihd_data(); /** * @brief 重新载入置信区间 * @return int */ int reload_ci_dist(); /** * @brief task执行函数 */ virtual void task_mon_pro(); /** * @brief 生成样本id * ruleid(3,21)_starttime_endtime * @return string */ string get_id(mix_cc::time_range_t time_range); /** * @brief task 任务 计算的数据 * 算法 2-监控变量-上下限 * 4-动作反馈-上下限 * 5-监控变量-上下限-持续 * @return TaskReturnType */ TaskReturnType task_base_proc(); /** * @brief * @param vlid 计算结果是否合法 * @return int */ int update_t_sample_mag(bool vlid); /** * @brief 检测是否超区间 * @param value My Param doc * @return true 超出区间 false 在区间内 */ bool detect_up_down(const double &value); /** * @brief task进程接口 运行前提条件 * @param i My Param doc * @return true * @return false */ bool task_prr(int row); };