feiyu02
2024-06-27 e8f935a01d75c89ac591a80b9318eac2480e2dcd
src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionAnalysis.kt
@@ -1,5 +1,6 @@
package com.flightfeather.uav.biz.dataanalysis
import com.flightfeather.uav.biz.FactorFilter
import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionResult
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType
@@ -34,24 +35,26 @@
     * 生成一条异常分析结果
     */
    open fun newResult(
        start: BaseRealTimeData, end: BaseRealTimeData?, factorIndex: Int,
        start: BaseRealTimeData, end: BaseRealTimeData?, factor: FactorFilter.SelectedFactor,
        exceptionData: List<BaseRealTimeData>,
    ): ExceptionResult {
        val eType = getExceptionType()
        val factorType = FactorType.getByIndex(factorIndex)
        return ExceptionResult().apply {
            missionCode = config.mission.missionCode
            deviceCode = start.deviceCode
            exception = eType.des
            exceptionType = eType.value
            factorId = factorType?.value
            factorName = factorType?.des
            factorId = factor.main.value
            factorName = factor.main.des
            subFactorId = factor.subs.map { it.value }
            subFactorName = factor.subs.map { it.des }
            selectedFactor = factor
            startTime = DateUtil.instance.dateToString(start.dataTime, DateUtil.DateStyle.HH_MM_SS)
            endTime = DateUtil.instance.dateToString(end?.dataTime, DateUtil.DateStyle.HH_MM_SS) ?: startTime
            startData = start.getByFactorIndex(factorIndex)
            endData = end?.getByFactorIndex(factorIndex) ?: startData
            startData = start.getByFactorType(factor.main)
            endData = end?.getByFactorType(factor.main) ?: startData
            val s = dataSummary(exceptionData, factorIndex)
            val s = dataSummary(exceptionData, factor.main)
            avg = s.first
            min = s.second
            max = s.third
@@ -60,13 +63,13 @@
        }
    }
    fun dataSummary(exceptionData: List<BaseRealTimeData?>, factorIndex: Int): Triple<Float, Float, Float> {
    fun dataSummary(exceptionData: List<BaseRealTimeData?>, factorType: FactorType): Triple<Float, Float, Float> {
        var min = -1f
        var max = -1f
        var total = 0f
        var count = 0
        exceptionData.forEach {
            val value = it?.getByFactorIndex(factorIndex) ?: return@forEach
            val value = it?.getByFactorType(factorType) ?: return@forEach
            if (min == -1f || min > value) {
                min = value
            }