From 5353617c7b2135ab00f98d8e05b2f8dfb2e096ed Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 30 六月 2021 09:55:40 +0800
Subject: [PATCH] 1. 新增污染权重分析功能

---
 src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt
index 247845c..82e258b 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/BaseWeight.kt
@@ -1,21 +1,53 @@
 package com.flightfeather.uav.model
 
+import com.flightfeather.uav.lightshare.bean.DataVo
+
 /**
  * 鏉冮噸
  * 鏌愮褰卞搷鍥犵礌鍦ㄤ笉鍚屾儏鍐典笅瀵规煇绉嶇洃娴嬫暟鎹骇鐢熺殑鏉冮噸褰卞搷
  */
-abstract class BaseWeight {
+abstract class BaseWeight <M: BaseMData, S : BaseSOP> {
 
-//    鍖洪棿闃堝��
+    abstract val tag:String
+
+    // 鍖洪棿闃堝��
     abstract val sectionValues: List<Double>
-//    鍖洪棿瀵瑰簲鏉冮噸
+
+    // 鍖洪棿瀵瑰簲鏉冮噸
     abstract val weights: List<Double>
+
+    // 涓婃璁$畻鐨勬潈閲嶅��
+    private var lastWeight = -1.0
+
+    // 鏉冮噸鏄惁鍙樺寲
+    var isChange = true
+
+    fun getWeight(mData: M, sop: S): Double? {
+        if (!isChange) {
+            if (lastWeight < 0) {
+                val v = onWeightFactor(mData, sop) ?: return null
+                lastWeight = weightCal(v)
+            }
+//            println("$tag: $lastWeight")
+            return lastWeight
+        } else {
+            val v = onWeightFactor(mData, sop) ?: return null
+            lastWeight = weightCal(v)
+//            println("$tag: $lastWeight")
+            return lastWeight
+        }
+    }
+
+    /**
+     * 鑾峰彇鏉冮噸鍥犲瓙鍊�
+     */
+    abstract fun onWeightFactor(mData: M, sop: S): Double?
 
     /**
      * 鏉冮噸璁$畻
      * @param value 褰卞搷鍥犵礌鐨勫��
      */
-    fun weightCal(value: Double): Double {
+    private fun weightCal(value: Double): Double {
         for (i in sectionValues.indices) {
             if (value < sectionValues[i]) {
                 return weights[i]

--
Gitblit v1.9.3