riku
2021-06-30 5353617c7b2135ab00f98d8e05b2f8dfb2e096ed
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
package com.flightfeather.uav.model
 
import com.flightfeather.uav.lightshare.bean.DataVo
 
/**
 * 权重
 * 某种影响因素在不同情况下对某种监测数据产生的权重影响
 */
abstract class BaseWeight <M: BaseMData, S : BaseSOP> {
 
    abstract val tag:String
 
    // 区间阈值
    abstract val sectionValues: List<Double>
 
    // 区间对应权重
    abstract val weights: List<Double>
 
    // 上次计算的权重值
    private var lastWeight = -1.0
 
    // 权重是否变化
    var isChange = true
 
    fun getWeight(mData: M, sop: S): Double? {
        if (!isChange) {
            if (lastWeight < 0) {
                val v = onWeightFactor(mData, sop) ?: return null
                lastWeight = weightCal(v)
            }
//            println("$tag: $lastWeight")
            return lastWeight
        } else {
            val v = onWeightFactor(mData, sop) ?: return null
            lastWeight = weightCal(v)
//            println("$tag: $lastWeight")
            return lastWeight
        }
    }
 
    /**
     * 获取权重因子值
     */
    abstract fun onWeightFactor(mData: M, sop: S): Double?
 
    /**
     * 权重计算
     * @param value 影响因素的值
     */
    private fun weightCal(value: Double): Double {
        for (i in sectionValues.indices) {
            if (value < sectionValues[i]) {
                return weights[i]
            }
        }
        return weights.last()
    }
}