riku
2021-06-30 5353617c7b2135ab00f98d8e05b2f8dfb2e096ed
src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt
@@ -1,21 +1,53 @@
package com.flightfeather.uav.model
import com.flightfeather.uav.lightshare.bean.DataVo
/**
 * 权重
 * 某种影响因素在不同情况下对某种监测数据产生的权重影响
 */
abstract class BaseWeight {
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 影响因素的值
     */
    fun weightCal(value: Double): Double {
    private fun weightCal(value: Double): Double {
        for (i in sectionValues.indices) {
            if (value < sectionValues[i]) {
                return weights[i]