| | |
| | | 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 |
| | | import com.flightfeather.uav.common.utils.DateUtil |
| | | import com.flightfeather.uav.domain.entity.BaseRealTimeData |
| | | import com.flightfeather.uav.domain.entity.avg |
| | | import com.flightfeather.uav.socket.eunm.FactorType |
| | | import java.time.Duration |
| | | |
| | |
| | | * 生成一条异常分析结果 |
| | | */ |
| | | 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 avgData = exceptionData.avg() |
| | | // 求取污染数据的中心坐标 |
| | | longitude = avgData.longitude |
| | | latitude = avgData.latitude |
| | | // 求取主污染因子的均值和范围 |
| | | val s = dataSummary(exceptionData, factor.main) |
| | | avg = s.first |
| | | min = s.second |
| | | max = s.third |
| | |
| | | } |
| | | } |
| | | |
| | | fun dataSummary(exceptionData: List<BaseRealTimeData?>, factorIndex: Int): Triple<Float, Float, Float> { |
| | | private 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 |
| | | } |