[ref]同步711

This commit is contained in:
shi_jq 2025-03-13 11:20:48 +08:00
parent 95701fb017
commit 7a756a047d
9 changed files with 337 additions and 349 deletions

View File

@ -6,18 +6,20 @@
*/ */
#include "CalcServerThread.h" #include "CalcServerThread.h"
#include "pub_lua_engine_api/LuaEngineInterface.h" #include <string>
#include <exception> #include <exception>
#include <algorithm>
#include "pub_lua_engine_api/LuaEngineInterface.h"
#include "common/Common.h" #include "common/Common.h"
#include "boost/algorithm/string.hpp" #include "boost/algorithm/string.hpp"
#include "boost/lexical_cast.hpp" #include "boost/lexical_cast.hpp"
#include "net_msg_bus_api/CMbCommunicator.h" #include "net_msg_bus_api/CMbCommunicator.h"
#include "CalcServerCommon.h" #include "CalcServerCommon.h"
#include "string"
#include "common/MessageChannel.h" #include "common/MessageChannel.h"
#include "pub_utility_api/TimeUtil.h" #include "pub_utility_api/TimeUtil.h"
#include "service/common/CommonDefine.h" #include "service/common/CommonDefine.h"
#include "string" #include "pub_utility_api/FileUtil.h"
#include "pub_utility_api/CommonConfigParse.h"
using namespace std; using namespace std;
using namespace iot_public; using namespace iot_public;
@ -37,6 +39,9 @@ SInPointInfoMap CalcServerThread::m_inPointInfoMAP; //输入
SOutPointInfoMap CalcServerThread::m_outPointInfoMap; //保存上次发送的点值和状态 SOutPointInfoMap CalcServerThread::m_outPointInfoMap; //保存上次发送的点值和状态
SInOutVecMap CalcServerThread::m_inOutVecMap; SInOutVecMap CalcServerThread::m_inOutVecMap;
const int CN_Calc_Period = 1000; //计算周期,单位ms
const int CN_Send_Data_Period = 15 * 1000; //定时发送所有计算数据的周期单位ms
iot_service::CalcServerThread::CalcServerThread(const iot_public::SRunAppInfo &stRunAppInfo) iot_service::CalcServerThread::CalcServerThread(const iot_public::SRunAppInfo &stRunAppInfo)
:iot_public::CTimerThreadBase("CalcServerThread",0), :iot_public::CTimerThreadBase("CalcServerThread",0),
m_stRunAppInfo(stRunAppInfo), m_stRunAppInfo(stRunAppInfo),
@ -46,6 +51,8 @@ iot_service::CalcServerThread::CalcServerThread(const iot_public::SRunAppInfo &s
clean(); clean();
m_lastCheckCfgTime = 0; //上次检查配置时间 m_lastCheckCfgTime = 0; //上次检查配置时间
m_lastCalcTime = 0; m_lastCalcTime = 0;
m_nCalcPeriod = CN_Calc_Period;
m_nSendAllDataPeriod = CN_Send_Data_Period;
} }
iot_service::CalcServerThread::~CalcServerThread() iot_service::CalcServerThread::~CalcServerThread()
{ {
@ -63,6 +70,16 @@ iot_service::CalcServerThread::~CalcServerThread()
//初始化 //初始化
int iot_service::CalcServerThread::initialize() int iot_service::CalcServerThread::initialize()
{ {
//加载配置文件
if(!loadConfig())
{
LOGERROR("加载配置文件proc_param_cfg.xml失败");
return iotFailed;
}
//初始化发送消息的结构体
initDataMsgCache();
//1.初始化内存表操作类 //1.初始化内存表操作类
m_ptrCalcTableOpt=boost::make_shared<CalcRtdbTableOperate> (m_stRunAppInfo); m_ptrCalcTableOpt=boost::make_shared<CalcRtdbTableOperate> (m_stRunAppInfo);
if(m_ptrCalcTableOpt ==NULL) if(m_ptrCalcTableOpt ==NULL)
@ -143,22 +160,9 @@ int iot_service::CalcServerThread::initialize()
LOGERROR("CalcServerThread::initialize() 初始化lua失败"); LOGERROR("CalcServerThread::initialize() 初始化lua失败");
return iotFailed; return iotFailed;
} }
luabridge::getGlobalNamespace(lua_state)
.beginNamespace ("kbd") registFunctionToLua();
.addFunction ("getDataByIndex",&CalcServerThread::getDataByIndex)
.endNamespace ();
luabridge::getGlobalNamespace(lua_state)
.beginNamespace ("kbd")
.addFunction ("getInParamNum",&CalcServerThread::getInParamNum)
.endNamespace ();
luabridge::getGlobalNamespace(lua_state)
.beginNamespace ("kbd")
.addFunction ("getBitAnd",&CalcServerThread::getBitAnd)
.endNamespace ();
luabridge::getGlobalNamespace(lua_state)
.beginNamespace ("kbd")
.addFunction ("getBitOr",&CalcServerThread::getBitOr)
.endNamespace ();
return iotSuccess; return iotSuccess;
} }
//设置为主 //设置为主
@ -217,11 +221,13 @@ void iot_service::CalcServerThread::execute()
} }
//3.计算结果并发送(变化+定时)给data_process //3.计算结果并发送(变化+定时)给data_process
if(nCurTimeMSec - m_lastCalcTime > 1000) //一秒钟计算一次,没必要太频繁,提高效率 if(nCurTimeMSec - m_lastCalcTime > m_nCalcPeriod) //一秒钟计算一次,没必要太频繁,提高效率
{ {
m_lastCalcTime = nCurTimeMSec ;
calcAndSend(); //变化发送 calcAndSend(); //变化发送
timersendtoDp();//定时发送默认5000ms发一次 timersendtoDp();//定时发送默认5000ms发一次
hanleDataMsgCache(); //发送缓冲区数据
m_lastCalcTime = nCurTimeMSec ;
} }
return ; return ;
} }
@ -908,15 +914,8 @@ void iot_service::CalcServerThread::sendToDp(const std::string strName,const std
varValue.set_edatatype( CN_DATATYPE_DOUBLE ); varValue.set_edatatype( CN_DATATYPE_DOUBLE );
varValue.set_dvalue(atof(outValue.c_str())); varValue.set_dvalue(atof(outValue.c_str()));
} }
if(AddOptSetData(strTableName,strTagName,nAddStatus,nDelStatus,varValue) == iotSuccess)
{ AddOptSetData(nPointType,strTableName,strTagName,nAddStatus,nDelStatus,varValue);
sendCalcData(nPointType,false);
}
else
{
m_stOptDataMsg.clear_seq_set_data_info();
m_stOptDataMsg.Clear();
}
return; return;
} }
@ -945,10 +944,17 @@ int CalcServerThread::needSend(const string strName, const string outValue, cons
} }
return iotSuccess; return iotSuccess;
} }
int iot_service::CalcServerThread::AddOptSetData(const string strTableName, const string strTagName,
int iot_service::CalcServerThread::AddOptSetData(const int nPntType,const string strTableName, const string strTagName,
const int nAddStatus, const int nDelStatus, const SVariable varValue) const int nAddStatus, const int nDelStatus, const SVariable varValue)
{ {
SOptSetDataMsg *OptSetData = m_stOptDataMsg.add_seq_set_data_info() ; if(nPntType >= m_vecMsg.size())
{
LOGERROR("添加计算结果到发送缓冲区失败.原因:无法识别的数据类型%d",nPntType);
return iotFailed;
}
SOptSetDataMsg *OptSetData = m_vecMsg[nPntType].add_seq_set_data_info() ;
if(OptSetData) if(OptSetData)
{ {
OptSetData->set_str_tag_name(strTagName); OptSetData->set_str_tag_name(strTagName);
@ -958,7 +964,7 @@ int iot_service::CalcServerThread::AddOptSetData(const string strTableName, cons
} }
else else
{ {
m_stOptDataMsg.clear_seq_set_data_info(); m_vecMsg[nPntType].clear_seq_set_data_info();
LOGERROR("AddOptSetData, key_id_tag = %s.%s, nAddStatus=%d,nDelStatus=%d Fail ",\ LOGERROR("AddOptSetData, key_id_tag = %s.%s, nAddStatus=%d,nDelStatus=%d Fail ",\
strTableName.c_str(), strTagName.c_str(), nAddStatus, nDelStatus); strTableName.c_str(), strTagName.c_str(), nAddStatus, nDelStatus);
return iotFailed; return iotFailed;
@ -966,38 +972,6 @@ int iot_service::CalcServerThread::AddOptSetData(const string strTableName, cons
return iotSuccess; return iotSuccess;
} }
void iot_service::CalcServerThread::sendCalcData(const int nPointType, const bool bNotAlarm)
{
int nNum = m_stOptDataMsg.seq_set_data_info_size() ;
//需要发送的数据为空
if ( nNum <1 )
{
//LOGDEBUG("CSrvDataPublish::SendOptData(): nNum =0, send return !") ;
return;
}
SOptDataPkgHead stHead;
stHead.set_str_src_tag("calc_server");
stHead.set_b_not_alarm(bNotAlarm); //是否初始化
stHead.set_n_point_type(nPointType); //点类型
stHead.set_n_opt_time(getUTCTimeMsec());
m_stOptDataMsg.mutable_package_head()->CopyFrom(stHead);
string strSendBuff;
m_stOptDataMsg.SerializeToString(&strSendBuff) ;
int nRetCode = m_ptrMsgbusMng->sendToHost(MT_OPT_SET_CAL_DATA_DOWN,CH_OPT_TO_SCADA_VALUE_SET,strSendBuff);
if (nRetCode == false)
{
LOGERROR("CalcServerThread::SendOptData(), nRetCode = %d, buf_size = %d, sendToHost Error",
nRetCode, (int)strSendBuff.size());
}
m_stOptDataMsg.clear_package_head();
m_stOptDataMsg.clear_seq_set_data_info();
m_stOptDataMsg.Clear();
return;
}
void CalcServerThread::timersendtoDp() void CalcServerThread::timersendtoDp()
{ {
@ -1009,7 +983,7 @@ void CalcServerThread::timersendtoDp()
if(it != m_outPointInfoMap.end()) if(it != m_outPointInfoMap.end())
{ {
SOutPointInfo &sConstTimeOutDataInfo = it->second; SOutPointInfo &sConstTimeOutDataInfo = it->second;
if(iot_public::getUTCTimeMsec() > (sConstTimeOutDataInfo.nTime + 5000)) if(iot_public::getUTCTimeMsec() > static_cast<int64>(sConstTimeOutDataInfo.nTime + m_nSendAllDataPeriod))
{ {
sConstTimeOutDataInfo.nTime = iot_public::getUTCTimeMsec(); sConstTimeOutDataInfo.nTime = iot_public::getUTCTimeMsec();
sendToDp(it->first,sConstTimeOutDataInfo.value,sConstTimeOutDataInfo.nvalid); sendToDp(it->first,sConstTimeOutDataInfo.value,sConstTimeOutDataInfo.nvalid);
@ -1150,3 +1124,92 @@ int CalcServerThread::dealLuaRef(luabridge::LuaRef ret, string &strValue, int &n
} }
return iotSuccess; return iotSuccess;
} }
bool CalcServerThread::loadConfig()
{
iot_public::CCommonConfigParse configParse;
if (iotSuccess != configParse.load(iot_public::CFileUtil::getPathOfCfgFile("proc_param_cfg.xml")))
{
LOGERROR("加载配置文件proc_param_cfg.xml失败");
return false;
}
m_nCalcPeriod = configParse.getIntWithDefault(CN_ProcName_CalcServer,"calc_period",CN_Calc_Period);
m_nSendAllDataPeriod = configParse.getIntWithDefault(CN_ProcName_CalcServer,"calc_period",CN_Calc_Period);
return true;
}
void CalcServerThread::initDataMsgCache()
{
SOptSetDataPkg stMsg;
SOptDataPkgHead *pHead = stMsg.mutable_package_head();
pHead->set_str_src_tag(CN_ProcName_CalcServer);
pHead->set_b_not_alarm(false); //产生告警,若为true则测点不会生成告警
pHead->set_n_opt_time(0);
std::vector<int> vecPntType = {POINT_TYPE_ANA,POINT_TYPE_DIG,POINT_TYPE_MIX,POINT_TYPE_ACC};
int nMaxSize = *std::max_element(vecPntType.begin(),vecPntType.end()) + 1;
m_vecMsg.resize(nMaxSize,stMsg);
for(int i = 0; i < static_cast<int>(m_vecMsg.size()); i++)
{
m_vecMsg[i].mutable_package_head()->set_n_point_type(i);
}
}
void CalcServerThread::hanleDataMsgCache()
{
for(size_t i = 0; i < m_vecMsg.size();i++)
{
sendMsgToDP(m_vecMsg[i]);
}
}
void CalcServerThread::sendMsgToDP(iot_idl::SOptSetDataPkg &stMsg)
{
if(stMsg.seq_set_data_info().empty())
{
return;
}
stMsg.mutable_package_head()->set_n_opt_time(getUTCTimeMsec());
string strSendBuff;
if(!stMsg.SerializeToString(&strSendBuff))
{
stMsg.clear_seq_set_data_info();
LOGERROR("序列化计算结果失败");
return;
}
bool nRetCode = m_ptrMsgbusMng->sendToHost(MT_OPT_SET_CAL_DATA_DOWN,CH_OPT_TO_SCADA_VALUE_SET,strSendBuff);
if (!nRetCode)
{
LOGERROR("CalcServerThread::SendOptData(), nRetCode = %d, buf_size = %d, sendToHost Error",
nRetCode, (int)strSendBuff.size());
}
stMsg.clear_seq_set_data_info();
}
void CalcServerThread::registFunctionToLua()
{
luabridge::getGlobalNamespace(lua_state)
.beginNamespace ("kbd")
.addFunction ("getDataByIndex",&CalcServerThread::getDataByIndex)
.addFunction ("getInParamNum",&CalcServerThread::getInParamNum)
.addFunction ("getBitAnd",&CalcServerThread::getBitAnd)
.addFunction ("getBitOr",&CalcServerThread::getBitOr)
.endNamespace ();
//< 更换为新命名空间,老的命名空间不再新增函数
luabridge::getGlobalNamespace(lua_state)
.beginNamespace ("iot")
.addFunction ("getDataByIndex",&CalcServerThread::getDataByIndex)
.addFunction ("getInParamNum",&CalcServerThread::getInParamNum)
.addFunction ("getBitAnd",&CalcServerThread::getBitAnd)
.addFunction ("getBitOr",&CalcServerThread::getBitOr)
.endNamespace ();
}

View File

@ -34,6 +34,27 @@ namespace iot_service {
public: public:
CalcServerThread(const iot_public::SRunAppInfo &stRunAppInfo); CalcServerThread(const iot_public::SRunAppInfo &stRunAppInfo);
virtual ~CalcServerThread(); virtual ~CalcServerThread();
/**
* @brief execute
*/
virtual void execute();
/**
* @brief initialize
* @return iotSuccess
*/
int initialize();
/**
* @brief setMaster
* @return iotSuccess
*/
int setMaster();
/**
* @brief setSlave
* @return iotSuccess
*/
int setSlave();
private:
/** /**
* @brief getDataByIndex 使 * @brief getDataByIndex 使
* @param index * @param index
@ -63,26 +84,6 @@ namespace iot_service {
* @return * @return
*/ */
static luabridge::LuaRef getBitOr(double first,double second,lua_State *LuaState); static luabridge::LuaRef getBitOr(double first,double second,lua_State *LuaState);
/**
* @brief initialize
* @return iotSuccess
*/
int initialize();
/**
* @brief setMaster
* @return iotSuccess
*/
int setMaster();
/**
* @brief setSlave
* @return iotSuccess
*/
int setSlave();
/**
* @brief execute
*/
virtual void execute();
/** /**
* @brief TryReadConfig * @brief TryReadConfig
* @return falsetrue * @return falsetrue
@ -250,15 +251,8 @@ namespace iot_service {
* @param strValue * @param strValue
* @param bSendImme * @param bSendImme
*/ */
int AddOptSetData(const std::string strTableName,const std::string strTagName,const int nAddStatus, int AddOptSetData(const int nPntType,const std::string strTableName,const std::string strTagName,
const int nDelStatus,const iot_idl::SVariable varValue); const int nAddStatus,const int nDelStatus,const iot_idl::SVariable varValue);
/**
* @brief sendCalcData dp
* @param nPointType
* @param bInit
* @param nDstDomain
*/
void sendCalcData(const int nPointType, const bool bNotAlarm = false); //-1为本域
/** /**
* @brief timersendtoDp dp 5 * @brief timersendtoDp dp 5
*/ */
@ -278,15 +272,45 @@ namespace iot_service {
* @return * @return
*/ */
int dealLuaRef(luabridge::LuaRef ret, std::string &strValue, int &nStatus, bool &isChange); int dealLuaRef(luabridge::LuaRef ret, std::string &strValue, int &nStatus, bool &isChange);
/**
* @brief
* @return
*/
bool loadConfig();
/**
* @brief
* @return
*/
void initDataMsgCache();
/**
* @brief
* @return
*/
void hanleDataMsgCache();
/**
* @brief
* @param stMsg
* @return
*/
void sendMsgToDP(iot_idl::SOptSetDataPkg &stMsg);
/**
* @brief C++lua环境中
* @return
*/
void registFunctionToLua();
private: private:
int64 m_lastCheckCfgTime; //上次检查配置时间 int64 m_lastCheckCfgTime; //上次检查配置时间
int64 m_lastCalcTime; //上次计算公式时间 int64 m_lastCalcTime; //上次计算公式时间
int m_nCalcPeriod; //计算周期,单位ms
int m_nSendAllDataPeriod; //定时发送所有计算数据的周期单位ms
iot_public::SRunAppInfo m_stRunAppInfo; //本应用运行参数 iot_public::SRunAppInfo m_stRunAppInfo; //本应用运行参数
CalcRtdbTableOperatePtr m_ptrCalcTableOpt; //计算量相关内存表操作类 CalcRtdbTableOperatePtr m_ptrCalcTableOpt; //计算量相关内存表操作类
CalcMsgBusMngPtr m_ptrMsgbusMng; //消息总线管理类 CalcMsgBusMngPtr m_ptrMsgbusMng; //消息总线管理类
iot_service::CDpcdaForAppPtr m_ptrCdpcda; //订阅点 iot_service::CDpcdaForAppPtr m_ptrCdpcda; //订阅点
std::vector<iot_idl::SOptSetDataPkg> m_vecMsg; //操作数据缓存,下标与数据类型对应
iot_idl::SOptSetDataPkg m_stOptDataMsg; //操作数据
CDataProcessApiPtr m_ptrDataProcApi; CDataProcessApiPtr m_ptrDataProcApi;
iot_dbms::CRdbTableMngPtr m_ptrRdbTableMng; iot_dbms::CRdbTableMngPtr m_ptrRdbTableMng;

View File

@ -21,10 +21,12 @@ iot_service::CComputeUnit::CComputeUnit(QObject *parent, CComputeTaskPtr taskPtr
m_iteration(0), m_iteration(0),
m_iteration_cnt(0), m_iteration_cnt(0),
m_luaState(luaL_newstate()), m_luaState(luaL_newstate()),
m_objFunc(m_luaState), //m_objFunc(m_luaState),
m_taskPtr(taskPtr), m_taskPtr(taskPtr),
m_parentWorker(parentWorker) // 计算完成发送信号, m_parentWorker(parentWorker) // 计算完成发送信号,
{ {
m_pLuaFunc = new luabridge::LuaRef(m_luaState);
//< 设置定时期类型 //< 设置定时期类型
m_timer.setTimerType(Qt::PreciseTimer); m_timer.setTimerType(Qt::PreciseTimer);
@ -60,6 +62,9 @@ iot_service::CComputeUnit::~CComputeUnit()
} }
} }
delete m_pLuaFunc;
m_pLuaFunc = NULL;
if (m_luaState != NULL) if (m_luaState != NULL)
{ {
lua_close(m_luaState); lua_close(m_luaState);
@ -407,7 +412,7 @@ int iot_service::CComputeUnit::initLuaEnv()
} }
//< 赋值函数 //< 赋值函数
m_objFunc = luabridge::getGlobal(m_luaState, m_taskPtr->statTemplate()->_template_tag.c_str()); *m_pLuaFunc = luabridge::getGlobal(m_luaState, m_taskPtr->statTemplate()->_template_tag.c_str());
return iotSuccess; return iotSuccess;
} }
@ -536,31 +541,31 @@ int iot_service::CComputeUnit::callFunction(std::vector<luabridge::LuaRef> &vecA
// LOGTRACE("当前计算统计实例%s,调用函数个数%d",m_taskPtr->tagName().c_str(),vecArgs.size()); // LOGTRACE("当前计算统计实例%s,调用函数个数%d",m_taskPtr->tagName().c_str(),vecArgs.size());
switch (vecArgs.size()) { switch (vecArgs.size()) {
case 0: case 0:
ret = m_objFunc(); ret = (*m_pLuaFunc)();
break; break;
case 1: case 1:
ret = m_objFunc(vecArgs[0]); ret = (*m_pLuaFunc)(vecArgs[0]);
break; break;
case 2: case 2:
ret = m_objFunc(vecArgs[0],vecArgs[1]); ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1]);
break; break;
case 3: case 3:
ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2]); ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2]);
break; break;
case 4: case 4:
ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3]); ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3]);
break; break;
case 5: case 5:
ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4]); ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4]);
break; break;
case 6: case 6:
ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5]); ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5]);
break; break;
case 7: case 7:
ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5],vecArgs[6]); ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5],vecArgs[6]);
break; break;
case 8: case 8:
ret = m_objFunc(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5],vecArgs[6],vecArgs[7]); ret = (*m_pLuaFunc)(vecArgs[0],vecArgs[1],vecArgs[2],vecArgs[3],vecArgs[4],vecArgs[5],vecArgs[6],vecArgs[7]);
break; break;
default: default:
break; break;

View File

@ -55,7 +55,8 @@ private:
int m_state; //< 计算单元的状态 good 1 bad 0 int m_state; //< 计算单元的状态 good 1 bad 0
lua_State* m_luaState; lua_State* m_luaState;
luabridge::LuaRef m_objFunc; //luabridge::LuaRef m_objFunc;
luabridge::LuaRef *m_pLuaFunc;
CComputeTaskPtr m_taskPtr; CComputeTaskPtr m_taskPtr;
CComputeWorker* m_parentWorker; CComputeWorker* m_parentWorker;
qint64 m_nextComputeTimestamp; qint64 m_nextComputeTimestamp;

View File

@ -36,6 +36,8 @@ iot_service::CMainThreadMng::~CMainThreadMng()
//< 清空数据结构 //< 清空数据结构
m_mapTagTemplate.reset(); m_mapTagTemplate.reset();
m_mapTagTask.reset(); m_mapTagTask.reset();
//delete computeworker;
//computeworker = NULL;
} }
int iot_service::CMainThreadMng::initialize() int iot_service::CMainThreadMng::initialize()
@ -70,14 +72,14 @@ int iot_service::CMainThreadMng::initialize()
connect(this,&CMainThreadMng::subDpCHgWorkerInit,subDpChgWorker,&CSubDpChgWorker::initialize,Qt::BlockingQueuedConnection); connect(this,&CMainThreadMng::subDpCHgWorkerInit,subDpChgWorker,&CSubDpChgWorker::initialize,Qt::BlockingQueuedConnection);
connect(this,&CMainThreadMng::start,computeworker,&CComputeWorker::startAll,Qt::QueuedConnection);//< 开始计算 connect(this,&CMainThreadMng::start,computeworker,&CComputeWorker::startAll,Qt::QueuedConnection);//< 开始计算
connect(this,&CMainThreadMng::stop,computeworker,&CComputeWorker::stopAll,Qt::QueuedConnection); //< 停止计算 connect(this,&CMainThreadMng::stop,computeworker,&CComputeWorker::stopAll,Qt::DirectConnection); //< 停止计算
connect(this,&CMainThreadMng::restart,computeworker,&CComputeWorker::restartAll,Qt::QueuedConnection); //< 停止并重新开始计算 connect(this,&CMainThreadMng::restart,computeworker,&CComputeWorker::restartAll,Qt::QueuedConnection); //< 停止并重新开始计算
connect(computeworker,&CComputeWorker::computed,publishWorker,&CPublishWorker::publishResult,Qt::QueuedConnection); //<计算完发布 connect(computeworker,&CComputeWorker::computed,publishWorker,&CPublishWorker::publishResult,Qt::QueuedConnection); //<计算完发布
connect(subDpChgWorker,&CSubDpChgWorker::needCompute,computeworker,&CComputeWorker::compute,Qt::QueuedConnection); connect(subDpChgWorker,&CSubDpChgWorker::needCompute,computeworker,&CComputeWorker::compute,Qt::QueuedConnection);
connect(this,&CMainThreadMng::start,subDpChgWorker,&CSubDpChgWorker::sub,Qt::QueuedConnection);//< 开始订阅变化点 connect(this,&CMainThreadMng::start,subDpChgWorker,&CSubDpChgWorker::sub,Qt::QueuedConnection);//< 开始订阅变化点
connect(this,&CMainThreadMng::stop,subDpChgWorker,&CSubDpChgWorker::unsub,Qt::QueuedConnection); //< 停止订阅变化点 connect(this,&CMainThreadMng::stop,subDpChgWorker,&CSubDpChgWorker::unsub,Qt::DirectConnection); //< 停止订阅变化点
//< 清空缓存 //< 清空缓存
removeCache(); removeCache();
@ -109,6 +111,7 @@ void iot_service::CMainThreadMng::stopCompute()
{ {
LOGDEBUG("stopCompute()"); LOGDEBUG("stopCompute()");
g_is_need_stopcompute = true; g_is_need_stopcompute = true;
// disconnect(computeworker,&CComputeWorker::computed,publishWorker,&CPublishWorker::publishResult); //<计算完发布
emit this->stop(); emit this->stop();
} }

View File

@ -11,6 +11,7 @@
#include "pub_utility_api/TimeUtil.h" #include "pub_utility_api/TimeUtil.h"
#include "boost/lexical_cast.hpp" #include "boost/lexical_cast.hpp"
#include "common/MessageChannel.h" #include "common/MessageChannel.h"
#include "../stat_server_function/global_var.h"
iot_service::CPublishWorker::CPublishWorker(QObject *parent, const iot_public::SRunAppInfo &stRunAppInfo): iot_service::CPublishWorker::CPublishWorker(QObject *parent, const iot_public::SRunAppInfo &stRunAppInfo):
QObject(parent),m_stRunAppInfo(stRunAppInfo) QObject(parent),m_stRunAppInfo(stRunAppInfo)
@ -89,6 +90,10 @@ int iot_service::CPublishWorker::initialize()
void iot_service::CPublishWorker::publishResult(QString instTag, double value, int status, bool isBind, QString pointTag) void iot_service::CPublishWorker::publishResult(QString instTag, double value, int status, bool isBind, QString pointTag)
{ {
if(g_is_need_stopcompute)
{
return;
}
// checkMainThread(); // checkMainThread();
LOGTRACE("发布结果,返回值标签%s,值%f,状态%d(1有效,0无效),是否绑定测点%d(1绑定,0不绑定),绑定测点标签%s",instTag.toStdString().c_str(),value,status,(int)isBind,pointTag.toStdString().c_str()); LOGTRACE("发布结果,返回值标签%s,值%f,状态%d(1有效,0无效),是否绑定测点%d(1绑定,0不绑定),绑定测点标签%s",instTag.toStdString().c_str(),value,status,(int)isBind,pointTag.toStdString().c_str());

View File

@ -37,12 +37,12 @@ bool iot_service::CStatSrvApp::start(int argc, char *argv[], int &nStatus)
} }
//< 3.避免进程重复启动 //< 3.避免进程重复启动
if(isAlreadyRunning()) // if(isAlreadyRunning())
{ // {
LOGERROR("进程已存在,不允许再次启动"); // LOGERROR("进程已存在,不允许再次启动");
nStatus = iotFailed; // nStatus = iotFailed;
return false; // return false;
} // }
//< 4.初始化消息总线和tsdb_api() //< 4.初始化消息总线和tsdb_api()
if(!initMsgBusAndTsdb()) if(!initMsgBusAndTsdb())

View File

@ -24,197 +24,76 @@ bool g_is_need_stopcompute = false;
void iot_service::CLuaBuiltInFunc::loadKbdFunctions(lua_State *luaState) void iot_service::CLuaBuiltInFunc::loadKbdFunctions(lua_State *luaState)
{ {
//< 线程暂停测试
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("threadStop", CLuaBuiltInFunc::threadStop)
.endNamespace ();
//< 加载PCS收益与各时段统计
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("PcsIncomeAndPerPeriod", CLuaBuiltInFunc::PcsIncomeAndPerPeriod)
.endNamespace ();
//< 加载PV收益与各时段统计
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("PvIncomeAndPerPeriod", CLuaBuiltInFunc::PvIncomeAndPerPeriod)
.endNamespace ();
//< 加载尖峰平谷计算
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getCurveChg", CLuaBuiltInFunc::getCurveChg)
.endNamespace ();
//< 加载时统计差量比
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getHourRatio", CLuaBuiltInFunc::getHourRatio)
.endNamespace ();
//< 加载日统计差量比
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getDayRatio", CLuaBuiltInFunc::getDayRatio)
.endNamespace ();
//< 加载月统计差量比
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getMonthRatio", CLuaBuiltInFunc::getMonthRatio)
.endNamespace ();
//< 加载年统计差量比
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getYearRatio", CLuaBuiltInFunc::getYearRatio)
.endNamespace ();
//< 加载最新时统计差量
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getLatestHourDiff", CLuaBuiltInFunc::getLatestHourDiff)
.endNamespace ();
//< 加载最新日统计差量
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getLatestDayDiff", CLuaBuiltInFunc::getLatestDayDiff)
.endNamespace ();
//< 加载最新月统计差量
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getLatestMonthDiff", CLuaBuiltInFunc::getLatestMonthDiff)
.endNamespace ();
//< 加载最新年统计差量
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getLatestYearDiff", CLuaBuiltInFunc::getLatestYearDiff)
.endNamespace ();
//< 加载日统计累计值(差值计算)
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getDayDiff", CLuaBuiltInFunc::getDayDiff)
.endNamespace ();
//< 加载月统计累计值(差值计算)
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getMonthDiff", CLuaBuiltInFunc::getMonthDiff)
.endNamespace ();
//< 加载年统计累计值(差值计算)
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getYearDiff", CLuaBuiltInFunc::getYearDiff)
.endNamespace ();
//< 加载累计量统计输出(差值计算)
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("monthPerYear", CLuaBuiltInFunc::MonthPerYear)
.endNamespace ();
luabridge::getGlobalNamespace(luaState) luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd") .beginNamespace ("kbd")
.addFunction ("threadStop", CLuaBuiltInFunc::threadStop) //< 线程暂停测试
.addFunction ("PcsIncomeAndPerPeriod", CLuaBuiltInFunc::PcsIncomeAndPerPeriod) //< 加载PCS收益与各时段统计
.addFunction ("PvIncomeAndPerPeriod", CLuaBuiltInFunc::PvIncomeAndPerPeriod) //< 加载PV收益与各时段统计
.addFunction ("getCurveChg", CLuaBuiltInFunc::getCurveChg) //< 加载尖峰平谷计算
.addFunction ("getHourRatio", CLuaBuiltInFunc::getHourRatio) //< 加载时统计差量比
.addFunction ("getDayRatio", CLuaBuiltInFunc::getDayRatio) //< 加载日统计差量比
.addFunction ("getMonthRatio", CLuaBuiltInFunc::getMonthRatio) //< 加载月统计差量比
.addFunction ("getYearRatio", CLuaBuiltInFunc::getYearRatio) //< 加载年统计差量比
.addFunction ("getLatestHourDiff", CLuaBuiltInFunc::getLatestHourDiff) //< 加载最新时统计差量
.addFunction ("getLatestDayDiff", CLuaBuiltInFunc::getLatestDayDiff) //< 加载最新日统计差量
.addFunction ("getLatestMonthDiff", CLuaBuiltInFunc::getLatestMonthDiff) //< 加载最新月统计差量
.addFunction ("getLatestYearDiff", CLuaBuiltInFunc::getLatestYearDiff) //< 加载最新年统计差量
.addFunction ("getDayDiff", CLuaBuiltInFunc::getDayDiff) //< 加载日统计累计值(差值计算)
.addFunction ("getMonthDiff", CLuaBuiltInFunc::getMonthDiff) //< 加载月统计累计值(差值计算)
.addFunction ("getYearDiff", CLuaBuiltInFunc::getYearDiff) //< 加载年统计累计值(差值计算)
.addFunction ("monthPerYear", CLuaBuiltInFunc::MonthPerYear) //< 加载累计量统计输出(差值计算)
.addFunction ("hourPerDay", CLuaBuiltInFunc::hourPerDay) .addFunction ("hourPerDay", CLuaBuiltInFunc::hourPerDay)
.endNamespace ();
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("dayPerMonth", CLuaBuiltInFunc::DayPerMonth) .addFunction ("dayPerMonth", CLuaBuiltInFunc::DayPerMonth)
.endNamespace ();
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("genPrice", CLuaBuiltInFunc::genPrice) .addFunction ("genPrice", CLuaBuiltInFunc::genPrice)
.endNamespace ();
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("log", CLuaBuiltInFunc::log) .addFunction ("log", CLuaBuiltInFunc::log)
.endNamespace ();
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getLastVal", CLuaBuiltInFunc::getLastVal) .addFunction ("getLastVal", CLuaBuiltInFunc::getLastVal)
.addFunction ("chargeCount", CLuaBuiltInFunc::chargeCount) //< 充放电次数和充放电时长计算
.addFunction ("getAccFromDaily", CLuaBuiltInFunc::getAccFromDaily) //< 充放电次数和充放电时长计算
.addFunction ("getHourChangeCnt", CLuaBuiltInFunc::getHourChangeCnt) //< 加载时统计变化次数
.addFunction ("getDayChangeCnt", CLuaBuiltInFunc::getDayChangeCnt) //< 加载日统计变化次数
.addFunction ("getMonthChangeCnt", CLuaBuiltInFunc::getMonthChangeCnt) //< 加载月统计变化次数
.addFunction ("getYearChangeCnt", CLuaBuiltInFunc::getYearChangeCnt) //< 加载年统计变化次数
.addFunction ("getHourRunningTime", CLuaBuiltInFunc::getHourRunningTime) //< 加载时统计变化次数
.addFunction ("getDayRunningTime", CLuaBuiltInFunc::getDayRunningTime) //< 加载日统计变化次数
.addFunction ("getMonthRunningTime", CLuaBuiltInFunc::getMonthRunningTime) //< 加载月统计变化次数
.addFunction ("getYearRunningTime", CLuaBuiltInFunc::getYearRunningTime) //< 加载年统计变化次数
.endNamespace (); .endNamespace ();
//< 充放电次数和充放电时长计算 //< 更换为新命名空间,老的命名空间不再新增函数
luabridge::getGlobalNamespace(luaState) luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd") .beginNamespace ("iot")
.addFunction ("chargeCount", CLuaBuiltInFunc::chargeCount) .addFunction ("threadStop", CLuaBuiltInFunc::threadStop) //< 线程暂停测试
.addFunction ("PcsIncomeAndPerPeriod", CLuaBuiltInFunc::PcsIncomeAndPerPeriod) //< 加载PCS收益与各时段统计
.addFunction ("PvIncomeAndPerPeriod", CLuaBuiltInFunc::PvIncomeAndPerPeriod) //< 加载PV收益与各时段统计
.addFunction ("getCurveChg", CLuaBuiltInFunc::getCurveChg) //< 加载尖峰平谷计算
.addFunction ("getHourRatio", CLuaBuiltInFunc::getHourRatio) //< 加载时统计差量比
.addFunction ("getDayRatio", CLuaBuiltInFunc::getDayRatio) //< 加载日统计差量比
.addFunction ("getMonthRatio", CLuaBuiltInFunc::getMonthRatio) //< 加载月统计差量比
.addFunction ("getYearRatio", CLuaBuiltInFunc::getYearRatio) //< 加载年统计差量比
.addFunction ("getLatestHourDiff", CLuaBuiltInFunc::getLatestHourDiff) //< 加载最新时统计差量
.addFunction ("getLatestDayDiff", CLuaBuiltInFunc::getLatestDayDiff) //< 加载最新日统计差量
.addFunction ("getLatestMonthDiff", CLuaBuiltInFunc::getLatestMonthDiff) //< 加载最新月统计差量
.addFunction ("getLatestYearDiff", CLuaBuiltInFunc::getLatestYearDiff) //< 加载最新年统计差量
.addFunction ("getDayDiff", CLuaBuiltInFunc::getDayDiff) //< 加载日统计累计值(差值计算)
.addFunction ("getMonthDiff", CLuaBuiltInFunc::getMonthDiff) //< 加载月统计累计值(差值计算)
.addFunction ("getYearDiff", CLuaBuiltInFunc::getYearDiff) //< 加载年统计累计值(差值计算)
.addFunction ("monthPerYear", CLuaBuiltInFunc::MonthPerYear) //< 加载累计量统计输出(差值计算)
.addFunction ("hourPerDay", CLuaBuiltInFunc::hourPerDay)
.addFunction ("dayPerMonth", CLuaBuiltInFunc::DayPerMonth)
.addFunction ("genPrice", CLuaBuiltInFunc::genPrice)
.addFunction ("log", CLuaBuiltInFunc::log)
.addFunction ("getLastVal", CLuaBuiltInFunc::getLastVal)
.addFunction ("chargeCount", CLuaBuiltInFunc::chargeCount) //< 充放电次数和充放电时长计算
.addFunction ("getAccFromDaily", CLuaBuiltInFunc::getAccFromDaily) //< 充放电次数和充放电时长计算
.addFunction ("getHourChangeCnt", CLuaBuiltInFunc::getHourChangeCnt) //< 加载时统计变化次数
.addFunction ("getDayChangeCnt", CLuaBuiltInFunc::getDayChangeCnt) //< 加载日统计变化次数
.addFunction ("getMonthChangeCnt", CLuaBuiltInFunc::getMonthChangeCnt) //< 加载月统计变化次数
.addFunction ("getYearChangeCnt", CLuaBuiltInFunc::getYearChangeCnt) //< 加载年统计变化次数
.addFunction ("getHourRunningTime", CLuaBuiltInFunc::getHourRunningTime) //< 加载时统计变化次数
.addFunction ("getDayRunningTime", CLuaBuiltInFunc::getDayRunningTime) //< 加载日统计变化次数
.addFunction ("getMonthRunningTime", CLuaBuiltInFunc::getMonthRunningTime) //< 加载月统计变化次数
.addFunction ("getYearRunningTime", CLuaBuiltInFunc::getYearRunningTime) //< 加载年统计变化次数
.endNamespace (); .endNamespace ();
//< 充放电次数和充放电时长计算
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getAccFromDaily", CLuaBuiltInFunc::getAccFromDaily)
.endNamespace ();
//< 加载时统计变化次数
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getHourChangeCnt", CLuaBuiltInFunc::getHourChangeCnt)
.endNamespace ();
//< 加载日统计变化次数
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getDayChangeCnt", CLuaBuiltInFunc::getDayChangeCnt)
.endNamespace ();
//< 加载月统计变化次数
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getMonthChangeCnt", CLuaBuiltInFunc::getMonthChangeCnt)
.endNamespace ();
//< 加载年统计变化次数
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getYearChangeCnt", CLuaBuiltInFunc::getYearChangeCnt)
.endNamespace ();
//< 加载时统计变化次数
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getHourRunningTime", CLuaBuiltInFunc::getHourRunningTime)
.endNamespace ();
//< 加载日统计变化次数
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getDayRunningTime", CLuaBuiltInFunc::getDayRunningTime)
.endNamespace ();
//< 加载月统计变化次数
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getMonthRunningTime", CLuaBuiltInFunc::getMonthRunningTime)
.endNamespace ();
//< 加载年统计变化次数
luabridge::getGlobalNamespace(luaState)
.beginNamespace ("kbd")
.addFunction ("getYearRunningTime", CLuaBuiltInFunc::getYearRunningTime)
.endNamespace ();
} }
void iot_service::CLuaBuiltInFunc::threadStop(){ void iot_service::CLuaBuiltInFunc::threadStop(){
@ -1085,7 +964,7 @@ double iot_service::CLuaBuiltInFunc::getPeriodDiff(const std::string keyIdTag, i
{ {
LOGERROR("influxdb连接异常"); LOGERROR("influxdb连接异常");
//< 赋值给返回结果 //< 赋值给返回结果
return 0; return -INFINITY;
} }
else{ else{
} }
@ -1105,18 +984,27 @@ double iot_service::CLuaBuiltInFunc::getPeriodDiff(const std::string keyIdTag, i
//< 查询最后一个值 //< 查询最后一个值
if(!findLastVal(*conn.get(),key,-1,endTime,&vecStatusNotHave,endVal)) if(!findLastVal(*conn.get(),key,-1,endTime,&vecStatusNotHave,endVal))
{ {
LOGERROR("查询右边界值错误"); LOGERROR("tag[%s]查询右边界值错误key[%s],start[%lld],end[%lld]", keyIdTag.c_str(), tagName.c_str(), startTime, endTime);
return 0; return -INFINITY;
} }
//< 查询左边界值 //< 查询左边界值
if(!findLastVal(*conn.get(),key,-1,startTime,&vecStatusNotHave,startVal)) if(!findLastVal(*conn.get(),key,startTime-43200000,startTime,&vecStatusNotHave,startVal))
{ {
LOGERROR("查询左边界值错误"); LOGERROR("tag[%s]查询左边界值错误key[%s],start[%lld],end[%lld]", keyIdTag.c_str(), tagName.c_str(), startTime, endTime);
return endVal; return endVal;
} }
if (endVal - startVal >= 0)
{
LOGTRACE("tag[%s]计算值key[%s],start[%lld],end[%lld],startVal[%f],endVal[%f]", keyIdTag.c_str(), tagName.c_str(), startTime, endTime, startVal, endVal);
return endVal - startVal; return endVal - startVal;
}
else
{
LOGERROR("tag[%s]query-error-key[%s],start[%lld],end[%lld],startVal[%f],endVal[%f]", keyIdTag.c_str(), tagName.c_str(), startTime, endTime, startVal, endVal);
return -INFINITY;
}
} }
double iot_service::CLuaBuiltInFunc::getDayDiff(std::string keyIdTag) double iot_service::CLuaBuiltInFunc::getDayDiff(std::string keyIdTag)

View File

@ -10,7 +10,6 @@
#include <pub_sysinfo_api/SysInfoApi.h> #include <pub_sysinfo_api/SysInfoApi.h>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/rational.hpp> #include <boost/rational.hpp>
#include <dbms/tsdb_api/TsdbApi.h> #include <dbms/tsdb_api/TsdbApi.h>
#include <public/pub_utility_api/FileUtil.h> #include <public/pub_utility_api/FileUtil.h>
@ -222,7 +221,7 @@ bool iot_service::StatUtil::findYieldPoints(iot_dbms::CTsdbConn &objConn, const
for(std::size_t i = 0 ; i < vecResult[0]->size();i++) for(std::size_t i = 0 ; i < vecResult[0]->size();i++)
{ {
double value = boost::lexical_cast<double>(vecResult[0]->at(i).m_varValue); double value = boost::get<boost::float64_t>(vecResult[0]->at(i).m_varValue);
if((int)(value) !=0) if((int)(value) !=0)
{ {
outYieldPoints.push_back(vecResult[0]->at(i)); outYieldPoints.push_back(vecResult[0]->at(i));
@ -253,7 +252,7 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin
} }
// ms级别是十三位 // ms级别是十三位
firstCurveTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); firstCurveTime = vecResult[0]->at(0).m_nTime;
delete vecResult[0]; delete vecResult[0];
} }
else{ else{
@ -271,7 +270,7 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin
return false; return false;
} }
firstChargeVal = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); // ms级别是十三位 firstChargeVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue); // ms级别是十三位
delete vecResult[0]; delete vecResult[0];
} }
@ -294,9 +293,9 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin
return false; return false;
} }
firstChargeVal = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); firstChargeVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
firstChargeTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); firstChargeTime = vecResult[0]->at(0).m_nTime;
delete vecResult[0]; delete vecResult[0];
} }
@ -315,8 +314,8 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin
return false; return false;
} }
firstCurveVal = boost::lexical_cast<int>(vecResult[0]->at(0).m_varValue); firstCurveVal = boost::get<boost::int32_t>(vecResult[0]->at(0).m_varValue);
firstCurveTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime);// ms级别是十三位 firstCurveTime = (vecResult[0]->at(0).m_nTime);// ms级别是十三位
delete vecResult[0]; delete vecResult[0];
} }
} }
@ -340,8 +339,8 @@ bool iot_service::StatUtil::findPvFirstPoints(iot_dbms::CTsdbConn &objConn, quin
} }
firstCurveVal = boost::lexical_cast<int>(vecResult[0]->at(0).m_varValue); firstCurveVal = boost::get<boost::int32_t>(vecResult[0]->at(0).m_varValue);
firstCurveTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); firstCurveTime = (vecResult[0]->at(0).m_nTime);
delete vecResult[0]; delete vecResult[0];
} }
return true; return true;
@ -373,7 +372,7 @@ bool iot_service::StatUtil::handleChgYieldPoints(iot_dbms::CTsdbConn &objConn, c
return false; return false;
} }
endChargeVal = boost::lexical_cast<boost::float64_t>(vecResult[0]->at(0).m_varValue); endChargeVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
diffChargeVal = endChargeVal - startChargeVal; //< 计算该区间放电差值 diffChargeVal = endChargeVal - startChargeVal; //< 计算该区间放电差值
resultTmp[startCurveVal] += diffChargeVal; resultTmp[startCurveVal] += diffChargeVal;
@ -383,14 +382,14 @@ bool iot_service::StatUtil::handleChgYieldPoints(iot_dbms::CTsdbConn &objConn, c
//< 为下一个区间计算作准备 //< 为下一个区间计算作准备
startChargeVal = endChargeVal; startChargeVal = endChargeVal;
startCurveVal += (int)(boost::lexical_cast<boost::float64_t>(yieldPoints.at(i).m_varValue)); startCurveVal += boost::get<boost::int32_t>(yieldPoints.at(i).m_varValue);
if(startCurveVal < 1 || startCurveVal > 4 ) if(startCurveVal < 1 || startCurveVal > 4 )
{ {
LOGERROR("峰平谷尖值不正确,%d",startCurveVal); LOGERROR("峰平谷尖值不正确,%d",startCurveVal);
return false; return false;
} }
startCurveTime = boost::lexical_cast<quint64>(yieldPoints.at(i).m_nTime); startCurveTime = (yieldPoints.at(i).m_nTime);
LOGTRACE("处理区间%d完成",(int)i); LOGTRACE("处理区间%d完成",(int)i);
} }
@ -412,8 +411,8 @@ bool iot_service::StatUtil::handleChgYieldPoints(iot_dbms::CTsdbConn &objConn, c
return false; return false;
} }
lastChargeTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); lastChargeTime = (vecResult[0]->at(0).m_nTime);
lastChargeVal = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); lastChargeVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
resultTmp[startCurveVal] += lastChargeVal - startChargeVal; // ms级别是十三位 resultTmp[startCurveVal] += lastChargeVal - startChargeVal; // ms级别是十三位
@ -460,7 +459,7 @@ bool iot_service::StatUtil::handlePvYieldPoints(iot_dbms::CTsdbConn &objConn, co
return false; return false;
} }
endChargeVal = boost::lexical_cast<boost::float64_t>(vecResult[0]->at(0).m_varValue); endChargeVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
//< 检查当前区间是否跨天,如果跨天,当前时段的发电度量清零 //< 检查当前区间是否跨天,如果跨天,当前时段的发电度量清零
if(!isSameDay(startCurveTime,currentTimeEpoch)) if(!isSameDay(startCurveTime,currentTimeEpoch))
@ -510,21 +509,21 @@ bool iot_service::StatUtil::handlePvYieldPoints(iot_dbms::CTsdbConn &objConn, co
return false; return false;
} }
resultTmp[9] += diffChargeVal * boost::lexical_cast<boost::float64_t>(vecResult[0]->at(0).m_varValue); resultTmp[9] += diffChargeVal * boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
} }
//< 为下一个区间计算作准备 //< 为下一个区间计算作准备
startChargeVal = endChargeVal; startChargeVal = endChargeVal;
startCurveVal += (int)(boost::lexical_cast<boost::float64_t>(yieldPoints.at(i).m_varValue)); startCurveVal += boost::get<boost::int32_t>(yieldPoints.at(i).m_varValue);
if(startCurveVal < 1 || startCurveVal > 4 ) if(startCurveVal < 1 || startCurveVal > 4 )
{ {
LOGERROR("峰平谷尖值不正确,%d",startCurveVal); LOGERROR("峰平谷尖值不正确,%d",startCurveVal);
return false; return false;
} }
startCurveTime = boost::lexical_cast<quint64>(yieldPoints.at(i).m_nTime); startCurveTime = (yieldPoints.at(i).m_nTime);
LOGTRACE("处理区间%d完成",(int)i); LOGTRACE("处理区间%d完成",(int)i);
} }
@ -546,8 +545,8 @@ bool iot_service::StatUtil::handlePvYieldPoints(iot_dbms::CTsdbConn &objConn, co
return false; return false;
} }
lastChargeTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); lastChargeTime = (vecResult[0]->at(0).m_nTime);
lastChargeVal = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); lastChargeVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
//< 检查当前区间是否跨天,如果跨天,当前时段的发电度量清零 //< 检查当前区间是否跨天,如果跨天,当前时段的发电度量清零
if(!isSameDay(startCurveTime,currentTimeEpoch)) if(!isSameDay(startCurveTime,currentTimeEpoch))
@ -583,7 +582,7 @@ bool iot_service::StatUtil::handlePvYieldPoints(iot_dbms::CTsdbConn &objConn, co
if(vecResult[0]->size() == 1) if(vecResult[0]->size() == 1)
{ {
resultTmp[9] += (lastChargeVal - startChargeVal) * boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); resultTmp[9] += (lastChargeVal - startChargeVal) * boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
} }
delete vecResult[0]; delete vecResult[0];
} }
@ -608,7 +607,7 @@ bool iot_service::StatUtil::findFirstTime(iot_dbms::CTsdbConn &objConn, const st
return false; return false;
} }
result = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); result = (vecResult[0]->at(0).m_nTime);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -629,8 +628,8 @@ bool iot_service::StatUtil::findFirstTimeAndVal(iot_dbms::CTsdbConn &objConn, co
return false; return false;
} }
resultTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); resultTime = (vecResult[0]->at(0).m_nTime);
resultVal = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_varValue); resultVal = boost::get<boost::int32_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -661,8 +660,8 @@ bool iot_service::StatUtil::findFirstLargerValAndTime(iot_dbms::CTsdbConn &objCo
return false; return false;
} }
resultTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); resultTime = (vecResult[0]->at(0).m_nTime);
resultVal = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); resultVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
@ -693,8 +692,8 @@ bool iot_service::StatUtil::findFirstLessOrEqualValAndTime(iot_dbms::CTsdbConn &
return false; return false;
} }
resultTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); resultTime = (vecResult[0]->at(0).m_nTime);
resultVal = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); resultVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -716,7 +715,7 @@ bool iot_service::StatUtil::findLastTime(iot_dbms::CTsdbConn &objConn, const std
return false; return false;
} }
result = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); result = (vecResult[0]->at(0).m_nTime);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -737,8 +736,8 @@ bool iot_service::StatUtil::findLastTimeAndVal(iot_dbms::CTsdbConn &objConn, con
return false; return false;
} }
resultTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); resultTime = (vecResult[0]->at(0).m_nTime);
resultVal = boost::lexical_cast<int>(vecResult[0]->at(0).m_varValue); resultVal = boost::get<boost::int32_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -761,8 +760,8 @@ bool iot_service::StatUtil::findLastTimeAndVal(iot_dbms::CTsdbConn &objConn, con
return false; return false;
} }
resultTime = boost::lexical_cast<quint64>(vecResult[0]->at(0).m_nTime); resultTime = (vecResult[0]->at(0).m_nTime);
resultVal = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); resultVal = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -811,7 +810,7 @@ bool iot_service::StatUtil::findFirstVal(iot_dbms::CTsdbConn &objConn, const std
return false; return false;
} }
result = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); result = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -832,7 +831,7 @@ bool iot_service::StatUtil::findLastVal(iot_dbms::CTsdbConn &objConn, const std:
return false; return false;
} }
result = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); result = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -853,7 +852,7 @@ bool iot_service::StatUtil::findLastVal(iot_dbms::CTsdbConn &objConn, const std:
return false; return false;
} }
result = (int)boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); result = boost::get<boost::int32_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -880,7 +879,7 @@ bool iot_service::StatUtil::findLastVal(iot_dbms::CTsdbConn &objConn, const std:
if(vecResult[0]->size() == 1) if(vecResult[0]->size() == 1)
{ {
result = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); result = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
} }
else else
{ {
@ -906,7 +905,7 @@ bool iot_service::StatUtil::findMedianVal(iot_dbms::CTsdbConn &objConn, const st
return false; return false;
} }
result = boost::lexical_cast<double>(vecResult[0]->at(0).m_varValue); result = boost::get<boost::float64_t>(vecResult[0]->at(0).m_varValue);
delete vecResult[0]; delete vecResult[0];
return true; return true;
} }
@ -1262,7 +1261,7 @@ bool iot_service::StatUtil::handlePcsYieldPoints(iot_dbms::CTsdbConn &objConn,
startChargeVal = endChargeVal; startChargeVal = endChargeVal;
startDischargeVal = endDischargeVal; startDischargeVal = endDischargeVal;
startCurveTime = boost::int64_t(yieldPoints.at(i).m_nTime); startCurveTime = boost::int64_t(yieldPoints.at(i).m_nTime);
startCurveVal += (int)boost::lexical_cast<double>(yieldPoints.at(i).m_varValue); startCurveVal += boost::get<boost::int32_t>(yieldPoints.at(i).m_varValue);
if(startCurveVal < 1 || startCurveVal > 4 ) if(startCurveVal < 1 || startCurveVal > 4 )
{ {