From b10c22af595bd995e56946bff63b8f2f984b13e8 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 14 八月 2025 17:25:05 +0800
Subject: [PATCH] 2025.8.14 1. 动态溯源模块添加滑动平均异常计算(调试中)

---
 src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/ExceptionResult.kt |   82 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/ExceptionResult.kt b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/ExceptionResult.kt
index 8ae9ffa..23e3d65 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/ExceptionResult.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/ExceptionResult.kt
@@ -1,19 +1,32 @@
 package com.flightfeather.uav.biz.dataanalysis.model
 
+import com.flightfeather.uav.biz.FactorFilter
+import com.flightfeather.uav.biz.dataanalysis.BaseExceptionResult
+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.socket.eunm.FactorType
 import java.math.BigDecimal
+import java.util.*
 
 /**
  * 寮傚父缁撴灉
  */
-open class ExceptionResult {
+open class ExceptionResult(): BaseExceptionResult() {
     var missionCode: String? = null
     var deviceCode: String? = null
     var exception: String? = null
     var exceptionType: Int? = null
     var exceptionValue: Float? = null
-    var factorId: Int? = null
-    var factorName: String? = 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 startDate: Date? = null
+    var endDate: Date? = null
     var startTime: String? = null
     var endTime: String? = null
     var startData: Float? = null
@@ -21,6 +34,8 @@
     var avg: Float? = null
     var min: Float? = null
     var max: Float? = null
+    // 閫旂粡璺
+    var road: String? = null
     // 涓績鐐圭粡绾害
     var longitude: BigDecimal? = null
     var latitude: BigDecimal? = null
@@ -28,6 +43,65 @@
     var relatedSceneId: List<String>? = null
     // 鐩稿叧浼佷笟鍚嶇О锛堝悕绉颁箣闂�;鍒嗛殧锛�
     var relatedSceneName: List<String>? = null
-    // 寮傚父鏁版嵁锛屽ご灏惧彲鑳藉寘鍚竴瀹氶噺鐨勫亸绉�
+    var relatedSceneList: List<SceneInfo?>? = null
+    // 寮傚父鏁版嵁
     var dataList: MutableList<BaseRealTimeData> = mutableListOf()
+    var dataVoList: List<DataVo>? = null
+
+    constructor(
+        start: BaseRealTimeData,
+        end: BaseRealTimeData?,
+        factor: FactorFilter.SelectedFactor,
+        exceptionData: List<BaseRealTimeData>,
+        missionCode: String?,
+        eType: ExceptionType,
+    ) : this() {
+        this.missionCode = missionCode
+        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
+        startDate = start.dataTime
+        endDate = end?.dataTime
+        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) }
+    }
+
+    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)
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3