feiyu02
2025-07-04 9c797fa0d704ef8ffb65cd1716b8eb694b4c46c3
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt
@@ -6,6 +6,7 @@
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.lightshare.bean.DataVo
import java.util.Date
/**
 * 污染数据
@@ -13,16 +14,6 @@
 * @author feiyu02
 */
class PollutedData() {
    /**
     *
     * 1. 软风1.5m/s及以下,
     *    前后值上升幅度在50%以上1次,认为是临近发生(50米)
     *    前后值上升幅度在20%以上1次,认为是远距离发生(50米 - 500米)
     *    1.5 m/s及以下,静稳天气,临近发生(50米)
     * 2. 1.6 - 7.9 m/s,前后值上升幅度在20%以上3次,认为是远距离发生(50米 - 1公里)
     * 3. 8 - 13.8 m/s 以上,前后值上升幅度在10%以上3次,认为是远距离发生(50米 - 2公里)
     */
    /**
     * 9. 关联因子
@@ -38,8 +29,9 @@
        end: BaseRealTimeData?,
        factor: FactorFilter.SelectedFactor,
        exceptionData: List<BaseRealTimeData>,
        historyData: List<BaseRealTimeData>,
        eType: ExceptionType,
        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition,
        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition?,
    ) : this() {
        exception = eType.des
        exceptionType = eType.value
@@ -49,19 +41,26 @@
        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
        startData = start.getByFactorType(factor.main)
        endData = end?.getByFactorType(factor.main) ?: startData
        startTime = start.dataTime
        endTime = end?.dataTime
//        startData = start.getByFactorType(factor.main)
//        endData = end?.getByFactorType(factor.main) ?: startData
        startData = start
        endData = end
        windSpeed = exceptionData.first().windSpeed?.toDouble()
        percentage = windLevelCondition.mutationRate.first
        times = windLevelCondition.countLimit
        percentage = windLevelCondition?.mutationRate?.first
        times = windLevelCondition?.countLimit
        dataList.add(start)
        exceptionData.forEach {
            dataList.add(it)
            dataVoList.add(it.toDataVo())
        }
        dataVoList.addAll(dataList.map { it.toDataVo() })
        historyDataList.addAll(historyData.map { it.toDataVo() })
        calPer()
        calRate()
    }
    var deviceCode: String? = null
@@ -75,22 +74,57 @@
    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: Float? = null
    var endData: Float? = null
    var startData: BaseRealTimeData? = null
    var endData: BaseRealTimeData? = null
    // 风速
    var windSpeed: Double? = null
    // 因子量级变化幅度
    var percentage: Double? = null
    // 因子量级平均变化幅度
    var avgPer: Double? = null
    // 因子量级平均变化速率
    var avgRate: Double? = null
    // 发生次数
    var times: Int? = null
    var historyDataList = mutableListOf<DataVo>()
    // 异常监测数据
    var dataList: MutableList<BaseRealTimeData> = mutableListOf()
    var dataVoList: MutableList<DataVo> = mutableListOf()
    private fun calPer() {
        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) / p
        }
        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)
    }
}