#include "ConsistencyResult.h" #include "GlobalInfo.h" #include "spdlog/spdlog.h" /* -------------------------------------------------------------------------------- * 一致性检测参数 StConsistencyParam * -------------------------------------------------------------------------------- */ StConsistencyParam::StConsistencyParam() { Init(); } StConsistencyParam::StConsistencyParam(const StConsistencyParam& obj) { *this = obj; } StConsistencyParam& StConsistencyParam::operator=(const StConsistencyParam& obj) { m_bConsistencySwitch = obj.m_bConsistencySwitch; m_iConsistencyThreshold = obj.m_iConsistencyThreshold; m_iConsistencyThresholdNum = obj.m_iConsistencyThresholdNum; m_iConsistencyThresholdNot = obj.m_iConsistencyThresholdNot; m_iConsistencyThresholdNotNum = obj.m_iConsistencyThresholdNotNum; m_nConsistencyThresholdWarningNum = obj.m_nConsistencyThresholdWarningNum; return *this; } void StConsistencyParam::Init() { m_bConsistencySwitch = false; m_iConsistencyThreshold = 0; m_iConsistencyThresholdNum = 0; m_iConsistencyThresholdNot = 0; m_iConsistencyThresholdNotNum = 0; m_nConsistencyThresholdWarningNum = 0; } /* -------------------------------------------------------------------------------- * 一致性检测参数 StConsistencyResult * -------------------------------------------------------------------------------- */ StConsistencyResult::StConsistencyResult() { // Init(); } // StConsistencyResult::StConsistencyResult(StConsistencyParam ¶m) // { // // Init(); // // m_stConsistencyParam = param; // } StConsistencyResult::~StConsistencyResult() { } StConsistencyResult::StConsistencyResult(const StConsistencyResult& obj) { *this = obj; } StConsistencyResult& StConsistencyResult::operator=(const StConsistencyResult &obj) { // m_bIsNoiseOfCur = obj.m_bIsNoiseOfCur; // m_stNoiseConsistencyParam = obj.m_stNoiseConsistencyParam; // // m_nRetPythonCompareFile = obj.m_nRetPythonCompareFile; // m_stConsistencyParam = obj.m_stConsistencyParam; // iCurPos = obj.iCurPos; // for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i) // { // aryOfDelN[i] = obj.aryOfDelN[i]; // aryOfSimilarity[i] = obj.aryOfSimilarity[i]; // } for(int i = 0; i < 10; ++i) { aryOfAICompareFile[i] = obj.aryOfAICompareFile[i]; } return *this; } // void StConsistencyResult::Init() // { // m_bIsNoiseOfCur = false; // InitAICompareFile(); // // m_nRetPythonCompareFile = ERCF_3_CompareFile_Unkonw; // iCurPos = 0; // for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i) // { // aryOfDelN[i] = 0; // aryOfSimilarity[i] = 0.0; // } // } void StConsistencyResult::InitAICompareFile() { // m_tLastAITime = QDateTime::currentDateTime(); // m_nLastRetAICompareFile = ERCF_3_CompareFile_Unkonw; for(int i = 0; i < 10; ++i) { aryOfAICompareFile[i] = -1.0; } } // int StConsistencyResult::GetLastRetAICompareFile() // { // // auto span = m_tLastAITime.secsTo(QDateTime::currentDateTime()); // // if (span < GInfo.compareTimeSpan()) // // { // // return m_nLastRetAICompareFile; // // } // return ERCF_3_CompareFile_Unkonw; // } int StConsistencyResult::AddRetAICompareFile(float fVal) { for(int i = 8; i >= 0; --i) { aryOfAICompareFile[i+1] = aryOfAICompareFile[i]; } aryOfAICompareFile[0] = fVal; // m_tLastAITime = QDateTime::currentDateTime(); // if (fVal > 0.99) // { // m_nLastRetAICompareFile = ERCF_1_CompareFile_TRUE; // } // else // { // m_nLastRetAICompareFile = ERCF_0_CompareFile_FALSE; // } return 10; } bool StConsistencyResult::IsAIConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue) { bool bConsistency = true; if (nThresholdNum < 0) nThresholdNum = 1; if (nThresholdNum > 10) nThresholdNum = 10; for(int i = 0; i < nThresholdNum; ++i) { if (aryOfAICompareFile[i] < -0.9) { strAIValue += "数据未初始化直接返回 -1"; return -1; } if (aryOfAICompareFile[i] < dThreshold) { bConsistency = false; strAIValue = fmt::format("{},{:.3f}<{:.3f}不能判断为一致", strAIValue, aryOfAICompareFile[i], dThreshold); break; } else { strAIValue = fmt::format("{},{:.3f}", strAIValue, aryOfAICompareFile[i]); } } if (bConsistency) { strAIValue = fmt::format("{},{}", strAIValue, ",判断为一致"); } return bConsistency; } bool StConsistencyResult::IsAINotConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue) { bool bNotConsistency = true; if (nThresholdNum < 0) nThresholdNum = 1; if (nThresholdNum > 10) nThresholdNum = 10; for(int i = 0; i < nThresholdNum; ++i) { if (aryOfAICompareFile[i] < -0.9) { strAIValue = fmt::format("数据未初始化直接返回 -1"); return -1; } if (aryOfAICompareFile[i] > dThreshold) { bNotConsistency = false; strAIValue = fmt::format("{},{:.3f} > {:.3f}不能判断为不一致", strAIValue, aryOfAICompareFile[i], dThreshold); break; } else { strAIValue = fmt::format("{}, {:.3f}", strAIValue, aryOfAICompareFile[i]); } } if (bNotConsistency) { strAIValue = fmt::format("{},判断为不一致", strAIValue); } return bNotConsistency; } // std::string StConsistencyResult::OutPutConsistencyInfo(const bool bConsistencyInfo) // { // std::string strInfo; // for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i) // { // std::string str = fmt::format("{:.2f}(相似度) {}(采样率偏移量)", aryOfSimilarity[i], aryOfDelN[i]); // strInfo += str; // } // StConsistencyParam param = m_stConsistencyParam; // if (m_bIsNoiseOfCur) // { // param = m_stNoiseConsistencyParam; // } // std::string strMsg = fmt::format("{}: {}-{} {}-{}", strInfo, // param.GetConsistencyThreshold(), // param.GetConsistencyThresholdNum(), // param.GetConsistencyThresholdNot(), // param.GetConsistencyThresholdNotNum()); // SPDLOG_DEBUG("一致性检测结果: {}", strMsg); // return strMsg; // } // bool StConsistencyResult::IsConsistency() const // { // StConsistencyParam param = m_stConsistencyParam; // if (m_bIsNoiseOfCur) // { // param = m_stNoiseConsistencyParam; // } // if(param.GetConsistencyThreshold() <= GetMaxResult()) // { // return true; // } // return false; // } // bool StConsistencyResult::IsNotConsistency() const // { // StConsistencyParam param = m_stConsistencyParam; // if (m_bIsNoiseOfCur) // { // param = m_stNoiseConsistencyParam; // } // if(param.GetConsistencyThresholdNot() > GetMaxResult()) // { // return true; // } // return false; // } // int StConsistencyResult::GetMaxResult() const // { // int iRet = 0; // for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i) // { // int iTmp = aryOfSimilarity[i]; // if(iRet <= iTmp) // { // iRet = iTmp; // } // } // return iRet; // } // int StConsistencyResult::AddResult(const float f, const int iDelN) // { // if(iCurPos < RESULT_NUM_OF_ONETIME_COMPARE) // { // return -1; // } // aryOfDelN[iCurPos] = iDelN; // aryOfSimilarity[iCurPos] = f; // return ++iCurPos; // } // int StConsistencyResult::GetConsistencyThresholdNum() const // { // int iNum = m_stConsistencyParam.GetConsistencyThresholdNum(); // if (iNum < m_stNoiseConsistencyParam.GetConsistencyThresholdNum()) // { // iNum = m_stNoiseConsistencyParam.GetConsistencyThresholdNum(); // } // return iNum; // } // int StConsistencyResult::GetConsistencyThresholdNotNum() const // { // int iNotNum = m_stConsistencyParam.GetConsistencyThresholdNotNum(); // if (iNotNum < m_stNoiseConsistencyParam.GetConsistencyThresholdNotNum()) // { // iNotNum = m_stNoiseConsistencyParam.GetConsistencyThresholdNotNum(); // } // return iNotNum; // } // int StConsistencyResult::GetConsistencyThresholdWarningNum() const // { // int iNum = m_stConsistencyParam.GetConsistencyThresholdWarningNum(); // if (iNum < m_stNoiseConsistencyParam.GetConsistencyThresholdWarningNum()) // { // iNum = m_stNoiseConsistencyParam.GetConsistencyThresholdWarningNum(); // } // return iNum; // } // ************************** stConsistency ************************** 】】 /* -------------------------------------------------------------------------------- * 一致性检测结果 ConsistencyResult_t * -------------------------------------------------------------------------------- */ ConsistencyResult_t::ConsistencyResult_t() { Init(); } ConsistencyResult_t::ConsistencyResult_t(const ConsistencyResult_t& obj) { } ConsistencyResult_t& ConsistencyResult_t::operator=(const ConsistencyResult_t& obj) { m_fInitThreshold = obj.m_fInitThreshold; m_nCurPos = obj.m_nCurPos; for(int i = 0; i < m_numArryCount; ++i) { m_arryResult[i] = obj.m_arryResult[i]; } return *this; } void ConsistencyResult_t::Init() { m_fInitThreshold = 0.9; /* 初始化阈值 */ m_nCurPos = 0; for(int i = 0; i < m_numArryCount; ++i) { m_arryResult[i] = -1.0; } } /* 添加结果 */ bool ConsistencyResult_t::AddResult(float fVal) { for(int i = 8; i >= 0; --i) { m_arryResult[i + 1] = m_arryResult[i]; } m_arryResult[0] = fVal; return true; } /* 计算一致性 计算要求:需要 nThresholdNum 全部大于一致性阈值 fThreshold 方可判断为一致,否则返回无法判断为一致 */ eConsistencyState ConsistencyResult_t::computeConsistency(int nThresholdNum, float fThreshold, std::string& strInfo) { strInfo.clear(); bool bConsistency = true; if (nThresholdNum < 0) { nThresholdNum = 1; strInfo += "一致性最小检测数目为1 "; } if (nThresholdNum > 10) { nThresholdNum = 10; strInfo += "一致性最大检测数目为10 "; } for(int i = 0; i < nThresholdNum; ++i) { if (m_arryResult[i] < -0.9) { strInfo += "数据未初始化"; return eConsistencyState::eCS_Unknown; } if (m_arryResult[i] < fThreshold) { bConsistency = false; strInfo = fmt::format("{},{:.3f}<{:.3f}不能判断为一致", strInfo, m_arryResult[i], fThreshold); break; } else { strInfo = fmt::format("{},{:.3f}", strInfo, m_arryResult[i]); } } if (bConsistency) { return eConsistencyState::eCS_Consistency; }else { return eConsistencyState::eCS_Unknown; } } /* 计算不一致性 */ eConsistencyState ConsistencyResult_t::computeNotConsistency(int nThresholdNum, float fThreshold, std::string& strInfo) { strInfo.clear(); bool bNotConsistency = true; if (nThresholdNum < 0) { nThresholdNum = 1; strInfo += "一致性最小检测数目为1 "; } if (nThresholdNum > 10) { nThresholdNum = 10; strInfo += "一致性最大检测数目为10 "; } for(int i = 0; i < nThresholdNum; ++i) { if (m_arryResult[i] < -0.9) { strInfo = fmt::format("数据未初始化直接返回"); return eConsistencyState::eCS_Unknown; } if (m_arryResult[i] > fThreshold) { bNotConsistency = false; strInfo = fmt::format("{},{:.3f} > {:.3f}不能判断为不一致", strInfo, m_arryResult[i], fThreshold); break; } else { strInfo = fmt::format("{}, {:.3f}", strInfo, m_arryResult[i]); } } if (bNotConsistency) { strInfo = fmt::format("{}, 判断为不一致", strInfo); } if(bNotConsistency) { return eConsistencyState::eCS_NotConsistency; }else { return eConsistencyState::eCS_Unknown; } }