From c6842e8498c2d9b469890b38cd9f0d714392c445 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期五, 01 十二月 2023 13:22:02 +0800 Subject: [PATCH] 1. 修改优化日统计和风险统计的逻辑 --- src/main/java/com/flightfeather/monitor/analysis/dust/exception/ExceptionSlideAverage.kt | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/flightfeather/monitor/analysis/dust/exception/ExceptionSlideAverage.kt b/src/main/java/com/flightfeather/monitor/analysis/dust/exception/ExceptionSlideAverage.kt index fa5ff5a..fe7f1f9 100644 --- a/src/main/java/com/flightfeather/monitor/analysis/dust/exception/ExceptionSlideAverage.kt +++ b/src/main/java/com/flightfeather/monitor/analysis/dust/exception/ExceptionSlideAverage.kt @@ -2,6 +2,7 @@ import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting import com.flightfeather.monitor.domain.ds1.entity.DustSiteData +import com.flightfeather.monitor.enumration.dust.DataStatus import com.flightfeather.monitor.enumration.dust.ExceptionType import kotlin.math.abs @@ -12,7 +13,7 @@ private val historyDataList = mutableListOf<DustSiteData>() private val tempDataList = mutableListOf<DustSiteData>() - private val avgListReverse = mutableListOf<Double>() + private val avgListReverse = mutableListOf<Pair<Double, Boolean>>() private var startData: DustSiteData? = null private var lastData: DustSiteData? = null private var sIndex = 0 @@ -67,11 +68,17 @@ */ private fun calAvg(list: List<DustSiteData>) { var total = .0 + var valid = true val count = list.size if (count == 0) return - list.forEach { total += it.dustValue } + list.forEach { + total += it.dustValue + if (it.flag != DataStatus.N.value) { + valid = false + } + } val avg = total / count - avgListReverse.add(0, avg) + avgListReverse.add(0, Pair(avg, valid)) } /** @@ -84,14 +91,14 @@ return false } else { // 婊戝姩鍧囧�兼弧瓒虫暟閲忔椂锛岃绠楀潎鍊间箣闂存槸鍚﹁繛缁秴杩囬檺瀹氭瘮鐜� - val rateList = mutableListOf<Double>() + val rateList = mutableListOf<Pair<Double, Boolean>>() for (i in avgListReverse.indices) { if (i >= config.changeTrendTimes) break val r = calAvgChangeRate(avgListReverse[i], avgListReverse[i + config.changeTrendInterval]) rateList.add(r) } for (y in rateList) { - if (y < config.changeTrendRate) { + if (!y.second || y.first < config.changeTrendRate) { return false } } @@ -102,11 +109,12 @@ /** * 璁$畻婊戝姩鍧囧�煎彉鍖栫巼 */ - private fun calAvgChangeRate(a1: Double, a2: Double): Double { - return if (a2 == .0) { - 1.0 + private fun calAvgChangeRate(a1: Pair<Double, Boolean>, a2: Pair<Double, Boolean>): Pair<Double, Boolean> { + val valid = a1.second && a2.second + return if (a2.first == .0) { + Pair(1.0, valid) } else { - abs(a1 - a2) / a2 + Pair(abs(a1.first - a2.first) / a2.first, valid) } } -- Gitblit v1.9.3