feiyu02
2023-11-14 aa94ef4e1f060b184e6ea9fb37254b376a1eb60e
src/main/java/com/flightfeather/monitor/analysis/dust/risk/DustRiskMonthAnalysis.kt
@@ -1,6 +1,9 @@
package com.flightfeather.monitor.analysis.dust.risk
import com.flightfeather.monitor.domain.ds1.entity.*
import java.time.LocalDate
import java.time.ZoneId
import java.util.*
class DustRiskMonthAnalysis(val config: DustExceptionSetting) {
@@ -17,8 +20,12 @@
    /**
     * 每轮次的初始化
     */
    fun roundInit() {
        resultList.add(RiskValue())
    fun roundInit(mnCode: String, date: LocalDate) {
        resultList.add(RiskValue().apply {
            this.mnCode = mnCode
            lst = Date.from(date.withDayOfMonth(1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())
            type = "month"
        })
    }
    /**
@@ -34,7 +41,6 @@
        riskExceedRate(res, list)
        riskExceptionRepetitionRate(res, list)
        riskExceptionType(res, list)
        onDone(res)
    }
    fun riskOnlineRate(riskValue: RiskValue, list: List<RiskValue?>) {
@@ -57,16 +63,14 @@
        riskValue.exceptionTypeAggregation = avg(list) { it.exceptionTypeAggregation }
    }
    fun onDone(riskValue: RiskValue) {
        riskValue.type = "month"
    }
    private fun avg(list: List<RiskValue?>, onNext: (value: RiskValue) -> Double): Double {
    private fun avg(list: List<RiskValue?>, onNext: (value: RiskValue) -> Double?): Double {
        var total = .0
        var count = 0
        list.forEach {
            if (it == null) return@forEach
            total += onNext(it)
            val a = onNext(it) ?: return@forEach
            total += a
            count++
        }
        return if (count == 0) .0 else total / count