¶Ô±ÈÐÂÎļþ |
| | |
| | | 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) |
| | | } |
| | | } |
| | | } |
| | | } |