feiyu02
2025-08-14 b10c22af595bd995e56946bff63b8f2f984b13e8
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcWindLevel.kt
@@ -29,12 +29,30 @@
        this.callback = callback
    }
    override var excludedFactor: List<FactorType> = listOf(FactorType.NO2)
    private var callback: NewPolluteClueCallback? = null
    abstract var windLevelCondition: RTExcWindLevelConfig.WindLevelCondition
    override var judgeMethod: JudgeMethod = JudgeMethod.M1
    override fun getExceptionType(): ExceptionType {
        return ExceptionType.TYPE4
    }
    override fun judgeDataScale(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 || n.windSpeed == null) {
                res[f] = (false)
                return@forEach
            }
            val nValue = n.getByFactorType(f)!!
            val minValue = FactorType.getVMin(f)
            res[f] = nValue >= minValue
        }
        return res
    }
    override fun judgeException(p: BaseRealTimeData?, n: BaseRealTimeData): MutableMap<FactorType, Boolean> {
@@ -48,30 +66,33 @@
            val con = windLevelCondition
            if (n.windSpeed!! in con.windSpeed.first..con.windSpeed.second) {
                println("风速:${n.windSpeed},[${con.windSpeed.first} - ${con.windSpeed.second}]")
                val pValue = p.getByFactorType(f)!!
                val nValue = n.getByFactorType(f)!!
                // 计算后一个数据相比于前一个数据的变化率
                val r = (nValue - pValue) / pValue
                val b1 = r >= con.mutationRate.first
                val b1 = r >= con.mutationRate.first && r < con.mutationRate.second
                println("因子:${f.des},幅度:${r},限定:${con.mutationRate.first},${b1}")
                res[f] = b1
            } else {
                res[f] = false
            }
        }
        return res
    }
    override fun judgeExceptionCount(tag: ExceptionTag): Boolean {
    override fun judgeExceptionCount(tag: ExceptionTag, factorType: FactorType?): Boolean {
        return tag.exceptionData.size >= windLevelCondition.countLimit
    }
    override fun needCut(tag: ExceptionTag, hasException: Boolean?): Boolean {
    override fun needCut(tag: ExceptionTag, hasException: Boolean?, data: BaseRealTimeData): Boolean {
        // 按照时长和距离限制将异常截取
        if (tag.exceptionData.isEmpty()) return false
        val se = tag.exceptionData.first()
        val ee = tag.exceptionData.last()
        val ee = data
        val sTime = LocalDateTime.ofInstant(se.dataTime?.toInstant(), ZoneId.systemDefault())
        val eTime = LocalDateTime.ofInstant(ee.dataTime?.toInstant(), ZoneId.systemDefault())
@@ -93,29 +114,46 @@
        return b1 || b2
    }
    override fun immeExcCheck(tag: ExceptionTag): Boolean {
    override fun immeExcCheck(tag: ExceptionTag, factorType: FactorType): Boolean {
        // 异常出现等于限定次数时,就需要形成污染线索
        return tag.exceptionData.size == windLevelCondition.countLimit
    }
    override fun newResult(
        start: BaseRealTimeData,
        end: BaseRealTimeData?,
        factor: FactorFilter.SelectedFactor,
        exceptionData: List<BaseRealTimeData>,
    ): PollutedClue {
        return PollutedClue(start, end, factor, exceptionData, getExceptionType(), config, windLevelCondition)
    override fun newResult(tag: ExceptionTag, factor: FactorFilter.SelectedFactor): PollutedClue {
        return PollutedClue()
    }
    override fun onNewException(
        tag: ExceptionTag,
        factor: FactorFilter.SelectedFactor,
        exceptionStatus: ExceptionStatusType,
    ) {
        super.onNewException(tag, factor, exceptionStatus)
    override fun newResult(exceptions: List<Pair<FactorFilter.SelectedFactor, ExceptionTag>>): PollutedClue {
        return if (exceptions.isEmpty())
            PollutedClue()
        else
            PollutedClue(exceptions, getExceptionType(), config, windLevelCondition)
    }
    //    override fun newResult(
//        start: BaseRealTimeData,
//        end: BaseRealTimeData?,
//        factor: FactorFilter.SelectedFactor,
//        exceptionData: List<BaseRealTimeData>,
//    ): PollutedClue {
//        return PollutedClue(start, end, factor, exceptionData, getExceptionType(), config, windLevelCondition)
//    }
//    override fun mergeExceptionResult() {
//        super.mergeExceptionResult()
//        callback?.let { func ->
//            result.forEach {
//                func.invoke(it)
//            }
//        }
//    }
    override fun onNewResult(result: List<PollutedClue>) {
        callback?.let { func ->
            val exc = tag.exceptionResult.last()
            func.invoke(exc as PollutedClue)
            result.forEach {
                func.invoke(it)
            }
        }
    }
}