| | |
| | | // 末尾数据对象 |
| | | protected var lastData: BaseRealTimeData? = null |
| | | |
| | | /** |
| | | * 后置判断:当相邻数据时间不连续时,或者满足自定义条件时,对之前已有的异常进行记录 |
| | | */ |
| | | open fun afterExcCheck(isContinue: Boolean, tag: T, hasException: Boolean?): Boolean { |
| | | return !isContinue || needCut(tag, hasException) |
| | | } |
| | | // 最新的一组异常,根据设定参数,将相关联的因子产生的异常合并 |
| | | protected val latestExceptionResult = mutableListOf<BaseExceptionResult>() |
| | | |
| | | // 最新的一组合并异常 |
| | | protected val latestCombinedResult = mutableListOf<List<BaseExceptionResult>>() |
| | | |
| | | /** |
| | | * 立即判断:当出现异常时,缓存异常数据的同时,立即对已有异常进行判断是否满足异常结果要求 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 判断数据量级在异常判断的范围内 |
| | | * 默认所有量级都在异常判断的范围内 |
| | | */ |
| | | open fun judgeDataScale(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> { |
| | | val res = mutableMapOf<FactorType, Boolean>() |
| | | config.factorFilter.mainList().forEach { f -> res[f] = true } |
| | | return res |
| | | } |
| | | |
| | | /** |
| | | * 判断前后数据是否满足异常条件 |
| | | */ |
| | | abstract fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> |
| | |
| | | abstract fun judgeExceptionCount(tag: T, factorType: FactorType?): Boolean |
| | | |
| | | /** |
| | | * 判断监测因子是否出现异常 |
| | | */ |
| | | open fun judge(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> { |
| | | val jds = judgeDataScale(p, n) |
| | | val jex = judgeException(p, n) |
| | | val res = mutableMapOf<FactorType, Boolean>() |
| | | jds.forEach { (t, u) -> |
| | | res[t] = u && jex[t] ?: false |
| | | } |
| | | return res |
| | | } |
| | | |
| | | /** |
| | | * 异常数据的截取判断 |
| | | * @return |
| | | */ |
| | | open fun needCut(tag: T, hasException: Boolean?): Boolean { |
| | | open fun needCut(tag: T, hasException: Boolean?, data: BaseRealTimeData): Boolean { |
| | | // 默认判断条件为 当异常不再重复出现时,形成异常结果 |
| | | return tag.exceptionExisted && hasException == false |
| | | } |
| | |
| | | |
| | | override fun onNextData(data: BaseRealTimeData) { |
| | | val isContinue = isContinuous(lastData, data) |
| | | val hasException = judgeException(lastData, data) |
| | | val hasException = judge(lastData, data) |
| | | config.factorFilter.selectedList.forEach { s -> |
| | | val f = s.main |
| | | tagMap[f]?.let { |
| | |
| | | |
| | | // 对于异常的生成分别执行后置判断、和立即判断 |
| | | // 1. 后置判断:当相邻数据时间不连续时,或者满足自定义条件时,对之前已有的异常进行记录,形成异常结果 |
| | | if (afterExcCheck(isContinue, it, hasException[f])) { |
| | | // 数据不连续时或者满足主动截断条件时,记录异常情况 |
| | | recordException(s, it, data) |
| | | } |
| | | // if (afterExcCheck(isContinue, it, hasException[f])) { |
| | | // // 数据不连续时或者满足主动截断条件时,记录异常情况 |
| | | // recordException(s, it, data) |
| | | // } |
| | | // 2. 立即判断:当出现异常时,缓存异常数据的同时,立即对已有异常进行判断是否满足异常结果要求 |
| | | else if (hasException[f] == true) { |
| | | if (hasException[f] == true) { |
| | | |
| | | // afterExcCheck(isContinue, it, hasException[f]) |
| | | if (needCut(it, hasException[f], data)) { |
| | | it.refreshWithNextException(data) |
| | | } |
| | | // 有异常出现时,记录异常数据 |
| | | it.addExceptionData(data) |
| | | // 当立即判断通过时,形成异常结果 |
| | |
| | | } |
| | | // 3. 数据正常,无任何异常时d |
| | | // TODO("2025.6.3:其他子类的此处刷新逻辑待完成“) |
| | | else { |
| | | it.refreshWithNoException(data) |
| | | } |
| | | // else { |
| | | // it.refreshWithNextException(data) |
| | | // } |
| | | } |
| | | } |
| | | lastData = data |
| | | |
| | | mergeExceptionResult() |
| | | } |
| | | |
| | | override fun onDone() { |
| | |
| | | } else { |
| | | config.factorFilter.selectedList.forEach { f -> |
| | | val tag1 = tagMap[f.main] ?: return@forEach |
| | | if (tag1.exceptionExisted && judgeExceptionCount(tag1, null)) { |
| | | if (tag1.exceptionExisted && judgeExceptionCount(tag1, f.main)) { |
| | | onNewException(tag1, f, exceptionStatus) |
| | | } |
| | | } |
| | |
| | | // 异常未创建时,新建异常信息 |
| | | else { |
| | | tag.exceptionResult.add(ex) |
| | | // resultList.add(ex) |
| | | tag.exceptionCreated = true |
| | | } |
| | | |
| | | latestExceptionResult.add(ex) |
| | | } |
| | | |
| | | /** |
| | | * 合并异常 |
| | | */ |
| | | open fun mergeExceptionResult() { |
| | | // 遍历所有的因子组合 |
| | | config.combination?.forEach {c -> |
| | | val res = mutableListOf<BaseExceptionResult>() |
| | | var exist = true |
| | | // 查看组合内的所有因子是否都同时出现异常 |
| | | c.forEach { f-> |
| | | val r = latestExceptionResult.find { e-> |
| | | e.factorId == f.value |
| | | } |
| | | if (r != null) { |
| | | res.add(r) |
| | | } else { |
| | | exist = false |
| | | } |
| | | } |
| | | // 如果组合内的所有因子都存在异常,则存储为合并异常 |
| | | if (exist) { |
| | | // 将合并异常从单个异常集合中去除 |
| | | res.forEach { r-> |
| | | latestExceptionResult.removeIf { e-> e.factorId == r.factorId } |
| | | } |
| | | // 将合并异常存储 |
| | | latestCombinedResult.add(res) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |