From bb2e504688442f71f62736cf042a85e86d637f31 Mon Sep 17 00:00:00 2001 From: xiaowusky Date: Fri, 14 Jul 2023 11:05:38 +0800 Subject: [PATCH] =?UTF-8?q?desc:=E6=A0=B9=E6=8D=AE=E6=B0=94=E4=BD=93?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=88=9B=E5=BB=BAmap=E3=80=82=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=96=B0=E7=9A=84=E7=AE=80=E5=86=99=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../watcher/ui/QueryDataActivity.kt | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/QueryDataActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/QueryDataActivity.kt index 9730b5b..eb30bba 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/QueryDataActivity.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/QueryDataActivity.kt @@ -136,24 +136,29 @@ class QueryDataActivity : BaseActivity() { val gasDao = DBUtils.gasDao() val gasList = gasDao.getAllByTime(startTime, endTime) // 多气体,分开创建list,存储之后。 再分步 - val gasTypeDao = DBUtils.gasTypeDao() - val gasTypes = gasTypeDao.getAll() - // 每种气体建立一个list - val gasMap = HashMap>() - // 预先创建分步合一之后的list - val gasNewMap = HashMap>() - gasTypes.forEach { - gasMap[it.type] = mutableListOf() - gasNewMap[it.type] = mutableListOf() - } - // 分开各个气体的数据 - gasList.forEach { - val list = gasMap[it.gasName] - list?.add(it) + val gasMap = gasList.groupBy { + it.gasName } + val gasNewMap = HashMap>() +// // 多气体,分开创建list,存储之后。 再分步 +// val gasTypeDao = DBUtils.gasTypeDao() +// val gasTypes = gasTypeDao.getAll() +// // 每种气体建立一个list +// val gasMap = HashMap>() +// // 预先创建分步合一之后的list +// val gasNewMap = HashMap>() +// gasTypes.forEach { +// gasMap[it.type] = mutableListOf() +// gasNewMap[it.type] = mutableListOf() +// } +// // 分开各个气体的数据 +// gasList.forEach { +// val list = gasMap[it.gasName] +// list?.add(it) +// } //根据步长分割数据填充新的列表 gasMap.forEach { (type, list) -> - val newMapList = gasNewMap[type] + val newMapList = mutableListOf() var startGas: Gas? = null var gasValue = 0.0 var tempTime = 0L @@ -169,14 +174,14 @@ class QueryDataActivity : BaseActivity() { if (gasValue >= 0.0) { startGas!!.gasValue = gasValue / count startGas!!.time = tempTime - newMapList?.add(startGas!!) + newMapList.add(startGas!!) } val offsetTime = gas.time - tempTime val num = offsetTime / intervalMs if (num > 0) { for (i in num downTo 1) { tempTime += intervalMs - newMapList?.add(gas.copy(time = tempTime, gasValue = -1.0)) + newMapList.add(gas.copy(time = tempTime, gasValue = -1.0)) } } tempTime += intervalMs @@ -193,10 +198,11 @@ class QueryDataActivity : BaseActivity() { if (gasValue >= 0.0) { startGas!!.gasValue = gasValue / count startGas!!.time = tempTime - newMapList?.add(startGas!!) + newMapList.add(startGas!!) } } } + gasNewMap[type] = newMapList } mGasNewMap = gasNewMap var newList = mutableListOf()