#ifndef CONSISTENCYRESULT_H_ #define CONSISTENCYRESULT_H_ #include "GlobalVariable.h" #include "ChannelParam.h" #include enum ERetPythonCompareFile { ERCF_0_CompareFile_FALSE = 0, // 对比返回不一致 ERCF_1_CompareFile_TRUE = 1, // 对比返回一致 ERCF_2_CompareFile_NOT = 2, // 未启动文件对比(如服务地址为空) ERCF_3_CompareFile_Unkonw = 3, // 对比返回未知,判断不出一致性 }; /* 新版本的一致性状态 */ enum class eConsistencyState { eCS_Unknown = 0, // 未知状态 eCS_Consistency = 1, // 一致性 eCS_NotConsistency = 2, // 不一致性 eCS_ConsistencyWarning, // 一致性预警 }; /** * @brief 一致性检测参数 * */ struct StConsistencyParam { StConsistencyParam(); StConsistencyParam(const StConsistencyParam& obj); StConsistencyParam& operator=(const StConsistencyParam& obj); void Init(); // ********* 一致性 ********* [[ void SetConsistencySwitch(bool b) { m_bConsistencySwitch = b; } bool GetConsistencySwitch() { return m_bConsistencySwitch; } int GetConsistencyThreshold() const { return m_iConsistencyThreshold; } void SetConsistencyThreshold(int ival) { m_iConsistencyThreshold = ival; } int GetConsistencyThresholdNum() const { return m_iConsistencyThresholdNum; } void SetConsistencyThresholdNum(int ival) { m_iConsistencyThresholdNum = ival; } int GetConsistencyThresholdNot() const { return m_iConsistencyThresholdNot; } void SetConsistencyThresholdNot(int ival) { m_iConsistencyThresholdNot = ival; } int GetConsistencyThresholdNotNum() const { return m_iConsistencyThresholdNotNum; } // 不一致的判定更严谨,全部为不一致时,才判定为不一致 int GetConsistencyThresholdNotNumEx() const { return m_iConsistencyThresholdNotNum * 2; } void SetConsistencyThresholdNotNum(int ival) { m_iConsistencyThresholdNotNum = ival; } int GetConsistencyThresholdWarningNum() const { return m_nConsistencyThresholdWarningNum; } void SetConsistencyThresholdWarningNum(int ival) { m_nConsistencyThresholdWarningNum = ival; } private: // 一致性监测开关 bool m_bConsistencySwitch; // 一致性阀值 // 持续时间内,如果有m_iConsistencyThresholdNum相似度个比阀值大,就表示一致性 int m_iConsistencyThreshold; int m_iConsistencyThresholdNum; // 一致性阀值预警次数: 多少个不一致时,开启不一致预警 int m_nConsistencyThresholdWarningNum; // 不一致性阀值 // 持续时间内,如果有m_iConsistencyThresholdNotNum相似度个比阀值小,就表示不一致性 int m_iConsistencyThresholdNot; int m_iConsistencyThresholdNotNum; }; /** * @brief 保存n次一致性比较的结果,相似度的值,根据传入的阈值,计算是否是一致的 * */ struct StConsistencyResult { StConsistencyResult(); // StConsistencyResult(StConsistencyParam ¶m); virtual ~StConsistencyResult(); StConsistencyResult(const StConsistencyResult& obj); StConsistencyResult& operator=(const StConsistencyResult& obj); // void Init(); // std::string OutPutConsistencyInfo(const bool bConsistencyInfo); // int AddResult(const float f, const int iDelN); // int GetCount() const { return iCurPos; } // int GetMaxResult() const; // // 这个一致性不能用于判定是否一致性,一致性判定要在 CConsistencyList 里面判定,计算一致性的个数 // bool IsConsistency() const; // bool IsNotConsistency() const; // bool m_bIsNoiseOfCur; // StConsistencyParam m_stConsistencyParam; // StConsistencyParam m_stNoiseConsistencyParam; // int GetConsistencyThresholdNum() const; // int GetConsistencyThresholdNotNum() const; // int GetConsistencyThresholdWarningNum() const; // int GetDelNAt(const int nIndex = 0) const { return aryOfDelN[nIndex]; } // Python对比结果 // int m_nRetPythonCompareFile; // AI对比结果 void InitAICompareFile(); int AddRetAICompareFile(float fVal); // nThresholdNum表示持续次数, dThresholdNum判断阀值 bool IsAIConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue); bool IsAINotConsistency(int nThresholdNum, float dThreshold, std::string &strAIValue); // int GetLastRetAICompareFile(); private: // QDateTime m_tLastAITime; // int m_nLastRetAICompareFile; // AI对比结果,范围[0,1] float aryOfAICompareFile[10]; /* fResult 相似度 delN 偏差(时间偏移) 这里的偏差就是错位的意思,相似度是在这个错位下计算出来的,如下: 1010001011010101110 xxx1010001011010101110 xxx的位数就是偏差量了 */ // int aryOfDelN[RESULT_NUM_OF_ONETIME_COMPARE]; // // 相似度数组 // float aryOfSimilarity[RESULT_NUM_OF_ONETIME_COMPARE]; // // 数组实际保存了多少个数据,当前可以填充数据的位置 // int iCurPos; }; /** * @brief 一致性计算结果,新版本 * */ struct ConsistencyResult_t { ConsistencyResult_t(); ConsistencyResult_t(const ConsistencyResult_t& obj); ConsistencyResult_t& operator=(const ConsistencyResult_t& obj); void Init(); /* 添加结果 */ bool AddResult(float fVal); /* 计算一致性 */ eConsistencyState computeConsistency(int nThresholdNum, float fThreshold, std::string& strInfo); /* 计算不一致性 */ eConsistencyState computeNotConsistency(int nThresholdNum, float fThreshold, std::string& strInfo); /* 获取当前已存储的结果个数 */ int GetCount() const { return m_nCurPos; } private: float m_fInitThreshold = 0.9; /* 初始化阈值 */ const int m_numArryCount = 10; float m_arryResult[10]; /* 结果数组 */ int m_nCurPos; /* 当前结果位置 */ }; #endif // CONSISTENCYRESULT_H_