desc:根据气体类型创建map。使用新的简写方式

main
xiaowusky 2 years ago
parent 511999b753
commit bb2e504688

@ -136,24 +136,29 @@ class QueryDataActivity : BaseActivity() {
val gasDao = DBUtils.gasDao() val gasDao = DBUtils.gasDao()
val gasList = gasDao.getAllByTime(startTime, endTime) val gasList = gasDao.getAllByTime(startTime, endTime)
// 多气体分开创建list存储之后。 再分步 // 多气体分开创建list存储之后。 再分步
val gasTypeDao = DBUtils.gasTypeDao() val gasMap = gasList.groupBy {
val gasTypes = gasTypeDao.getAll() it.gasName
// 每种气体建立一个list
val gasMap = HashMap<String, MutableList<Gas>>()
// 预先创建分步合一之后的list
val gasNewMap = HashMap<String, MutableList<Gas>>()
gasTypes.forEach {
gasMap[it.type] = mutableListOf()
gasNewMap[it.type] = mutableListOf()
}
// 分开各个气体的数据
gasList.forEach {
val list = gasMap[it.gasName]
list?.add(it)
} }
val gasNewMap = HashMap<String, MutableList<Gas>>()
// // 多气体分开创建list存储之后。 再分步
// val gasTypeDao = DBUtils.gasTypeDao()
// val gasTypes = gasTypeDao.getAll()
// // 每种气体建立一个list
// val gasMap = HashMap<String, MutableList<Gas>>()
// // 预先创建分步合一之后的list
// val gasNewMap = HashMap<String, MutableList<Gas>>()
// gasTypes.forEach {
// gasMap[it.type] = mutableListOf()
// gasNewMap[it.type] = mutableListOf()
// }
// // 分开各个气体的数据
// gasList.forEach {
// val list = gasMap[it.gasName]
// list?.add(it)
// }
//根据步长分割数据填充新的列表 //根据步长分割数据填充新的列表
gasMap.forEach { (type, list) -> gasMap.forEach { (type, list) ->
val newMapList = gasNewMap[type] val newMapList = mutableListOf<Gas>()
var startGas: Gas? = null var startGas: Gas? = null
var gasValue = 0.0 var gasValue = 0.0
var tempTime = 0L var tempTime = 0L
@ -169,14 +174,14 @@ class QueryDataActivity : BaseActivity() {
if (gasValue >= 0.0) { if (gasValue >= 0.0) {
startGas!!.gasValue = gasValue / count startGas!!.gasValue = gasValue / count
startGas!!.time = tempTime startGas!!.time = tempTime
newMapList?.add(startGas!!) newMapList.add(startGas!!)
} }
val offsetTime = gas.time - tempTime val offsetTime = gas.time - tempTime
val num = offsetTime / intervalMs val num = offsetTime / intervalMs
if (num > 0) { if (num > 0) {
for (i in num downTo 1) { for (i in num downTo 1) {
tempTime += intervalMs tempTime += intervalMs
newMapList?.add(gas.copy(time = tempTime, gasValue = -1.0)) newMapList.add(gas.copy(time = tempTime, gasValue = -1.0))
} }
} }
tempTime += intervalMs tempTime += intervalMs
@ -193,10 +198,11 @@ class QueryDataActivity : BaseActivity() {
if (gasValue >= 0.0) { if (gasValue >= 0.0) {
startGas!!.gasValue = gasValue / count startGas!!.gasValue = gasValue / count
startGas!!.time = tempTime startGas!!.time = tempTime
newMapList?.add(startGas!!) newMapList.add(startGas!!)
} }
} }
} }
gasNewMap[type] = newMapList
} }
mGasNewMap = gasNewMap mGasNewMap = gasNewMap
var newList = mutableListOf<Gas>() var newList = mutableListOf<Gas>()

Loading…
Cancel
Save