From db7243622e8b5f4cc23de5594b2d973562f0b2a3 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 10 十一月 2021 09:54:36 +0800
Subject: [PATCH] 1. 添加网格化数据分钟均值计算逻辑
---
src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt | 80 +++++++++++++++++++++++++++++++++++-----
1 files changed, 70 insertions(+), 10 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt b/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt
index f0ec25c..7751fbc 100644
--- a/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/repository/impl/AirDataRepositoryImpl.kt
@@ -1,12 +1,8 @@
package com.flightfeather.uav.repository.impl
import com.flightfeather.uav.common.utils.GsonUtils
-import com.flightfeather.uav.domain.MyMapper
import com.flightfeather.uav.domain.entity.*
-import com.flightfeather.uav.domain.mapper.RealTimeDataGridMapper
-import com.flightfeather.uav.domain.mapper.RealTimeDataMapper
-import com.flightfeather.uav.domain.mapper.RealTimeDataUavMapper
-import com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper
+import com.flightfeather.uav.domain.mapper.*
import com.flightfeather.uav.lightshare.bean.DataVo
import com.flightfeather.uav.repository.AirDataRepository
import com.flightfeather.uav.socket.bean.AirData
@@ -19,7 +15,11 @@
import tk.mybatis.mapper.entity.Example
import java.math.BigDecimal
import java.text.SimpleDateFormat
+import java.time.LocalDateTime
+import java.time.ZoneId
import java.util.*
+import kotlin.math.abs
+import kotlin.math.sqrt
/**
* @author riku
@@ -30,11 +30,19 @@
private val realTimeDataMapper: RealTimeDataMapper,
private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper,
private val realTimeDataUavMapper: RealTimeDataUavMapper,
- private val realTimeDataGridMapper: RealTimeDataGridMapper
+ private val realTimeDataGridMapper: RealTimeDataGridMapper,
+ private val factorCalibrationMapper: FactorCalibrationMapper
): AirDataRepository {
// FIXME: 2021/10/25 涓存椂杞﹁浇鏁版嵁锛岀敱浜庢棤浜烘満閮ㄥ垎鐩戞祴鍥犲瓙鏁版嵁鏃犳晥锛屽洜姝ゆ殏鏃堕噰鐢ㄨ溅杞芥暟鎹綔涓哄~鍏�
private val tmpVehicleDataList = mutableListOf<BaseRealTimeData>()
+
+ // 璧拌埅鐩戞祴鏍″噯绯绘暟
+ private val calibrationMap = mutableMapOf<String, MutableMap<Int, Float>>()
+ // 璧拌埅鐩戞祴鏍″噯绯绘暟鏇存柊鏃堕棿
+ private var cUpdateTime = LocalDateTime.now()
+ // 璧拌埅鐩戞祴鏍″噯绯绘暟鏇存柊鏃堕棿闂撮殧锛堝垎閽燂級
+ private val cInterval = 5L
override fun saveAirData(dataPackage: AirDataPackage): Int {
val data = RealTimeData().apply {
@@ -129,10 +137,7 @@
dataTransform(vo, d)
/***************************************************************************************************/
// FIXME: 2021/10/27 杞﹁浇鐩戞祴閮ㄥ垎鍥犲瓙閲忕骇璋冩暣锛歂O2*0.6锛孒2S*0.3, SO2*0.2, O3*0.5锛屽叾浠栬绱犱笉鍙�
- d.no2 = d.no2?.times(0.6f)
- d.h2s = d.h2s?.times(0.3f)
- d.so2 = d.so2?.times(0.2f)
- d.o3 = d.o3?.times(0.5f)
+ calibration(d, UWDeviceType.VEHICLE)
/***************************************************************************************************/
realTimeDataVehicleMapper.insert(d)
count++
@@ -165,8 +170,37 @@
UWDeviceType.GRID -> {
val d = RealTimeDataGrid()
dataTransform(vo, d)
+ /**************************************************************************/
+ // FIXME: 2021/11/8 閽堝鍘嗗彶缃戞牸鍖栧師濮嬫暟鎹紝杩涜涓存椂鏍″噯澶勭悊
+ val dTime = LocalDateTime.ofInstant(d.dataTime?.toInstant(), ZoneId.systemDefault())
+ // CO: 2021.8.28 17:27璧� *0.25
+ val coTime = LocalDateTime.of(2021, 8, 28, 17, 27, 0)
+ if (dTime.isAfter(coTime)) {
+ d.co = d.co?.times(0.25f)
+ }
+
+ // NO2
+ d.no2 = d.no2?.times(0.6f)
+
+ // O3
+ d.o3 = abs(d.o3?.minus(d.no2?.div(2) ?: 0f) ?: 0f) * 1.5f
+
+ // SO2: *0.2, 2021.8.29 6:00璧� *0.08
+ val so2Time = LocalDateTime.of(2021, 8, 29, 6, 0, 0)
+ d.so2 = if (dTime.isAfter(so2Time)) {
+ d.so2?.times(0.08f)
+ } else {
+ d.so2?.times(0.2f)
+ }
+
+ // H2S
+ d.h2s = d.h2s?.let { sqrt(it) * 2 }
+ /**************************************************************************/
realTimeDataGridMapper.insert(d)
count++
+ }
+ UWDeviceType.BOAT -> {
+
}
}
}
@@ -267,4 +301,30 @@
}
}
+
+ private fun calibration(data: BaseRealTimeData, type: UWDeviceType) {
+ //1. 鏍″噯绯绘暟鎸夌収涓�瀹氭椂闂撮棿闅旇繘琛屽埛鏂�
+ val now = LocalDateTime.now()
+ if (calibrationMap.isEmpty() || now.minusMinutes(cInterval).isAfter(cUpdateTime)) {
+ cUpdateTime = now
+ calibrationMap[type.value] = mutableMapOf()
+ factorCalibrationMapper.selectByExample(Example(FactorCalibration::class.java).apply {
+ createCriteria().andEqualTo("deviceType", type.value)
+ }).forEach {
+ calibrationMap[type.value]?.put(it.factorId, it.factorScale)
+ }
+ }
+ //2. 鏍规嵁鏍″噯绯绘暟璁$畻
+ calibrationMap[type.value]?.let{
+ data.voc = data.voc?.times(it[FactorType.VOC.value] ?: 1f)
+ data.co = data.co?.times(it[FactorType.CO.value] ?: 1f)
+ data.pm25 = data.pm25?.times(it[FactorType.PM25.value] ?: 1f)
+ data.pm10 = data.pm10?.times(it[FactorType.PM10.value] ?: 1f)
+
+ data.no2 = data.no2?.times(it[FactorType.NO2.value] ?: 1f)
+ data.h2s = data.h2s?.times(it[FactorType.H2S.value] ?: 1f)
+ data.so2 = data.so2?.times(it[FactorType.SO2.value] ?: 1f)
+ data.o3 = data.o3?.times(it[FactorType.O3.value] ?: 1f)
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3