opt BlockStrategy.kt

This commit is contained in:
tongchenfei
2021-01-11 14:18:18 +08:00
parent 3ffec794c7
commit 07f8ccfcb6
6 changed files with 97 additions and 5 deletions

View File

@@ -50,7 +50,7 @@ private const val SPEED_NORMAL_COUNT = "SPEED _NORMAL_COUNT"
*/
class BlockStrategy(private val context: Context, private val apis: IMogoServiceApis) {
private var startRecordTime: Long = 0
private var speedCacheList = ArrayList<Float>()
private var speedCacheList = ArrayList<Int>()
/**
* 停车标志位当速度为0时加1超过[STOP_FLAG_THRESHOLD]判定为停车,不认为是拥堵,这组数据无效
@@ -91,9 +91,9 @@ class BlockStrategy(private val context: Context, private val apis: IMogoService
speedCacheList.clear()
}
speedCacheList.add(speed)
speedCacheList.add(currentSpeed)
if (speed == 0F) {
if (currentSpeed == 0) {
stopFlag++
} else if (stopFlag < STOP_FLAG_THRESHOLD) {
// 如果本次计算期间stopFlag还没超过阈值就置为零如果超过阈值了说明本次计算期间存在超过阈值的停止次数就舍弃掉本次计算
@@ -135,7 +135,7 @@ class BlockStrategy(private val context: Context, private val apis: IMogoService
// 到达时间限制,上报速度,数据清空
if (stopFlag < STOP_FLAG_THRESHOLD) {
// 停车标志位小于阈值,判定不是停车,计算平均值,进行上报
var sum = 0F
var sum = 0
speedCacheList.forEach {
sum += it
}