src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseAnalysisConfig.kt
@@ -1,7 +1,6 @@ package com.flightfeather.uav.biz.dataanalysis import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.socket.eunm.FactorType /** * æ°æ®åæé ç½®åæ°åºç±» @@ -11,4 +10,7 @@ abstract class BaseAnalysisConfig( // å åçé val factorFilter: FactorFilter, ) ){ // æ°æ®å¼å¸¸åå¹¶æ¶ï¼å è®¸å»¶è¿æå¤§æ°æ®å¨æ var maxDelayPeriod: Int = 1 } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
@@ -2,10 +2,10 @@ import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag import com.flightfeather.uav.biz.sourcetrace.model.RemainException import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.lightshare.eunm.ExceptionStatusType import com.flightfeather.uav.socket.eunm.FactorType import org.springframework.beans.BeanUtils import java.time.Duration /** @@ -34,17 +34,20 @@ protected var lastData: BaseRealTimeData? = null // ææ°çä¸ç»å¼å¸¸ï¼è®°å½åå åå¼å¸¸ protected val latestExceptions = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>() val latestExceptions = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>() /** * ææ°çä¸ç»åå¹¶å¼å¸¸ï¼æ ¹æ®é ç½®åæ°ä»[latestExceptions]åå åå¼å¸¸ä¸ï¼åå¹¶å¼å¸¸ */ protected val latestCombinedExc = mutableListOf<List<Pair<FactorFilter.SelectedFactor, T>>>() // è®°å½éè¦å»¶è¿æ°æ®å¨æè¿è¡åå¹¶çå¼å¸¸ val remainingExceptions = mutableListOf<RemainException<T>>() /** * å¼å¸¸ç»æ */ protected val result = mutableListOf<Y>() val result = mutableListOf<Y>() /** * ä¸éç¨äºæ¤å¼å¸¸ç±»åççæµå å @@ -150,7 +153,10 @@ } lastData = data mergeExceptionResult() removeSingleFactor(data) checkDelayedExceptions(data) mergeExceptionResult(data) onNewResult(result) clearExceptions(data) } @@ -277,54 +283,163 @@ } /** * å°ä¸å¨å ³èå ³ç³»ä¸ççæµå åå¼å¸¸åå¨ï¼å¹¶åé¤ */ fun removeSingleFactor(data: BaseRealTimeData) { // æ¥æ¾ä¸å¨å åå ³èç»åä¸çå¼å¸¸å å val sfList = latestExceptions.filter { config.factorFilter.combination.find { c -> c.find { f -> f == it.first.main } != null } == null } // çæå¯¹åºçå¼å¸¸ç»æï¼å¹¶åå§å该å¼å¸¸ sfList.forEach { result.add(newResult(listOf(it))) it.second.refreshWithNextException(data) } // åé¤ latestExceptions.removeAll(sfList) } /** * æ£æ¥å»¶è¿çå¾ åå¹¶å¼å¸¸ä¸å½åå¼å¸¸æ¯å¦è½å¹é * 1. å°éççè¶ è¿çå¾ æ°æ®å¨æçå¼å¸¸åå¨ * 2. å°å¹é æåçåå¹¶å¼å¸¸åå¨ * 3. ä¿ç便§æªåå¹¶æåå¹¶ä¸å¯ç»§ç»çå¾ çå¼å¸¸ * @return 被å¹é æåçå ³èå ³ç³» */ fun checkDelayedExceptions(data: BaseRealTimeData): List<List<FactorType>> { // 被å¹é æåççæµå åå ³èå ³ç³» val fittedComb = mutableListOf<List<FactorType>>() // éççè¿å ¥ä¸ä¸ä¸ªæ°æ®å¨æå夿çå¾ åå¹¶å¼å¸¸éå val leftExc = mutableListOf<RemainException<T>>() // æåå¹é çåå¹¶å¼å¸¸éå val combinedExc = mutableListOf<List<Pair<FactorFilter.SelectedFactor, T>>>() // æ¬æ¬¡æ°æ®å¨æä¸ï¼è¢«å¹é æåçå¼å¸¸éå val exceps = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>() remainingExceptions.forEach { // æ£æ¥å½åæ°å¼å¸¸ä¸ï¼æ¯å¦å å«å åå ³èå ³ç³»ä¸çå¼å¸¸ val combRes = matchCombFactor(it.combination, latestExceptions) val res = combRes.second // å¤ææ¬æ¬¡æ°æ®å¨æä¸æ¾å°çå ååå·²æçå 忝妿»¡è¶³å ³èå ³ç³» val findFactors = mutableListOf<FactorType>() res.forEach {r -> findFactors.add(r.first.main) } it.exceptions.forEach {r -> findFactors.add(r.first.main) } // 夿æ¯å¦è¿æç¼ºå¤±å¼å¸¸ val isFitAll = findFactors.distinct() == it.combination // å¦æå·²ç»æ²¡æç¼ºå¤±çå¼å¸¸å åï¼åå¯å并为ç»åå¼å¸¸ if (isFitAll) { fittedComb.add(it.combination) // å°æ¥æ¾ç»ææ·»å è³å·²æå¼å¸¸éåä¸ it.addExceptions(res) // // è®°å½è¢«å¹é æåçå¼å¸¸ // res.forEach { r-> // if (exceps.find { e -> e.second == r.second } == null) { // exceps.add(r) // } // } // å°åå¹¶å¼å¸¸åå¨ combinedExc.add(it.exceptions) } // å¦åçä½ä¸æ¬¡æ°æ®å¨æåå¤å®åå ¥å¾ åå¹¶å¼å¸¸éå else { it.period++ // å½å¾ åå¹¶çå¼å¸¸çå¾ æ°æ®å¨æå¤§äºè®¾å®å¼æ¶ï¼ä¸åçå¾ ï¼ç´æ¥è¾åºå¼å¸¸ if (it.period > config.maxDelayPeriod) { result.add(newResult(it.exceptions)) return@forEach } else { fittedComb.add(it.combination) // å°æ¥æ¾ç»ææ·»å è³å·²æå¼å¸¸éåä¸ it.addExceptions(res) // // è®°å½è¢«å¹é æåçå¼å¸¸ // res.forEach { r-> // if (exceps.find { e -> e.second == r.second } == null) { // exceps.add(r) // } // } leftExc.add(it) } } } // åå¨åå¹¶å¼å¸¸ combinedExc.forEach { result.add(newResult(it)) } // // å°è¢«å¹é æåçå¼å¸¸å·æ°ï¼å¹¶ä»æ¬æ¬¡æ°æ®å¨æçå¼å¸¸éåä¸ç§»é¤ // exceps.forEach { r-> r.second.refreshWithNextException(data) } // latestExceptions.removeAll(exceps) // ä¿çæªå¹é çç»å remainingExceptions.clear() remainingExceptions.addAll(leftExc) return fittedComb } /** * åå¹¶å¼å¸¸ */ open fun mergeExceptionResult() { open fun mergeExceptionResult(data: BaseRealTimeData) { val combinedExc = mutableListOf<List<Pair<FactorFilter.SelectedFactor, T>>>() // éåææçå åç»å config.factorFilter.combination.forEach { c -> val res = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>() var exist = true // æ¥çç»åå çææå 忝å¦é½åæ¶åºç°å¼å¸¸ c.forEach { f -> val r = latestExceptions.find { e -> e.first.main == f } if (r != null) { res.add(r) } else { exist = false } } val combRes = matchCombFactor(c, latestExceptions) val res = combRes.second val exist = combRes.first // 妿ç»åå çææå åé½åå¨å¼å¸¸ï¼ååå¨ä¸ºåå¹¶å¼å¸¸ if (exist) { // å°åå¹¶å¼å¸¸ä»å个å¼å¸¸éåä¸å»é¤ res.forEach { r -> latestExceptions.removeIf { e -> e.first.main == r.first.main } } // å°åå¹¶å¼å¸¸åå¨ latestCombinedExc.add(res) combinedExc.add(res) } // å¦åå°å¼å¸¸çæ·±æ·è´çæ¬åå ¥å¾ åå¹¶å¼å¸¸éå // TODO 2025.8.4: åç»æ·»å å½å ³èççæµå å累计å¼å¸¸è®¡æ°æ¥è¿é弿¶ï¼æåå ¥éåçé»è¾ else { remainingExceptions.add(RemainException(res, c)) } } // åå¨å¼å¸¸ç»æ latestExceptions.forEach { result.add(newResult(listOf(it))) } latestCombinedExc.forEach { // åå¨åå¹¶å¼å¸¸ combinedExc.forEach { result.add(newResult(it)) } } /** * å¹é å ³èå¼å¸¸å å * @param comb å ³èå åå ³ç³» * @param exceptions åçæµå åå¼å¸¸éå * @return exist表示æ¯å¦æ¾å°å ³èå ³ç³»[comb]䏿æçå åï¼res表示æ¾å°çç»æ */ private fun matchCombFactor( comb: List<FactorType>, exceptions: List<Pair<FactorFilter.SelectedFactor, T>>, ): Pair<Boolean, MutableList<Pair<FactorFilter.SelectedFactor, T>>> { val res = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>() var exist = true // æ¥çç»åå çææå 忝å¦é½åæ¶åºç°å¼å¸¸ comb.forEach { f -> val r = exceptions.find { e -> e.first.main == f } if (r != null) { res.add(r) } else { exist = false } } return exist to res } abstract fun onNewResult(result: List<Y>) /** * å¨å¼å¸¸çæç»æåï¼è¿è¡åå§å */ private fun clearExceptions(data: BaseRealTimeData) { // æ¤æ¶latestExceptionsä¸åºè¯¥å å«ç便§æ¯æ¬æ¬¡æ°æ®å¨æå çææå¼å¸¸ latestExceptions.forEach { it.second.refreshWithNextException(data) } latestExceptions.clear() latestCombinedExc.forEach { it.forEach { e -> e.second.refreshWithNextException(data) } } latestCombinedExc.clear() result.clear() } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/exceptiontype/ExceptionDataExceed.kt
@@ -48,4 +48,8 @@ override fun newResult(exceptions: List<Pair<FactorFilter.SelectedFactor, ExceptionTag>>): ExceptionResult { return ExceptionResult() } override fun onNewResult(result: List<ExceptionResult>) { TODO("Not yet implemented") } } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/exceptiontype/ExceptionValueMutation.kt
@@ -1,6 +1,7 @@ package com.flightfeather.uav.biz.dataanalysis.exceptiontype import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig import com.flightfeather.uav.biz.dataanalysis.model.ExceptionResult import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType import com.flightfeather.uav.domain.entity.BaseRealTimeData @@ -53,4 +54,8 @@ // println("sIndex: $sIndex --- eIndex: $eIndex --- special: $special") return b1 || b2 } override fun onNewResult(result: List<ExceptionResult>) { TODO("Not yet implemented") } } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/ExceptionTag.kt
@@ -2,16 +2,20 @@ import com.flightfeather.uav.biz.dataanalysis.BaseExceptionResult import com.flightfeather.uav.domain.entity.BaseRealTimeData import org.apache.commons.lang3.SerializationUtils import org.springframework.beans.BeanUtils import java.io.Serializable /** * å¼å¸¸æ°æ®æ ç¾ * @date 2025/5/13 * @author feiyu02 */ open class ExceptionTag { open class ExceptionTag : Serializable { companion object { const val MAX_HISTORY = 10 } // èµ·å§æ°æ®ä¸æ var sIndex = 0 @@ -53,7 +57,7 @@ } } fun addExceptionData(data: BaseRealTimeData){ fun addExceptionData(data: BaseRealTimeData) { exceptionExisted = true exceptionData.add(data) } @@ -69,4 +73,22 @@ exceptionExisted = false exceptionCreated = false } fun clone(): ExceptionTag { val exceptionTag = SerializationUtils.clone(this) // val exceptionTag = ExceptionTag() // BeanUtils.copyProperties(this, exceptionTag) // exceptionTag.apply { // this.sIndex = this@ExceptionTag.sIndex // this.startData = this@ExceptionTag.startData // this.eIndex = this@ExceptionTag.eIndex // this.endData = this@ExceptionTag.endData // this.exceptionData = this@ExceptionTag.exceptionData // this.historyData = this@ExceptionTag.historyData // this.exceptionExisted = this@ExceptionTag.exceptionExisted // this.exceptionCreated = this@ExceptionTag.exceptionCreated // this.exceptionResult = this@ExceptionTag.exceptionResult // } return exceptionTag } } src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/config/RTExcWindLevelConfig.kt
@@ -21,12 +21,15 @@ } // æ¯å¦èç½æ¥æ¾å¯¹åºè·¯æ®µå°åä¿¡æ¯ var isSearchAddress = true // éå®è·ç¦»å ï¼åä½ï¼ç±³ï¼ var distanceLimit = 3000 // é宿¶é´å ï¼åä½ï¼åéï¼ var timeLimit = 3 // æº¯æºæ©æ£åç§»è§åº¦ï¼åä½ï¼åº¦ï¼ var sourceTraceDegOffset = 120.0 // 宿¶çº¿ç´¢åææ¶é´é´é(åä½ï¼åé) var analysisPeriod = 5 // 宿¶åæé´éä¸ï¼ç«å³è¿è¡çº¿ç´¢åæçæå°çº¿ç´¢é(åä½ï¼ä¸ª) src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcChangeRate.kt
@@ -122,30 +122,20 @@ PollutedClue(exceptions, getExceptionType(), config, changeRate[exceptions[0].first.main]) } override fun onNewException( tag: ExceptionTag, factor: FactorFilter.SelectedFactor, exceptionStatus: ExceptionStatusType, ) { super.onNewException(tag, factor, exceptionStatus) // override fun mergeExceptionResult() { // super.mergeExceptionResult() // callback?.let { func -> // val exc = tag.exceptionResult.last() // func.invoke(exc as PollutedClue) // result.forEach { // func.invoke(it) // } // } } // } override fun mergeExceptionResult() { super.mergeExceptionResult() override fun onNewResult(result: List<PollutedClue>) { callback?.let { func -> result.forEach { func.invoke(it) } // latestExceptions.forEach { // func.invoke(listOf(it as PollutedClue)) // } // latestCombinedExc.forEach { // func.invoke(it as List<PollutedClue>) // } } } } src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcWindLevel.kt
@@ -139,30 +139,21 @@ // return PollutedClue(start, end, factor, exceptionData, getExceptionType(), config, windLevelCondition) // } override fun onNewException( tag: ExceptionTag, factor: FactorFilter.SelectedFactor, exceptionStatus: ExceptionStatusType, ) { super.onNewException(tag, factor, exceptionStatus) // callback?.let { func -> // val exc = tag.exceptionResult.last() // func.invoke(exc as PollutedClue) // } } override fun mergeExceptionResult() { super.mergeExceptionResult() // override fun mergeExceptionResult() { // super.mergeExceptionResult() // callback?.let { func -> // result.forEach { // func.invoke(it) // } // } // } override fun onNewResult(result: List<PollutedClue>) { callback?.let { func -> result.forEach { func.invoke(it) } // latestExceptions.forEach { // func.invoke(listOf(it as PollutedClue)) // } // latestCombinedExc.forEach { // func.invoke(it as List<PollutedClue>) // } } } } src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/RealTimeExceptionValueMutation.kt
@@ -3,6 +3,7 @@ import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType import com.flightfeather.uav.biz.sourcetrace.RealTimeAnalysisConfig import com.flightfeather.uav.biz.sourcetrace.model.RealTimeExceptionResult import com.flightfeather.uav.common.utils.MapUtil import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.socket.eunm.FactorType @@ -90,4 +91,8 @@ return b1 || b2 } override fun onNewResult(result: List<RealTimeExceptionResult>) { TODO("Not yet implemented") } } src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt
@@ -63,7 +63,7 @@ val pair = avgData.longitude!!.toDouble() to avgData.latitude!!.toDouble() polygon = calSector( avgData.windDirection!!.toDouble(), avgData.windDirection?.toDouble() ?: .0, pair, windLevelCondition.distanceType.disRange, config.sourceTraceDegOffset src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedClue.kt
@@ -45,6 +45,7 @@ var exceptionData = mutableListOf<BaseRealTimeData>() var historyData = mutableListOf<BaseRealTimeData>() exceptions.forEach { e -> // å°éæ ·æ¶é´ææ©çä½ä¸ºå¼å§æ°æ® if (startData == null) { startData = e.second.startData } else { @@ -53,6 +54,7 @@ } } // å°éæ ·æ¶é´ææçä½ä¸ºç»ææ°æ® if (endData == null) { endData = e.second.endData } else { @@ -61,6 +63,7 @@ } } // å°ææå¼å¸¸æ°æ®å»éåå¹¶ if (exceptionData.isEmpty()) { exceptionData = e.second.exceptionData } else { @@ -71,6 +74,7 @@ } } // å°ææå岿°æ®å»éåå¹¶ if (historyData.isEmpty()) { historyData = e.second.historyData } else { @@ -81,10 +85,12 @@ } } } // æç §éæ ·æ¶é´ååºæå exceptionData.sortBy { it.dataTime } historyData.sortBy { it.dataTime } val factorList = exceptions.map { it.first } // è·åå»éåççæµå åç±»å val factorList = exceptions.map { it.first }.distinct() pollutedData = PollutedData( startData!!, endData, factorList, exceptionData, historyData, eType, windLevelCondition ) src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedData.kt
@@ -127,8 +127,8 @@ var total = .0 for (i in 0 until list.size - 1) { val p = list[i].getByFactorType(factorType)!! val n = list[i + 1].getByFactorType(factorType)!! val p = list[i].getByFactorType(factorType) ?: .0f val n = list[i + 1].getByFactorType(factorType) ?: .0f total += (n - p) / p } return total / (list.size - 1) @@ -140,8 +140,8 @@ var total = .0 for (i in 0 until list.size - 1) { val p = list[i].getByFactorType(factorType)!! val n = list[i + 1].getByFactorType(factorType)!! val p = list[i].getByFactorType(factorType) ?: .0f val n = list[i + 1].getByFactorType(factorType) ?: .0f total += (n - p) / 4 } return total / (list.size - 1) src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/RemainException.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,62 @@ package com.flightfeather.uav.biz.sourcetrace.model import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag import com.flightfeather.uav.socket.eunm.FactorType /** * å¾ åå¹¶å¼å¸¸ * å¼å¸¸åºç°åï¼è¥ç¸å ³çå ¶ä»å å累计å¼å¸¸æ¬¡æ°æ¥è¿éå¼ï¼å该å¼å¸¸å¯ä»¥çå¾ è¥å¹²ä¸ªæ°æ®å¨æåååå¹¶ã * @date 2025/8/1 * @author feiyu02 */ class RemainException<T : ExceptionTag>( exceptions: List<Pair<FactorFilter.SelectedFactor, T>>, combination: List<FactorType>, ) { // å·²æçå¼å¸¸ var exceptions = mutableListOf<Pair<FactorFilter.SelectedFactor, T>>() // éè¦å»¶è¿æ£æµçå åå ³èå ³ç³» val combination = mutableListOf<FactorType>() // 缺失ççæµå å val lackFactors = mutableListOf<FactorType>() // å·²ç»è¿çæ°æ®å¨æ var period: Int = 1 init { // åå¨çæµå åå¼å¸¸å¯¹è±¡çå éçæ¬ï¼ this.exceptions.addAll(exceptions.map { it.first to (it.second.clone() as T) }) this.combination.addAll(combination) calLackFactors() } /** * æ·»å æ°çå¼å¸¸éå */ fun addExceptions(exceptions: List<Pair<FactorFilter.SelectedFactor, T>>) { // åå¨çæµå åå¼å¸¸å¯¹è±¡çå éçæ¬ï¼ this.exceptions.addAll(exceptions.map { it.first to (it.second.clone() as T) }) calLackFactors() } /** * 计ç®ç¼ºå¤±ççæµå å */ private fun calLackFactors() { lackFactors.clear() combination.forEach { c -> val e = exceptions.find { it.first.main == c } if (e == null) { lackFactors.add(c) } } } } src/main/kotlin/com/flightfeather/uav/common/exception/BizException.kt
@@ -6,8 +6,8 @@ class BizException : Exception { constructor():super() constructor(message: String) : super(message) constructor(message: String, cause: Throwable) : super(message, cause) constructor(cause: Throwable) : super(cause) constructor(message: String, cause: Throwable, enableSuppression: Boolean, writableStackTrace: Boolean) constructor(message: String, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) constructor(message: String, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super(message, cause, enableSuppression, writableStackTrace) } src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
@@ -105,7 +105,7 @@ a["streetNumber"].asJsonObject["street"].asString, ) } catch (e: Exception) { throw BizException("é«å¾·APIåæ è½¬æ¢é误ï¼${e.message}") throw BizException("é«å¾·APIåæ è½¬æ¢é误ï¼${e.message}", e.cause) } } src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt
@@ -5,6 +5,7 @@ import com.flightfeather.uav.lightshare.bean.DataVo import com.flightfeather.uav.socket.bean.AirData import com.flightfeather.uav.socket.eunm.FactorType import java.io.Serializable import java.math.BigDecimal import java.time.LocalDateTime import java.time.ZoneId @@ -21,7 +22,7 @@ /** * 宿¶çæµæ°æ®åºç±» */ open class BaseRealTimeData { open class BaseRealTimeData : Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Int? = null @@ -277,7 +278,9 @@ } return RealTimeDataGridMin().apply { val time = LocalDateTime.ofInstant(get(0).dataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) val time = LocalDateTime .ofInstant(get(0).dataTime?.toInstant() ?: Date().toInstant(), ZoneId.systemDefault()) .withSecond(0) deviceCode = get(0).deviceCode dataTime = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()) createTime = dataTime src/test/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuousTest.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,156 @@ package com.flightfeather.uav.biz.dataanalysis import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType import com.flightfeather.uav.biz.sourcetrace.config.RTExcWindLevelConfig import com.flightfeather.uav.biz.sourcetrace.exceptiontype.* import com.flightfeather.uav.biz.sourcetrace.model.PollutedClue import com.flightfeather.uav.biz.sourcetrace.model.RemainException import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.socket.eunm.FactorType import org.junit.Test import kotlin.test.assertContentEquals class BaseExceptionContinuousTest { private val exceptionTag = ExceptionTag().apply { sIndex = 1 startData = BaseRealTimeData().apply { id = 1 } eIndex = 5 endData = BaseRealTimeData().apply { id = 4 } exceptionData = mutableListOf( startData!!, BaseRealTimeData().apply { id = 2 }, BaseRealTimeData().apply { id = 3 }, endData!! ) historyData = mutableListOf() exceptionExisted = true exceptionCreated = false // exceptionResult = } private val combination = listOf( listOf(FactorType.PM25, FactorType.PM10), listOf(FactorType.VOC, FactorType.CO), listOf(FactorType.VOC, FactorType.PM25), listOf(FactorType.VOC, FactorType.PM25, FactorType.CO), ) private val config = RTExcWindLevelConfig( FactorFilter.builder() .withMain(FactorType.NO2) .withMain(FactorType.CO) // .withMain(FactorType.H2S) // .withMain(FactorType.SO2) .withMain(FactorType.O3) .withMain(FactorType.PM25) .withMain(FactorType.PM10) .withMain(FactorType.VOC) .withCombination(combination) .create() ).apply { isSearchAddress = false } private fun taskList() = mutableListOf( RTExcWindLevel1(config).also { it.init() }, // RTExcWindLevel1_1(config).also { it.init() }, // RTExcWindLevel4(config).also { it.init() }, // RTExcWindLevel6(config).also { it.init() }, RTExcChangeRate1(config).also { it.init() }, // RTExcChangeRate4(config).also { it.init() }, // RTExcChangeRate6(config).also { it.init() }, // RTWarnChangeRate(config).also { it.init() }, // RTWarnChangeRate2(config).also { it.init() } ) // ææ°çä¸ç»å¼å¸¸ï¼è®°å½åå åå¼å¸¸ private fun exceptions() = mutableListOf( FactorFilter.SelectedFactor(FactorType.NO2) to exceptionTag.clone(), FactorFilter.SelectedFactor(FactorType.CO) to exceptionTag.clone(), FactorFilter.SelectedFactor(FactorType.O3) to exceptionTag.clone(), FactorFilter.SelectedFactor(FactorType.PM25) to exceptionTag.clone(), FactorFilter.SelectedFactor(FactorType.PM10) to exceptionTag.clone(), FactorFilter.SelectedFactor(FactorType.VOC) to exceptionTag.clone(), ) @Test fun removeSingleFactor() { taskList().forEach { exc -> exc.latestExceptions.clear() exc.latestExceptions.addAll(exceptions()) exc.removeSingleFactor(BaseRealTimeData()) val resList = exc.result.map { it.pollutedData?.statisticMap?.entries?.map { e -> e.key } } assertContentEquals( listOf(listOf(FactorType.NO2), listOf(FactorType.O3)), resList, "å¼å¸¸ç»æåºè¯¥é½æ¯ä¸å¨ç»åä¸çå¼å¸¸" ) val resList2 = exc.latestExceptions.map { it.first.main } assertContentEquals( listOf(FactorType.CO, FactorType.PM25, FactorType.PM10, FactorType.VOC), resList2, "å©ä½çåºè¯¥æ¯ä¸å¨ç»åä¸çå¼å¸¸" ) } } @Test fun checkDelayedExceptions() { taskList().forEach { exc -> val e = exceptions() exc.remainingExceptions.add(RemainException(listOf(e[3], e[5]), listOf(FactorType.VOC, FactorType.PM25, FactorType.CO))) exc.remainingExceptions.add(RemainException(listOf(e[1]), listOf(FactorType.VOC, FactorType.CO))) exc.remainingExceptions.add(RemainException(listOf(e[3]), listOf(FactorType.PM10, FactorType.PM25))) exc.latestExceptions.clear() exc.latestExceptions.addAll(exceptions()) exc.removeSingleFactor(BaseRealTimeData()) val resList = exc.result.map { it.pollutedData?.statisticMap?.entries?.map { e -> e.key } } assertContentEquals( listOf(listOf(FactorType.NO2), listOf(FactorType.O3)), resList, "å¼å¸¸ç»æåºè¯¥é½æ¯ä¸å¨ç»åä¸çå¼å¸¸" ) val resList2 = exc.latestExceptions.map { it.first.main } assertContentEquals( listOf(FactorType.CO, FactorType.PM25, FactorType.PM10, FactorType.VOC), resList2, "å©ä½çåºè¯¥æ¯ä¸å¨ç»åä¸çå¼å¸¸" ) } } @Test fun mergeExceptionResult() { val factorList = listOf( FactorFilter.SelectedFactor(FactorType.PM10), FactorFilter.SelectedFactor(FactorType.PM25), FactorFilter.SelectedFactor(FactorType.CO), ) val factorList2 = listOf( FactorFilter.SelectedFactor(FactorType.CO), FactorFilter.SelectedFactor(FactorType.PM25), FactorFilter.SelectedFactor(FactorType.PM10), ) println(factorList == factorList2) } @Test fun clearExceptions() { } }