feiyu02
2025-08-14 b10c22af595bd995e56946bff63b8f2f984b13e8
src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
@@ -154,8 +154,8 @@
        lastData = data
        removeSingleFactor(data)
        checkDelayedExceptions(data)
        mergeExceptionResult(data)
        val fittedComb = checkDelayedExceptions(data)
        mergeExceptionResult(data, fittedComb)
        onNewResult(result)
        clearExceptions(data)
    }
@@ -286,6 +286,8 @@
     * 将不在关联关系中的监测因子异常存储,并剔除
     */
    fun removeSingleFactor(data: BaseRealTimeData) {
        if (latestExceptions.isEmpty()) return
        // 查找不在因子关联组合中的异常因子
        val sfList = latestExceptions.filter {
            config.factorFilter.combination.find { c -> c.find { f -> f == it.first.main } != null } == null
@@ -302,11 +304,13 @@
    /**
     * 检查延迟的待合并异常与当前异常是否能匹配
     * 1. 将遗留的超过等待数据周期的异常存储
     * 2. 将匹配成功的合并异常存储
     * 2. 将匹配成功的合并异常存储,同时将关联关系标记为已匹配
     * 3. 保留依旧未合并成功并且可继续等待的异常
     * @return 被匹配成功的关联关系
     */
    fun checkDelayedExceptions(data: BaseRealTimeData): List<List<FactorType>> {
        if (latestExceptions.isEmpty()) return emptyList()
        // 被匹配成功的监测因子关联关系
        val fittedComb = mutableListOf<List<FactorType>>()
        // 遗留的进入下一个数据周期做判断的待合并异常集合
@@ -316,14 +320,13 @@
        // 本次数据周期中,被匹配成功的异常集合
        val exceps = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>()
        remainingExceptions.forEach {
            // 检查当前新异常中,是否包含因子关联关系中的异常
            // 检查本次数据周期的异常中,是否包含因子关联关系中的异常
            val combRes = matchCombFactor(it.combination, latestExceptions)
            val res = combRes.second
            // 判断本次数据周期中找到的因子和已有的因子是否满足关联关系
            val findFactors = mutableListOf<FactorType>()
            res.forEach {r -> findFactors.add(r.first.main) }
            it.exceptions.forEach {r -> findFactors.add(r.first.main) }
            // 判断是否还有缺失异常
            val isFitAll = findFactors.distinct() == it.combination
            // 如果已经没有缺失的异常因子,则可合并为组合异常
            if (isFitAll) {
@@ -377,11 +380,20 @@
    /**
     * 合并异常
     * @param data 当前监测数据
     * @param fittedComb 在遗留的异常[remainingExceptions]判断中,已经进行匹配判断的关联关系,将不再进行匹配
     */
    open fun mergeExceptionResult(data: BaseRealTimeData) {
    open fun mergeExceptionResult(data: BaseRealTimeData, fittedComb: List<List<FactorType>>) {
        if (latestExceptions.isEmpty()) return
        val combinedExc = mutableListOf<List<Pair<FactorFilter.SelectedFactor, T>>>()
        // 遍历所有的因子组合
        config.factorFilter.combination.forEach { c ->
            /**
             * 跳过已经在[checkDelayedExceptions]中判断过的关联关系
             */
            if (fittedComb.indexOf(c) >= 0) return@forEach
            val combRes = matchCombFactor(c, latestExceptions)
            val res = combRes.second
            val exist = combRes.first
@@ -392,7 +404,7 @@
            }
            // 否则将异常的深拷贝版本存入待合并异常集合
            // TODO 2025.8.4: 后续添加当关联的监测因子累计异常计数接近阈值时,才存入集合的逻辑
            else {
            else if (res.isNotEmpty()) {
                remainingExceptions.add(RemainException(res, c))
            }
        }