refactor: 删除 ExpModule 类(已被 ExpressionEngine 替代)
This commit is contained in:
parent
3f8d281596
commit
e9b2c178ba
@ -1,138 +0,0 @@
|
||||
#include <eqpalg/gb_item_memory.h>
|
||||
#include <eqpalg/utility/ExpModule.h>
|
||||
#include <glob/SingletonTemplate.h>
|
||||
ExpModule::ExpModule(std::map<std::string, double> &vars_ref,
|
||||
vector<string> &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<LOG>("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<MExp>(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<double, Eigen::Dynamic, Eigen::Dynamic> queried_data,
|
||||
std::vector<TimePoint> 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<double, Eigen::Dynamic, Eigen::Dynamic> queried_data,
|
||||
std::vector<TimePoint> 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<GlobaltemSharedMemory>::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<milliseconds>(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<GlobaltemSharedMemory>::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<milliseconds>(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); }
|
||||
@ -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 <chrono>
|
||||
#include <eqpalg/utility/StatExp.hpp>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
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<std::string, double> &vars_ref, vector<string> &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<double, Eigen::Dynamic, Eigen::Dynamic> queried_data,
|
||||
std::vector<TimePoint> 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<double, Eigen::Dynamic, Eigen::Dynamic> queried_data,
|
||||
std::vector<TimePoint> queried_time, int row);
|
||||
|
||||
private:
|
||||
map<string, double> &mm_vars;
|
||||
map<string, double> exp_result_;
|
||||
map<string, std::unique_ptr<MExp>> exp_ptr_;
|
||||
map<string, string> exp_str_;
|
||||
vector<string> &m_tags;
|
||||
std::unique_ptr<LOG> logger_;
|
||||
TimePoint now_time_;
|
||||
/**
|
||||
* @brief 自定义带状态函数
|
||||
*/
|
||||
StatExp::FunVars fun_vars_;
|
||||
bool &is_exp_alg_;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user