ConsistencyResult.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #include "ConsistencyResult.h"
  2. #include "GlobalInfo.h"
  3. #include "spdlog/spdlog.h"
  4. // ************************** StConsistencyResult ************************** 【【
  5. StConsistencyResult::StConsistencyResult()
  6. {
  7. Init();
  8. }
  9. StConsistencyResult::StConsistencyResult(StConsistencyParam &param)
  10. {
  11. Init();
  12. m_stConsistencyParam = param;
  13. }
  14. StConsistencyResult::~StConsistencyResult()
  15. {
  16. }
  17. StConsistencyResult::StConsistencyResult(const StConsistencyResult& obj)
  18. {
  19. *this = obj;
  20. }
  21. StConsistencyResult& StConsistencyResult::operator=(const StConsistencyResult &obj)
  22. {
  23. m_bIsNoiseOfCur = obj.m_bIsNoiseOfCur;
  24. m_stNoiseConsistencyParam = obj.m_stNoiseConsistencyParam;
  25. // m_nRetPythonCompareFile = obj.m_nRetPythonCompareFile;
  26. m_stConsistencyParam = obj.m_stConsistencyParam;
  27. iCurPos = obj.iCurPos;
  28. for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i)
  29. {
  30. aryOfDelN[i] = obj.aryOfDelN[i];
  31. aryOfSimilarity[i] = obj.aryOfSimilarity[i];
  32. }
  33. for(int i = 0; i < 10; ++i)
  34. {
  35. aryOfAICompareFile[i] = obj.aryOfAICompareFile[i];
  36. }
  37. return *this;
  38. }
  39. void StConsistencyResult::Init()
  40. {
  41. m_bIsNoiseOfCur = false;
  42. InitAICompareFile();
  43. // m_nRetPythonCompareFile = ERCF_3_CompareFile_Unkonw;
  44. iCurPos = 0;
  45. for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i)
  46. {
  47. aryOfDelN[i] = 0;
  48. aryOfSimilarity[i] = 0.0;
  49. }
  50. }
  51. void StConsistencyResult::InitAICompareFile()
  52. {
  53. m_tLastAITime = QDateTime::currentDateTime();
  54. m_nLastRetAICompareFile = ERCF_3_CompareFile_Unkonw;
  55. for(int i = 0; i < 10; ++i)
  56. {
  57. aryOfAICompareFile[i] = -1.0;
  58. }
  59. }
  60. int StConsistencyResult::GetLastRetAICompareFile()
  61. {
  62. auto span = m_tLastAITime.secsTo(QDateTime::currentDateTime());
  63. if (span < GInfo.compareTimeSpan())
  64. {
  65. return m_nLastRetAICompareFile;
  66. }
  67. return ERCF_3_CompareFile_Unkonw;
  68. }
  69. int StConsistencyResult::AddRetAICompareFile(float fVal)
  70. {
  71. for(int i = 8; i >= 0; --i)
  72. {
  73. aryOfAICompareFile[i+1] = aryOfAICompareFile[i];
  74. }
  75. aryOfAICompareFile[0] = fVal;
  76. m_tLastAITime = QDateTime::currentDateTime();
  77. if (fVal > 0.99)
  78. {
  79. m_nLastRetAICompareFile = ERCF_1_CompareFile_TRUE;
  80. }
  81. else
  82. {
  83. m_nLastRetAICompareFile = ERCF_0_CompareFile_FALSE;
  84. }
  85. return 10;
  86. }
  87. bool StConsistencyResult::IsAIConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue)
  88. {
  89. bool bConsistency = true;
  90. if (nThresholdNum < 0) nThresholdNum = 1;
  91. if (nThresholdNum > 10) nThresholdNum = 10;
  92. for(int i = 0; i < nThresholdNum; ++i)
  93. {
  94. if (aryOfAICompareFile[i] < -0.9)
  95. {
  96. strAIValue += ",数据未初始化直接返回-1";
  97. return -1;
  98. }
  99. if (aryOfAICompareFile[i] < dThreshold)
  100. {
  101. bConsistency = false;
  102. strAIValue = fmt::format("{},{:.3f}<{:.3f}不能判断为一致", strAIValue, aryOfAICompareFile[i], dThreshold);
  103. break;
  104. }
  105. else
  106. {
  107. strAIValue = fmt::format("{},{:.3f}", strAIValue, aryOfAICompareFile[i]);
  108. }
  109. }
  110. if (bConsistency)
  111. {
  112. strAIValue = fmt::format("{},{}", strAIValue, ",判断为一致");
  113. }
  114. return bConsistency;
  115. }
  116. bool StConsistencyResult::IsAINotConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue)
  117. {
  118. bool bNotConsistency = true;
  119. if (nThresholdNum < 0) nThresholdNum = 1;
  120. if (nThresholdNum > 10) nThresholdNum = 10;
  121. for(int i = 0; i < nThresholdNum; ++i)
  122. {
  123. if (aryOfAICompareFile[i] < -0.9)
  124. {
  125. strAIValue = fmt::format("{}, 数据未初始化直接返回-1", strAIValue);
  126. return -1;
  127. }
  128. if (aryOfAICompareFile[i] > dThreshold)
  129. {
  130. bNotConsistency = false;
  131. strAIValue = fmt::format("{},{:.3f} > {:.3f}不能判断为不一致", strAIValue, aryOfAICompareFile[i], dThreshold);
  132. break;
  133. }
  134. else
  135. {
  136. strAIValue = fmt::format("{}, {:.3f}", strAIValue, aryOfAICompareFile[i]);
  137. }
  138. }
  139. if (bNotConsistency)
  140. {
  141. strAIValue = fmt::format("{},判断为不一致", strAIValue);
  142. }
  143. return bNotConsistency;
  144. }
  145. std::string StConsistencyResult::OutPutConsistencyInfo(const bool bConsistencyInfo)
  146. {
  147. std::string strInfo;
  148. for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i)
  149. {
  150. std::string str = fmt::format("{:.2f}(相似度) {}(采样率偏移量)", aryOfSimilarity[i], aryOfDelN[i]);
  151. strInfo += str;
  152. }
  153. StConsistencyParam param = m_stConsistencyParam;
  154. if (m_bIsNoiseOfCur)
  155. {
  156. param = m_stNoiseConsistencyParam;
  157. }
  158. std::string strMsg = fmt::format("{}: {}-{} {}-{}", strInfo,
  159. param.GetConsistencyThreshold(),
  160. param.GetConsistencyThresholdNum(),
  161. param.GetConsistencyThresholdNot(),
  162. param.GetConsistencyThresholdNotNum());
  163. SPDLOG_DEBUG("一致性检测结果: {}", strMsg);
  164. return strMsg;
  165. }
  166. bool StConsistencyResult::IsConsistency() const
  167. {
  168. StConsistencyParam param = m_stConsistencyParam;
  169. if (m_bIsNoiseOfCur)
  170. {
  171. param = m_stNoiseConsistencyParam;
  172. }
  173. if(param.GetConsistencyThreshold() <= GetMaxResult())
  174. {
  175. return true;
  176. }
  177. return false;
  178. }
  179. bool StConsistencyResult::IsNotConsistency() const
  180. {
  181. StConsistencyParam param = m_stConsistencyParam;
  182. if (m_bIsNoiseOfCur)
  183. {
  184. param = m_stNoiseConsistencyParam;
  185. }
  186. if(param.GetConsistencyThresholdNot() > GetMaxResult())
  187. {
  188. return true;
  189. }
  190. return false;
  191. }
  192. int StConsistencyResult::GetMaxResult() const
  193. {
  194. int iRet = 0;
  195. for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i)
  196. {
  197. int iTmp = aryOfSimilarity[i];
  198. if(iRet <= iTmp)
  199. {
  200. iRet = iTmp;
  201. }
  202. }
  203. return iRet;
  204. }
  205. int StConsistencyResult::AddResult(const float f, const int iDelN)
  206. {
  207. if(iCurPos < RESULT_NUM_OF_ONETIME_COMPARE)
  208. {
  209. return -1;
  210. }
  211. aryOfDelN[iCurPos] = iDelN;
  212. aryOfSimilarity[iCurPos] = f;
  213. return ++iCurPos;
  214. }
  215. int StConsistencyResult::GetConsistencyThresholdNum() const
  216. {
  217. int iNum = m_stConsistencyParam.GetConsistencyThresholdNum();
  218. if (iNum < m_stNoiseConsistencyParam.GetConsistencyThresholdNum())
  219. {
  220. iNum = m_stNoiseConsistencyParam.GetConsistencyThresholdNum();
  221. }
  222. return iNum;
  223. }
  224. int StConsistencyResult::GetConsistencyThresholdNotNum() const
  225. {
  226. int iNotNum = m_stConsistencyParam.GetConsistencyThresholdNotNum();
  227. if (iNotNum < m_stNoiseConsistencyParam.GetConsistencyThresholdNotNum())
  228. {
  229. iNotNum = m_stNoiseConsistencyParam.GetConsistencyThresholdNotNum();
  230. }
  231. return iNotNum;
  232. }
  233. int StConsistencyResult::GetConsistencyThresholdWarningNum() const
  234. {
  235. int iNum = m_stConsistencyParam.GetConsistencyThresholdWarningNum();
  236. if (iNum < m_stNoiseConsistencyParam.GetConsistencyThresholdWarningNum())
  237. {
  238. iNum = m_stNoiseConsistencyParam.GetConsistencyThresholdWarningNum();
  239. }
  240. return iNum;
  241. }
  242. // ************************** stConsistency ************************** 】】