| | |
| | | config: V, private val tagClz: Class<T>, |
| | | ) : BaseExceptionAnalysis<V, Y>(config) { |
| | | |
| | | enum class JudgeMethod(val des: String) { |
| | | M1("在一定的空间和时间范围内,数据累计出现N次异常后,认为该异常成立"), |
| | | M2("要求数据不间断连续出现N次异常后,认为该异常成立"), |
| | | } |
| | | |
| | | companion object { |
| | | // 记录异常数据段时,分别向起始前和末尾后额外记录的数据个数偏移量 |
| | | private const val OFFSET = 10 |
| | |
| | | * 异常结果 |
| | | */ |
| | | protected val result = mutableListOf<Y>() |
| | | |
| | | /** |
| | | * 不适用于此异常类型的监测因子 |
| | | */ |
| | | open var excludedFactor: List<FactorType> = emptyList() |
| | | |
| | | abstract var judgeMethod: JudgeMethod |
| | | |
| | | /** |
| | | * 立即判断:当出现异常时,缓存异常数据的同时,立即对已有异常进行判断是否满足异常结果要求 |
| | |
| | | * @return |
| | | */ |
| | | open fun needCut(tag: T, hasException: Boolean?, data: BaseRealTimeData): Boolean { |
| | | // 默认判断条件为 当异常不再重复出现时,形成异常结果 |
| | | // 默认判断条件为 当异常不再重复出现时 |
| | | return tag.exceptionExisted && hasException == false |
| | | } |
| | | |
| | |
| | | val hasException = judge(lastData, data) |
| | | config.factorFilter.selectedList.forEach { s -> |
| | | val f = s.main |
| | | tagMap[f]?.let { |
| | | it.addHistoryData(data) |
| | | // 排除此异常类型不适用的监测因子 |
| | | if (excludedFactor.contains(f)) return@forEach |
| | | |
| | | tagMap[f]?.let { |
| | | it.eIndex++ |
| | | // 起始数据 |
| | | it.endData = data |
| | |
| | | it.refreshWithNextException(data) |
| | | } |
| | | |
| | | // 对于异常的生成分别执行后置判断、和立即判断 |
| | | // 1. 后置判断:当相邻数据时间不连续时,或者满足自定义条件时,对之前已有的异常进行记录,形成异常结果 |
| | | // if (afterExcCheck(isContinue, it, hasException[f])) { |
| | | // // 数据不连续时或者满足主动截断条件时,记录异常情况 |
| | | // recordException(s, it, data) |
| | | // } |
| | | // 2. 立即判断:当出现异常时,缓存异常数据的同时,立即对已有异常进行判断是否满足异常结果要求 |
| | | if (hasException[f] == true) { |
| | | // 按照不同的方式进行异常判断 |
| | | when (judgeMethod) { |
| | | JudgeMethod.M1 -> judgeMethod1(hasException, f, it, data, s) |
| | | JudgeMethod.M2 -> judgeMethod2(isContinue, hasException, f, it, data, s) |
| | | } |
| | | |
| | | // afterExcCheck(isContinue, it, hasException[f]) |
| | | if (needCut(it, hasException[f], data)) { |
| | | it.refreshWithNextException(data) |
| | | } |
| | | // 有异常出现时,记录异常数据 |
| | | it.addExceptionData(data) |
| | | // 当立即判断通过时,形成异常结果 |
| | | if (immeExcCheck(it, f)) { |
| | | recordException(s, it, data) |
| | | } |
| | | } |
| | | // 3. 数据正常,无任何异常时d |
| | | // TODO("2025.6.3:其他子类的此处刷新逻辑待完成“) |
| | | // else { |
| | | // it.refreshWithNextException(data) |
| | | // } |
| | | it.addHistoryData(data) |
| | | } |
| | | } |
| | | lastData = data |
| | |
| | | } |
| | | |
| | | /** |
| | | * 数据异常判断方式一 |
| | | * 在一定的空间和时间范围内,数据累计出现N次异常后,认为该异常成立 |
| | | */ |
| | | private fun judgeMethod1( |
| | | hasException: MutableMap<FactorType, Boolean>, |
| | | f: FactorType, |
| | | tag: T, |
| | | data: BaseRealTimeData, |
| | | s: FactorFilter.SelectedFactor, |
| | | ) { |
| | | // 出现异常 |
| | | if (hasException[f] == true) { |
| | | // 判断数据在空间和时间变化上是否超出限定范围,若超出则删除遗留的异常记录,刷新起始点数据 |
| | | if (needCut(tag, hasException[f], data)) { |
| | | tag.refreshWithNextException(data) |
| | | } |
| | | // 记录异常数据 |
| | | tag.addExceptionData(data) |
| | | // 当立即判断通过时,形成异常结果 |
| | | if (immeExcCheck(tag, f)) { |
| | | recordException(s, tag, data) |
| | | } |
| | | } |
| | | // 数据正常,并且没有历史异常数据时,刷新起始点数据 |
| | | else if (!tag.exceptionExisted) { |
| | | tag.refreshWithNextException(data) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 数据异常判断方式二 |
| | | * 要求数据不间断连续出现N次异常后,认为该异常成立 |
| | | */ |
| | | private fun judgeMethod2( |
| | | isContinue: Boolean, |
| | | hasException: MutableMap<FactorType, Boolean>, |
| | | f: FactorType, |
| | | tag: T, |
| | | data: BaseRealTimeData, |
| | | s: FactorFilter.SelectedFactor, |
| | | ) { |
| | | // 当相邻数据时间不连续时,刷新起始点数据,移除历史异常记录 |
| | | if (!isContinue) { |
| | | tag.refreshWithNextException(data) |
| | | } |
| | | // 出现异常 |
| | | else if (hasException[f] == true) { |
| | | // 有异常出现时,记录异常数据 |
| | | tag.addExceptionData(data) |
| | | // 当立即判断通过时,形成异常结果 |
| | | if (immeExcCheck(tag, f)) { |
| | | recordException(s, tag, data) |
| | | } |
| | | } |
| | | // 数据正常,刷新起始点数据,移除历史异常记录 |
| | | else { |
| | | tag.refreshWithNextException(data) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 异常结束,记录异常 |
| | | * 判断已有的异常数据是否满足异常条件,满足则记录,不满足则略过 |
| | | */ |