ConsistencyResult.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef CONSISTENCYRESULT_H_
  2. #define CONSISTENCYRESULT_H_
  3. #include "GlobalVariable.h"
  4. #include "ChannelParam.h"
  5. #include <QDateTime>
  6. enum ERetPythonCompareFile
  7. {
  8. ERCF_0_CompareFile_FALSE = 0, // 对比返回不一致
  9. ERCF_1_CompareFile_TRUE = 1, // 对比返回一致
  10. ERCF_2_CompareFile_NOT = 2, // 未启动文件对比(如服务地址为空)
  11. ERCF_3_CompareFile_Unkonw = 3, // 对比返回未知,判断不出一致性
  12. };
  13. /* 新版本的一致性状态 */
  14. enum class eConsistencyState
  15. {
  16. eCS_Unknown = 0, // 未知状态
  17. eCS_Consistency = 1, // 一致性
  18. eCS_NotConsistency = 2, // 不一致性
  19. eCS_ConsistencyWarning, // 一致性预警
  20. };
  21. /**
  22. * @brief 一致性检测参数
  23. *
  24. */
  25. struct StConsistencyParam
  26. {
  27. StConsistencyParam();
  28. StConsistencyParam(const StConsistencyParam& obj);
  29. StConsistencyParam& operator=(const StConsistencyParam& obj);
  30. void Init();
  31. // ********* 一致性 ********* [[
  32. void SetConsistencySwitch(bool b) { m_bConsistencySwitch = b; }
  33. bool GetConsistencySwitch() { return m_bConsistencySwitch; }
  34. int GetConsistencyThreshold() const { return m_iConsistencyThreshold; }
  35. void SetConsistencyThreshold(int ival) { m_iConsistencyThreshold = ival; }
  36. int GetConsistencyThresholdNum() const { return m_iConsistencyThresholdNum; }
  37. void SetConsistencyThresholdNum(int ival) { m_iConsistencyThresholdNum = ival; }
  38. int GetConsistencyThresholdNot() const { return m_iConsistencyThresholdNot; }
  39. void SetConsistencyThresholdNot(int ival) { m_iConsistencyThresholdNot = ival; }
  40. int GetConsistencyThresholdNotNum() const { return m_iConsistencyThresholdNotNum; }
  41. // 不一致的判定更严谨,全部为不一致时,才判定为不一致
  42. int GetConsistencyThresholdNotNumEx() const { return m_iConsistencyThresholdNotNum * 2; }
  43. void SetConsistencyThresholdNotNum(int ival) { m_iConsistencyThresholdNotNum = ival; }
  44. int GetConsistencyThresholdWarningNum() const { return m_nConsistencyThresholdWarningNum; }
  45. void SetConsistencyThresholdWarningNum(int ival) { m_nConsistencyThresholdWarningNum = ival; }
  46. private:
  47. // 一致性监测开关
  48. bool m_bConsistencySwitch;
  49. // 一致性阀值
  50. // 持续时间内,如果有m_iConsistencyThresholdNum相似度个比阀值大,就表示一致性
  51. int m_iConsistencyThreshold;
  52. int m_iConsistencyThresholdNum;
  53. // 一致性阀值预警次数: 多少个不一致时,开启不一致预警
  54. int m_nConsistencyThresholdWarningNum;
  55. // 不一致性阀值
  56. // 持续时间内,如果有m_iConsistencyThresholdNotNum相似度个比阀值小,就表示不一致性
  57. int m_iConsistencyThresholdNot;
  58. int m_iConsistencyThresholdNotNum;
  59. };
  60. /**
  61. * @brief 保存n次一致性比较的结果,相似度的值,根据传入的阈值,计算是否是一致的
  62. *
  63. */
  64. struct StConsistencyResult
  65. {
  66. StConsistencyResult();
  67. // StConsistencyResult(StConsistencyParam &param);
  68. virtual ~StConsistencyResult();
  69. StConsistencyResult(const StConsistencyResult& obj);
  70. StConsistencyResult& operator=(const StConsistencyResult& obj);
  71. // void Init();
  72. // std::string OutPutConsistencyInfo(const bool bConsistencyInfo);
  73. // int AddResult(const float f, const int iDelN);
  74. // int GetCount() const { return iCurPos; }
  75. // int GetMaxResult() const;
  76. // // 这个一致性不能用于判定是否一致性,一致性判定要在 CConsistencyList 里面判定,计算一致性的个数
  77. // bool IsConsistency() const;
  78. // bool IsNotConsistency() const;
  79. // bool m_bIsNoiseOfCur;
  80. // StConsistencyParam m_stConsistencyParam;
  81. // StConsistencyParam m_stNoiseConsistencyParam;
  82. // int GetConsistencyThresholdNum() const;
  83. // int GetConsistencyThresholdNotNum() const;
  84. // int GetConsistencyThresholdWarningNum() const;
  85. // int GetDelNAt(const int nIndex = 0) const { return aryOfDelN[nIndex]; }
  86. // Python对比结果
  87. // int m_nRetPythonCompareFile;
  88. // AI对比结果
  89. void InitAICompareFile();
  90. int AddRetAICompareFile(float fVal);
  91. // nThresholdNum表示持续次数, dThresholdNum判断阀值
  92. bool IsAIConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue);
  93. bool IsAINotConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue);
  94. // int GetLastRetAICompareFile();
  95. private:
  96. // QDateTime m_tLastAITime;
  97. // int m_nLastRetAICompareFile;
  98. // AI对比结果,范围[0,1]
  99. float aryOfAICompareFile[10];
  100. /*
  101. fResult 相似度 delN 偏差(时间偏移)
  102. 这里的偏差就是错位的意思,相似度是在这个错位下计算出来的,如下:
  103. 1010001011010101110
  104. xxx1010001011010101110
  105. xxx的位数就是偏差量了
  106. */
  107. // int aryOfDelN[RESULT_NUM_OF_ONETIME_COMPARE];
  108. // // 相似度数组
  109. // float aryOfSimilarity[RESULT_NUM_OF_ONETIME_COMPARE];
  110. // // 数组实际保存了多少个数据,当前可以填充数据的位置
  111. // int iCurPos;
  112. };
  113. /**
  114. * @brief 一致性计算结果,新版本
  115. *
  116. */
  117. struct ConsistencyResult_t
  118. {
  119. ConsistencyResult_t();
  120. ConsistencyResult_t(const ConsistencyResult_t& obj);
  121. ConsistencyResult_t& operator=(const ConsistencyResult_t& obj);
  122. void Init();
  123. /* 添加结果 */
  124. bool AddResult(float fVal);
  125. /* 计算一致性 */
  126. eConsistencyState computeConsistency(int nThresholdNum, float fThreshold, std::string& strInfo);
  127. /* 计算不一致性 */
  128. eConsistencyState computeNotConsistency(int nThresholdNum, float fThreshold, std::string& strInfo);
  129. /* 获取当前已存储的结果个数 */
  130. int GetCount() const { return m_nCurPos; }
  131. private:
  132. float m_fInitThreshold = 0.9; /* 初始化阈值 */
  133. const int m_numArryCount = 10;
  134. float m_arryResult[10]; /* 结果数组 */
  135. int m_nCurPos; /* 当前结果位置 */
  136. };
  137. #endif // CONSISTENCYRESULT_H_