From c2a5872d4ab060e0e19a14be271a4b50d5e6059e Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 21 六月 2021 11:04:30 +0800
Subject: [PATCH] 1. 新增走航检测污染溯源模型逻辑

---
 src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt   |   18 ++++++
 src/main/kotlin/com/flightfeather/uav/UAVApplication.kt            |    6 -
 src/main/kotlin/com/flightfeather/uav/model/BaseSection.kt         |    9 +++
 src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt |    3 +
 src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt          |   26 ++++++++
 src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt        |   38 ++++++++++++
 src/main/kotlin/com/flightfeather/uav/socket/UAVByteDataDecoder.kt |    6 +-
 src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt   |   32 ++++++++++
 src/main/kotlin/com/flightfeather/uav/model/package-info.java      |    5 +
 9 files changed, 136 insertions(+), 7 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/UAVApplication.kt b/src/main/kotlin/com/flightfeather/uav/UAVApplication.kt
index 0557bb3..f9023b1 100644
--- a/src/main/kotlin/com/flightfeather/uav/UAVApplication.kt
+++ b/src/main/kotlin/com/flightfeather/uav/UAVApplication.kt
@@ -18,12 +18,10 @@
     @Autowired
     lateinit var electricProcessor: ElectricProcessor
 
-    private val socketServer = UnderwaySocketServer()
-
     @Bean
     fun runner() = ApplicationRunner{
-        socketServer.startUnderwayServer(9030, underwayProcessor)
-        socketServer.startElectricServer(9009, electricProcessor)
+        UnderwaySocketServer().startUnderwayServer(9030, underwayProcessor)
+        UnderwaySocketServer().startElectricServer(9009, electricProcessor)
     }
 }
 
diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt
index 3c9d5fb..678ec0a 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt
@@ -11,6 +11,9 @@
 import java.text.SimpleDateFormat
 import java.util.*
 
+/**
+ * 鏃犱汉鑸归噰闆嗘暟鎹牸寮忚浆鎹�
+ */
 class FileExchange {
 
     companion object {
diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseSection.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseSection.kt
new file mode 100644
index 0000000..01a3310
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/BaseSection.kt
@@ -0,0 +1,9 @@
+package com.flightfeather.uav.model
+
+/**
+ * 缁熻鍒嗘鎴潰
+ * 鍚屼竴绫诲瀷鐨勭洃娴嬪洜瀛愭寜鐓ф煇涓�灞炴�ц繘琛屽垎娈电患鍚堢粺璁★紝杈撳嚭缁熻缁撴灉锛�
+ * 甯歌鐨勫鎸夌収鏃堕棿杩涜鍒嗘缁熻
+ */
+abstract class BaseSection {
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt
new file mode 100644
index 0000000..247845c
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt
@@ -0,0 +1,26 @@
+package com.flightfeather.uav.model
+
+/**
+ * 鏉冮噸
+ * 鏌愮褰卞搷鍥犵礌鍦ㄤ笉鍚屾儏鍐典笅瀵规煇绉嶇洃娴嬫暟鎹骇鐢熺殑鏉冮噸褰卞搷
+ */
+abstract class BaseWeight {
+
+//    鍖洪棿闃堝��
+    abstract val sectionValues: List<Double>
+//    鍖洪棿瀵瑰簲鏉冮噸
+    abstract val weights: List<Double>
+
+    /**
+     * 鏉冮噸璁$畻
+     * @param value 褰卞搷鍥犵礌鐨勫��
+     */
+    fun weightCal(value: Double): Double {
+        for (i in sectionValues.indices) {
+            if (value < sectionValues[i]) {
+                return weights[i]
+            }
+        }
+        return weights.last()
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt
new file mode 100644
index 0000000..be8689e
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWModel.kt
@@ -0,0 +1,38 @@
+package com.flightfeather.uav.model.epw
+
+import com.flightfeather.uav.domain.entity.Company
+import com.flightfeather.uav.lightshare.bean.DataVo
+import java.math.BigDecimal
+
+/**
+ * 宸ヤ笟浼佷笟姹℃煋鏉冮噸鍒嗘瀽妯″瀷
+ * 鏍规嵁璧拌埅鐩戞祴鏁版嵁锛岀粨鍚堥閫熴�侀鍚戙�佺洃娴嬬偣涓庝紒涓氱殑鐩稿浣嶇疆绛夊洜绱狅紝璁$畻浼佷笟瀵圭洃娴嬪尯鍩熺殑褰卞搷绋嬪害
+ * @author riku
+ */
+class EPWModel {
+
+//    private val windDirWeight = WindDirWeight()
+//    private val windDisWeight = WindDisWeight()
+
+    private lateinit var datas: List<DataVo>
+    private lateinit var sources: List<Company>
+
+    fun execute() {
+        datas.forEach d@{d ->
+            if (d.lng == null || d.lng == 0.0 || d.lat == null || d.lat == 0.0) {
+                return@d
+            }
+
+            sources.forEach s@ { s ->
+                // 缁忕含搴︽湁鏁堟�у垽鏂�
+                if (s.ciLongitude == null || s.ciLongitude == BigDecimal(0) || s.ciLatitude == null || s.ciLatitude == BigDecimal(0)) {
+                    return@s
+                }
+
+                val p1 = Pair(d.lng!!, d.lat!!)
+                val p2 = Pair(s.ciLongitude.toDouble(), s.ciLatitude.toDouble())
+//                windDirWeight.getWeight(p1, p2)
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt
new file mode 100644
index 0000000..16baf70
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt
@@ -0,0 +1,32 @@
+package com.flightfeather.uav.model.epw
+
+import com.flightfeather.uav.model.BaseWeight
+import kotlin.math.PI
+import kotlin.math.abs
+import kotlin.math.atan2
+import kotlin.math.sqrt
+
+/**
+ *
+ */
+class WindDirWeight : BaseWeight() {
+    override val sectionValues: List<Double> = listOf(22.5, 67.5, 112.5, 157.5, 180.0)
+    override val weights: List<Double> = listOf(1.0, 0.8, 0.5, 0.2, 0.1)
+
+    fun getWeight(deg: Double):Double {
+        return weightCal(deg)
+    }
+
+    fun getWeight(p1: Pair<Double, Double>, p2: Pair<Double, Double>, wd: Int): Double {
+        val dx = p2.first - p1.first
+        val dy = p2.second - p1.second
+        var x1 = atan2(dy, dx) * 180 / PI
+        if (x1 < 0) x1 += 360
+        var x2 = 270 - wd
+        if (x2 < 0) x2 += 360
+        x1 = abs(x2 - x1)
+        if (x1>180) x1 = 360 - x1
+
+        return weightCal(x1)
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt
new file mode 100644
index 0000000..4a61f24
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDisWeight.kt
@@ -0,0 +1,18 @@
+package com.flightfeather.uav.model.epw
+
+import com.flightfeather.uav.model.BaseWeight
+
+/**
+ * 椋庨�熻窛绂绘潈閲�
+ * 鐩戞祴鐐逛笌姹℃煋婧愪箣闂寸殑鐗╃悊璺濈涓庡綋鍓嶉閫熷緱鍑虹殑鏉冮噸
+ */
+class WindDisWeight : BaseWeight() {
+
+    override val sectionValues: List<Double> = listOf(2.0, 5.0, 8.0, 12.0, 20.0, 30.0)
+    override val weights: List<Double> = listOf(1.0, 0.8, 0.6, 0.5, 0.3, 0.0)
+
+    fun getWeight(dis: Double, ws: Double): Double {
+        val value = dis / ws / 60
+        return weightCal(value)
+    }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/model/package-info.java b/src/main/kotlin/com/flightfeather/uav/model/package-info.java
new file mode 100644
index 0000000..5f1176f
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/model/package-info.java
@@ -0,0 +1,5 @@
+package com.flightfeather.uav.model;
+/*
+* 绠楁硶妯″瀷鐩稿叧
+* 鍖呮嫭姹℃煋婧簮銆佹薄鏌撻噸鐐瑰尯鍩熷垎鏋愮瓑鍔熻兘
+* */
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/UAVByteDataDecoder.kt b/src/main/kotlin/com/flightfeather/uav/socket/UAVByteDataDecoder.kt
index 47017e0..9b22dbf 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/UAVByteDataDecoder.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/UAVByteDataDecoder.kt
@@ -16,8 +16,8 @@
         const val BASE_LENGTH = DataPackageDecoder.HEAD_BYTES + DataPackageDecoder.COMMAND_UNIT_BYTES +
                 DataPackageDecoder.DEVICE_CODE_BYTES + DataPackageDecoder.DATA_LENGTH + DataPackageDecoder.BCC_BYTES
         const val HEAD1 = 0x01.toByte()
-        const val COMMAND_1 = 0x01.toByte()
-        const val COMMAND_2 = 0x01.toByte()
+        const val COMMAND_1 = 0x04.toByte()
+        const val COMMAND_2 = 0x05.toByte()
         const val HEAD_LENGTH = DataPackageDecoder.HEAD_BYTES + DataPackageDecoder.COMMAND_UNIT_BYTES +
                 DataPackageDecoder.DEVICE_CODE_BYTES
     }
@@ -46,7 +46,7 @@
                     val b = ByteArray(HEAD_LENGTH)
                     it.readBytes(b)
                     if (b[0] == HEAD1 &&
-                        (b[1] == COMMAND_1 || b[2] == COMMAND_2)) {
+                        (b[1] == COMMAND_1 || b[1] == COMMAND_2)) {
                         b.forEach {b ->
                             dataList.add(b)
                         }

--
Gitblit v1.9.3