ConsistencyResult.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. #include "ConsistencyResult.h"
  2. #include "GlobalInfo.h"
  3. #include "spdlog/spdlog.h"
  4. /* --------------------------------------------------------------------------------
  5. * 一致性检测参数 StConsistencyParam
  6. * -------------------------------------------------------------------------------- */
  7. StConsistencyParam::StConsistencyParam()
  8. {
  9. Init();
  10. }
  11. StConsistencyParam::StConsistencyParam(const StConsistencyParam& obj)
  12. {
  13. *this = obj;
  14. }
  15. StConsistencyParam& StConsistencyParam::operator=(const StConsistencyParam& obj)
  16. {
  17. m_bConsistencySwitch = obj.m_bConsistencySwitch;
  18. m_iConsistencyThreshold = obj.m_iConsistencyThreshold;
  19. m_iConsistencyThresholdNum = obj.m_iConsistencyThresholdNum;
  20. m_iConsistencyThresholdNot = obj.m_iConsistencyThresholdNot;
  21. m_iConsistencyThresholdNotNum = obj.m_iConsistencyThresholdNotNum;
  22. m_nConsistencyThresholdWarningNum = obj.m_nConsistencyThresholdWarningNum;
  23. return *this;
  24. }
  25. void StConsistencyParam::Init()
  26. {
  27. m_bConsistencySwitch = false;
  28. m_iConsistencyThreshold = 0;
  29. m_iConsistencyThresholdNum = 0;
  30. m_iConsistencyThresholdNot = 0;
  31. m_iConsistencyThresholdNotNum = 0;
  32. m_nConsistencyThresholdWarningNum = 0;
  33. }
  34. /* --------------------------------------------------------------------------------
  35. * 一致性检测参数 StConsistencyResult
  36. * -------------------------------------------------------------------------------- */
  37. StConsistencyResult::StConsistencyResult()
  38. {
  39. // Init();
  40. }
  41. // StConsistencyResult::StConsistencyResult(StConsistencyParam &param)
  42. // {
  43. // // Init();
  44. // // m_stConsistencyParam = param;
  45. // }
  46. StConsistencyResult::~StConsistencyResult()
  47. {
  48. }
  49. StConsistencyResult::StConsistencyResult(const StConsistencyResult& obj)
  50. {
  51. *this = obj;
  52. }
  53. StConsistencyResult& StConsistencyResult::operator=(const StConsistencyResult &obj)
  54. {
  55. // m_bIsNoiseOfCur = obj.m_bIsNoiseOfCur;
  56. // m_stNoiseConsistencyParam = obj.m_stNoiseConsistencyParam;
  57. // // m_nRetPythonCompareFile = obj.m_nRetPythonCompareFile;
  58. // m_stConsistencyParam = obj.m_stConsistencyParam;
  59. // iCurPos = obj.iCurPos;
  60. // for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i)
  61. // {
  62. // aryOfDelN[i] = obj.aryOfDelN[i];
  63. // aryOfSimilarity[i] = obj.aryOfSimilarity[i];
  64. // }
  65. for(int i = 0; i < 10; ++i)
  66. {
  67. aryOfAICompareFile[i] = obj.aryOfAICompareFile[i];
  68. }
  69. return *this;
  70. }
  71. // void StConsistencyResult::Init()
  72. // {
  73. // m_bIsNoiseOfCur = false;
  74. // InitAICompareFile();
  75. // // m_nRetPythonCompareFile = ERCF_3_CompareFile_Unkonw;
  76. // iCurPos = 0;
  77. // for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i)
  78. // {
  79. // aryOfDelN[i] = 0;
  80. // aryOfSimilarity[i] = 0.0;
  81. // }
  82. // }
  83. void StConsistencyResult::InitAICompareFile()
  84. {
  85. // m_tLastAITime = QDateTime::currentDateTime();
  86. // m_nLastRetAICompareFile = ERCF_3_CompareFile_Unkonw;
  87. for(int i = 0; i < 10; ++i)
  88. {
  89. aryOfAICompareFile[i] = -1.0;
  90. }
  91. }
  92. // int StConsistencyResult::GetLastRetAICompareFile()
  93. // {
  94. // // auto span = m_tLastAITime.secsTo(QDateTime::currentDateTime());
  95. // // if (span < GInfo.compareTimeSpan())
  96. // // {
  97. // // return m_nLastRetAICompareFile;
  98. // // }
  99. // return ERCF_3_CompareFile_Unkonw;
  100. // }
  101. int StConsistencyResult::AddRetAICompareFile(float fVal)
  102. {
  103. for(int i = 8; i >= 0; --i)
  104. {
  105. aryOfAICompareFile[i+1] = aryOfAICompareFile[i];
  106. }
  107. aryOfAICompareFile[0] = fVal;
  108. // m_tLastAITime = QDateTime::currentDateTime();
  109. // if (fVal > 0.99)
  110. // {
  111. // m_nLastRetAICompareFile = ERCF_1_CompareFile_TRUE;
  112. // }
  113. // else
  114. // {
  115. // m_nLastRetAICompareFile = ERCF_0_CompareFile_FALSE;
  116. // }
  117. return 10;
  118. }
  119. bool StConsistencyResult::IsAIConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue)
  120. {
  121. bool bConsistency = true;
  122. if (nThresholdNum < 0) nThresholdNum = 1;
  123. if (nThresholdNum > 10) nThresholdNum = 10;
  124. for(int i = 0; i < nThresholdNum; ++i)
  125. {
  126. if (aryOfAICompareFile[i] < -0.9)
  127. {
  128. strAIValue += "数据未初始化直接返回 -1";
  129. return -1;
  130. }
  131. if (aryOfAICompareFile[i] < dThreshold)
  132. {
  133. bConsistency = false;
  134. strAIValue = fmt::format("{},{:.3f}<{:.3f}不能判断为一致", strAIValue, aryOfAICompareFile[i], dThreshold);
  135. break;
  136. } else
  137. {
  138. strAIValue = fmt::format("{},{:.3f}", strAIValue, aryOfAICompareFile[i]);
  139. }
  140. }
  141. if (bConsistency)
  142. {
  143. strAIValue = fmt::format("{},{}", strAIValue, ",判断为一致");
  144. }
  145. return bConsistency;
  146. }
  147. bool StConsistencyResult::IsAINotConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue)
  148. {
  149. bool bNotConsistency = true;
  150. if (nThresholdNum < 0) nThresholdNum = 1;
  151. if (nThresholdNum > 10) nThresholdNum = 10;
  152. for(int i = 0; i < nThresholdNum; ++i)
  153. {
  154. if (aryOfAICompareFile[i] < -0.9)
  155. {
  156. strAIValue = fmt::format("数据未初始化直接返回 -1");
  157. return -1;
  158. }
  159. if (aryOfAICompareFile[i] > dThreshold)
  160. {
  161. bNotConsistency = false;
  162. strAIValue = fmt::format("{},{:.3f} > {:.3f}不能判断为不一致", strAIValue, aryOfAICompareFile[i], dThreshold);
  163. break;
  164. } else
  165. {
  166. strAIValue = fmt::format("{}, {:.3f}", strAIValue, aryOfAICompareFile[i]);
  167. }
  168. }
  169. if (bNotConsistency)
  170. {
  171. strAIValue = fmt::format("{},判断为不一致", strAIValue);
  172. }
  173. return bNotConsistency;
  174. }
  175. // std::string StConsistencyResult::OutPutConsistencyInfo(const bool bConsistencyInfo)
  176. // {
  177. // std::string strInfo;
  178. // for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i)
  179. // {
  180. // std::string str = fmt::format("{:.2f}(相似度) {}(采样率偏移量)", aryOfSimilarity[i], aryOfDelN[i]);
  181. // strInfo += str;
  182. // }
  183. // StConsistencyParam param = m_stConsistencyParam;
  184. // if (m_bIsNoiseOfCur)
  185. // {
  186. // param = m_stNoiseConsistencyParam;
  187. // }
  188. // std::string strMsg = fmt::format("{}: {}-{} {}-{}", strInfo,
  189. // param.GetConsistencyThreshold(),
  190. // param.GetConsistencyThresholdNum(),
  191. // param.GetConsistencyThresholdNot(),
  192. // param.GetConsistencyThresholdNotNum());
  193. // SPDLOG_DEBUG("一致性检测结果: {}", strMsg);
  194. // return strMsg;
  195. // }
  196. // bool StConsistencyResult::IsConsistency() const
  197. // {
  198. // StConsistencyParam param = m_stConsistencyParam;
  199. // if (m_bIsNoiseOfCur)
  200. // {
  201. // param = m_stNoiseConsistencyParam;
  202. // }
  203. // if(param.GetConsistencyThreshold() <= GetMaxResult())
  204. // {
  205. // return true;
  206. // }
  207. // return false;
  208. // }
  209. // bool StConsistencyResult::IsNotConsistency() const
  210. // {
  211. // StConsistencyParam param = m_stConsistencyParam;
  212. // if (m_bIsNoiseOfCur)
  213. // {
  214. // param = m_stNoiseConsistencyParam;
  215. // }
  216. // if(param.GetConsistencyThresholdNot() > GetMaxResult())
  217. // {
  218. // return true;
  219. // }
  220. // return false;
  221. // }
  222. // int StConsistencyResult::GetMaxResult() const
  223. // {
  224. // int iRet = 0;
  225. // for(int i = 0; i < RESULT_NUM_OF_ONETIME_COMPARE; ++i)
  226. // {
  227. // int iTmp = aryOfSimilarity[i];
  228. // if(iRet <= iTmp)
  229. // {
  230. // iRet = iTmp;
  231. // }
  232. // }
  233. // return iRet;
  234. // }
  235. // int StConsistencyResult::AddResult(const float f, const int iDelN)
  236. // {
  237. // if(iCurPos < RESULT_NUM_OF_ONETIME_COMPARE)
  238. // {
  239. // return -1;
  240. // }
  241. // aryOfDelN[iCurPos] = iDelN;
  242. // aryOfSimilarity[iCurPos] = f;
  243. // return ++iCurPos;
  244. // }
  245. // int StConsistencyResult::GetConsistencyThresholdNum() const
  246. // {
  247. // int iNum = m_stConsistencyParam.GetConsistencyThresholdNum();
  248. // if (iNum < m_stNoiseConsistencyParam.GetConsistencyThresholdNum())
  249. // {
  250. // iNum = m_stNoiseConsistencyParam.GetConsistencyThresholdNum();
  251. // }
  252. // return iNum;
  253. // }
  254. // int StConsistencyResult::GetConsistencyThresholdNotNum() const
  255. // {
  256. // int iNotNum = m_stConsistencyParam.GetConsistencyThresholdNotNum();
  257. // if (iNotNum < m_stNoiseConsistencyParam.GetConsistencyThresholdNotNum())
  258. // {
  259. // iNotNum = m_stNoiseConsistencyParam.GetConsistencyThresholdNotNum();
  260. // }
  261. // return iNotNum;
  262. // }
  263. // int StConsistencyResult::GetConsistencyThresholdWarningNum() const
  264. // {
  265. // int iNum = m_stConsistencyParam.GetConsistencyThresholdWarningNum();
  266. // if (iNum < m_stNoiseConsistencyParam.GetConsistencyThresholdWarningNum())
  267. // {
  268. // iNum = m_stNoiseConsistencyParam.GetConsistencyThresholdWarningNum();
  269. // }
  270. // return iNum;
  271. // }
  272. // ************************** stConsistency ************************** 】】
  273. /* --------------------------------------------------------------------------------
  274. * 一致性检测结果 ConsistencyResult_t
  275. * -------------------------------------------------------------------------------- */
  276. ConsistencyResult_t::ConsistencyResult_t()
  277. {
  278. Init();
  279. }
  280. ConsistencyResult_t::ConsistencyResult_t(const ConsistencyResult_t& obj)
  281. {
  282. }
  283. ConsistencyResult_t& ConsistencyResult_t::operator=(const ConsistencyResult_t& obj)
  284. {
  285. m_fInitThreshold = obj.m_fInitThreshold;
  286. m_nCurPos = obj.m_nCurPos;
  287. for(int i = 0; i < m_numArryCount; ++i)
  288. {
  289. m_arryResult[i] = obj.m_arryResult[i];
  290. }
  291. return *this;
  292. }
  293. void ConsistencyResult_t::Init()
  294. {
  295. m_fInitThreshold = 0.9; /* 初始化阈值 */
  296. m_nCurPos = 0;
  297. for(int i = 0; i < m_numArryCount; ++i)
  298. {
  299. m_arryResult[i] = -1.0;
  300. }
  301. }
  302. /* 添加结果 */
  303. bool ConsistencyResult_t::AddResult(float fVal)
  304. {
  305. for(int i = 8; i >= 0; --i)
  306. {
  307. m_arryResult[i + 1] = m_arryResult[i];
  308. }
  309. m_arryResult[0] = fVal;
  310. return true;
  311. }
  312. /*
  313. 计算一致性
  314. 计算要求:需要 nThresholdNum 全部大于一致性阈值 fThreshold 方可判断为一致,否则返回无法判断为一致
  315. */
  316. eConsistencyState ConsistencyResult_t::computeConsistency(int nThresholdNum, float fThreshold, std::string& strInfo)
  317. {
  318. strInfo.clear();
  319. bool bConsistency = true;
  320. if (nThresholdNum < 0)
  321. {
  322. nThresholdNum = 1;
  323. strInfo += "一致性最小检测数目为1 ";
  324. }
  325. if (nThresholdNum > 10)
  326. {
  327. nThresholdNum = 10;
  328. strInfo += "一致性最大检测数目为10 ";
  329. }
  330. for(int i = 0; i < nThresholdNum; ++i)
  331. {
  332. if (m_arryResult[i] < -0.9)
  333. {
  334. strInfo += "数据未初始化";
  335. return eConsistencyState::eCS_Unknown;
  336. }
  337. if (m_arryResult[i] < fThreshold)
  338. {
  339. bConsistency = false;
  340. strInfo = fmt::format("{},{:.3f}<{:.3f}不能判断为一致", strInfo, m_arryResult[i], fThreshold);
  341. break;
  342. } else
  343. {
  344. strInfo = fmt::format("{},{:.3f}", strInfo, m_arryResult[i]);
  345. }
  346. }
  347. if (bConsistency)
  348. {
  349. return eConsistencyState::eCS_Consistency;
  350. }else {
  351. return eConsistencyState::eCS_Unknown;
  352. }
  353. }
  354. /* 计算不一致性 */
  355. eConsistencyState ConsistencyResult_t::computeNotConsistency(int nThresholdNum, float fThreshold, std::string& strInfo)
  356. {
  357. strInfo.clear();
  358. bool bNotConsistency = true;
  359. if (nThresholdNum < 0)
  360. {
  361. nThresholdNum = 1;
  362. strInfo += "一致性最小检测数目为1 ";
  363. }
  364. if (nThresholdNum > 10)
  365. {
  366. nThresholdNum = 10;
  367. strInfo += "一致性最大检测数目为10 ";
  368. }
  369. for(int i = 0; i < nThresholdNum; ++i)
  370. {
  371. if (m_arryResult[i] < -0.9)
  372. {
  373. strInfo = fmt::format("数据未初始化直接返回");
  374. return eConsistencyState::eCS_Unknown;
  375. }
  376. if (m_arryResult[i] > fThreshold)
  377. {
  378. bNotConsistency = false;
  379. strInfo = fmt::format("{},{:.3f} > {:.3f}不能判断为不一致", strInfo, m_arryResult[i], fThreshold);
  380. break;
  381. } else
  382. {
  383. strInfo = fmt::format("{}, {:.3f}", strInfo, m_arryResult[i]);
  384. }
  385. }
  386. if (bNotConsistency)
  387. {
  388. strInfo = fmt::format("{}, 判断为不一致", strInfo);
  389. }
  390. if(bNotConsistency)
  391. {
  392. return eConsistencyState::eCS_NotConsistency;
  393. }else {
  394. return eConsistencyState::eCS_Unknown;
  395. }
  396. }