feiyu02
2023-11-14 aa94ef4e1f060b184e6ea9fb37254b376a1eb60e
src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskAnalysis.kt
@@ -2,6 +2,9 @@
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.*
/**
 * 扬尘监测数据风险分析基类
@@ -21,8 +24,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,7 +44,6 @@
        riskExceedRate(res, list)
        riskExceptionRepetitionRate(res, dList)
        riskExceptionType(res, dList)
        onDone(res)
    }
    /**
@@ -66,7 +72,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 +98,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 +106,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 +131,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
}