feiyu02
2024-06-27 e8f935a01d75c89ac591a80b9318eac2480e2dcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.flightfeather.uav.biz.dataanalysis.exceptiontype
 
import com.flightfeather.uav.biz.dataanalysis.BaseExceptionContinuous
import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig
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) : BaseExceptionContinuous(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)
        }
//        repeat(config.factorCount) { i->
//            if (p?.getByFactorIndex(i) == null || n.getByFactorIndex(i) == null) {
//                res.add(false)
//                return@repeat
//            }
//            val pValue = p.getByFactorIndex(i)!!
//            val nValue = n.getByFactorIndex(i)!!
//            val r = abs((pValue - nValue) / pValue)
//            val b1 = r >= (2 * config.mutationRate)
//            val b2 = r >= config.mutationRate
//            if (b1) special = true
//            res.add(b1 || b2)
//        }
 
        return res
    }
 
    override fun judgeDuration(sIndex: Int, eIndex: Int): Boolean {
        val b1 = special && (eIndex - sIndex) >= (config.mutationNum / 2)
        val b2 = (eIndex - sIndex) >= config.mutationNum
        special = false
        return b1 || b2
    }
}