From 74ffc8ebf3a25d2e3cee758954ce6efc163cb864 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 02 十二月 2021 16:11:57 +0800
Subject: [PATCH] 1. 用电量日分析
---
src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt | 35 +++++++++++++++++++++++++++--------
1 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt b/src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt
index cb51649..2c6cc71 100644
--- a/src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt
+++ b/src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt
@@ -12,8 +12,7 @@
import java.util.*
import javax.persistence.Column
import javax.persistence.Id
-import kotlin.math.cos
-import kotlin.math.sin
+import kotlin.math.*
/**
* 瀹炴椂鐩戞祴鏁版嵁鍩虹被
@@ -111,10 +110,10 @@
}
}
-fun List<RealTimeDataGrid>.avg(): RealTimeDataGrid {
+fun List<BaseRealTimeData>.avg(): RealTimeDataGridMin {
//椋庡悜閲囩敤鍗曚綅鐭㈤噺娉曟眰鍙栧潎鍊�
- var u = 0f//涓滆タ鏂逛綅鍒嗛噺鎬诲拰
- var v = 0f//鍗楀寳鏂逛綅鍒嗛噺鎬诲拰
+ var u = .0//涓滆タ鏂逛綅鍒嗛噺鎬诲拰
+ var v = .0//鍗楀寳鏂逛綅鍒嗛噺鎬诲拰
var c = 0//椋庡悜鏁版嵁璁℃暟
//闄ら鍚戝鐨勫叾浠栧洜瀛愰噰鐢ㄧ畻鏈钩鍧囨硶姹傚彇鍧囧��
@@ -126,8 +125,9 @@
forEach {
//椋庡悜
it.windDirection?.let {w ->
- u += sin(w)
- v += cos(w)
+ val r = Math.toRadians(w.toDouble())
+ u += sin(r)
+ v += cos(r)
c++
}
//鍏朵綑鍥犲瓙
@@ -235,7 +235,7 @@
}
}
- return RealTimeDataGrid().apply {
+ return RealTimeDataGridMin().apply {
val time = LocalDateTime.ofInstant(get(0).dataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0)
deviceCode = get(0).deviceCode
dataTime = Date.from(time.atZone(ZoneId.systemDefault()).toInstant())
@@ -257,5 +257,24 @@
velocity = tmpList[14].avg()
windSpeed = tmpList[15].avg()
height = tmpList[16].avg()
+
+ if (c != 0) {
+ val avgU = u / c
+ val avgV = v / c
+ var a = atan(avgU / avgV)
+ a = Math.toDegrees(a)
+ /**
+ * avgU>0;avgV>0: 鐪熷疄瑙掑害澶勪簬绗竴璞¢檺锛屼慨姝e�间负+0掳
+ * avgU>0;avgV<0: 鐪熷疄瑙掑害澶勪簬绗簩璞¢檺锛屼慨姝e�间负+180掳
+ * avgU<0;avgV<0: 鐪熷疄瑙掑害澶勪簬绗笁璞¢檺锛屼慨姝e�间负+180掳
+ * avgU<0;avgV>0: 鐪熷疄瑙掑害澶勪簬绗洓璞¢檺锛屼慨姝e�间负+360掳
+ */
+ a += if (avgV > 0) {
+ if (avgU > 0) 0 else 360
+ } else {
+ 180
+ }
+ windDirection = round(a.toFloat())
+ }
}
}
\ No newline at end of file
--
Gitblit v1.9.3