From e5bdf2e02090357cbd580d54e6cd2406dd541760 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期五, 21 三月 2025 17:39:30 +0800 Subject: [PATCH] 1. 新增卫星遥测网格热力图计算逻辑(待完成) --- src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt | 5 src/main/kotlin/com/flightfeather/uav/model/underwaygrid/UnderwayGridModel.kt | 31 ++ src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt | 52 ++-- src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridCellAndData.kt | 40 +++ src/main/kotlin/com/flightfeather/uav/biz/satellite/GridGroupOption.kt | 17 + src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt | 16 src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridUtil.kt | 78 ++++++ src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt | 3 src/main/kotlin/com/flightfeather/uav/domain/entity/GridDataDetail.java | 233 ++++++++++++++++++ src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridCellSop.kt | 23 + src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt | 1 src/main/kotlin/com/flightfeather/uav/lightshare/service/SatelliteDataCalculateService.kt | 7 src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImplTest.kt | 12 src/main/resources/generator/generatorConfig.xml | 4 src/test/kotlin/com/flightfeather/uav/Test.kt | 40 ++- src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt | 2 src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt | 17 src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridWindDisWeight.kt | 38 +++ src/main/kotlin/com/flightfeather/uav/model/underwaygrid/UnderwayGridDataPrep.kt | 18 + src/main/kotlin/com/flightfeather/uav/lightshare/web/SatelliteTelemetryController.kt | 7 src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt | 2 src/main/resources/mapper/GridDataDetailMapper.xml | 18 + src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridWindDirWeight.kt | 40 +++ 23 files changed, 631 insertions(+), 73 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/biz/satellite/GridGroupOption.kt b/src/main/kotlin/com/flightfeather/uav/biz/satellite/GridGroupOption.kt new file mode 100644 index 0000000..83a26c8 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/biz/satellite/GridGroupOption.kt @@ -0,0 +1,17 @@ +package com.flightfeather.uav.biz.satellite + +/** + * 鍗槦缃戞牸缁勭殑鍙傛暟锛屼竴涓崼鏄熺綉鏍肩粍搴旇涓虹煩褰㈠舰寮� + * @date 2025/3/21 + * @author feiyu02 + */ +class GridGroupOption( + // 缃戞牸瀹藉害锛屾寚涓滆タ鏂瑰悜涓婄殑缃戞牸鏁伴噺 + val width: Int, + // 缃戞牸楂樺害锛屾寚鍗楀寳鏂瑰悜涓婄殑缃戞牸鏁伴噺 + val height: Int, + // 缁嗗垎缃戞牸瀹藉害锛屽鏋滅綉鏍肩粍鏄粏鍒嗙綉鏍硷紝鍒欒〃绀哄搴斿師濮嬬綉鏍间腑鍗曚釜缃戞牸涓嬬粏鍒嗙殑缃戞牸鏁伴噺 + val eachWith: Int, + // 缁嗗垎缃戞牸楂樺害锛屽鏋滅綉鏍肩粍鏄粏鍒嗙綉鏍硷紝鍒欒〃绀哄搴斿師濮嬬綉鏍间腑鍗曚釜缃戞牸涓嬬粏鍒嗙殑缃戞牸鏁伴噺 + val eachHeight: Int, +) \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt index bea89eb..bd61d61 100644 --- a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt +++ b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt @@ -2,6 +2,7 @@ import com.flightfeather.uav.common.utils.MapUtil import com.flightfeather.uav.domain.entity.* +import org.springframework.beans.BeanUtils import kotlin.math.PI import kotlin.math.sqrt @@ -237,12 +238,13 @@ realTimeDataList.forEach { if (it.longitude == null || it.latitude == null) return@forEach - searchGirdIn(it.longitude!!.toDouble() to it.latitude!!.toDouble(), gridCellList)?.let { cell -> - if (!dataMap.containsKey(cell)) { - dataMap[cell] = mutableListOf() + SatelliteGridUtil.searchGirdIn(it.longitude!!.toDouble() to it.latitude!!.toDouble(), gridCellList) + ?.let { cell -> + if (!dataMap.containsKey(cell)) { + dataMap[cell] = mutableListOf() + } + dataMap[cell]?.add(it) } - dataMap[cell]?.add(it) - } } // 缁熻姣忎釜缃戞牸涓殑鍧囧�� @@ -250,11 +252,26 @@ val gridDataDetailList = mutableListOf<GridDataDetail>() dataMap.forEach { (k, v) -> val avgData = v.avg() - val dataDetail = GridDataDetail().apply { + val dataDetail = GridDataDetail() + BeanUtils.copyProperties(avgData, dataDetail) + dataDetail.apply { dataId = gridData?.id groupId = k.groupId cellId = k.cellIndex - pm25 = avgData.pm25 +// 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) @@ -269,27 +286,6 @@ return gridDataDetailList } - /** - * 璁$畻鍧愭爣鐐瑰湪鍝釜鍗槦缃戞牸鍐� - * @date 2025.2.14 - * @param point 鍧愭爣鐐� - * @param gridCellList 鍗槦缃戞牸 - */ - fun searchGirdIn(point: Pair<Double, Double>, gridCellList: List<GridCell?>): GridCell? { - for (i in gridCellList.indices) { - val gridCell = gridCellList[i] ?: continue - val polygon = listOf( - gridCell.point1Lon.toDouble() to gridCell.point1Lat.toDouble(), - gridCell.point2Lon.toDouble() to gridCell.point2Lat.toDouble(), - gridCell.point3Lon.toDouble() to gridCell.point3Lat.toDouble(), - gridCell.point4Lon.toDouble() to gridCell.point4Lat.toDouble(), - ) - if (MapUtil.isPointInPolygon(point, polygon)) { - return gridCell - } - } - return null - } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridUtil.kt b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridUtil.kt new file mode 100644 index 0000000..6010859 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridUtil.kt @@ -0,0 +1,78 @@ +package com.flightfeather.uav.biz.satellite + +import com.flightfeather.uav.common.utils.MapUtil +import com.flightfeather.uav.domain.entity.GridCell +import kotlin.math.ceil + +/** + * 鍗槦缃戞牸璁$畻宸ュ叿 + */ +object SatelliteGridUtil { + + /** + * 璁$畻鍧愭爣鐐瑰湪鍝釜鍗槦缃戞牸鍐� + * @date 2025.2.14 + * @param point 鍧愭爣鐐� + * @param gridCellList 鍗槦缃戞牸 + */ + fun searchGirdIn(point: Pair<Double, Double>, gridCellList: List<GridCell?>): GridCell? { + for (i in gridCellList.indices) { + val gridCell = gridCellList[i] ?: continue + val polygon = listOf( + gridCell.point1Lon.toDouble() to gridCell.point1Lat.toDouble(), + gridCell.point2Lon.toDouble() to gridCell.point2Lat.toDouble(), + gridCell.point3Lon.toDouble() to gridCell.point3Lat.toDouble(), + gridCell.point4Lon.toDouble() to gridCell.point4Lat.toDouble(), + ) + if (MapUtil.isPointInPolygon(point, polygon)) { + return gridCell + } + } + + return null + } + + /** + * 璁$畻鎵╂暎缃戞牸锛屾牴鎹粰瀹氱綉鏍硷紝璁$畻鍦ㄥ叾鍛ㄥ洿鍥哄畾鍗婂緞涓嬬殑鎵�鏈夌綉鏍� + * 缃戞牸鐨勫舰寮忎负鍘熷鍗槦閬ユ祴缃戞牸浠ュ強缁嗗垎缃戞牸 + * 鍘熷鍗槦閬ユ祴缃戞牸鐨勭紪鍙烽『搴忎负浠庡乏鍒板彸锛屼粠涓婂埌涓嬬紪鍙蜂緷娆¢�掑 + * 缁嗗垎缃戞牸鍦ㄥ師濮嬪崼鏄熼仴娴嬬綉鏍肩殑鍩虹涓婏紝姣忎釜缃戞牸鍐呴儴鎸変粠宸﹀埌鍙筹紝浠庝笂鍒颁笅缂栧彿渚濇閫掑 + * @param gridCellIndex 涓績鐐圭綉鏍肩储寮曞�� + * @param gridCellList 鎵�鏈夌綉鏍兼暟缁� + * @param option 缃戞牸缁勭殑鍙傛暟淇℃伅 + * @param searchLength 鎵╂暎鐨勭綉鏍煎崐寰勬暟閲� + * @return 璁$畻寰楀嚭鐨勬墿鏁g綉鏍煎璞℃暟缁� + */ + fun searchDiffuseGrid( + gridCellIndex: Int, + gridCellList: List<GridCell?>, + option: GridGroupOption, + searchLength: Int, + ): List<GridCell> { + return emptyList() + } + + /** + * 鏍规嵁缃戞牸绱㈠紩锛岃幏鍙栧叾鎵�鍦ㄤ笢瑗挎柟鍚戠殑缃戞牸绱㈠紩鑼冨洿 + * @param cellIndex 缃戞牸绱㈠紩 + * @param width 缃戞牸瀹藉害锛屾寚涓滆タ鏂瑰悜涓婄殑缃戞牸鏁伴噺 + * @param height 缃戞牸楂樺害锛屾寚鍗楀寳鏂瑰悜涓婄殑缃戞牸鏁伴噺 + * @return 杩斿洖缃戞牸绱㈠紩鍊艰寖鍥� + */ + fun getCellWidthRange(cellIndex: Int, width: Int, height: Int): Pair<Double, Double>? { + val total = width * height; + val x = ceil(cellIndex.toDouble() / total) - 1; + val first = 1 + x * total + val last = width + x * total; + var scale = 0; + while (scale < height) { + val min = first + scale * width; + val max = last + scale * width; + if (cellIndex >= min && cellIndex <= max) { + return min to max + } + scale++; + } + return null + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/domain/entity/GridDataDetail.java b/src/main/kotlin/com/flightfeather/uav/domain/entity/GridDataDetail.java index c563a81..710ec06 100644 --- a/src/main/kotlin/com/flightfeather/uav/domain/entity/GridDataDetail.java +++ b/src/main/kotlin/com/flightfeather/uav/domain/entity/GridDataDetail.java @@ -26,10 +26,47 @@ @Column(name = "cell_id") private Integer cellId; + private Integer rank; + + @Column(name = "NO2") + private Float no2; + + @Column(name = "CO") + private Float co; + + @Column(name = "H2S") + private Float h2s; + + @Column(name = "SO2") + private Float so2; + + @Column(name = "O3") + private Float o3; + @Column(name = "PM25") private Float pm25; - private Integer rank; + @Column(name = "PM10") + private Float pm10; + + private Float temperature; + + private Float humidity; + + @Column(name = "VOC") + private Float voc; + + @Column(name = "NOI") + private Float noi; + + @Column(name = "NO") + private Float no; + + @Column(name = "wind_speed") + private Float windSpeed; + + @Column(name = "wind_direction") + private Float windDirection; /** * @return id @@ -100,6 +137,90 @@ } /** + * @return rank + */ + public Integer getRank() { + return rank; + } + + /** + * @param rank + */ + public void setRank(Integer rank) { + this.rank = rank; + } + + /** + * @return NO2 + */ + public Float getNo2() { + return no2; + } + + /** + * @param no2 + */ + public void setNo2(Float no2) { + this.no2 = no2; + } + + /** + * @return CO + */ + public Float getCo() { + return co; + } + + /** + * @param co + */ + public void setCo(Float co) { + this.co = co; + } + + /** + * @return H2S + */ + public Float getH2s() { + return h2s; + } + + /** + * @param h2s + */ + public void setH2s(Float h2s) { + this.h2s = h2s; + } + + /** + * @return SO2 + */ + public Float getSo2() { + return so2; + } + + /** + * @param so2 + */ + public void setSo2(Float so2) { + this.so2 = so2; + } + + /** + * @return O3 + */ + public Float getO3() { + return o3; + } + + /** + * @param o3 + */ + public void setO3(Float o3) { + this.o3 = o3; + } + + /** * @return PM25 */ public Float getPm25() { @@ -114,16 +235,114 @@ } /** - * @return rank + * @return PM10 */ - public Integer getRank() { - return rank; + public Float getPm10() { + return pm10; } /** - * @param rank + * @param pm10 */ - public void setRank(Integer rank) { - this.rank = rank; + public void setPm10(Float pm10) { + this.pm10 = pm10; + } + + /** + * @return temperature + */ + public Float getTemperature() { + return temperature; + } + + /** + * @param temperature + */ + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + /** + * @return humidity + */ + public Float getHumidity() { + return humidity; + } + + /** + * @param humidity + */ + public void setHumidity(Float humidity) { + this.humidity = humidity; + } + + /** + * @return VOC + */ + public Float getVoc() { + return voc; + } + + /** + * @param voc + */ + public void setVoc(Float voc) { + this.voc = voc; + } + + /** + * @return NOI + */ + public Float getNoi() { + return noi; + } + + /** + * @param noi + */ + public void setNoi(Float noi) { + this.noi = noi; + } + + /** + * @return NO + */ + public Float getNo() { + return no; + } + + /** + * @param no + */ + public void setNo(Float no) { + this.no = no; + } + + /** + * @return wind_speed + */ + public Float getWindSpeed() { + return windSpeed; + } + + /** + * @param windSpeed + */ + public void setWindSpeed(Float windSpeed) { + this.windSpeed = windSpeed; + } + + /** + * @return wind_direction + */ + public Float getWindDirection() { + return windDirection; + } + + /** + * @param windDirection + */ + public void setWindDirection(Float windDirection) { + this.windDirection = windDirection; } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt index 7ac9d4b..ab8b068 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/DataVo.kt @@ -1,6 +1,5 @@ package com.flightfeather.uav.lightshare.bean -import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonInclude import com.flightfeather.uav.model.BaseMData import com.flightfeather.uav.socket.bean.AirData diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/SatelliteDataCalculateService.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/SatelliteDataCalculateService.kt index 98bfe6e..494fcaa 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/SatelliteDataCalculateService.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/SatelliteDataCalculateService.kt @@ -36,4 +36,11 @@ * @param groupId */ fun dataFusion(missionCode: String, groupId: Int): List<GridDataDetail?> + + /** + * 灏嗚蛋鑸綉鏍兼暟鎹敓鎴愬搴旂殑鐑姏缃戞牸鍥� + * @param groupId 浣跨敤鐨勭綉鏍肩粍id + * @param gridDataDetail 浣跨敤鐨勮蛋鑸綉鏍兼暟鎹� + */ + fun buildHeatmap(groupId: Int, gridDataDetail: List<GridDataDetail>): List<GridDataDetail> } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt index 248b091..a765aa6 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImpl.kt @@ -180,4 +180,9 @@ return gridDataDetailList } } + + override fun buildHeatmap(groupId: Int, gridDataDetail: List<GridDataDetail>): List<GridDataDetail> { + val gridCellList = satelliteGridRep.fetchGridCell(groupId) + + } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt index d83ba68..4038e82 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteTelemetryServiceImpl.kt @@ -58,7 +58,7 @@ val res = satelliteGridRep.fetchGridDataDetail(dataId, groupId, cellId) res.forEach { if (it?.pm25 != null) { - it.pm25 = round(it.pm25 * 100) / 100 + it.pm25 = round(it.pm25 * 10) / 10 } } return res diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/SatelliteTelemetryController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/SatelliteTelemetryController.kt index 5e5c4ff..8187d15 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/SatelliteTelemetryController.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/SatelliteTelemetryController.kt @@ -145,5 +145,10 @@ @ApiParam("缃戞牸缁刬d") @RequestParam groupId: Int, ) = resPack { satelliteDataCalculateService.dataFusion(missionCode, groupId) } - + @ApiOperation(value = "鐢熸垚璧拌埅鐑姏鍥�") + @PostMapping("/product/underway/heatmap/build") + fun buildUnderwayHeatmap( + @ApiParam("浣跨敤鐨勭綉鏍肩粍id") @RequestParam groupId: Int, + @ApiParam("浣跨敤鐨勮蛋鑸綉鏍兼暟鎹�") @RequestBody gridDataDetail: List<GridDataDetail> + ) = resPack { satelliteDataCalculateService.buildHeatmap(groupId, gridDataDetail) } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt index 0f5ea52..1ac2269 100644 --- a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt +++ b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt @@ -3,7 +3,6 @@ import com.flightfeather.uav.common.utils.DateUtil import com.flightfeather.uav.common.utils.ExcelUtil import com.flightfeather.uav.socket.eunm.FactorType -import org.apache.poi.hssf.usermodel.HSSFWorkbook import org.apache.poi.xssf.streaming.SXSSFWorkbook import java.io.File import java.io.FileOutputStream @@ -14,7 +13,7 @@ * 姹℃煋婧愬奖鍝嶇▼搴︽潈閲嶅垎鏋愭ā鍨� * 鍩虹被 */ -abstract class BaseModel<M : BaseMData> { +abstract class BaseModel<M : BaseMData, S: BaseSOP> { data class ResultCell( var total: Double = 0.0, @@ -27,26 +26,26 @@ } } - abstract var dataPrep: BaseDataPrep<M, BaseSOP> + abstract var dataPrep: BaseDataPrep<M, S> // 鏉冮噸鍥犲瓙锛屽湪杩涜璁$畻鍒嗘瀽鏃朵娇鐢ㄧ殑鐩戞祴鍥犲瓙 abstract var factorTypes: List<FactorType> // 鏉冮噸鍊硷紝澶氱鏉冮噸杩涜涔樼Н璁$畻 - abstract var weights: List<BaseWeight<M, BaseSOP>> + abstract var weights: List<BaseWeight<M, S>> // 璁$畻缁撴灉 private val rMap = mutableMapOf<String, MutableMap<String, MutableMap<String, ResultCell>>>() // 缁撴灉绛涢�夋柟寮� - abstract var sections: List<BaseSection<M, BaseSOP>> + abstract var sections: List<BaseSection<M, S>> /** * 姹℃煋婧愬奖鍝嶇▼搴﹁绠� * @param mDataList 鐩戞祴鏁版嵁闆嗗悎 * @param sopList 姹℃煋婧愰泦鍚� */ - fun execute(mDataList: List<M>, sopList: List<BaseSOP>, hasNext: Boolean = false) { + open fun execute(mDataList: List<M>, sopList: List<S>, hasNext: Boolean = false) { if (!hasNext) rMap.clear() //1. 鏁版嵁棰勫鐞� @@ -68,7 +67,7 @@ * @param mData 鐩戞祴鏁版嵁 * @param sop 姹℃煋婧� */ - private fun weightCompute(mData: M, sop: BaseSOP) { + private fun weightCompute(mData: M, sop: S) { val effect = BaseEffect(sop.sourceId, sop.sourceName, sop.index) // 灏嗗師鐩戞祴鏁版嵁鎸夌収鏉冮噸璁$畻鍑虹粨鏋滃�� @@ -132,7 +131,7 @@ val lKey = "$se($factorType)" if (lMap.containsKey(lKey)) { val resultCell = lMap[lKey] ?: return@type - val size = resultCell.count +// val size = resultCell.count // 娣诲姞璇ュ垎绫讳綔涓鸿〃澶� val h = lKey // val h = "$lKey($size)" @@ -234,5 +233,5 @@ /** * 姹℃煋婧愭暟鎹悎娉曟�ф鏌� */ - abstract fun sopCheck(s: BaseSOP): Boolean + abstract fun sopCheck(s: S): Boolean } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt index 7e9d2a1..d593b94 100644 --- a/src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt +++ b/src/main/kotlin/com/flightfeather/uav/model/BaseSOP.kt @@ -6,12 +6,18 @@ * Source of pollution * 姹℃煋婧� 鍩虹被 */ -open class BaseSOP( +open class BaseSOP() { + // 姹℃煋婧愭爣璇� - var sourceId: String, - var sourceName: String, - var index: String -) { + lateinit var sourceId: String + lateinit var sourceName: String + lateinit var index: String + + constructor(sourceId: String, sourceName: String, index: String) : this() { + this.sourceId = sourceId + this.sourceName = sourceName + this.index = index + } /** * 涓績缁忓害 */ diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt index 50e5bb9..06183cf 100644 --- a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt +++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWGridModel.kt @@ -10,7 +10,7 @@ * 鏍规嵁璧拌埅鐩戞祴鏁版嵁銆佸畾鐐圭洃娴嬫暟鎹紝缁撳悎椋庨�熴�侀鍚戙�佺洃娴嬬偣涓庣綉鏍间腑蹇冪殑鐩稿浣嶇疆绛夊洜绱狅紝璁$畻缃戞牸鍖哄煙瀵圭洃娴嬪尯鍩熺殑褰卞搷绋嬪害 * @author riku */ -class EPWGridModel : BaseModel<DataVo>() { +class EPWGridModel : BaseModel<DataVo, BaseSOP>() { // 榛樿鐩戞祴鐐圭粡绾害 var defaultLocation: Pair<Double, Double>? = null set(value) { diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt index b832b60..c096d17 100644 --- a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt +++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt @@ -1,6 +1,5 @@ package com.flightfeather.uav.model.epw -import com.flightfeather.uav.lightshare.bean.CompanySOP import com.flightfeather.uav.lightshare.bean.DataVo import com.flightfeather.uav.model.* import com.flightfeather.uav.socket.eunm.FactorType @@ -11,7 +10,7 @@ * 鏍规嵁璧拌埅鐩戞祴鏁版嵁锛岀粨鍚堥閫熴�侀鍚戙�佺洃娴嬬偣涓庝紒涓氱殑鐩稿浣嶇疆绛夊洜绱狅紝璁$畻浼佷笟瀵圭洃娴嬪尯鍩熺殑褰卞搷绋嬪害 * @author riku */ -class EPWModel : BaseModel<DataVo>() { +class EPWModel : BaseModel<DataVo, BaseSOP>() { // 榛樿鐩戞祴鐐圭粡绾害 var defaultLocation: Pair<Double, Double>? = null diff --git a/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridCellAndData.kt b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridCellAndData.kt new file mode 100644 index 0000000..75f6439 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridCellAndData.kt @@ -0,0 +1,40 @@ +package com.flightfeather.uav.model.underwaygrid + +import com.flightfeather.uav.domain.entity.GridCell +import com.flightfeather.uav.domain.entity.GridDataDetail +import com.flightfeather.uav.model.BaseMData +import com.flightfeather.uav.socket.eunm.FactorType +import com.flightfeather.uav.socket.eunm.FactorType.* + +/** + * 鍗槦缃戞牸鍧愭爣鍜岀洃娴嬫暟鎹� + * @date 2025/3/21 + * @author feiyu02 + */ +class GridCellAndData(val gridCell: GridCell, val gridDataDetail: GridDataDetail): BaseMData() { + + override fun getFactorData(type: FactorType): Double? { + return when (type) { +// NO2 -> NO2 +// CO -> CO +// H2S -> H2S +// SO2 -> SO2 +// O3 -> O3 + PM25 -> gridDataDetail.pm25.toDouble() +// PM10 -> PM10 +// TEMPERATURE -> TEMPERATURE +// HUMIDITY -> HUMIDITY +// VOC -> VOC +// NOI -> NOI +// LNG -> LNG +// LAT -> LAT +// VELOCITY -> VELOCITY +// TIME -> TIME +// WIND_SPEED -> WIND_SPEED +// WIND_DIRECTION -> WIND_DIRECTION +// HEIGHT -> HEIGHT +// NO -> NO + else -> null + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridCellSop.kt b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridCellSop.kt new file mode 100644 index 0000000..3c21f36 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridCellSop.kt @@ -0,0 +1,23 @@ +package com.flightfeather.uav.model.underwaygrid + +import com.flightfeather.uav.domain.entity.GridCell +import com.flightfeather.uav.model.BaseSOP + +/** + * 鍗槦姹℃煋婧愮綉鏍� + * @date 2025/3/21 + * @author feiyu02 + */ +class GridCellSop : BaseSOP { + val gridCell:GridCell + + constructor(gridCell: GridCell) : super(){ + this.gridCell = gridCell + } + constructor(gridCell: GridCell, sourceId: String, sourceName: String, index: String) : super( + sourceId, + sourceName, index + ){ + this.gridCell = gridCell + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridWindDirWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridWindDirWeight.kt new file mode 100644 index 0000000..254adcb --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridWindDirWeight.kt @@ -0,0 +1,40 @@ +package com.flightfeather.uav.model.underwaygrid + +import com.flightfeather.uav.model.BaseWeight +import com.flightfeather.uav.socket.eunm.FactorType +import java.math.BigDecimal +import kotlin.math.PI +import kotlin.math.abs +import kotlin.math.atan2 + +/** + * 椋庡悜鏉冮噸 + * @date 2025/3/21 + * @author feiyu02 + */ +class GridWindDirWeight : BaseWeight<GridCellAndData, GridCellSop>() { + override val tag: String = "椋庡悜鏉冮噸" + + override val sectionValues: List<Double> = listOf(22.5, 67.5, 112.5, 157.5, 180.0) + + override val weights: List<Double> = listOf(1.0, 0.8, 0.5, 0.2, 0.1) + + override fun onWeightFactor(mData: GridCellAndData, sop: GridCellSop): Double? { + val p1 = Pair(mData.gridCell.longitude, mData.gridCell.latitude) + val p2 = Pair(sop.gridCell.longitude, sop.gridCell.latitude) + val wd = mData.getFactorData(FactorType.WIND_DIRECTION) ?: 0.0 + return getAngle(p1, p2, wd) + } + + private fun getAngle(p1: Pair<BigDecimal, BigDecimal>, p2: Pair<BigDecimal, BigDecimal>, wd: Double): Double { + val dx = p2.first - p1.first + val dy = p2.second - p1.second + var x1 = atan2(dy.toDouble(), dx.toDouble()) * 180 / PI + 180 + if (x1 < 0) x1 += 360 + var x2 = 270 - wd + if (x2 < 0) x2 += 360 + x1 = abs(x2 - x1) + if (x1 > 180) x1 = 360 - x1 + return x1 + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridWindDisWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridWindDisWeight.kt new file mode 100644 index 0000000..813f542 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/GridWindDisWeight.kt @@ -0,0 +1,38 @@ +package com.flightfeather.uav.model.underwaygrid + +import com.flightfeather.uav.model.BaseWeight +import com.flightfeather.uav.socket.eunm.FactorType +import java.math.BigDecimal +import kotlin.math.abs +import kotlin.math.max +import kotlin.math.sqrt + +/** + * 椋庨�熻窛绂绘潈閲� + * 鐩戞祴鐐逛笌姹℃煋婧愪箣闂寸殑鐗╃悊璺濈涓庡綋鍓嶉閫熷緱鍑虹殑鏉冮噸 + * @date 2025/3/21 + * @author feiyu02 + */ +class GridWindDisWeight : BaseWeight<GridCellAndData, GridCellSop>() { + + override val tag: String = "椋庨�熻窛绂绘潈閲�" + + override val sectionValues: List<Double> = listOf(2.0, 5.0, 8.0, 12.0, 20.0, 30.0) + + override val weights: List<Double> = listOf(1.0, 0.8, 0.6, 0.5, 0.3, 0.0) + + override fun onWeightFactor(mData: GridCellAndData, sop: GridCellSop): Double? { + val p1 = Pair(mData.gridCell.longitude, mData.gridCell.latitude) + val p2 = Pair(sop.gridCell.longitude, sop.gridCell.latitude) + val ws = mData.getFactorData(FactorType.WIND_SPEED) + return if (ws == null) null else getWindSpeed(p1, p2, ws) + } + + private fun getWindSpeed(p1: Pair<BigDecimal, BigDecimal>, p2: Pair<BigDecimal, BigDecimal>, ws: Double): Double { + val dx = (p2.first - p1.first).toDouble() + val dy = (p2.second - p1.second).toDouble() + val dis = sqrt(abs(dx * dx) + abs(dy * dy)) * 100 + val min = dis * 1000 / max(ws, 1.0) / 60 + return min + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/UnderwayGridDataPrep.kt b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/UnderwayGridDataPrep.kt new file mode 100644 index 0000000..d2c36bd --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/UnderwayGridDataPrep.kt @@ -0,0 +1,18 @@ +package com.flightfeather.uav.model.underwaygrid + +import com.flightfeather.uav.model.BaseDataPrep + +/** + * 璧拌埅缃戞牸鏁版嵁棰勫鐞� + * @date 2025/3/21 + * @author feiyu02 + */ +class UnderwayGridDataPrep : BaseDataPrep<GridCellAndData, GridCellSop>() { + override fun mDataPrep(mDataList: List<GridCellAndData>): List<GridCellAndData> { + return mDataList + } + + override fun sopPrep(sopList: List<GridCellSop>): List<GridCellSop> { + return sopList + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/UnderwayGridModel.kt b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/UnderwayGridModel.kt new file mode 100644 index 0000000..5ff8e3f --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/model/underwaygrid/UnderwayGridModel.kt @@ -0,0 +1,31 @@ +package com.flightfeather.uav.model.underwaygrid + +import com.flightfeather.uav.model.BaseDataPrep +import com.flightfeather.uav.model.BaseModel +import com.flightfeather.uav.model.BaseSection +import com.flightfeather.uav.model.BaseWeight +import com.flightfeather.uav.model.epw.WeightType +import com.flightfeather.uav.socket.eunm.FactorType + +/** + * + * @date 2025/3/21 + * @author feiyu02 + */ +class UnderwayGridModel : BaseModel<GridCellAndData, GridCellSop>() { + override var dataPrep: BaseDataPrep<GridCellAndData, GridCellSop> = UnderwayGridDataPrep() + + override var factorTypes: List<FactorType> = WeightType.weightType + + override var weights: List<BaseWeight<GridCellAndData, GridCellSop>> = listOf(GridWindDirWeight(), GridWindDisWeight()) + + override var sections: List<BaseSection<GridCellAndData, GridCellSop>> = emptyList() + + override fun mDataCheck(m: GridCellAndData): Boolean { + return m.gridDataDetail.pm25 != null + } + + override fun sopCheck(s: GridCellSop): Boolean { + return s.gridCell.longitude != null && s.gridCell.latitude != null + } +} \ No newline at end of file diff --git a/src/main/resources/generator/generatorConfig.xml b/src/main/resources/generator/generatorConfig.xml index 4daa38b..ce7dc0e 100644 --- a/src/main/resources/generator/generatorConfig.xml +++ b/src/main/resources/generator/generatorConfig.xml @@ -66,9 +66,9 @@ <!-- <table tableName="real_time_data_grid_opt" domainObjectName="RealTimeDataGridOpt" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="scene_info" domainObjectName="SceneInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="segment_info" domainObjectName="SegmentInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> - <table tableName="grid_group" domainObjectName="GridGroup" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> +<!-- <table tableName="grid_group" domainObjectName="GridGroup" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="grid_cell" domainObjectName="GridCell" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="grid_data" domainObjectName="GridData" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> -<!-- <table tableName="grid_data_detail" domainObjectName="GridDataDetail" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> + <table tableName="grid_data_detail" domainObjectName="GridDataDetail" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> </context> </generatorConfiguration> \ No newline at end of file diff --git a/src/main/resources/mapper/GridDataDetailMapper.xml b/src/main/resources/mapper/GridDataDetailMapper.xml index 7574d75..1321311 100644 --- a/src/main/resources/mapper/GridDataDetailMapper.xml +++ b/src/main/resources/mapper/GridDataDetailMapper.xml @@ -9,14 +9,28 @@ <result column="data_id" jdbcType="INTEGER" property="dataId" /> <result column="group_id" jdbcType="INTEGER" property="groupId" /> <result column="cell_id" jdbcType="INTEGER" property="cellId" /> - <result column="PM25" jdbcType="REAL" property="pm25" /> <result column="rank" jdbcType="INTEGER" property="rank" /> + <result column="NO2" jdbcType="REAL" property="no2" /> + <result column="CO" jdbcType="REAL" property="co" /> + <result column="H2S" jdbcType="REAL" property="h2s" /> + <result column="SO2" jdbcType="REAL" property="so2" /> + <result column="O3" jdbcType="REAL" property="o3" /> + <result column="PM25" jdbcType="REAL" property="pm25" /> + <result column="PM10" jdbcType="REAL" property="pm10" /> + <result column="temperature" jdbcType="REAL" property="temperature" /> + <result column="humidity" jdbcType="REAL" property="humidity" /> + <result column="VOC" jdbcType="REAL" property="voc" /> + <result column="NOI" jdbcType="REAL" property="noi" /> + <result column="NO" jdbcType="REAL" property="no" /> + <result column="wind_speed" jdbcType="REAL" property="windSpeed" /> + <result column="wind_direction" jdbcType="REAL" property="windDirection" /> </resultMap> <sql id="Base_Column_List"> <!-- WARNING - @mbg.generated --> - id, data_id, group_id, cell_id, PM25, rank + id, data_id, group_id, cell_id, rank, NO2, CO, H2S, SO2, O3, PM25, PM10, temperature, + humidity, VOC, NOI, NO, wind_speed, wind_direction </sql> <!-- 娣诲姞鎵归噺鏇存柊PM25鐨勫嚱鏁� --> diff --git a/src/test/kotlin/com/flightfeather/uav/Test.kt b/src/test/kotlin/com/flightfeather/uav/Test.kt index 77ad87b..ead18b4 100644 --- a/src/test/kotlin/com/flightfeather/uav/Test.kt +++ b/src/test/kotlin/com/flightfeather/uav/Test.kt @@ -3,18 +3,18 @@ import com.flightfeather.uav.common.utils.DateUtil import com.flightfeather.uav.common.utils.FileExchange import com.flightfeather.uav.common.utils.FileUtil +import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.domain.entity.Company -import com.flightfeather.uav.lightshare.eunm.SatelliteDataType +import com.flightfeather.uav.domain.entity.GridDataDetail import com.flightfeather.uav.socket.bean.DataUnit import com.flightfeather.uav.socket.decoder.AirDataDecoder import com.flightfeather.uav.socket.eunm.AirCommandUnit import com.google.gson.Gson -import org.jetbrains.kotlin.konan.util.visibleName import org.junit.Test +import org.springframework.beans.BeanUtils import java.io.File import java.io.FileOutputStream import java.io.OutputStreamWriter -import java.math.BigDecimal import java.text.SimpleDateFormat import java.util.* @@ -56,7 +56,8 @@ @Test fun listCopy() { - val l1 = listOf(Company().apply { ciGuid = "a" }, Company().apply { ciGuid = "b" }, Company().apply { ciGuid = "c" }) + val l1 = + listOf(Company().apply { ciGuid = "a" }, Company().apply { ciGuid = "b" }, Company().apply { ciGuid = "c" }) val l2 = mutableListOf<Company>().apply { addAll(l1) } l2[1].ciGuid = "d" println(l1) @@ -73,8 +74,9 @@ } @Test - fun get_crc16(){ - val dataSegment = "QN=20210713133901044;ST=22;CN=2011;PW=555555;MN=FYHB0DT0100001;Flag=1;CP=&&DataTime=20210713133800;a34001-Avg=0.017,a34001-CPM=3.9,a34001-Flag=N;a50001-Avg=71.1,a50001-Flag=N;a01001-Avg=34.0,a01001-Flag=N;a01002-Avg=59.3,a01002-Flag=N;a01007-Avg=0.6,a01007-Flag=N;a01008-Avg=256.3,a01008-Flag=N;Period=1;Scale=1.0;SelfTemp=0.0;SelfHum=0.0;IsReplacement=N&&" + fun get_crc16() { + val dataSegment = + "QN=20210713133901044;ST=22;CN=2011;PW=555555;MN=FYHB0DT0100001;Flag=1;CP=&&DataTime=20210713133800;a34001-Avg=0.017,a34001-CPM=3.9,a34001-Flag=N;a50001-Avg=71.1,a50001-Flag=N;a01001-Avg=34.0,a01001-Flag=N;a01002-Avg=59.3,a01002-Flag=N;a01007-Avg=0.6,a01007-Flag=N;a01008-Avg=256.3,a01008-Flag=N;Period=1;Scale=1.0;SelfTemp=0.0;SelfHum=0.0;IsReplacement=N&&" var CRC = 0x0000ffff val POLYNOMIAL = 0x0000a001 var i: Int @@ -129,11 +131,25 @@ @Test fun foo17() { - println(SatelliteDataType.Original.name) - println(SatelliteDataType.Original.value) - println(SatelliteDataType.Original.ordinal) - println(SatelliteDataType.Original.toString()) - println(SatelliteDataType.Original.visibleName) - println(SatelliteDataType.Original) + val avgData = BaseRealTimeData().apply { + no2 = 50f + co = 50f + h2s = 50f + so2 = 50f + o3 = 50f + pm25 = 50f + pm10 = 50f + temperature = 50f + humidity = 50f + voc = 50f + noi = 50f + no = 50f + windSpeed = 2f + windDirection = 240f + } + val dataDetail = GridDataDetail() + BeanUtils.copyProperties(avgData, dataDetail) + + println(dataDetail) } } \ No newline at end of file diff --git a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImplTest.kt b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImplTest.kt index 0ad77e0..151383a 100644 --- a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImplTest.kt +++ b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/SatelliteDataCalculateServiceImplTest.kt @@ -50,7 +50,7 @@ val groupIdList = listOf(2, 4) val dataId = listOf(34, 29, 25, 18, 8) - groupIdList.forEach {g -> + groupIdList.forEach { g -> dataId.forEach { d -> satelliteDataCalculateService.splitData(g, d) } @@ -61,7 +61,15 @@ @Test fun dataFusion() { val missionList = - listOf("SH-CN-20241202", "SH-CN-20241127", "SH-CN-20241126-1", "SH-CN-20241126-2", "SH-CN-20241108", "SH-CN-20240823") + listOf( + "SH-CN-20241216", + "SH-CN-20241202", + "SH-CN-20241127", + "SH-CN-20241126-1", + "SH-CN-20241126-2", + "SH-CN-20241108", + "SH-CN-20240823" + ) missionList.forEach { m -> satelliteDataCalculateService.dataFusion(m, 3) } -- Gitblit v1.9.3