From 316bb4380e276a0b9e2745ad126a5c6c0e4b221d Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 22 十一月 2021 13:28:18 +0800
Subject: [PATCH] 2021.11.22
---
src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt | 105 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 96 insertions(+), 9 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
index 3f23d11..08c1e5e 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
@@ -1,11 +1,16 @@
package com.flightfeather.uav.model.epw
+import com.flightfeather.uav.common.utils.DateUtil
+import com.flightfeather.uav.common.utils.GsonUtils
import com.flightfeather.uav.lightshare.bean.CompanySOP
import com.flightfeather.uav.lightshare.bean.DataVo
import com.flightfeather.uav.model.BaseDataPrep
+import com.flightfeather.uav.socket.bean.AirData
+import com.flightfeather.uav.socket.bean.AirDataPackage
import com.flightfeather.uav.socket.eunm.FactorType
import kotlin.math.max
import kotlin.math.min
+import kotlin.math.round
import kotlin.math.sqrt
class EPWDataPrep : BaseDataPrep<DataVo, CompanySOP>() {
@@ -63,7 +68,7 @@
list.addAll(mDataList.subList(thisIndex, i))
// 鍘婚櫎鏃犳晥鍊肩殑骞冲潎
- val avg = average(list, it.factorName)
+ val avg = average(list, it.factorName) ?: continue
// 鍘婚櫎鏃犳晥鍊肩殑鏍囧噯宸�
val std = standardDeviation(avg.first, list, it.factorName)
// 鍚堢悊鏈�澶у��
@@ -86,7 +91,8 @@
}
lastData.clear()
- mDataList.subList(mDataList.lastIndex - ncal + 1, mDataList.lastIndex + 1).forEach {
+ val s = if ((mDataList.lastIndex - ncal + 1) < 0) 0 else mDataList.lastIndex - ncal + 1
+ mDataList.subList(s, mDataList.lastIndex + 1).forEach {
lastData.add(it.copy())
}
@@ -97,20 +103,96 @@
return sopList
}
+ fun mDataPrep2(dataPackage: AirDataPackage): List<DataVo> {
+ val vo = dataPackage.toDataVo()
+ return mDataPrep2(listOf(vo))
+ }
+
+ fun mDataPrep2(mDataList: List<DataVo>): List<DataVo> {
+ var i = ncal
+ if (lastData.isNotEmpty()) {
+ i = 0
+ }
+ while (i < mDataList.size) {
+ for (y in mDataList[i].values?.indices ?: 0..0) {
+ val it = mDataList[i].values?.get(y) ?: continue
+
+ if (!calTypes.contains(it.factorName)) continue
+ val vMax = FactorType.getVMax(it.factorName) ?: continue
+// it.factorData ?: continue
+
+ if (it.factorData!! > vMax) {
+ val lastDataIndex = i
+ val thisIndex = if (i-ncal<0) 0 else i - ncal
+ val list = mutableListOf<DataVo>()
+ if (lastDataIndex < lastData.size) {
+ list.addAll(lastData.subList(lastDataIndex, lastData.lastIndex + 1))
+ }
+ list.addAll(mDataList.subList(thisIndex, i))
+
+ // 鍘婚櫎鏃犳晥鍊肩殑骞冲潎锛屽綋鎵�鏈夋暟鎹兘鏄棤鏁堝�兼椂锛屾殏涓嶅仛澶勭悊
+ average(list, it.factorName)?.let { avg ->
+ // 鍘婚櫎鏃犳晥鍊肩殑鏍囧噯宸�
+ val std = standardDeviation(avg.first, list, it.factorName)
+ // 鍚堢悊鏈�澶у��
+ val max = max(avg.first + std * nstd, avg.first + avg.first * xratio)
+ // 鍚堢悊鏈�灏忓��
+ val min = min(avg.first - std * nstd, avg.first / (1 + xratio))
+
+ // 鏁版嵁涓嶅浜庡悎鐞嗚寖鍥村苟涓旀湁鏁堜釜鏁拌揪鏍囨椂锛岄噰鐢ㄨ绠楁墍寰楀潎鍊间唬鏇垮師濮嬪��
+ if (avg.second > max(ncal / 5, 2)
+ && (it.factorData!! < min || it.factorData!! > max)
+ ) {
+ // 鍘熷鏁版嵁
+// it.factorData = null
+ it.factorData = avg.first
+ }
+ }
+ }
+ }
+
+ i++
+ }
+
+ // 灏嗘柊鏁版嵁鐨勮嚦澶氭渶鍚�15涓繚瀛樹笅鏉ワ紙宸茬粡杩囬澶勭悊锛夛紝鐢ㄤ簬涓嬩竴娆$殑鍒ゆ柇
+ val newList = mutableListOf<DataVo>()
+ val s = if ((mDataList.lastIndex - ncal + 1) < 0) 0 else mDataList.lastIndex - ncal + 1
+ mDataList.subList(s, mDataList.lastIndex + 1).forEach {
+ newList.add(it.copy())
+ }
+ // 褰撴柊鏁版嵁涓庢棫鏁版嵁閲囨牱鏃堕棿宸秴杩�1鍒嗛挓鏃讹紝璁や负涓ょ粍鏁版嵁宸叉棤鍏宠仈鎬э紝娓呯┖鏃ф暟鎹�
+ if (lastData.isNotEmpty() && newList.isNotEmpty()) {
+ val lastTime = DateUtil.instance.StringToDate(lastData.last().time)
+ val thisTime = DateUtil.instance.StringToDate(newList.first().time)
+ if (thisTime?.time?.minus(lastTime?.time ?: 0) ?: 0 >= (60 * 1000)) {
+ lastData.clear()
+ }
+ }
+ lastData.addAll(newList)
+ // 纭繚淇濆瓨鐨勬暟鎹渶澶氬彧鏈夋渶鏂扮殑15涓�
+ while (lastData.size > ncal) {
+ lastData.removeAt(0)
+ }
+
+ return mDataList
+ }
+
/**
* 鍘婚櫎鏃犳晥鍊肩殑骞冲潎
* @param list 鐩戞祴鏁版嵁
* @return 鍧囧�煎拰鏈夋晥鏁版嵁涓暟
*/
- private fun average(list: List<DataVo>, factorName:String?): Pair<Double, Int> {
+ private fun average(list: List<DataVo>, factorName:String?): Pair<Double, Int>? {
var t = 0.0
var c = 0
list.forEach {
for (i in it.values?.indices ?: 0..0) {
val f = it.values?.get(i)
if (f?.factorName == factorName) {
- if (f?.factorData != null) {
- t += f.factorData!!
+ val range = FactorType.getRange(f?.factorName) ?: continue
+ //鍒ゆ柇鏁版嵁鏄惁鍦ㄥ悎鐞嗚寖鍥村唴
+ if (f?.factorData ?: 0.0 in range.first..range.second) {
+ t += f?.factorData!!
c++
}
break
@@ -121,10 +203,14 @@
val avg = if (c == 0) {
0.0
} else {
- t / c
+ round(t / c * 1000) / 1000
}
- return Pair(avg, c)
+ return if (c == 0) {
+ null
+ } else {
+ Pair(avg, c)
+ }
}
/**
@@ -137,8 +223,9 @@
for (i in it.values?.indices ?: 0..0) {
val f = it.values?.get(i)
if (f?.factorName == factorName) {
- if (f?.factorData != null) {
- t += (f.factorData!! - avg) * (f.factorData!! - avg)
+ val range = FactorType.getRange(f?.factorName) ?: continue
+ if (f?.factorData ?: 0.0 in range.first..range.second) {
+ t += (f?.factorData!! - avg) * (f.factorData!! - avg)
c++
}
break
--
Gitblit v1.9.3