package com.flightfeather.uav.model
|
|
import com.flightfeather.uav.lightshare.bean.DataVo
|
|
/**
|
* 统计分类
|
* 同一类型的监测因子按照某一属性进行分段综合统计,输出统计结果,
|
* 常见的如按照时间进行分段统计
|
*/
|
abstract class BaseSection<M : BaseMData, S : BaseSOP> {
|
|
// 区间阈值
|
abstract val sectionValues: List<Double>
|
|
// 区间对应类型
|
abstract val sectionType: List<String>
|
|
// 常驻标签
|
open val constType = listOf<String>()
|
|
abstract val tagClz: Class<out BaseTag>
|
|
fun filter(mData: M, sop: S, effect: BaseEffect) {
|
val v = onSectionValue(mData, sop, effect)
|
val type = sectionCal(v)
|
val tag = tagClz.newInstance()
|
tag.level = type.first
|
tag.levelName = type.second
|
effect.tag.add(tag)
|
|
var level = sectionType.size
|
constType.forEach {
|
val cTag = tagClz.newInstance()
|
cTag.level = level
|
cTag.levelName = it
|
effect.tag.add(cTag)
|
level++
|
}
|
}
|
|
abstract fun onSectionValue(mData: M, sop: S, effect: BaseEffect): Double
|
|
/**
|
* 类型筛选
|
* @param value 影响因素的值
|
*/
|
private fun sectionCal(value: Double): Pair<Int, String> {
|
for (i in sectionValues.indices) {
|
if (value < sectionValues[i]) {
|
return Pair(i, sectionType[i])
|
}
|
}
|
return Pair(sectionType.lastIndex, sectionType.last())
|
}
|
}
|