package cn.flightfeather.supervision.business.autooutput.dataanalysis
|
|
import cn.flightfeather.supervision.business.autooutput.AopOutput
|
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataSource
|
import cn.flightfeather.supervision.business.autooutput.datasource.AopDbMapper
|
import cn.flightfeather.supervision.business.autooutput.datasource.AopSceneTypeCheck
|
import cn.flightfeather.supervision.domain.ds3.entity.JSDustData
|
import cn.flightfeather.supervision.domain.ds3.entity.JSDustSiteMap
|
import cn.flightfeather.supervision.domain.ds3.enum.JSSceneType
|
import cn.flightfeather.supervision.domain.ds3.mapper.JSDustDataMapper
|
import cn.flightfeather.supervision.domain.ds3.mapper.JSDustSiteMapMapper
|
import tk.mybatis.mapper.entity.Example
|
import java.time.Duration
|
import java.time.LocalDateTime
|
import java.time.ZoneId
|
import kotlin.math.round
|
|
/**
|
* 金山扬尘监测数据统计
|
*/
|
abstract class JSDustDataAnalysis(
|
aopDbMapper: AopDbMapper,
|
aopSceneTypeCheck: AopSceneTypeCheck,
|
aopOutput: AopOutput,
|
private val jsDustDataMapper: JSDustDataMapper,
|
private val jsDustSiteMapMapper: JSDustSiteMapMapper,
|
) : AopDataAnalysis<JSDustData>(aopDbMapper, aopSceneTypeCheck, aopOutput){
|
|
abstract var sceneType: JSSceneType
|
|
override fun districtAvg(source: AopDataSource?): Double? {
|
var total = .0
|
var count = 0
|
|
var page = 0
|
val perPage = 20000
|
var hasNextPage = false
|
do {
|
val res = jsDustDataMapper
|
.getDataBySceneType(source?.config?.startTime, source?.config?.endTime, sceneType.value,
|
page * perPage, perPage)
|
res.forEach {
|
it?.dustValue?.let { v ->
|
total += v
|
count++
|
}
|
}
|
page++
|
hasNextPage = res.isNotEmpty()
|
println("均值计算:当前页码 $page")
|
} while (hasNextPage)
|
|
return if (count == 0) {
|
.0
|
} else {
|
round((total / count) * 1000) / 1000
|
}
|
}
|
|
override fun getDeviceCode(data: JSDustData?): String? {
|
return data?.mnCode
|
}
|
|
override fun fetchDataResources(evaluationScene: AopDataSource.EvaluationScene): List<List<JSDustData?>> {
|
val dustSiteMaps = jsDustSiteMapMapper.selectByExample(Example(JSDustSiteMap::class.java).apply {
|
createCriteria().andEqualTo("svUserId", evaluationScene.userInfo.value?.guid)
|
.andIsNotNull("jsDeviceCode")
|
})
|
if (dustSiteMaps.isEmpty()) return emptyList()
|
|
val mnCodeList = dustSiteMaps.map { it?.jsDeviceCode }
|
val map = mutableMapOf<String?, MutableList<JSDustData?>>()
|
jsDustDataMapper.selectByExample(Example(JSDustData::class.java).apply {
|
createCriteria().andBetween("lst", evaluationScene.config?.startTime, evaluationScene.config?.endTime)
|
.andIn("mnCode", mnCodeList)
|
}).forEach {
|
if (!map.containsKey(it?.mnCode)) {
|
map[it?.mnCode] = mutableListOf()
|
}
|
map[it?.mnCode]?.add(it)
|
}
|
val res = mutableListOf<List<JSDustData?>>()
|
map.forEach { (_, u) ->
|
res.add(u)
|
}
|
return res
|
}
|
|
override fun exceedTimes(data: JSDustData, t: TempResult) {
|
data.dustValue?.let {
|
if (it >= 1) {
|
t.count++
|
}
|
}
|
}
|
|
override fun avg(data: JSDustData, t: TempResult) {
|
data.dustValue?.let {
|
t.total += it
|
t.count++
|
}
|
}
|
|
override fun max(data: JSDustData, t: TempResult) {
|
data.dustValue?.let {
|
if (it > t.total) {
|
t.total = it
|
}
|
}
|
}
|
|
override fun min(data: JSDustData, t: TempResult) {
|
data.dustValue?.let {
|
if (t.count == 0 || it < t.total) {
|
t.total = it
|
}
|
// 通过t.count 来判定是否是初始化状态
|
if (t.count == 0) t.count = 1
|
}
|
}
|
|
override fun overAvgRate(avg: Double, dAvg: Double?): Double? {
|
return super.overAvgRate(avg, dAvg)
|
}
|
|
override fun effectiveRate(
|
dataList: List<List<JSDustData?>>,
|
evaluationScene: AopDataSource.EvaluationScene,
|
): Double {
|
if (dataList.isEmpty()) return .0
|
|
val st = LocalDateTime.ofInstant(evaluationScene.config?.startTime?.toInstant(), ZoneId.systemDefault())
|
val et = LocalDateTime.ofInstant(evaluationScene.config?.endTime?.toInstant(), ZoneId.systemDefault())
|
val days = Duration.between(st, et).toDays() + 1
|
|
return if (days == 0L) {
|
.0
|
} else {
|
round((count(dataList) / (dataList.size * days * 24 * 4).toDouble()) * 1000) / 1000
|
}
|
}
|
}
|