#include "ConsistencyResult.h" #include "GlobalInfo.h" #include "spdlog/spdlog.h" // ************************** 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", strAIValue); 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 ************************** 】】