src/main/kotlin/com/flightfeather/uav/biz/FactorFilter.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,47 @@ package com.flightfeather.uav.biz import com.flightfeather.uav.socket.eunm.FactorType /** * æé主è¦åæå åï¼ä»¥åå ³èå å * å¨åæ°æ®å¼å¸¸åæä»¥åæ°æ®ç»è®¡æ¶ï¼ç¨äºå³å®æ¯å¦éè¦è¿è¡å¤ç该å åã * @date 2024/6/27 * @author feiyu02 */ class FactorFilter private constructor(){ data class SelectedFactor( val main:FactorType, var subs:List<FactorType> = emptyList() ) inner class Builder{ fun withMain(factorType: FactorType): Builder { selectedList.add(SelectedFactor(factorType)) return this } fun withSubs(subs: List<FactorType>): Builder { if (selectedList.isNotEmpty()) { selectedList.last().subs = subs } return this } fun create(): FactorFilter { return this@FactorFilter } } companion object{ fun builder() = FactorFilter().Builder() fun default() = builder().create() } // æéå åéå val selectedList = mutableListOf<SelectedFactor>() fun mainList(): List<FactorType> { return selectedList.map { it.main } } } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionAnalysis.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.biz.dataanalysis import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig import com.flightfeather.uav.biz.dataanalysis.model.ExceptionResult import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType @@ -34,24 +35,26 @@ * çæä¸æ¡å¼å¸¸åæç»æ */ open fun newResult( start: BaseRealTimeData, end: BaseRealTimeData?, factorIndex: Int, start: BaseRealTimeData, end: BaseRealTimeData?, factor: FactorFilter.SelectedFactor, exceptionData: List<BaseRealTimeData>, ): ExceptionResult { val eType = getExceptionType() val factorType = FactorType.getByIndex(factorIndex) return ExceptionResult().apply { missionCode = config.mission.missionCode deviceCode = start.deviceCode exception = eType.des exceptionType = eType.value factorId = factorType?.value factorName = factorType?.des factorId = factor.main.value factorName = factor.main.des subFactorId = factor.subs.map { it.value } subFactorName = factor.subs.map { it.des } selectedFactor = factor startTime = DateUtil.instance.dateToString(start.dataTime, DateUtil.DateStyle.HH_MM_SS) endTime = DateUtil.instance.dateToString(end?.dataTime, DateUtil.DateStyle.HH_MM_SS) ?: startTime startData = start.getByFactorIndex(factorIndex) endData = end?.getByFactorIndex(factorIndex) ?: startData startData = start.getByFactorType(factor.main) endData = end?.getByFactorType(factor.main) ?: startData val s = dataSummary(exceptionData, factorIndex) val s = dataSummary(exceptionData, factor.main) avg = s.first min = s.second max = s.third @@ -60,13 +63,13 @@ } } fun dataSummary(exceptionData: List<BaseRealTimeData?>, factorIndex: Int): Triple<Float, Float, Float> { fun dataSummary(exceptionData: List<BaseRealTimeData?>, factorType: FactorType): Triple<Float, Float, Float> { var min = -1f var max = -1f var total = 0f var count = 0 exceptionData.forEach { val value = it?.getByFactorIndex(factorIndex) ?: return@forEach val value = it?.getByFactorType(factorType) ?: return@forEach if (min == -1f || min > value) { min = value } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuous.kt
@@ -1,7 +1,9 @@ package com.flightfeather.uav.biz.dataanalysis import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.socket.eunm.FactorType /** * è¿ç»ç±»åçå¼å¸¸åæåºç±»,éç¨äºå½åæ°æ®ä¸ç¸é»æ°æ®ä¹é´æå ³èå ³ç³»çæ åµ @@ -13,29 +15,58 @@ private const val OFFSET = 10 } // èµ·å§æ°æ®ä¸æ protected var sIndex = mutableListOf<Int>() inner class Tag { // èµ·å§æ°æ®ä¸æ var sIndex = 0 // èµ·å§æ°æ®å¯¹è±¡ protected var startData = mutableListOf<BaseRealTimeData?>() // èµ·å§æ°æ®å¯¹è±¡ var startData :BaseRealTimeData? = null // æ«å°¾æ°æ®ä¸æ protected var eIndex = mutableListOf<Int>() // æ«å°¾æ°æ®ä¸æ var eIndex = -1 // æ«å°¾æ°æ®å¯¹è±¡ protected var lastData: BaseRealTimeData? = null // æ«å°¾æ°æ®å¯¹è±¡ var endData: BaseRealTimeData? = null // å¼å¸¸æ°æ®æ®µ protected var exceptionData = mutableListOf<MutableList<BaseRealTimeData>>() // å¼å¸¸æ°æ®æ®µ var exceptionData = mutableListOf<BaseRealTimeData>() // æ¯å¦åå¨å¼å¸¸ var existException = false fun refreshAfterCheckResult(data: BaseRealTimeData) { sIndex = eIndex startData = data exceptionData.clear() exceptionData.add(data) } } protected val tagMap = mutableMapOf<FactorType, Tag>() // // èµ·å§æ°æ®ä¸æ // protected var sIndex = mutableListOf<Int>() // // // èµ·å§æ°æ®å¯¹è±¡ // protected var startData = mutableListOf<BaseRealTimeData?>() // // // æ«å°¾æ°æ®ä¸æ // protected var eIndex = mutableListOf<Int>() // // // å¼å¸¸æ°æ®æ®µ // protected var exceptionData = mutableListOf<MutableList<BaseRealTimeData>>() // protected var existException = mutableListOf<Boolean>() // èµ·å§æ°æ®ä¸æ«å°¾æ°æ®é´é open var durationCount = 1 protected var existException = mutableListOf<Boolean>() // æ«å°¾æ°æ®å¯¹è±¡ protected var lastData: BaseRealTimeData? = null /** * 夿æ¯å¦æ»¡è¶³å¼å¸¸æ¡ä»¶ */ abstract fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): List<Boolean> abstract fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> /** * 夿å¼å¸¸åºç°çè¿ç»æ¶é¿æ¯å¦æ»¡è¶³æ¡ä»¶ @@ -45,44 +76,75 @@ override fun init() { super.init() lastData = null repeat(config.factorCount) { startData.add(null) sIndex.add(0) eIndex.add(-1) existException.add(false) exceptionData.add(mutableListOf()) // repeat(config.factorCount) { // startData.add(null) // sIndex.add(0) // eIndex.add(-1) // existException.add(false) // exceptionData.add(mutableListOf()) // } config.factorFilter.mainList().forEach {f-> tagMap[f] = Tag() } } override fun onNextData(data: BaseRealTimeData) { val isContinue = isContinuous(lastData, data) val hasException = judgeException(lastData, data) repeat(config.factorCount) { i -> eIndex[i]++ // èµ·å§æ°æ® if (lastData == null) { refreshAfterCheckResult(i, data) } // 夿ç¸é»æ°æ®æ¯å¦è¿ç»å¹¶ä¸æ¯å¦æ»¡è¶³å¼å¸¸å¤æ if (!isContinue) { checkResult() // æ°æ®ä¸è¿ç»æ¶ï¼è®°å½å¼å¸¸æ åµ if (eIndex[i] - sIndex[i] >= durationCount) { refreshAfterCheckResult(i, data) config.factorFilter.mainList().forEach {f-> tagMap[f]?.let { it.eIndex++ // èµ·å§æ°æ® if (it.endData == null) { it.refreshAfterCheckResult(data) } } else { if (hasException[i]) { existException[i] = true exceptionData[i].add(data) } else { // å¼å¸¸ä¸åéå¤åºç°æ¶ï¼è®°å½å¼å¸¸æ åµ // 夿ç¸é»æ°æ®æ¯å¦è¿ç»å¹¶ä¸æ¯å¦æ»¡è¶³å¼å¸¸å¤æ if (!isContinue) { checkResult() if (eIndex[i] - sIndex[i] >= durationCount) { refreshAfterCheckResult(i, data) // æ°æ®ä¸è¿ç»æ¶ï¼è®°å½å¼å¸¸æ åµ if (it.eIndex - it.sIndex >= durationCount) { it.refreshAfterCheckResult(data) } } else { if (hasException[f] == true) { it.existException = true it.exceptionData.add(data) } else { // å¼å¸¸ä¸åéå¤åºç°æ¶ï¼è®°å½å¼å¸¸æ åµ checkResult() if (it.eIndex - it.sIndex >= durationCount) { it.refreshAfterCheckResult(data) } } } } } // repeat(config.factorCount) { i -> // eIndex[i]++ // // èµ·å§æ°æ® // if (lastData == null) { // refreshAfterCheckResult(i, data) // } // // 夿ç¸é»æ°æ®æ¯å¦è¿ç»å¹¶ä¸æ¯å¦æ»¡è¶³å¼å¸¸å¤æ // if (!isContinue) { // checkResult() // // æ°æ®ä¸è¿ç»æ¶ï¼è®°å½å¼å¸¸æ åµ // if (eIndex[i] - sIndex[i] >= durationCount) { // refreshAfterCheckResult(i, data) // } // } else { // if (hasException[i]) { // existException[i] = true // exceptionData[i].add(data) // } else { // // å¼å¸¸ä¸åéå¤åºç°æ¶ï¼è®°å½å¼å¸¸æ åµ // checkResult() // if (eIndex[i] - sIndex[i] >= durationCount) { // refreshAfterCheckResult(i, data) // } // } // } // } lastData = data } @@ -90,33 +152,43 @@ checkResult() } fun refreshAfterCheckResult(i:Int, data: BaseRealTimeData) { sIndex[i] = eIndex[i] startData[i] = data exceptionData[i].clear() exceptionData[i].add(data) } // fun refreshAfterCheckResult(i:Int, data: BaseRealTimeData) { // sIndex[i] = eIndex[i] // startData[i] = data // exceptionData[i].clear() // exceptionData[i].add(data) // } /** * æ£æ¥è¿ç»å¼å¸¸ç»ææ¶ï¼æ¯å¦ç¬¦åå¼å¸¸å卿¡ä»¶ */ open fun checkResult(index: Int? = null) { if (index != null) { if (existException[index] && judgeDuration(sIndex[index], eIndex[index])) { startData[index]?.let { resultList.add(newResult(it, lastData, index, exceptionData[index])) open fun checkResult(factor: FactorFilter.SelectedFactor? = null) { val tag = tagMap[factor?.main] if (factor != null && tag != null) { if (tag.existException && judgeDuration(tag.sIndex, tag.eIndex)) { tag.startData?.let { resultList.add(newResult(it, lastData, factor, tag.exceptionData)) } existException[index] = false tag.existException = false } } else { repeat(config.factorCount) { i -> if (existException[i] && judgeDuration(sIndex[i], eIndex[i])) { startData[i]?.let { resultList.add(newResult(it, lastData, i, exceptionData[i])) config.factorFilter.selectedList.forEach { f -> val tag1 = tagMap[f.main] ?: return@forEach if (tag1.existException && judgeDuration(tag1.sIndex, tag1.eIndex)) { tag1.startData?.let { resultList.add(newResult(it, lastData, f, tag1.exceptionData)) } existException[i] = false tag1.existException = false } } // repeat(config.factorCount) { i -> // if (existException[i] && judgeDuration(sIndex[i], eIndex[i])) { // startData[i]?.let { // resultList.add(newResult(it, lastData, i, exceptionData[i])) // } // existException[i] = false // } // } } } } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/BaseExceptionContinuousSingle.kt
@@ -11,29 +11,54 @@ override fun onNextData(data: BaseRealTimeData) { val isContinue = isContinuous(lastData, data) val hasException = judgeException(lastData, data) repeat(config.factorCount) { i -> eIndex[i]++ if (lastData == null) { startData[i] = data } // 夿ç¸é»æ°æ®æ¯å¦è¿ç»å¹¶ä¸æ¯å¦æ»¡è¶³å¼å¸¸å¤æ if (!isContinue) { checkResult() sIndex[i] = eIndex[i] startData[i] = data } else { if (hasException[i]) { // ä¿®æ¹äºèµ·å§æ°æ®çä½ç½®,åæ´ä¸ºåºç°å¼å¸¸ç该å¼,è䏿¯åæ¥çåºç°å¼å¸¸çæ°æ®çåä¸ä¸ªå¼ if (!existException[i]) { sIndex[i] = eIndex[i] startData[i] = data } existException[i] = true } else { config.factorFilter.mainList().forEach {f-> tagMap[f]?.let { it.eIndex++ if (lastData == null) { it.startData = data } // 夿ç¸é»æ°æ®æ¯å¦è¿ç»å¹¶ä¸æ¯å¦æ»¡è¶³å¼å¸¸å¤æ if (!isContinue) { checkResult() it.sIndex = it.eIndex it.startData = data } else { if (hasException[f] == true) { // ä¿®æ¹äºèµ·å§æ°æ®çä½ç½®,åæ´ä¸ºåºç°å¼å¸¸ç该å¼,è䏿¯åæ¥çåºç°å¼å¸¸çæ°æ®çåä¸ä¸ªå¼ if (!it.existException) { it.sIndex = it.eIndex it.startData = data } it.existException = true } else { checkResult() } } } } // repeat(config.factorCount) { i -> // eIndex[i]++ // if (lastData == null) { // startData[i] = data // } // // 夿ç¸é»æ°æ®æ¯å¦è¿ç»å¹¶ä¸æ¯å¦æ»¡è¶³å¼å¸¸å¤æ // if (!isContinue) { // checkResult() // sIndex[i] = eIndex[i] // startData[i] = data // } else { // if (hasException[i]) { // // ä¿®æ¹äºèµ·å§æ°æ®çä½ç½®,åæ´ä¸ºåºç°å¼å¸¸ç该å¼,è䏿¯åæ¥çåºç°å¼å¸¸çæ°æ®çåä¸ä¸ªå¼ // if (!existException[i]) { // sIndex[i] = eIndex[i] // startData[i] = data // } // existException[i] = true // } else { // checkResult() // } // } // } lastData = data } } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.biz.dataanalysis import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.dataanalysis.exceptiontype.ExceptionDataExceed import com.flightfeather.uav.biz.dataanalysis.exceptiontype.ExceptionValueMutation import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig @@ -29,9 +30,9 @@ } } fun run(mission: Mission): List<ExceptionResult> { fun run(mission: Mission, factorFilter: FactorFilter): List<ExceptionResult> { running = true val config = DataAnalysisConfig(mission, ExceptionSetting(), 8) val config = DataAnalysisConfig(mission, ExceptionSetting(), 8, factorFilter) initTask(config) val result = mutableListOf<ExceptionResult>() src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/exceptiontype/ExceptionDataExceed.kt
@@ -4,6 +4,7 @@ import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.socket.eunm.FactorType /** * æ°æ®è¶ æ å¼å¸¸åæ @@ -12,18 +13,28 @@ override fun getExceptionType(): ExceptionType = ExceptionType.TYPE2 override fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): List<Boolean> { val res = mutableListOf<Boolean>() repeat(config.factorCount) { i -> val data = n.getByFactorIndex(i) val limit = config.exceptionSetting.getByFactorIndex(i) override fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> { val res = mutableMapOf<FactorType, Boolean>() config.factorFilter.mainList().forEach { f -> val data = n.getByFactorType(f) val limit = config.exceptionSetting.getByFactorType(f) val bool = if (data != null && limit != null) { data >= limit } else { false } res.add(bool) res[f] = bool } // repeat(config.factorCount) { i -> // val data = n.getByFactorIndex(i) // val limit = config.exceptionSetting.getByFactorIndex(i) // val bool = if (data != null && limit != null) { // data >= limit // } else { // false // } // res.add(bool) // } return res } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/exceptiontype/ExceptionValueMutation.kt
@@ -4,6 +4,7 @@ import com.flightfeather.uav.biz.dataanalysis.model.DataAnalysisConfig import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.socket.eunm.FactorType import kotlin.math.abs /** @@ -19,21 +20,34 @@ override fun getExceptionType(): ExceptionType = ExceptionType.TYPE4 override fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): List<Boolean> { val res = mutableListOf<Boolean>() repeat(config.factorCount) { i-> if (p?.getByFactorIndex(i) == null || n.getByFactorIndex(i) == null) { res.add(false) return@repeat override fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> { val res = mutableMapOf<FactorType, Boolean>() config.factorFilter.mainList().forEach { f -> if (p?.getByFactorType(f) == null || n.getByFactorType(f) == null) { res[f] = (false) return@forEach } val pValue = p.getByFactorIndex(i)!! val nValue = n.getByFactorIndex(i)!! val pValue = p.getByFactorType(f)!! val nValue = n.getByFactorType(f)!! val r = abs((pValue - nValue) / pValue) val b1 = r >= (2 * config.mutationRate) val b2 = r >= config.mutationRate if (b1) special = true res.add(b1 || b2) res[f] = (b1 || b2) } // repeat(config.factorCount) { i-> // if (p?.getByFactorIndex(i) == null || n.getByFactorIndex(i) == null) { // res.add(false) // return@repeat // } // val pValue = p.getByFactorIndex(i)!! // val nValue = n.getByFactorIndex(i)!! // val r = abs((pValue - nValue) / pValue) // val b1 = r >= (2 * config.mutationRate) // val b2 = r >= config.mutationRate // if (b1) special = true // res.add(b1 || b2) // } return res } src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/DataAnalysisConfig.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.biz.dataanalysis.model import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.domain.entity.Mission /** @@ -12,6 +13,8 @@ val exceptionSetting: ExceptionSetting, // æ¶åçæµå åæ°é val factorCount: Int, // å åçé val factorFilter: FactorFilter, ){ // è¿ç»çªåæ°æ®ä¸ªæ° var mutationNum = 6 src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/ExceptionResult.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.biz.dataanalysis.model import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.domain.entity.BaseRealTimeData import java.math.BigDecimal @@ -14,6 +15,9 @@ var exceptionValue: Float? = null var factorId: Int? = null var factorName: String? = null var subFactorId: List<Int>? = null var subFactorName: List<String>? = null var selectedFactor: FactorFilter.SelectedFactor? = null var startTime: String? = null var endTime: String? = null var startData: Float? = null src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/model/ExceptionSetting.kt
@@ -1,5 +1,7 @@ package com.flightfeather.uav.biz.dataanalysis.model import com.flightfeather.uav.socket.eunm.FactorType /** * èµ°èªæ°æ®å¼å¸¸æ å */ @@ -28,4 +30,28 @@ else -> null } } fun getByFactorType(factorType: FactorType): Float? { return when (factorType) { FactorType.NO2 -> no2 FactorType.CO -> co FactorType.H2S -> h2s FactorType.SO2 -> so2 FactorType.O3 -> o3 FactorType.PM25 -> pm25 FactorType.PM10 -> pm10 // FactorType.TEMPERATURE -> temperature // FactorType.HUMIDITY -> humidity FactorType.VOC -> voc // FactorType.NOI -> noi // FactorType.LNG -> longitude?.toFloat() // FactorType.LAT -> latitude?.toFloat() // FactorType.VELOCITY -> velocity // FactorType.TIME -> noi // FactorType.WIND_SPEED -> windSpeed // FactorType.WIND_DIRECTION -> windDirection // FactorType.HEIGHT -> height else -> null } } } src/main/kotlin/com/flightfeather/uav/biz/datamerge/GridMerge.kt
@@ -3,7 +3,7 @@ import com.flightfeather.uav.lightshare.bean.DataVo /** * * ç½æ ¼è忍¡å¼ï¼æ ¹æ®èµ°èªèå´ï¼ååç©å½¢ç½æ ¼ï¼å°ææçæµæ°æ®æ ¹æ®ç»çº¬åº¦ååè³å¯¹åºç½æ ¼ï¼è®¡ç®è·åç½æ ¼çæµæ°æ®åå¼ï¼ * @date 2024/6/26 * @author feiyu02 */ @@ -11,8 +11,9 @@ fun merge(data:List<DataVo>) { //1. ç¡®å®æ°æ®èå´ï¼ç¨ç©å½¢æ¡åºææçæµæ°æ® val lt = foo1(data) //2. æ ¹æ®æ£æ¹å½¢ç½æ ¼çè¾¹é¿ï¼è®¡ç®å¾åºæææ£æ¹å½¢ç½æ ¼ //3. å¹é çæµæ°æ®å对åºç½æ ¼ï¼è®¡ç®ç½æ ¼åå¼ } src/main/kotlin/com/flightfeather/uav/biz/report/MissionReport.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.biz.report import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.dataanalysis.ExceptionAnalysisController import com.flightfeather.uav.biz.dataanalysis.model.ExceptionResult import com.flightfeather.uav.biz.dataprocess.PreData @@ -54,7 +55,7 @@ */ fun addExceptions(exceptions: List<ExceptionResult>) { this.exceptions = exceptions.map { val byteArray = DataToChartUtil.lineToByteArray(FactorType.getByValue(it.factorId!!), it.dataList) val byteArray = DataToChartUtil.lineToByteArray(it.selectedFactor, it.dataList) val base64Str = ImageUtil.compressImage2(byteArray, 400, needPrefix = false) val c = ExceptionChart() BeanUtils.copyProperties(it, c) @@ -91,13 +92,16 @@ private val dateFormatter = DateTimeFormatter.ofPattern("HH:mm") // è·åå¼å¸¸åæç»æ fun exceptionAnalysis(mission: Mission): List<ExceptionResult> { return exceptionAnalysisController.run(mission) fun exceptionAnalysis(mission: Mission, factorFilter: FactorFilter): List<ExceptionResult> { return exceptionAnalysisController.run(mission, factorFilter) } // 计ç®åå¼åæ°æ®èå´ fun dataSummary(mission: Mission): List<Summary> { val preData = PreData(DateUtil.instance.dateToString(mission.startTime, DateUtil.DateStyle.YYYY_MM_DD)) fun dataSummary(mission: Mission, factorFilter: FactorFilter): List<Summary> { val preData = PreData( DateUtil.instance.dateToString(mission.startTime, DateUtil.DateStyle.YYYY_MM_DD), factorFilter.mainList() ) val realTimeData = realTimeDataRep.fetchData(mission) realTimeData.forEach { preData.add(it.toDataVo()) @@ -123,13 +127,13 @@ // çæåæ° // æ ¹æ®æ¥å模æ¿çæå¯¹åºæ¥å fun execute(missionCode: String): String { fun execute(missionCode: String, factorFilter: FactorFilter): String { // 1. ä»»å¡åæ³æ§æ£æ¥ val mission = missionRep.findOne(missionCode) ?: throw BizException("该任å¡ç¼å·ä¸åå¨") // 2. è·åæ°æ®å¼å¸¸ç»è®¡ç»æ val exceptions = exceptionAnalysis(mission) // 2. è·åæ°æ®å¼å¸¸ç»è®¡ç»æï¼æ ¹æ® val exceptions = exceptionAnalysis(mission, factorFilter) // 3. è·ååå¼ãèå´çç»è®¡æ°æ® val summaries = dataSummary(mission) val summaries = dataSummary(mission, factorFilter) // 4. çææ¥å val fileName = "report/" + "${mission.districtName}èµ°èªçæµæ¥å-${ DateUtil.instance.dateToString(mission.startTime, DateUtil.DateStyle.YYYY_MM_DD) src/main/kotlin/com/flightfeather/uav/common/chart/ChartUtil.kt
@@ -3,9 +3,16 @@ import org.jfree.chart.ChartFactory import org.jfree.chart.ChartUtils import org.jfree.chart.JFreeChart import org.jfree.chart.labels.StandardCategoryItemLabelGenerator import org.jfree.chart.labels.StandardCategorySeriesLabelGenerator import org.jfree.chart.plot.CategoryPlot import org.jfree.chart.renderer.category.LineAndShapeRenderer import org.jfree.chart.title.TextTitle import org.jfree.data.category.DefaultCategoryDataset import java.awt.BasicStroke import java.awt.Color import java.awt.Font import java.awt.Paint import java.io.ByteArrayOutputStream /** @@ -19,8 +26,9 @@ fun line(title: String, dataset: DefaultCategoryDataset): JFreeChart { val line = ChartFactory.createLineChart(title, "æ¶é´", "æµåº¦", dataset) line.categoryPlot.domainAxis.labelFont = Font("å®ä½", Font.PLAIN, 12) line.categoryPlot.rangeAxis.labelFont = Font("å®ä½", Font.PLAIN, 12) // line.categoryPlot.domainAxis.labelFont = Font("å®ä½", Font.PLAIN, 12) // line.categoryPlot.rangeAxis.labelFont = Font("å®ä½", Font.PLAIN, 12) setLine(line) return line } @@ -41,4 +49,31 @@ } return dataset } /** * 设置æçº¿å¾æ ·å¼ */ private fun setLine(chart: JFreeChart) { chart.legend.itemFont = Font("SimHei", Font.PLAIN, 16) chart.title.font = Font("SimHei", Font.BOLD, 20) chart.categoryPlot.apply { backgroundPaint = Color(255, 255, 255) rangeGridlinePaint = Color(200, 200, 200) rangeGridlineStroke = BasicStroke(1f) isRangeGridlinesVisible = true } } private fun setRenderer(plot:CategoryPlot, datasetList:List<DefaultCategoryDataset>) { val renderer = newBasicRenderer(paint = Color(191, 0, 0)) } private fun newBasicRenderer(series:Int = 0, paint:Paint): LineAndShapeRenderer { return LineAndShapeRenderer().apply { legendItemLabelGenerator = StandardCategorySeriesLabelGenerator() setSeriesStroke(series, BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 2000f)) setSeriesShapesVisible(series, false) setSeriesPaint(series, paint) } } } src/main/kotlin/com/flightfeather/uav/common/chart/DataToChartUtil.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.common.chart import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.common.utils.DateUtil import com.flightfeather.uav.domain.entity.BaseRealTimeData import com.flightfeather.uav.socket.eunm.FactorType @@ -11,13 +12,13 @@ */ object DataToChartUtil { fun lineToByteArray(type: FactorType?, data: List<BaseRealTimeData>): ByteArray { val title = type?.des ?: "æªç¥çæµå å" val seriesName = type?.des ?: "æªç¥ç³»å" fun lineToByteArray(type: FactorFilter.SelectedFactor?, data: List<BaseRealTimeData>): ByteArray { val title = type?.main?.des ?: "æªç¥çæµå å" val seriesName = type?.main?.des ?: "æªç¥ç³»å" val dataList = data.map { d -> ChartUtil.ChartValue( DateUtil.instance.dateToString(d.dataTime, DateUtil.DateStyle.HH_MM_SS), d.getByFactorType(type) ?: 0f d.getByFactorType(type?.main) ?: 0f ) } val dataset = ChartUtil.newDataset(dataList, seriesName) src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImpl.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.lightshare.service.impl import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.report.MissionReport import com.flightfeather.uav.common.exception.BizException import com.flightfeather.uav.domain.entity.Mission @@ -60,6 +61,6 @@ } override fun getReport(missionCode: String, response: HttpServletResponse) { missionReport.execute(missionCode) missionReport.execute(missionCode, FactorFilter.default()) } } src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt
@@ -1,5 +1,6 @@ package com.flightfeather.uav.lightshare.service.impl import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.report.MissionReport import com.flightfeather.uav.lightshare.service.MissionService import org.junit.Test @@ -23,6 +24,6 @@ @Test fun getReport() { missionReport.execute("SH-CN-20240514") missionReport.execute("SH-CN-20240514", FactorFilter.default()) } }