[Desc]fix step offset

main
AlexWang 2 years ago
parent 47bd380e10
commit 78fb46bd7f

@ -142,18 +142,29 @@ class QueryDataActivity : BaseActivity() {
val newMapList = gasNewMap[type] val newMapList = gasNewMap[type]
var startGas: Gas? = null var startGas: Gas? = null
var gasValue = 0.0 var gasValue = 0.0
var tempTime = 0L
var count = 0 var count = 0
list.forEachIndexed { index, gas -> list.forEachIndexed { index, gas ->
if (startGas == null) { if (startGas == null) {
startGas = gas startGas = gas
tempTime = gas.time - ((gas.time - startTime) % intervalMs)
gasValue = 0.0 gasValue = 0.0
count = 0 count = 0
} }
if (gas.time - startGas!!.time > intervalMs) { if (gas.time - tempTime > intervalMs) {
if (gasValue != 0.0) { 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))
}
}
if (gasValue >= 0.0) {
startGas!!.gasValue = gasValue / count startGas!!.gasValue = gasValue / count
newMapList?.add(startGas!!) newMapList?.add(startGas!!)
} }
tempTime += intervalMs
startGas = gas startGas = gas
gasValue = gas.gasValue gasValue = gas.gasValue
count = 1 count = 1
@ -164,7 +175,7 @@ class QueryDataActivity : BaseActivity() {
// 最后一个特殊处理 // 最后一个特殊处理
if (list.size - 1 == index) { if (list.size - 1 == index) {
if (gasValue != 0.0) { if (gasValue >= 0.0) {
startGas!!.gasValue = gasValue / count startGas!!.gasValue = gasValue / count
newMapList?.add(startGas!!) newMapList?.add(startGas!!)
} }

Loading…
Cancel
Save