| | |
| | | lastData = data |
| | | |
| | | removeSingleFactor(data) |
| | | checkDelayedExceptions(data) |
| | | mergeExceptionResult(data) |
| | | val fittedComb = checkDelayedExceptions(data) |
| | | mergeExceptionResult(data, fittedComb) |
| | | onNewResult(result) |
| | | clearExceptions(data) |
| | | } |
| | |
| | | * 将不在关联关系中的监测因子异常存储,并剔除 |
| | | */ |
| | | 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 |
| | |
| | | /** |
| | | * 检查延迟的待合并异常与当前异常是否能匹配 |
| | | * 1. 将遗留的超过等待数据周期的异常存储 |
| | | * 2. 将匹配成功的合并异常存储 |
| | | * 2. 将匹配成功的合并异常存储,同时将关联关系标记为已匹配 |
| | | * 3. 保留依旧未合并成功并且可继续等待的异常 |
| | | * @return 被匹配成功的关联关系 |
| | | */ |
| | | fun checkDelayedExceptions(data: BaseRealTimeData): List<List<FactorType>> { |
| | | if (latestExceptions.isEmpty()) return emptyList() |
| | | |
| | | // 被匹配成功的监测因子关联关系 |
| | | val fittedComb = mutableListOf<List<FactorType>>() |
| | | // 遗留的进入下一个数据周期做判断的待合并异常集合 |
| | |
| | | // 本次数据周期中,被匹配成功的异常集合 |
| | | 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) { |
| | |
| | | |
| | | /** |
| | | * 合并异常 |
| | | * @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 |
| | |
| | | } |
| | | // 否则将异常的深拷贝版本存入待合并异常集合 |
| | | // TODO 2025.8.4: 后续添加当关联的监测因子累计异常计数接近阈值时,才存入集合的逻辑 |
| | | else { |
| | | else if (res.isNotEmpty()) { |
| | | remainingExceptions.add(RemainException(res, c)) |
| | | } |
| | | } |