From 9f12f5605ebffbf6312db9d653f434d56cda20c3 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 30 六月 2021 11:49:55 +0800
Subject: [PATCH] 1. 调整运算逻辑,取消部分中间值的存储,减少内存消耗

---
 src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt        |   30 ++++++++++++++-
 src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt |   38 +++++++++---------
 2 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
index dc24be6..e451fb3 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/BaseModel.kt
@@ -27,6 +27,8 @@
     // 璁$畻缁撴灉
     private val result = mutableSetOf<BaseEffect>()
 
+    private val rMap = mutableMapOf<String, MutableMap<String, MutableMap<String?, MutableList<Double>>>>()
+
     // 缁撴灉绛涢�夋柟寮�
     abstract var sections: List<BaseSection<M, S>>
 
@@ -37,6 +39,7 @@
      */
     fun execute(mDataList: List<M>, sopList: List<S>) {
         result.clear()
+        rMap.clear()
 
         //1. 鏁版嵁棰勫鐞�
         val mList = dataPrep.mDataPrep(mDataList)
@@ -73,7 +76,8 @@
         sections.forEach { it.filter(mData, sop, effect) }
 
         // 淇濆瓨缁撴灉
-        result.add(effect)
+//        result.add(effect)
+        formatConversion2(effect)
     }
 
     fun outputToExcel(
@@ -83,7 +87,7 @@
         sheetName: String = "sheet1",
         done: Boolean = true
     ): Pair<HSSFWorkbook, FileOutputStream>? {
-        val rMap = formatConversion()
+//        val rMap = formatConversion()
 
         val workbook = _workbook ?: HSSFWorkbook()
         val fileName = fName ?: "姹℃煋婧簮鏉冮噸妯″瀷${DateUtil().DateToString(Date(), "yyyy-MM-ddHHmmss")}.xls"
@@ -204,6 +208,28 @@
         return rMap
     }
 
+    private fun formatConversion2(e: BaseEffect) {
+        val rKey = "${e.sourceName}(${e.index})"
+        if (!rMap.containsKey(rKey)) {
+            rMap[rKey] = mutableMapOf()
+        }
+        val lMap = rMap[rKey]!!
+        e.value.forEach { v ->
+            if (!lMap.containsKey(v.first.des)) {
+                lMap[v.first.des] = mutableMapOf()
+            }
+            val tMap = lMap[v.first.des]!!
+            e.tag.forEach { t ->
+                val factorName = v.first.des
+                val lKey = t.levelName + "($factorName)"
+                if (!tMap.containsKey(lKey)) {
+                    tMap[lKey] = mutableListOf()
+                }
+                tMap[lKey]?.add(v.second)
+            }
+        }
+    }
+
     /**
      * 鐩戞祴鏁版嵁鍚堟硶鎬ф鏌�
      */
diff --git a/src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt b/src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt
index 6503d9c..73dbd73 100644
--- a/src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt
+++ b/src/test/kotlin/com/flightfeather/uav/model/epw/EPWModelTest.kt
@@ -56,25 +56,25 @@
 
         val dataSet = mutableListOf<DataVo>()
         val timeSet = listOf(
-            Pair("2021-06-18 15:00:00", "2021-06-18 23:59:59"),
-            Pair("2021-06-19 00:00:00", "2021-06-19 23:59:59"),
-            Pair("2021-06-20 00:00:00", "2021-06-20 23:59:59"),
-            Pair("2021-06-21 00:00:00", "2021-06-21 23:59:59"),
-            Pair("2021-06-22 00:00:00", "2021-06-22 23:59:59"),
-            Pair("2021-06-23 00:00:00", "2021-06-23 23:59:59"),
-            Pair("2021-06-24 00:00:00", "2021-06-24 23:59:59"),
-            Pair("2021-06-25 00:00:00", "2021-06-25 23:59:59"),
-            Pair("2021-06-26 00:00:00", "2021-06-26 23:59:59"),
-            Pair("2021-06-27 00:00:00", "2021-06-27 23:59:59"),
-            Pair("2021-06-28 00:00:00", "2021-06-28 23:59:59"),
-            Pair("2021-06-29 00:00:00", "2021-06-29 23:59:59"),
-            Pair("2021-06-30 00:00:00", "2021-06-30 08:00:00"),
-//            Pair("2021-03-26 11:28:12", "2021-03-26 21:30:00"),
-//            Pair("2021-04-09 07:18:12", "2021-04-09 22:04:39"),
-//            Pair("2021-04-10 08:00:02", "2021-04-10 09:44:18"),
-//            Pair("2021-04-21 16:46:12", "2021-04-21 21:18:35"),
-//            Pair("2021-05-24 11:10:12", "2021-05-24 19:31:02"),
-//            Pair("2021-06-04 09:02:40", "2021-06-04 20:14:18"),
+//            Pair("2021-06-18 15:00:00", "2021-06-18 23:59:59"),
+//            Pair("2021-06-19 00:00:00", "2021-06-19 23:59:59"),
+//            Pair("2021-06-20 00:00:00", "2021-06-20 23:59:59"),
+//            Pair("2021-06-21 00:00:00", "2021-06-21 23:59:59"),
+//            Pair("2021-06-22 00:00:00", "2021-06-22 23:59:59"),
+//            Pair("2021-06-23 00:00:00", "2021-06-23 23:59:59"),
+//            Pair("2021-06-24 00:00:00", "2021-06-24 23:59:59"),
+//            Pair("2021-06-25 00:00:00", "2021-06-25 23:59:59"),
+//            Pair("2021-06-26 00:00:00", "2021-06-26 23:59:59"),
+//            Pair("2021-06-27 00:00:00", "2021-06-27 23:59:59"),
+//            Pair("2021-06-28 00:00:00", "2021-06-28 23:59:59"),
+//            Pair("2021-06-29 00:00:00", "2021-06-29 23:59:59"),
+//            Pair("2021-06-30 00:00:00", "2021-06-30 08:00:00"),
+            Pair("2021-03-26 11:28:12", "2021-03-26 21:30:00"),
+            Pair("2021-04-09 07:18:12", "2021-04-09 22:04:39"),
+            Pair("2021-04-10 08:00:02", "2021-04-10 09:44:18"),
+            Pair("2021-04-21 16:46:12", "2021-04-21 21:18:35"),
+            Pair("2021-05-24 11:10:12", "2021-05-24 19:31:02"),
+            Pair("2021-06-04 09:02:40", "2021-06-04 20:14:18"),
         )
 
         val epwModel = EPWModel()

--
Gitblit v1.9.3