From e9b2c178ba7604f009373d45cf00818c3426e9dd Mon Sep 17 00:00:00 2001 From: Huamonarch Date: Fri, 15 May 2026 13:15:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=20ExpModule=20?= =?UTF-8?q?=E7=B1=BB=EF=BC=88=E5=B7=B2=E8=A2=AB=20ExpressionEngine=20?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eqpalg/utility/ExpModule.cc | 138 ------------------------------------ eqpalg/utility/ExpModule.h | 112 ----------------------------- 2 files changed, 250 deletions(-) delete mode 100644 eqpalg/utility/ExpModule.cc delete mode 100644 eqpalg/utility/ExpModule.h diff --git a/eqpalg/utility/ExpModule.cc b/eqpalg/utility/ExpModule.cc deleted file mode 100644 index 737f7cb..0000000 --- a/eqpalg/utility/ExpModule.cc +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include -#include -ExpModule::ExpModule(std::map &vars_ref, - vector &m_tags, bool &is_exp_alg_ref) - : mm_vars(vars_ref), m_tags(m_tags), is_exp_alg_(is_exp_alg_ref) { - logger_ = std::make_unique("ExpModule"); - init(); -} - -ExpModule::~ExpModule() {} -int ExpModule::add_exp(string exp_name, string exp_str) { - if (exp_str_.find(exp_name) == exp_str_.end()) { - exp_str_[exp_name] = exp_str; - fun_vars_.add_exp_str(exp_str, &mm_vars); - exp_ptr_[exp_name] = std::make_unique(exp_str, &mm_vars); - try { - exp_result_[exp_name] = exp_ptr_[exp_name]->evaluate(); - } catch (const std::exception &e) { - logger_->Error() << "add_exp:" << e.what() << std::endl; - } - } -} -int ExpModule::update() { - if (is_exp_alg_ != true) { - this->refresh_exp_vars_mem(); - this->fun_vars_.refresh_fun_vars(false, &mm_vars); - } - - for (auto item : this->exp_str_) { - exp_result_[item.first] = exp_ptr_[item.first]->evaluate(); - } -} - -int ExpModule::update( - Eigen::Matrix queried_data, - std::vector queried_time, int row) { - if (is_exp_alg_ != true) { - this->refresh_exp_ihd_mem(queried_data, queried_time, row); - this->fun_vars_.refresh_fun_vars(false, &mm_vars); - } - - for (auto item : this->exp_str_) { - exp_result_[item.first] = exp_ptr_[item.first]->evaluate(); - } -} - -void ExpModule::refresh_exp_ihd_mem( - Eigen::Matrix queried_data, - std::vector queried_time, int row) { - if (queried_data.rows() == 0 || queried_data.cols() == 0) { - logger_->Error() << "refresh_exp_ihd_mem: queried_data is empty" - << std::endl; - return; - } - - for (unsigned int i = 0; i < m_tags.size(); i++) { - if (row >= queried_data.rows() || i >= (unsigned int)queried_data.cols()) { - continue; - } - mm_vars["p" + std::to_string(i + 1)] = - mm_vars["tag" + std::to_string(i + 1)]; - mm_vars["tag" + std::to_string(i + 1)] = queried_data(row, i); - mm_vars["now"] = mix_cc::mix_time_t(queried_time[row]).to_milliseconds(); - auto pv_str = "pv" + std::to_string(i + 1); - - mm_vars[pv_str + "_5"] = mm_vars[pv_str + "_4"]; - mm_vars[pv_str + "_4"] = mm_vars[pv_str + "_3"]; - mm_vars[pv_str + "_3"] = mm_vars[pv_str + "_2"]; - mm_vars[pv_str + "_2"] = mm_vars[pv_str + "_1"]; - mm_vars[pv_str + "_1"] = mm_vars[pv_str + "_0"]; - mm_vars[pv_str + "_0"] = mm_vars["tag" + std::to_string(i + 1)]; - } -} - -void ExpModule::refresh_exp_vars_mem() { - this->now_time_ = std::chrono::system_clock::now(); - for (unsigned int i = 0; i < m_tags.size(); i++) { - mm_vars["p" + std::to_string(i + 1)] = - mm_vars["tag" + std::to_string(i + 1)]; - mm_vars["tag" + std::to_string(i + 1)] = - SingletonTemplate::GetInstance()[m_tags[i]]; - auto pv_str = "pv" + std::to_string(i + 1); - mm_vars[pv_str + "_5"] = mm_vars[pv_str + "_4"]; - mm_vars[pv_str + "_4"] = mm_vars[pv_str + "_3"]; - mm_vars[pv_str + "_3"] = mm_vars[pv_str + "_2"]; - mm_vars[pv_str + "_2"] = mm_vars[pv_str + "_1"]; - mm_vars[pv_str + "_1"] = mm_vars[pv_str + "_0"]; - mm_vars[pv_str + "_0"] = mm_vars["tag" + std::to_string(i + 1)]; - } - mm_vars["now"] = - duration_cast(now_time_.time_since_epoch()).count(); -} -void ExpModule::init() { - this->now_time_ = std::chrono::system_clock::now(); - for (unsigned int i = 0; i < m_tags.size(); i++) { - double value = - SingletonTemplate::GetInstance()[m_tags[i]]; - mm_vars["p" + std::to_string(i + 1)] = value; - mm_vars["tag" + std::to_string(i + 1)] = value; - - mm_vars["now"] = - duration_cast(now_time_.time_since_epoch()).count(); - auto pv_str = "pv" + std::to_string(i + 1); - - mm_vars[pv_str + "_0"] = value; - mm_vars[pv_str + "_1"] = value; - mm_vars[pv_str + "_2"] = value; - mm_vars[pv_str + "_3"] = value; - mm_vars[pv_str + "_4"] = value; - mm_vars[pv_str + "_5"] = value; - } -} - -double ExpModule::get_value(string exp_name) { - try { - return exp_result_[exp_name]; - } catch (const std::exception &e) { - logger_->Error() << "get_value:" << e.what() << std::endl; - return 0; - } -} -void ExpModule::print_value() { - logger_->Debug() << "mm_vars:"; - for (auto item : mm_vars) { - logger_->Debug() << " " << item.first << ":" << item.second; - } - logger_->Debug() << std::endl; -} - -string ExpModule::get_exp_str(string exp_name) { - if (exp_str_.find(exp_name) == exp_str_.end()) { - return ""; - } - return exp_str_[exp_name]; -} - -void ExpModule::fun_reset() { fun_vars_.refresh_fun_vars(true, &mm_vars); } diff --git a/eqpalg/utility/ExpModule.h b/eqpalg/utility/ExpModule.h deleted file mode 100644 index dd68f3b..0000000 --- a/eqpalg/utility/ExpModule.h +++ /dev/null @@ -1,112 +0,0 @@ -#pragma once -/** - * @file ExpModule.h - * @brief 表达式模块 - * @author your name (you@domain.com) - * @version 0.1 - * @date 2025-08-20 - * - * Copyright: Baosight Co. Ltd. - * DO NOT COPY/USE WITHOUT PERMISSION - * - */ -#include "mix_cc/ihyper_db.h" -#include "mix_cc/json.h" -#include "mix_cc/matheval/matheval.hpp" -#include -#include -#include -#include -#include -#include -#include -using std::map; -using std::string; -using std::vector; -using MExp = mix_cc::matheval::Expression; -using namespace std::chrono; -using std::chrono::system_clock; -using TimePoint = system_clock::time_point; -using TimeDur = milliseconds; - -class ExpModule { -public: - ExpModule(std::map &vars_ref, vector &m_tags, - bool &is_exp_alg_ref); - ~ExpModule(); - ExpModule() = delete; - ExpModule &operator=(const ExpModule &) = delete; - - /** - * @brief 添加表达式 - * @param exp_name 表达式名称 - * @param exp_str 表达式字符串 - * @return int - */ - int add_exp(string exp_name, string exp_str); - /** - * @brief 更新数据,更新表达式的值 - * @return int - */ - int update(); - - void fun_reset(); - - /** - * @brief 更新数据,更新表达式的值 通过指定数据 - * @param queried_data 指定数据项 - * @return int - */ - int update(Eigen::Matrix queried_data, - std::vector queried_time, int row = 0); - /** - * @brief 获取表达式的值 - * @param exp_name 表达式名称 - * @return double - */ - double get_value(string exp_name); - /** - * @brief - */ - void print_value(); - - /** - * @brief Get the exp str object - * @param exp_name My Param doc - * @return string - */ - string get_exp_str(string exp_name); - -private: - /** - * @brief 表达式变量,表达式初始化 - */ - void init(); - - /** - * @brief 更新数据 共享内存 - */ - void refresh_exp_vars_mem(); - - /** - * @brief 更新数据 指定数据 - * @param queried_data - */ - void refresh_exp_ihd_mem( - Eigen::Matrix queried_data, - std::vector queried_time, int row); - -private: - map &mm_vars; - map exp_result_; - map> exp_ptr_; - map exp_str_; - vector &m_tags; - std::unique_ptr logger_; - TimePoint now_time_; - /** - * @brief 自定义带状态函数 - */ - StatExp::FunVars fun_vars_; - bool &is_exp_alg_; -};