feiyu02
2025-07-16 8fc27dba6719041402e3e3c099e2f3e01d9d52c7
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt
@@ -17,6 +17,23 @@
 */
class PollutedData() {
    inner class Statistic(){
        var factorId: Int? = null
        var factorName: String? = null
        var subFactorId: List<Int>? = null
        var subFactorName: List<String>? = null
        var selectedFactor: FactorFilter.SelectedFactor? = null
        // 因子量级平均变化幅度
        var avgPer: Double? = null
        // 因子量级平均变化速率
        var avgRate: Double? = null
        var avg: Double? = null
        var min: Double? = null
        var max: Double? = null
    }
    /**
     * 9. 关联因子
     *    a) pm2.5、pm10特别高,两者在各情况下同步展示,pm2.5占pm10的比重变化,比重越高,越有可能是餐饮
@@ -29,7 +46,7 @@
    constructor(
        start: BaseRealTimeData,
        end: BaseRealTimeData?,
        factor: FactorFilter.SelectedFactor,
        factorList: List<FactorFilter.SelectedFactor>,
        exceptionData: List<BaseRealTimeData>,
        historyData: List<BaseRealTimeData>,
        eType: ExceptionType,
@@ -37,11 +54,6 @@
    ) : this() {
        exception = eType.des
        exceptionType = eType.value
        factorId = factor.main.value
        factorName = factor.main.des
        subFactorId = factor.subs.map { it.value }
        subFactorName = factor.subs.map { it.des }
        selectedFactor = factor
        startTime = start.dataTime
        endTime = end?.dataTime
@@ -51,7 +63,6 @@
        endData = end
        windSpeed = exceptionData.first().windSpeed?.toDouble()
        percentage = windLevelCondition?.mutationRate?.first
        times = windLevelCondition?.countLimit
        dataList.add(start)
@@ -61,25 +72,30 @@
        dataVoList.addAll(dataList.map { it.toDataVo() })
        historyDataList.addAll(historyData.map { it.toDataVo() })
        calPer()
        calRate()
        val s = dataSummary(exceptionData, factor.main)
        avg = s.first
        min = s.second
        max = s.third
        factorList.forEach { f->
            statisticMap[f.main] = Statistic().apply {
                factorId = f.main.value
                factorName = f.main.des
                subFactorId = f.subs.map { it.value }
                subFactorName = f.subs.map { it.des }
                selectedFactor = f
                avgPer = calPer(f.main)
                avgRate = calRate(f.main)
                val s = dataSummary(exceptionData, f.main)
                avg = s.first
                min = s.second
                max = s.third
            }
        }
    }
    var deviceCode: String? = null
    var exception: String? = null
    var exceptionType: Int? = null
    var factorId: Int? = null
    var factorName: String? = null
    var subFactorId: List<Int>? = null
    var subFactorName: List<String>? = null
    var selectedFactor: FactorFilter.SelectedFactor? = null
    var startTime: Date? = null
    var endTime: Date? = null
@@ -90,17 +106,6 @@
    // 风速
    var windSpeed: Double? = null
    // 因子量级变化幅度
    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
@@ -109,34 +114,37 @@
    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 statisticMap = mutableMapOf<FactorType, Statistic>()
        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)
    fun toFactorNames(): String {
        val factors = statisticMap.entries.map { it.key }.sortedBy { it.value }.joinToString(";") { it.des }
        return factors
    }
    private fun calRate() {
    private fun calPer(factorType: FactorType): Double? {
        val list = dataList
//        list.add(startData)
//        list.addAll(dataList)
        if (list.size < 2) return
        if (list.size < 2) return null
        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)!!
            val p = list[i].getByFactorType(factorType)!!
            val n = list[i + 1].getByFactorType(factorType)!!
            total += (n - p) / p
        }
        return total / (list.size - 1)
    }
    private fun calRate(factorType: FactorType): Double? {
        val list = dataList
        if (list.size < 2) return null
        var total = .0
        for (i in 0 until list.size - 1) {
            val p = list[i].getByFactorType(factorType)!!
            val n = list[i + 1].getByFactorType(factorType)!!
            total += (n - p) / 4
        }
        avgRate = total / (list.size - 1)
        return total / (list.size - 1)
    }
    private fun dataSummary(exceptionData: List<BaseRealTimeData?>, factorType: FactorType): Triple<Double, Double,