#include "ConsistencyResult.h" #include "GlobalInfo.h" #include "spdlog/spdlog.h" /* -------------------------------------------------------------------------------- * 一致性检测结果 ConsistencyResult_t * -------------------------------------------------------------------------------- */ ConsistencyResult_t::ConsistencyResult_t() { Init(); } ConsistencyResult_t::ConsistencyResult_t(const ConsistencyResult_t& obj) { } ConsistencyResult_t& ConsistencyResult_t::operator=(const ConsistencyResult_t& obj) { m_fInitThreshold = obj.m_fInitThreshold; m_nCurPos = obj.m_nCurPos; for(int i = 0; i < m_numArryCount; ++i) { m_arryResult[i] = obj.m_arryResult[i]; } return *this; } void ConsistencyResult_t::Init() { m_fInitThreshold = 0.9; /* 初始化阈值 */ m_nCurPos = 0; for(int i = 0; i < m_numArryCount; ++i) { m_arryResult[i] = -1.0; } } /* 添加结果 */ bool ConsistencyResult_t::AddResult(float fVal) { for(int i = 8; i >= 0; --i) { m_arryResult[i + 1] = m_arryResult[i]; } m_arryResult[0] = fVal; return true; } /* 计算一致性 计算要求:需要 nThresholdNum 全部大于一致性阈值 fThreshold 方可判断为一致,否则返回无法判断为一致 */ eConsistencyState ConsistencyResult_t::computeConsistency(int nThresholdNum, float fThreshold, std::string& strInfo) { strInfo.clear(); bool bConsistency = true; if (nThresholdNum < 0) { nThresholdNum = 1; strInfo += "一致性最小检测数目为1 "; } if (nThresholdNum > 10) { nThresholdNum = 10; strInfo += "一致性最大检测数目为10 "; } for(int i = 0; i < nThresholdNum; ++i) { if (m_arryResult[i] < -0.9) { strInfo += "数据未初始化"; return eConsistencyState::eCS_Unknown; } if (m_arryResult[i] < fThreshold) { bConsistency = false; strInfo = fmt::format("{},{:.3f}<{:.3f}不能判断为一致", strInfo, m_arryResult[i], fThreshold); break; } else { strInfo = fmt::format("{},{:.3f}", strInfo, m_arryResult[i]); } } if (bConsistency) { return eConsistencyState::eCS_Consistency; }else { return eConsistencyState::eCS_Unknown; } } /* 计算不一致性 */ eConsistencyState ConsistencyResult_t::computeNotConsistency(int nThresholdNum, float fThreshold, std::string& strInfo) { strInfo.clear(); bool bNotConsistency = true; if (nThresholdNum < 0) { nThresholdNum = 1; strInfo += "一致性最小检测数目为1 "; } if (nThresholdNum > 10) { nThresholdNum = 10; strInfo += "一致性最大检测数目为10 "; } for(int i = 0; i < nThresholdNum; ++i) { if (m_arryResult[i] < -0.9) { strInfo = fmt::format("数据未初始化直接返回"); return eConsistencyState::eCS_Unknown; } if (m_arryResult[i] > fThreshold) { bNotConsistency = false; strInfo = fmt::format("{},{:.3f} > {:.3f}不能判断为不一致", strInfo, m_arryResult[i], fThreshold); break; } else { strInfo = fmt::format("{}, {:.3f}", strInfo, m_arryResult[i]); } } if (bNotConsistency) { strInfo = fmt::format("{}, 判断为不一致", strInfo); } if(bNotConsistency) { return eConsistencyState::eCS_NotConsistency; }else { return eConsistencyState::eCS_Unknown; } }