| | |
| | | package com.flightfeather.uav.biz.dataanalysis.model |
| | | |
| | | import com.flightfeather.uav.biz.FactorFilter |
| | | import com.flightfeather.uav.biz.dataanalysis.BaseExceptionResult |
| | | import com.flightfeather.uav.common.utils.DateUtil |
| | | import com.flightfeather.uav.domain.entity.BaseRealTimeData |
| | | import com.flightfeather.uav.domain.entity.SceneInfo |
| | | import com.flightfeather.uav.domain.entity.avg |
| | | import com.flightfeather.uav.lightshare.bean.DataVo |
| | | import com.flightfeather.uav.socket.eunm.FactorType |
| | | import java.math.BigDecimal |
| | | import java.util.* |
| | | |
| | | /** |
| | | * 异常结果 |
| | | */ |
| | | open class ExceptionResult { |
| | | open class ExceptionResult(): BaseExceptionResult() { |
| | | var missionCode: String? = null |
| | | var deviceCode: String? = null |
| | | var exception: String? = null |
| | | var exceptionType: Int? = null |
| | | var exceptionValue: Float? = null |
| | | var factorId: Int? = null |
| | | var factorName: String? = null |
| | | // var factorId: Int? = null |
| | | // var factorName: String? = null |
| | | var subFactorId: List<Int>? = null |
| | | var subFactorName: List<String>? = null |
| | | var selectedFactor: FactorFilter.SelectedFactor? = null |
| | |
| | | var relatedSceneId: List<String>? = null |
| | | // 相关企业名称(名称之间;分隔) |
| | | var relatedSceneName: List<String>? = null |
| | | // 异常数据,头尾可能包含一定量的偏移 |
| | | var relatedSceneList: List<SceneInfo?>? = null |
| | | // 异常数据 |
| | | var dataList: MutableList<BaseRealTimeData> = mutableListOf() |
| | | var dataVoList: List<DataVo>? = null |
| | | |
| | | constructor( |
| | | start: BaseRealTimeData, |
| | | end: BaseRealTimeData?, |
| | | factor: FactorFilter.SelectedFactor, |
| | | exceptionData: List<BaseRealTimeData>, |
| | | missionCode: String?, |
| | | eType: ExceptionType, |
| | | ) : this() { |
| | | this.missionCode = missionCode |
| | | deviceCode = start.deviceCode |
| | | exception = eType.des |
| | | exceptionType = eType.value |
| | | factorId = factor.main.value |
| | | factorName = factor.main.des |
| | | subFactorId = factor.subs.map { it.value } |
| | | subFactorName = factor.subs.map { it.des } |
| | | selectedFactor = factor |
| | | startDate = start.dataTime |
| | | endDate = end?.dataTime |
| | | 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.getByFactorType(factor.main) |
| | | endData = end?.getByFactorType(factor.main) ?: startData |
| | | |
| | | 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 |
| | | |
| | | exceptionData.forEach { dataList.add(it) } |
| | | } |
| | | |
| | | 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?.getByFactorType(factorType) ?: return@forEach |
| | | if (min == -1f || min > value) { |
| | | min = value |
| | | } |
| | | if (max == -1f || max < value) { |
| | | max = value |
| | | } |
| | | total += value |
| | | count++ |
| | | } |
| | | val avg = if (count == 0) 0f else total / count |
| | | return Triple(avg, min, max) |
| | | } |
| | | } |