| | |
| | | |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting |
| | | import com.flightfeather.monitor.domain.ds1.entity.DustSiteData |
| | | import com.flightfeather.monitor.enumration.dust.DataStatus |
| | | import com.flightfeather.monitor.enumration.dust.ExceptionType |
| | | import kotlin.math.abs |
| | | |
| | |
| | | |
| | | private val historyDataList = mutableListOf<DustSiteData>() |
| | | private val tempDataList = mutableListOf<DustSiteData>() |
| | | private val avgListReverse = mutableListOf<Double>() |
| | | private val avgListReverse = mutableListOf<Pair<Double, Boolean>>() |
| | | private var startData: DustSiteData? = null |
| | | private var lastData: DustSiteData? = null |
| | | private var sIndex = 0 |
| | |
| | | */ |
| | | private fun calAvg(list: List<DustSiteData>) { |
| | | var total = .0 |
| | | var valid = true |
| | | val count = list.size |
| | | if (count == 0) return |
| | | list.forEach { total += it.dustValue } |
| | | list.forEach { |
| | | total += it.dustValue |
| | | if (it.flag != DataStatus.N.value) { |
| | | valid = false |
| | | } |
| | | } |
| | | val avg = total / count |
| | | avgListReverse.add(0, avg) |
| | | avgListReverse.add(0, Pair(avg, valid)) |
| | | } |
| | | |
| | | /** |
| | |
| | | return false |
| | | } else { |
| | | // 滑动均值满足数量时,计算均值之间是否连续超过限定比率 |
| | | val rateList = mutableListOf<Double>() |
| | | val rateList = mutableListOf<Pair<Double, Boolean>>() |
| | | for (i in avgListReverse.indices) { |
| | | if (i >= config.changeTrendTimes) break |
| | | val r = calAvgChangeRate(avgListReverse[i], avgListReverse[i + config.changeTrendInterval]) |
| | | rateList.add(r) |
| | | } |
| | | for (y in rateList) { |
| | | if (y < config.changeTrendRate) { |
| | | if (!y.second || y.first < config.changeTrendRate) { |
| | | return false |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 计算滑动均值变化率 |
| | | */ |
| | | private fun calAvgChangeRate(a1: Double, a2: Double): Double { |
| | | return if (a2 == .0) { |
| | | 1.0 |
| | | private fun calAvgChangeRate(a1: Pair<Double, Boolean>, a2: Pair<Double, Boolean>): Pair<Double, Boolean> { |
| | | val valid = a1.second && a2.second |
| | | return if (a2.first == .0) { |
| | | Pair(1.0, valid) |
| | | } else { |
| | | abs(a1 - a2) / a2 |
| | | Pair(abs(a1.first - a2.first) / a2.first, valid) |
| | | } |
| | | } |
| | | |