1. 测试部分新增数据后期调整代码(一次性)
2. 优化走航路径自动归集路段功能
已修改6个文件
已添加1个文件
204 ■■■■■ 文件已修改
src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/common/location/TrackSegment.kt 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/domain/repository/MissionRep.kt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/domain/repository/SegmentInfoRep.kt 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/kotlin/com/flightfeather/uav/DataAlignment.kt 174 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegmentTest.kt 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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 ->
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
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) {
                // å‰ä¸€ä¸ªæœ‰æ•ˆç›‘测点
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)
    }
}
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(
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
    /**
     * å°†è‡­æ°§O3调整为逐步上升的一个过程
     * å‰ææ¡ä»¶ï¼šåŽŸå§‹çš„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
        }
        // æ ¹æ®å½“日国控点O3数据,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)
            }
        }
    }
}
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(jingan)") ?: 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)
//                }
//            }
//        }
    }
}