121 lines
4.3 KiB
C++
121 lines
4.3 KiB
C++
/******************************************************************************************************************
|
||
* Action instruction algorithm
|
||
*
|
||
* arg[0] data determination expression
|
||
*
|
||
*
|
||
*
|
||
* 1.0 2020-12-17 zoufuzhou
|
||
******************************************************************************************************************/
|
||
#include <eqpalg/algs/exp_material.h>
|
||
#include <eqpalg/utility/build_alarm_info.h>
|
||
#include <eqpalg/utility/equip_prod.h>
|
||
#include <mix_cc/ihyper_db/utility.h>
|
||
#include <mix_cc/type/mix_time.h>
|
||
#include <map>
|
||
#include <memory>
|
||
#include <string>
|
||
#include <utility>
|
||
/**
|
||
* @brief 重新载入结合物料算法
|
||
* @return int
|
||
*/
|
||
int ExpMaterial::init() {
|
||
int ret = 0;
|
||
try {
|
||
Exp::init();
|
||
pmem_trk_ = std::make_unique<CMemTrk>();
|
||
m_entId = (*pmem_trk_)(m_zone)->entId;
|
||
m_startpos = -1;
|
||
this->data_source_ = DataSource::MEMORY;
|
||
m_zone = rule_json_.at("action_condition").at("zone").at(1).get<int64>();
|
||
} catch (const std::exception& e) {
|
||
std::throw_with_nested(
|
||
mix_cc::Exception(-1, "load error", BOOST_CURRENT_LOCATION));
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
ExpMaterial::ExpMaterial(const string& name, const mix_cc::json& rule_json,
|
||
const string& ruleId)
|
||
: Exp(name, rule_json, ruleId, 1) {
|
||
logger_.reset(new LOG("ExpMaterial:" + rule_name_, AUTO_CATCH_PID));
|
||
}
|
||
|
||
ExpMaterial::~ExpMaterial() {}
|
||
|
||
AlarmInfo ExpMaterial::mon_proc() {
|
||
AlarmInfo now_alarm;
|
||
try {
|
||
act_triggered_ = exp_act_->evaluate();
|
||
// logger_->Debug() << "act_triggered_:" << exp_str_ << "=" <<
|
||
// act_triggered_
|
||
// << endl;
|
||
if (static_cast<bool>(act_triggered_)) {
|
||
this->print_exp_vars(exp_str_);
|
||
// 获得钢卷信息,同CPC算法
|
||
string entId = (*pmem_trk_)(m_zone)->entId;
|
||
if (m_startpos >= 0 && entId != m_entId) {
|
||
m_endpos = (*pmem_trk_).getHistory(m_zone, CS_TRK::BEFORE)->wplen;
|
||
if (m_endpos < 1000) {
|
||
logger_->Warn() << " end pos is zero " << endl;
|
||
m_endpos = 1500;
|
||
}
|
||
|
||
auto msg = rule_name_ + " 钢卷:" + m_entId + "位置m[" +
|
||
std::to_string(m_startpos / 1000) + "," +
|
||
std::to_string(m_endpos / 1000) + "T]," +
|
||
rule_json_.at("action_condition")
|
||
.at("error")
|
||
.at(1)
|
||
.get<std::string>();
|
||
logger_->Debug() << msg << endl;
|
||
|
||
now_alarm =
|
||
utility::build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
|
||
"EXP_MAT", msg, query_time_range_);
|
||
utility::equip_prod(
|
||
rule_id_, m_entId, m_startpos, m_endpos,
|
||
SingletonTemplate<
|
||
GlobaltemSharedMemory>::GetInstance()["D122_FUR_SPEED"]);
|
||
m_startpos = -1;
|
||
} else if (m_startpos < 0) {
|
||
m_startpos = (*pmem_trk_)(m_zone)->wplen;
|
||
m_entId = (*pmem_trk_)(m_zone)->entId;
|
||
auto msg = rule_name_ + "start 钢卷:" + m_entId +
|
||
"位置m:" + std::to_string(m_startpos / 1000) +
|
||
rule_json_.at("action_condition")
|
||
.at("error")
|
||
.at(1)
|
||
.get<std::string>();
|
||
logger_->Debug() << msg << endl;
|
||
}
|
||
} else if (m_startpos >= 0) {
|
||
int m_endpos = (*pmem_trk_)(m_zone)->wplen;
|
||
auto msg = rule_name_ + " 钢卷:" + m_entId + "位置m[" +
|
||
std::to_string(m_startpos / 1000) + "," +
|
||
std::to_string(m_endpos / 1000) + "]," +
|
||
rule_json_.at("action_condition")
|
||
.at("error")
|
||
.at(1)
|
||
.get<std::string>();
|
||
logger_->Debug() << msg << endl;
|
||
now_alarm =
|
||
utility::build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
|
||
"EXP_MAT", msg, query_time_range_);
|
||
utility::equip_prod(
|
||
rule_id_, m_entId, m_startpos, m_endpos,
|
||
SingletonTemplate<
|
||
GlobaltemSharedMemory>::GetInstance()["D122_FUR_SPEED"]);
|
||
m_startpos = -1;
|
||
} else {
|
||
m_startpos = -1;
|
||
m_entId = (*pmem_trk_)(m_zone)->entId;
|
||
}
|
||
} catch (const std::exception& e) {
|
||
std::throw_with_nested(
|
||
mix_cc::Exception(-1, "calc_once error", BOOST_CURRENT_LOCATION));
|
||
}
|
||
return now_alarm;
|
||
}
|