From 7d33080998a2c5b38e8a74dbed2b0f40d39bbe47 Mon Sep 17 00:00:00 2001
From: Riku <risaku@163.com>
Date: 星期三, 04 六月 2025 23:27:26 +0800
Subject: [PATCH] 1. 新增动态污染溯源新的判定逻辑(待完成)
---
src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt | 158 ++++++++++++++++++++++++++--------------------------
1 files changed, 78 insertions(+), 80 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
index 0c2e28a..ce55583 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
@@ -1,55 +1,45 @@
package com.flightfeather.uav.biz.dataanalysis
import com.flightfeather.uav.biz.FactorFilter
+import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag
import com.flightfeather.uav.domain.entity.BaseRealTimeData
+import com.flightfeather.uav.lightshare.eunm.ExceptionStatusType
import com.flightfeather.uav.socket.eunm.FactorType
import java.time.Duration
/**
* 杩炵画绫诲瀷鐨勫紓甯稿垎鏋愬熀绫�,閫傜敤浜庡綋鍓嶆暟鎹笌鐩搁偦鏁版嵁涔嬮棿鏈夊叧鑱斿叧绯荤殑鎯呭喌
*/
-abstract class BaseExceptionContinuous<V : BaseAnalysisConfig, Y : BaseExceptionResult>(config: V) :
- BaseExceptionAnalysis<V, Y>(config) {
+abstract class BaseExceptionContinuous<T : ExceptionTag, V : BaseAnalysisConfig, Y : BaseExceptionResult>(
+ config: V, private val tagClz: Class<T>
+) : BaseExceptionAnalysis<V, Y>(config) {
companion object {
// 璁板綍寮傚父鏁版嵁娈垫椂锛屽垎鍒悜璧峰鍓嶅拰鏈熬鍚庨澶栬褰曠殑鏁版嵁涓暟鍋忕Щ閲�
private const val OFFSET = 10
}
- inner class Tag {
- // 璧峰鏁版嵁涓嬫爣
- var sIndex = 0
-
- // 璧峰鏁版嵁瀵硅薄
- var startData: BaseRealTimeData? = null
-
- // 鏈熬鏁版嵁涓嬫爣
- var eIndex = -1
-
- // 鏈熬鏁版嵁瀵硅薄
- var endData: BaseRealTimeData? = null
-
- // 寮傚父鏁版嵁娈�
- var exceptionData = mutableListOf<BaseRealTimeData>()
-
- // 鏄惁瀛樺湪寮傚父
- var existException = false
-
- fun refreshAfterCheckResult(data: BaseRealTimeData) {
- sIndex = eIndex
- startData = data
- exceptionData.clear()
-// exceptionData.add(data)
- }
- }
-
- protected val tagMap = mutableMapOf<FactorType, Tag>()
+ protected val tagMap = mutableMapOf<FactorType, T>()
// 璧峰鏁版嵁涓庢湯灏炬暟鎹棿闅�
open var durationCount = 1
// 鏈熬鏁版嵁瀵硅薄
protected var lastData: BaseRealTimeData? = null
+
+ /**
+ * 鍚庣疆鍒ゆ柇锛氬綋鐩搁偦鏁版嵁鏃堕棿涓嶈繛缁椂锛屾垨鑰呮弧瓒宠嚜瀹氫箟鏉′欢鏃讹紝瀵逛箣鍓嶅凡鏈夌殑寮傚父杩涜璁板綍
+ */
+ open fun afterExcCheck(isContinue: Boolean, tag: T, hasException: Boolean?): Boolean {
+ return !isContinue || needCut(tag, hasException)
+ }
+
+ /**
+ * 绔嬪嵆鍒ゆ柇锛氬綋鍑虹幇寮傚父鏃讹紝缂撳瓨寮傚父鏁版嵁鐨勫悓鏃讹紝绔嬪嵆瀵瑰凡鏈夊紓甯歌繘琛屽垽鏂槸鍚︽弧瓒冲紓甯哥粨鏋滆姹�
+ */
+ open fun immeExcCheck(tag: T): Boolean {
+ return false
+ }
/**
* 鍒ゆ柇鐩搁偦鏁版嵁鏄惁杩炵画
@@ -63,7 +53,7 @@
}
/**
- * 鍒ゆ柇鏄惁婊¤冻寮傚父鏉′欢
+ * 鍒ゆ柇鍓嶅悗鏁版嵁鏄惁婊¤冻寮傚父鏉′欢
*/
abstract fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean>
@@ -71,15 +61,15 @@
* 鍒ゆ柇寮傚父鍑虹幇鐨勮繛缁釜鏁版槸鍚︽弧瓒虫潯浠�
* @param tag 寮傚父鏁版嵁瀵硅薄
*/
- abstract fun judgeExceptionCount(tag: Tag): Boolean
+ abstract fun judgeExceptionCount(tag: T): Boolean
/**
* 寮傚父鏁版嵁鐨勬埅鍙栧垽鏂�
- * 鏄惁闇�瑕侀檺鍒朵竴缁勫紓甯告暟鎹殑闀垮害
* @return 榛樿涓嶉渶瑕佹埅鍙�
*/
- open fun needCut(tag: Tag): Boolean {
- return false
+ open fun needCut(tag: T, hasException: Boolean?): Boolean {
+ // 榛樿鍒ゆ柇鏉′欢涓� 褰撳紓甯镐笉鍐嶉噸澶嶅嚭鐜版椂锛屽舰鎴愬紓甯哥粨鏋�
+ return tag.exceptionExisted && hasException == false
}
override fun init() {
@@ -87,7 +77,7 @@
lastData = null
tagMap.clear()
config.factorFilter.mainList().forEach { f ->
- tagMap[f] = Tag()
+ tagMap[f] = tagClz.newInstance()
}
}
@@ -101,28 +91,28 @@
// 璧峰鏁版嵁
it.endData = data
if (it.startData == null) {
- it.refreshAfterCheckResult(data)
+ it.refreshWithNextException(data)
}
- // 鍒ゆ柇鐩搁偦鏁版嵁鏄惁杩炵画骞朵笖鏄惁婊¤冻寮傚父鍒ゆ柇
- if (!isContinue || needCut(it)) {
- // 鏁版嵁涓嶈繛缁椂锛岃褰曞紓甯告儏鍐�
+
+ // 瀵逛簬寮傚父鐨勭敓鎴愬垎鍒墽琛屽悗缃垽鏂�佸拰绔嬪嵆鍒ゆ柇
+ // 1. 鍚庣疆鍒ゆ柇锛氬綋鐩搁偦鏁版嵁鏃堕棿涓嶈繛缁椂锛屾垨鑰呮弧瓒宠嚜瀹氫箟鏉′欢鏃讹紝瀵逛箣鍓嶅凡鏈夌殑寮傚父杩涜璁板綍锛屽舰鎴愬紓甯哥粨鏋�
+ if (afterExcCheck(isContinue, it, hasException[f])) {
+ // 鏁版嵁涓嶈繛缁椂鎴栬�呮弧瓒充富鍔ㄦ埅鏂潯浠舵椂锛岃褰曞紓甯告儏鍐�
recordException(s, it, data)
-// checkResult(s)
-// if (it.eIndex - it.sIndex >= durationCount) {
-// it.refreshAfterCheckResult(data)
-// }
- } else {
- if (hasException[f] == true) {
- it.existException = true
- it.exceptionData.add(data)
- } else {
- // 寮傚父涓嶅啀閲嶅鍑虹幇鏃讹紝璁板綍寮傚父鎯呭喌
+ }
+ // 2. 绔嬪嵆鍒ゆ柇锛氬綋鍑虹幇寮傚父鏃讹紝缂撳瓨寮傚父鏁版嵁鐨勫悓鏃讹紝绔嬪嵆瀵瑰凡鏈夊紓甯歌繘琛屽垽鏂槸鍚︽弧瓒冲紓甯哥粨鏋滆姹�
+ else if (hasException[f] == true) {
+ // 鏈夊紓甯稿嚭鐜版椂锛岃褰曞紓甯告暟鎹�
+ it.addExceptionData(data)
+ // 褰撶珛鍗冲垽鏂�氳繃鏃讹紝褰㈡垚寮傚父缁撴灉
+ if (immeExcCheck(it)) {
recordException(s, it, data)
-// checkResult(s)
-// if (it.eIndex - it.sIndex >= durationCount) {
-// it.refreshAfterCheckResult(data)
-// }
}
+ }
+ // 3. 鏁版嵁姝e父锛屾棤浠讳綍寮傚父鏃禿
+ // TODO("2025.6.3锛氬叾浠栧瓙绫荤殑姝ゅ鍒锋柊閫昏緫寰呭畬鎴愨��)
+ else {
+ it.refreshWithNoException(data)
}
}
}
@@ -130,53 +120,61 @@
}
override fun onDone() {
- checkResult()
+ checkResult(exceptionStatus = ExceptionStatusType.Ended)
}
- fun recordException(factor: FactorFilter.SelectedFactor, tag: Tag, data: BaseRealTimeData) {
- checkResult(factor)
- if (tag.eIndex - tag.sIndex >= durationCount) {
- tag.refreshAfterCheckResult(data)
- }
+ /**
+ * 寮傚父缁撴潫锛岃褰曞紓甯�
+ * 鍒ゆ柇宸叉湁鐨勫紓甯告暟鎹槸鍚︽弧瓒冲紓甯告潯浠讹紝婊¤冻鍒欒褰曪紝涓嶆弧瓒冲垯鐣ヨ繃
+ */
+ fun recordException(factor: FactorFilter.SelectedFactor, tag: T, data: BaseRealTimeData) {
+ checkResult(factor, ExceptionStatusType.Ended)
+ tag.refreshWithNextException(data)
}
/**
* 妫�鏌ヨ繛缁紓甯哥粨鏉熸椂锛屾槸鍚︾鍚堝紓甯稿瓨鍌ㄦ潯浠�
*/
- open fun checkResult(factor: FactorFilter.SelectedFactor? = null) {
+ open fun checkResult(
+ factor: FactorFilter.SelectedFactor? = null,
+ exceptionStatus: ExceptionStatusType = ExceptionStatusType.InProgress
+ ) {
val tag = tagMap[factor?.main]
if (factor != null && tag != null) {
- if (tag.existException && judgeExceptionCount(tag)) {
- onNewException(tag, factor)
+ if (tag.exceptionExisted && judgeExceptionCount(tag)) {
+ onNewException(tag, factor, exceptionStatus)
}
} else {
config.factorFilter.selectedList.forEach { f ->
val tag1 = tagMap[f.main] ?: return@forEach
- if (tag1.existException && judgeExceptionCount(tag1)) {
- onNewException(tag1, f)
+ if (tag1.exceptionExisted && judgeExceptionCount(tag1)) {
+ onNewException(tag1, f, exceptionStatus)
}
}
}
}
/**
- * 鏂板涓�鏉″紓甯�
+ * 鏂板鎴栨洿鏂颁竴鏉″紓甯�
*/
- open fun onNewException(tag:Tag, factor: FactorFilter.SelectedFactor) {
- tag.startData?.let {
- resultList.add(newResult(it, lastData, factor, tag.exceptionData))
+ open fun onNewException(tag: T, factor: FactorFilter.SelectedFactor, exceptionStatus: ExceptionStatusType) {
+ if (tag.startData == null) return
+ val ex = newResult(tag.startData!!, tag.endData, factor, tag.exceptionData)
+ .apply { status = exceptionStatus.value }
+ // 寮傚父宸插垱寤烘椂锛屾洿鏂板紓甯镐俊鎭�
+ if (tag.exceptionCreated) {
+ // 灏嗘渶鏂扮殑寮傚父鐨刧uid璧嬪�肩粰ex
+ val lastEx = tag.exceptionResult.last()
+ ex.guid = lastEx.guid
+ tag.exceptionResult.removeLast()
+ tag.exceptionResult.add(ex)
}
- tag.existException = false
+ // 寮傚父鏈垱寤烘椂锛屾柊寤哄紓甯镐俊鎭�
+ else {
+ tag.exceptionResult.add(ex)
+// resultList.add(ex)
+ tag.exceptionCreated = true
+ }
}
-
- /**
- * 鐢熸垚涓�鏉″紓甯稿垎鏋愮粨鏋�
- */
- abstract fun newResult(
- start: BaseRealTimeData,
- end: BaseRealTimeData?,
- factor: FactorFilter.SelectedFactor,
- exceptionData: List<BaseRealTimeData>,
- ): Y
}
\ No newline at end of file
--
Gitblit v1.9.3