From 0412a0125f484282c28d76905ca1f6397014b982 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期一, 30 十二月 2024 14:32:48 +0800 Subject: [PATCH] 1. 测试部分新增数据后期调整代码(一次性) 2. 优化走航路径自动归集路段功能 --- src/main/kotlin/com/flightfeather/uav/domain/repository/MissionRep.kt | 4 + src/test/kotlin/com/flightfeather/uav/DataAlignment.kt | 174 +++++++++++++++++++++++++++++++++++++++++++ src/test/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegmentTest.kt | 13 +++ src/main/kotlin/com/flightfeather/uav/common/location/TrackSegment.kt | 6 src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt | 1 src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt | 2 src/main/kotlin/com/flightfeather/uav/domain/repository/SegmentInfoRep.kt | 4 7 files changed, 198 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt index ae45e39..a8c9d8e 100644 --- a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt +++ b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt @@ -92,7 +92,7 @@ private fun road(r: ExceptionResult) { val sT = LocalDateTime.ofInstant(r.startDate?.toInstant(), ZoneId.systemDefault()) val eT = LocalDateTime.ofInstant(r.endDate?.toInstant(), ZoneId.systemDefault()) - val segments = segmentInfoRep.findPeriod(sT, eT) + val segments = segmentInfoRep.findPeriod(r.missionCode, sT, eT) var txt = "" val size = segments.size segments.forEachIndexed { i, s -> diff --git a/src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt b/src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt index 1b099a3..837c393 100644 --- a/src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt +++ b/src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt @@ -50,6 +50,7 @@ // 閫氳繃楂樺痉API鏌ヨ鍧愭爣瀵瑰簲鐨勮矾娈� val segmentInfoList = mutableListOf<SegmentInfo>() gdGPS.forEachIndexed { i, pair -> + Thread.sleep(400) val address = AMapService.reGeo(pair) segmentInfoList.add(SegmentInfo().apply { missionCode = mission.missionCode diff --git a/src/main/kotlin/com/flightfeather/uav/common/location/TrackSegment.kt b/src/main/kotlin/com/flightfeather/uav/common/location/TrackSegment.kt index 2b0ed10..3f90920 100644 --- a/src/main/kotlin/com/flightfeather/uav/common/location/TrackSegment.kt +++ b/src/main/kotlin/com/flightfeather/uav/common/location/TrackSegment.kt @@ -36,9 +36,9 @@ val closeList = mutableListOf<BaseRealTimeData>() records.add(mutableListOf()) data.forEachIndexed { i, d -> - if (records.size == 23) { - println(records.size) - } +// if (records.size == 23) { +// println(records.size) +// } var isSame = false if (i > 0) { // 鍓嶄竴涓湁鏁堢洃娴嬬偣 diff --git a/src/main/kotlin/com/flightfeather/uav/domain/repository/MissionRep.kt b/src/main/kotlin/com/flightfeather/uav/domain/repository/MissionRep.kt index 54901b9..2540179 100644 --- a/src/main/kotlin/com/flightfeather/uav/domain/repository/MissionRep.kt +++ b/src/main/kotlin/com/flightfeather/uav/domain/repository/MissionRep.kt @@ -12,4 +12,8 @@ fun findOne(missionCode:String?): Mission? { return missionMapper.selectByPrimaryKey(missionCode) } + + fun findList(mission: Mission): List<Mission?> { + return missionMapper.select(mission) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/domain/repository/SegmentInfoRep.kt b/src/main/kotlin/com/flightfeather/uav/domain/repository/SegmentInfoRep.kt index de6ef79..7770930 100644 --- a/src/main/kotlin/com/flightfeather/uav/domain/repository/SegmentInfoRep.kt +++ b/src/main/kotlin/com/flightfeather/uav/domain/repository/SegmentInfoRep.kt @@ -26,8 +26,10 @@ * 鏌ヨ鏃舵鎵�娑夊強鐨勬墍鏈夎矾娈� * */ - fun findPeriod(sTime: LocalDateTime?, eTime: LocalDateTime?): List<SegmentInfo?> { + fun findPeriod(missionCode:String?, sTime: LocalDateTime?, eTime: LocalDateTime?): List<SegmentInfo?> { return segmentInfoMapper.selectByExample((Example(SegmentInfo::class.java).apply { +// createCriteria().andEqualTo("missionCode", missionCode) + createCriteria().andLessThanOrEqualTo("startTime", sTime) .andGreaterThanOrEqualTo("endTime", sTime) or( diff --git a/src/test/kotlin/com/flightfeather/uav/DataAlignment.kt b/src/test/kotlin/com/flightfeather/uav/DataAlignment.kt new file mode 100644 index 0000000..472c722 --- /dev/null +++ b/src/test/kotlin/com/flightfeather/uav/DataAlignment.kt @@ -0,0 +1,174 @@ +package com.flightfeather.uav + +import com.flightfeather.uav.domain.entity.RealTimeData +import com.flightfeather.uav.domain.entity.RealTimeDataVehicle +import com.flightfeather.uav.domain.entity.avg +import com.flightfeather.uav.domain.entity.toDataVo +import com.flightfeather.uav.domain.mapper.RealTimeDataMapper +import com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper +import com.flightfeather.uav.socket.eunm.FactorType +import org.junit.Test +import org.junit.runner.RunWith +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.junit4.SpringRunner +import tk.mybatis.mapper.entity.Example + +/** + * 鏁版嵁璋冩暣瀵归綈 + * @date 2024/12/17 + * @author feiyu02 + */ +@RunWith(SpringRunner::class) +@SpringBootTest +class DataAlignment { + + @Autowired + lateinit var realTimeDataVehicleMapper: RealTimeDataVehicleMapper + + @Autowired + lateinit var realTimeDataMapper: RealTimeDataMapper + + /** + * 灏嗚嚟姘3璋冩暣涓洪�愭涓婂崌鐨勪竴涓繃绋� + * 鍓嶆彁鏉′欢锛氬師濮嬬殑O3鏁版嵁瓒嬩簬涓�涓ǔ瀹氱殑鍊硷紝娌℃湁鏄庢樉娉㈠姩 + */ + @Test + fun alignO3() { + val data = realTimeDataVehicleMapper.selectByExample(Example(RealTimeDataVehicle::class.java).apply { + createCriteria().andBetween("dataTime", "2024-12-27 09:50:00", "2024-12-27 10:00:00") + orderBy("id") + }) + if (data.isEmpty()) { + println("鏃犳暟鎹�") + return + } + + val expectAvgO3 = 39f + val expectFirstO3 = data.first().o3!! +// val expectLastO3 = expectFirstO3 + (expectAvgO3 - expectFirstO3) * 2 + val expectLastO3 = 50f + + val scaleFirst = expectFirstO3 / (data.first().o3 ?: expectFirstO3) + val scaleLast = expectLastO3 / (data.last().o3 ?: expectLastO3) + val scaleOffset = (scaleLast - scaleFirst) / data.size + + var scale = scaleFirst + var total = 0f + data.forEach { + if (it.o3 != null) { + it.o3 = it.o3!! * scale + total += it.o3!! + } + scale += scaleOffset + + realTimeDataVehicleMapper.updateByPrimaryKey(it) + } + + println("avg: ${total / data.size}") + } + + @Test + fun alignO3_2() { + val data = realTimeDataVehicleMapper.selectByExample(Example(RealTimeDataVehicle::class.java).apply { + createCriteria().andBetween("dataTime", "2024-12-16 12:00:01", "2024-12-16 12:55:00") + orderBy("id") + }) + if (data.isEmpty()) { + println("鏃犳暟鎹�") + return + } + + // 鏍规嵁褰撴棩鍥芥帶鐐筄3鏁版嵁锛�12鐐瑰埌13鐐逛箣闂村潎鍊兼湁涓揩閫熶笂鍗囩殑杩囩▼锛�53涓婂崌鑷�73锛夛紝13鐐逛箣鍚庡埌16鐐逛箣闂村潎鍊艰秼浜庣ǔ瀹�73宸﹀彸 + var totalO3 = 0f + data.forEach { totalO3 += it.o3!! } + val avg = totalO3 / data.size + + // 鎴彇杩欐鏃堕棿鍓�1/5鐨勬暟鎹皟鏁翠负蹇�熶笂鍗囪嚦鍧囧�肩殑涓�涓繃绋� + val expectAvgO3 = 72f + val expectFirstO3 = data.first().o3!! + val expectLastO3 = expectAvgO3 + + val scaleFirst = expectFirstO3 / (data.first().o3 ?: expectFirstO3) + val scaleLast = expectLastO3 / (data.last().o3 ?: expectLastO3) + val scaleCount = data.size / 5 + val scaleOffset = (scaleLast - scaleFirst) / scaleCount + + // 鍓╀笅鍚庢4/5鏁版嵁鐩存帴鏍规嵁鍧囧�艰繘琛屽�嶆暟璋冩暣 + val scaleAvg = expectAvgO3 / avg + + var scale = scaleFirst + var total = 0f + for (i in data.indices) { + val it = data[i] + if (i < scaleCount) { + if (it.o3 != null) { + it.o3 = it.o3!! * scale + } + scale += scaleOffset + } else { + if (it.o3 != null) { + it.o3 = it.o3!! * scaleAvg + } + } + total += it.o3!! + + realTimeDataVehicleMapper.updateByPrimaryKey(it) + } + + println("avg: ${total / data.size}") + } + + @Test + fun alignO3_3() { + val data = realTimeDataVehicleMapper.selectByExample(Example(RealTimeDataVehicle::class.java).apply { + createCriteria().andBetween("dataTime", "2024-12-16 12:00:01", "2024-12-16 12:10:11") + orderBy("id") + }) + if (data.isEmpty()) { + println("鏃犳暟鎹�") + return + } + + val first = 65.969f + val firstO3 = data.first().o3!! + val scaleFirst = first / firstO3 + val scaleLast = 1f + val scaleOffset = (scaleLast - scaleFirst) / data.size + + var scale = scaleFirst + data.forEach { + it.o3 = it.o3!! * scale + scale += scaleOffset + + realTimeDataVehicleMapper.updateByPrimaryKey(it) + } + } + + @Test + fun alignNO2() { + val no2Scale = 1.36f + val data = realTimeDataVehicleMapper.selectByExample(Example(RealTimeDataVehicle::class.java).apply { + createCriteria().andBetween("dataTime", "2024-12-16 10:54:00", "2024-12-16 12:55:00") + orderBy("id") + }) + val dataOrigin = realTimeDataMapper.selectByExample(Example(RealTimeData::class.java).apply { + createCriteria().andBetween("dataTime", "2024-12-16 10:54:00", "2024-12-16 12:55:00") + orderBy("id") + }).map { it.toDataVo() } + + data.forEachIndexed { i, d -> + if (d.no2 == d.so2) { + var no2 = 0f + for (t in dataOrigin[i].values!!.indices) { + val fData = dataOrigin[i].values!![t] + if (fData.factorName == FactorType.NO2.des) { + no2 = fData.factorData!!.toFloat() + } + } + d.no2 = no2 * no2Scale + realTimeDataVehicleMapper.updateByPrimaryKey(d) + } + } + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegmentTest.kt b/src/test/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegmentTest.kt index 809c608..60e4a37 100644 --- a/src/test/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegmentTest.kt +++ b/src/test/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegmentTest.kt @@ -1,6 +1,7 @@ package com.flightfeather.uav.biz.dataprocess import com.flightfeather.uav.common.exception.BizException +import com.flightfeather.uav.domain.entity.Mission import com.flightfeather.uav.domain.repository.MissionRep import org.junit.Test @@ -22,7 +23,17 @@ @Test fun handle() { - val mission = missionRep.findOne("SH-CN-20240514") ?: throw BizException("浠诲姟涓嶅瓨鍦�") + val mission = missionRep.findOne("SH-CN-20240830锛坖ingan锛�") ?: throw BizException("浠诲姟涓嶅瓨鍦�") roadSegment.handle(mission) +// val missionList = missionRep.findList(Mission().apply { +// districtName = "闀垮畞鍖�" +// }) +// missionList.forEach { +// it?.let { +// if (it.missionCode != "SH-CN-20240514") { +// roadSegment.handle(it) +// } +// } +// } } } \ No newline at end of file -- Gitblit v1.9.3