feiyu02
2025-08-14 b10c22af595bd995e56946bff63b8f2f984b13e8
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
62
package com.flightfeather.uav.biz.sourcetrace.model
 
import com.flightfeather.uav.biz.FactorFilter
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag
import com.flightfeather.uav.socket.eunm.FactorType
 
/**
 * 待合并异常
 * 异常出现后,若相关的其他因子累计异常次数接近阈值,则该异常可以等待若干个数据周期后再合并。
 * @date 2025/8/1
 * @author feiyu02
 */
class RemainException<T : ExceptionTag>(
    exceptions: List<Pair<FactorFilter.SelectedFactor, T>>,
    combination: List<FactorType>,
) {
 
    // 已有的异常
    var exceptions = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>()
 
    // 需要延迟检测的因子关联关系
    val combination = mutableListOf<FactorType>()
 
    // 缺失的监测因子
    val lackFactors = mutableListOf<FactorType>()
 
    // 已经过的数据周期
    var period: Int = 1
 
    init {
        // 存储监测因子异常对象的克隆版本,
        this.exceptions.addAll(exceptions.map {
            it.first to (it.second.clone() as T)
        })
        this.combination.addAll(combination)
        calLackFactors()
    }
 
    /**
     * 添加新的异常集合
     */
    fun addExceptions(exceptions: List<Pair<FactorFilter.SelectedFactor, T>>) {
        // 存储监测因子异常对象的克隆版本,
        this.exceptions.addAll(exceptions.map {
            it.first to (it.second.clone() as T)
        })
        calLackFactors()
    }
 
    /**
     * 计算缺失的监测因子
     */
    private fun calLackFactors() {
        lackFactors.clear()
        combination.forEach { c ->
            val e = exceptions.find { it.first.main == c }
            if (e == null) {
                lackFactors.add(c)
            }
        }
    }
}