feiyu02
2025-03-27 bde043c8fd1a076f44c402dd56c62d401afbfb16
src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
@@ -2,6 +2,10 @@
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.*
import com.flightfeather.uav.model.underwaygrid.GridCellAndData
import com.flightfeather.uav.model.underwaygrid.GridCellSop
import com.flightfeather.uav.model.underwaygrid.UnderwayGridModel
import com.flightfeather.uav.socket.eunm.FactorType
import org.springframework.beans.BeanUtils
import kotlin.math.PI
import kotlin.math.sqrt
@@ -258,20 +262,6 @@
                dataId = gridData?.id
                groupId = k.groupId
                cellId = k.cellIndex
//                no2 = avgData.no2
//                co = avgData.co
//                h2s = avgData.h2s
//                so2 = avgData.so2
//                o3 = avgData.o3
//                pm25 = avgData.pm25
//                pm10 = avgData.pm10
//                temperature = avgData.temperature
//                humidity = avgData.humidity
//                voc = avgData.voc
//                noi = avgData.noi
//                no = avgData.no
//                windSpeed
//                windDirection
                rank
            }
            gridDataDetailList.add(dataDetail)
@@ -286,6 +276,58 @@
        return gridDataDetailList
    }
    /**
     * 计算热力图网格,即网格周边扩散影响权重计算
     * @param gridDataDetail 网格监测数据
     * @param gridCellList 区域网格数组
     * @param option 区域网格参数信息
     * @param searchLength 计算周边八方向(上下左右及四个对角)网格的长度
     * @return 周边网格及对应的监测数据结果
     */
    fun heatMap(
        gridDataDetail: GridDataDetail, gridCellList: List<GridCell?>,
        option: GridGroupOption, searchLength: Int,
    ): List<GridDataDetail> {
        // 找到网格数据对应的网格信息
        val gridCell = gridCellList.find { it?.cellIndex == gridDataDetail.cellId }
            ?: throw IllegalArgumentException("网格数据和给定的区域网格不匹配")
        // 获取周边网格
        val surroundGridCellList =
            SatelliteGridUtil.searchDiffuseGrid(gridDataDetail.cellId, gridCellList, option, searchLength)
        // 使用走航网格权重模型,计算周边网格的监测数据值
        val underwayGridModel = UnderwayGridModel()
        val dataList = listOf(GridCellAndData(gridCell, gridDataDetail))
        val gridCellSopList = surroundGridCellList.map {
            GridCellSop(
                it,
                it.id.toString(),
                it.cellIndex.toString(),
                it.cellIndex.toString()
            ) }
        underwayGridModel.execute(dataList, gridCellSopList)
        val resMap = underwayGridModel.outputResult()
        // 格式化结果并返回
        val result = mutableListOf<GridDataDetail>()
        gridCellSopList.forEach {
            val resGridDataDetail = GridDataDetail().apply {
                dataId = gridDataDetail.dataId
                groupId = gridDataDetail.groupId
                cellId = it.gridCell.cellIndex
            }
            val key = "${it.sourceName};${it.index}"
            val d = resMap[key]
            d?.forEach { (t, u) ->
                val avg = u["综合(${t})"]?.average ?: .0
                resGridDataDetail.setFactorValue(FactorType.getByName(t), avg.toFloat())
            }
            result.add(resGridDataDetail)
        }
        return result
    }
}