ConsistencyResult.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "ConsistencyResult.h"
  2. #include "GlobalInfo.h"
  3. #include "spdlog/spdlog.h"
  4. /* --------------------------------------------------------------------------------
  5. * 一致性检测结果 ConsistencyResult_t
  6. * -------------------------------------------------------------------------------- */
  7. ConsistencyResult_t::ConsistencyResult_t()
  8. {
  9. Init();
  10. }
  11. ConsistencyResult_t::ConsistencyResult_t(const ConsistencyResult_t& obj)
  12. {
  13. }
  14. ConsistencyResult_t& ConsistencyResult_t::operator=(const ConsistencyResult_t& obj)
  15. {
  16. m_fInitThreshold = obj.m_fInitThreshold;
  17. m_nCurPos = obj.m_nCurPos;
  18. for(int i = 0; i < m_numArryCount; ++i)
  19. {
  20. m_arryResult[i] = obj.m_arryResult[i];
  21. }
  22. return *this;
  23. }
  24. void ConsistencyResult_t::Init()
  25. {
  26. m_fInitThreshold = 0.9; /* 初始化阈值 */
  27. m_nCurPos = 0;
  28. for(int i = 0; i < m_numArryCount; ++i)
  29. {
  30. m_arryResult[i] = -1.0;
  31. }
  32. }
  33. /* 添加结果 */
  34. bool ConsistencyResult_t::AddResult(float fVal)
  35. {
  36. for(int i = 8; i >= 0; --i)
  37. {
  38. m_arryResult[i + 1] = m_arryResult[i];
  39. }
  40. m_arryResult[0] = fVal;
  41. return true;
  42. }
  43. /*
  44. 计算一致性
  45. 计算要求:需要 nThresholdNum 全部大于一致性阈值 fThreshold 方可判断为一致,否则返回无法判断为一致
  46. */
  47. eConsistencyState ConsistencyResult_t::computeConsistency(int nThresholdNum, float fThreshold, std::string& strInfo)
  48. {
  49. strInfo.clear();
  50. bool bConsistency = true;
  51. if (nThresholdNum < 0)
  52. {
  53. nThresholdNum = 1;
  54. strInfo += "一致性最小检测数目为1 ";
  55. }
  56. if (nThresholdNum > 10)
  57. {
  58. nThresholdNum = 10;
  59. strInfo += "一致性最大检测数目为10 ";
  60. }
  61. for(int i = 0; i < nThresholdNum; ++i)
  62. {
  63. if (m_arryResult[i] < -0.9)
  64. {
  65. strInfo += "数据未初始化";
  66. return eConsistencyState::eCS_Unknown;
  67. }
  68. if (m_arryResult[i] < fThreshold)
  69. {
  70. bConsistency = false;
  71. strInfo = fmt::format("{},{:.3f}<{:.3f}不能判断为一致", strInfo, m_arryResult[i], fThreshold);
  72. break;
  73. } else
  74. {
  75. strInfo = fmt::format("{},{:.3f}", strInfo, m_arryResult[i]);
  76. }
  77. }
  78. if (bConsistency)
  79. {
  80. return eConsistencyState::eCS_Consistency;
  81. }else {
  82. return eConsistencyState::eCS_Unknown;
  83. }
  84. }
  85. /* 计算不一致性 */
  86. eConsistencyState ConsistencyResult_t::computeNotConsistency(int nThresholdNum, float fThreshold, std::string& strInfo)
  87. {
  88. strInfo.clear();
  89. bool bNotConsistency = true;
  90. if (nThresholdNum < 0)
  91. {
  92. nThresholdNum = 1;
  93. strInfo += "一致性最小检测数目为1 ";
  94. }
  95. if (nThresholdNum > 10)
  96. {
  97. nThresholdNum = 10;
  98. strInfo += "一致性最大检测数目为10 ";
  99. }
  100. for(int i = 0; i < nThresholdNum; ++i)
  101. {
  102. if (m_arryResult[i] < -0.9)
  103. {
  104. strInfo = fmt::format("数据未初始化直接返回");
  105. return eConsistencyState::eCS_Unknown;
  106. }
  107. if (m_arryResult[i] > fThreshold)
  108. {
  109. bNotConsistency = false;
  110. strInfo = fmt::format("{},{:.3f} > {:.3f}不能判断为不一致", strInfo, m_arryResult[i], fThreshold);
  111. break;
  112. } else
  113. {
  114. strInfo = fmt::format("{}, {:.3f}", strInfo, m_arryResult[i]);
  115. }
  116. }
  117. if (bNotConsistency)
  118. {
  119. strInfo = fmt::format("{}, 判断为不一致", strInfo);
  120. }
  121. if(bNotConsistency)
  122. {
  123. return eConsistencyState::eCS_NotConsistency;
  124. }else {
  125. return eConsistencyState::eCS_Unknown;
  126. }
  127. }