Riku
2025-06-11 d3b43d50df28c4fe27c104dcd146d35b2bad4d20
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.flightfeather.uav.biz.sourcetrace.model
 
import com.flightfeather.uav.biz.FactorFilter
import com.flightfeather.uav.biz.dataanalysis.BaseExceptionResult
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.domain.entity.SceneInfo
import com.flightfeather.uav.domain.entity.avg
import com.flightfeather.uav.lightshare.bean.DataVo
import com.flightfeather.uav.lightshare.eunm.ExceptionStatusType
import com.flightfeather.uav.socket.eunm.FactorType
import java.math.BigDecimal
import java.util.UUID
 
/**
 *
 * @date 2025/5/13
 * @author feiyu02
 */
@Deprecated("2025.5.29, 逻辑与业务不匹配,后续删除")
class RealTimeExceptionResult() : BaseExceptionResult() {
 
    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: String? = null
    var endTime: String? = null
 
    var startData: Float? = null
    var endData: Float? = null
    var avg: Float? = null
    var min: Float? = null
    var max: Float? = null
 
    // 异常数据,头尾可能包含一定量的偏移
    var dataList: MutableList<BaseRealTimeData> = mutableListOf()
    var dataVoList: MutableList<DataVo> = mutableListOf()
 
    // 中心点经纬度
    var longitude: BigDecimal? = null
    var latitude: BigDecimal? = null
 
    // 中间数据点坐标
    var midData: DataVo? = null
//    var midLongitude: BigDecimal? = null
//    var midLatitude: BigDecimal? = null
 
    // 溯源企业
    var relatedSceneList: List<SceneInfo?>? = null
 
    constructor(
        start: BaseRealTimeData,
        end: BaseRealTimeData?,
        factor: FactorFilter.SelectedFactor,
        exceptionData: List<BaseRealTimeData>,
        eType: ExceptionType,
    ) : this() {
        deviceCode = start.deviceCode
        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 = 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
 
        val avgData = exceptionData.avg()
        // 求取污染数据的中心坐标
        longitude = avgData.longitude
        latitude = avgData.latitude
        // 求取主污染因子的均值和范围
        val s = dataSummary(exceptionData, factor.main)
        avg = s.first
        min = s.second
        max = s.third
 
        exceptionData.forEach {
            dataList.add(it)
            dataVoList.add(it.toDataVo())
        }
    }
 
    private fun dataSummary(
        exceptionData: List<BaseRealTimeData?>,
        factorType: FactorType,
    ): Triple<Float, Float, Float> {
        var min = -1f
        var max = -1f
        var total = 0f
        var count = 0
        exceptionData.forEach {
            val value = it?.getByFactorType(factorType) ?: return@forEach
            if (min == -1f || min > value) {
                min = value
            }
            if (max == -1f || max < value) {
                max = value
            }
            total += value
            count++
        }
        val avg = if (count == 0) 0f else total / count
        return Triple(avg, min, max)
    }
}