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/risk/DustRiskAnalysis.kt | 39 +++++++++++++++++++++------------------ 1 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskAnalysis.kt b/src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskAnalysis.kt index df364e2..cd8748a 100644 --- a/src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskAnalysis.kt +++ b/src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskAnalysis.kt @@ -2,6 +2,10 @@ import com.flightfeather.monitor.domain.ds1.entity.* import com.flightfeather.monitor.enumration.dust.ExceptionType +import java.time.LocalDate +import java.time.ZoneId +import java.util.* +import kotlin.math.round /** * 鎵皹鐩戞祴鏁版嵁椋庨櫓鍒嗘瀽鍩虹被 @@ -21,8 +25,12 @@ /** * 姣忚疆娆$殑鍒濆鍖� */ - fun roundInit() { - resultList.add(RiskValue()) + fun roundInit(mnCode: String, date: LocalDate) { + resultList.add(RiskValue().apply { + this.mnCode = mnCode + lst = Date.from(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()) + type = "day" + }) } /** @@ -37,23 +45,22 @@ riskExceedRate(res, list) riskExceptionRepetitionRate(res, dList) riskExceptionType(res, dList) - onDone(res) } /** * 鍦ㄧ嚎鐜囬闄╁�� */ fun riskOnlineRate(riskValue: RiskValue, data: DustStatisticsValue) { - val dayOnline = data.dayOnline.substring(0, data.dayOnline.lastIndex).toDouble() / 100 - riskValue.onlineRisk = 1 - dayOnline + val dayOnline = data.dayOnline + riskValue.onlineRisk = round((1 - dayOnline) * 10000) / 10000 } /** * 鏈夋晥鐜囬闄╁�� */ fun riskValidRate(riskValue: RiskValue, data: DustStatisticsValue) { - val dayValid = data.dayValid.substring(0, data.dayValid.lastIndex).toDouble() / 100 - riskValue.validRisk = 1 - dayValid + val dayValid = data.dayValid + riskValue.validRisk = round((1 - dayValid) * 10000) / 10000 } /** @@ -66,7 +73,7 @@ var v2 = 0 // 鏃ヤ复杩戣秴鏍囨鏁�/7 var v3 = 0 - list.forEach {d -> + list.forEach { d -> if (d == null) return@forEach when { d.dustValue >= 2.0 -> v2++ @@ -92,7 +99,7 @@ var v1 = 0 var v2 = 0 var v3 = 0 - list.forEach { d-> + list.forEach { d -> if (d == null) return@forEach when (d.exceptionType) { ExceptionType.TYPE4.value -> v1++ @@ -100,10 +107,10 @@ ExceptionType.TYPE6.value -> v3++ } } - val e1 = upperLimit((v1 - 1) / 4.0) - val e2 = upperLimit((v2 - 1) / 3.0) - val e3 = upperLimit((v3 - 1) / 2.0) - riskValue.typicalExceptionRepetitionRate = upperLimit(e1 + e2 + e3) + val e1 = settingRange((v1 - 1) / 4.0) + val e2 = settingRange((v2 - 1) / 3.0) + val e3 = settingRange((v3 - 1) / 2.0) + riskValue.typicalExceptionRepetitionRate = settingRange(e1 + e2 + e3) } /** @@ -125,9 +132,5 @@ riskValue.exceptionTypeAggregation = exceptionTypes.size / 6.0 } - fun onDone(riskValue: RiskValue) { - riskValue.type = "day" - } - - private fun upperLimit(d:Double):Double = if (d > 1) 1.0 else d + private fun settingRange(d: Double): Double = if (d > 1) 1.0 else if (d < 0) .0 else d } \ No newline at end of file -- Gitblit v1.9.3