package com.flightfeather.uav.biz.dataanalysis.exceptiontype
|
|
import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig
|
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag
|
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType
|
import com.flightfeather.uav.domain.entity.BaseRealTimeData
|
import com.flightfeather.uav.socket.eunm.FactorType
|
import kotlin.math.abs
|
|
/**
|
* 量级突变异常分析
|
*/
|
class ExceptionValueMutation(config: DataAnalysisConfig) : ExceptionContinuous(config) {
|
|
/**
|
* 本异常的连续发生次数会根据异常的程度变化
|
* 当突变的量级超过设定值1倍时,连续发生次数要求减少1倍
|
*/
|
private var special = false
|
|
override fun getExceptionType(): ExceptionType = ExceptionType.TYPE4
|
|
override fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> {
|
val res = mutableMapOf<FactorType, Boolean>()
|
config.factorFilter.mainList().forEach { f ->
|
if (p?.getByFactorType(f) == null || n.getByFactorType(f) == null) {
|
res[f] = (false)
|
return@forEach
|
}
|
val pValue = p.getByFactorType(f)!!
|
val nValue = n.getByFactorType(f)!!
|
val r = abs((pValue - nValue) / pValue)
|
val b1 = r >= (2 * config.mutationRate)
|
val b2 = r >= config.mutationRate
|
if (b1) special = true
|
res[f] = (b1 || b2)
|
// if (res[f] == true) println("p: $pValue --- n: $nValue --- r: $r")
|
}
|
|
return res
|
}
|
|
override fun judgeExceptionCount(tag: ExceptionTag): Boolean {
|
// 首个数据没有前一个数据参照,不算异常值,最后一个数据是判断结束的正常值,因此异常数据个数的计算下标为sIndex和eIndex
|
val sIndex = tag.sIndex
|
val eIndex = tag.eIndex - 1
|
|
val b1 = special && (eIndex - sIndex) >= (config.mutationNum / 2)
|
val b2 = (eIndex - sIndex) >= config.mutationNum
|
special = false
|
// println("sIndex: $sIndex --- eIndex: $eIndex --- special: $special")
|
return b1 || b2
|
}
|
}
|