| | |
| | | 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) { |
| | | |
| | |
| | | /** |
| | | * 每轮次的初始化 |
| | | */ |
| | | 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" |
| | | }) |
| | | } |
| | | |
| | | /** |
| | |
| | | riskExceedRate(res, list) |
| | | riskExceptionRepetitionRate(res, list) |
| | | riskExceptionType(res, list) |
| | | onDone(res) |
| | | } |
| | | |
| | | fun riskOnlineRate(riskValue: RiskValue, list: List<RiskValue?>) { |
| | |
| | | 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 |