feiyu02
2025-07-10 c5f380b69707a9a09fe988a2f4bd98e142bf64ae
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt
@@ -6,6 +6,9 @@
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.lightshare.bean.DataVo
import com.flightfeather.uav.socket.eunm.FactorType
import java.util.Date
import kotlin.math.round
/**
 * 污染数据
@@ -40,8 +43,8 @@
        subFactorName = factor.subs.map { it.des }
        selectedFactor = factor
        startTime = DateUtil.instance.dateToString(start.dataTime, DateUtil.DateStyle.HH_MM_SS)
        endTime = DateUtil.instance.dateToString(end?.dataTime, DateUtil.DateStyle.HH_MM_SS) ?: startTime
        startTime = start.dataTime
        endTime = end?.dataTime
//        startData = start.getByFactorType(factor.main)
//        endData = end?.getByFactorType(factor.main) ?: startData
        startData = start
@@ -59,6 +62,12 @@
        historyDataList.addAll(historyData.map { it.toDataVo() })
        calPer()
        calRate()
        val s = dataSummary(exceptionData, factor.main)
        avg = s.first
        min = s.second
        max = s.third
    }
    var deviceCode: String? = null
@@ -72,8 +81,8 @@
    var subFactorName: List<String>? = null
    var selectedFactor: FactorFilter.SelectedFactor? = null
    var startTime: String? = null
    var endTime: String? = null
    var startTime: Date? = null
    var endTime: Date? = null
    var startData: BaseRealTimeData? = null
    var endData: BaseRealTimeData? = null
@@ -85,6 +94,12 @@
    var percentage: Double? = null
    // 因子量级平均变化幅度
    var avgPer: Double? = null
    // 因子量级平均变化速率
    var avgRate: Double? = null
    var avg: Double? = null
    var min: Double? = null
    var max: Double? = null
    // 发生次数
    var times: Int? = null
@@ -108,4 +123,40 @@
        }
        avgPer = total / (list.size - 1)
    }
    private fun calRate() {
        val list = dataList
//        list.add(startData)
//        list.addAll(dataList)
        if (list.size < 2) return
        var total = .0
        for (i in 0 until list.size - 1) {
            val p = list[i]?.getByFactorType(selectedFactor!!.main)!!
            val n = list[i + 1]?.getByFactorType(selectedFactor!!.main)!!
            total += (n - p) / 4
        }
        avgRate = total / (list.size - 1)
    }
    private fun dataSummary(exceptionData: List<BaseRealTimeData?>, factorType: FactorType): Triple<Double, Double,
            Double> {
        var min = -1.0
        var max = -1.0
        var total = .0
        var count = 0
        exceptionData.forEach {
            val value = it?.getByFactorType(factorType)?.toDouble() ?: return@forEach
            if (min == -1.0 || min > value) {
                min = round(value * 1000) / 1000
            }
            if (max == -1.0 || max < value) {
                max = round(value * 1000) / 1000
            }
            total += value
            count++
        }
        val avg = if (count == 0) .0 else round(total / count * 1000) / 1000
        return Triple(avg, min, max)
    }
}