feiyu02
2025-09-30 94fee0b511279679b43e210878d3d36e5a14384b
src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
@@ -29,10 +29,7 @@
    // 均值倍数参数
    private val xratio = 3
    // 连续数据的合理最大增长倍率
    private val multiplier = 20
    // 需要处理的因子类型
    // 需要平滑处理的因子类型
    private var calTypes = when (deviceType) {
        UWDeviceType.VEHICLE,
        UWDeviceType.UAV,
@@ -41,6 +38,25 @@
        UWDeviceType.GRID -> WeightType.prepFixed
        else -> WeightType.prepFixed
    }
    // 只需要检查范围和变化幅度的因子类型
    private var rangeTypes = listOf(
        FactorType.PM25.des,
        FactorType.PM10.des,
        FactorType.VOC.des
    )
    // 无需修正的因子类型
    private var noCalTypes = listOf(
        FactorType.TEMPERATURE.des,
        FactorType.HUMIDITY.des,
        FactorType.LNG.des,
        FactorType.LAT.des,
        FactorType.VELOCITY.des,
        FactorType.TIME.des,
        FactorType.WIND_DIRECTION.des,
        FactorType.HEIGHT.des
    )
    private val lastData = mutableListOf<DataVo>()
@@ -66,7 +82,7 @@
                val it = mDataList[i].values?.get(y) ?: continue
                if (!calTypes.contains(it.factorName)) continue
                val vMax = FactorType.getVMax(it.factorName) ?: continue
                val vMax = FactorType.getVMin(it.factorName) ?: continue
                it.factorData ?: continue
                if (it.factorData!! > vMax) {
@@ -134,7 +150,7 @@
        while (i < mDataList.size) {
            for (y in mDataList[i].values?.indices ?: 0..0) {
                val it = mDataList[i].values?.get(y) ?: continue
                val vMax = FactorType.getVMax(it.factorName) ?: continue
                val vMax = FactorType.getVMin(it.factorName) ?: continue
                it.factorData ?: continue
                if (it.factorData!! > vMax) {
@@ -151,26 +167,27 @@
                        // 去除无效值的标准差
                        val std = standardDeviation(avg.first, list, it.factorName)
                        // 合理最大值
                        val max = max(avg.first + std * nstd, avg.first + avg.first * xratio)
                        var maxValue = max(avg.first + std * nstd, avg.first + avg.first * xratio)
                        maxValue = max(maxValue, FactorType.getRange(it.factorName)?.second ?: .0)
                        // 合理最小值
                        val min = min(avg.first - std * nstd, avg.first / (1 + xratio))
                        val minValue = min(avg.first - std * nstd, avg.first / (1 + xratio))
                        // 判断监测因子是否需要进行平滑处理,
                        // 若不需要,则判断量级是否在合理范围内以及变化倍率是否在合理范围内
                        if (!calTypes.contains(it.factorName)) {
                            if (isInRange(it) != true || excessiveChange(it) == true) {
                                // 采用计算所得均值代替原始值
                                it.factorData = avg.first
                            }
                        } else {
                        if (calTypes.contains(it.factorName)) {
                            // 数据不处于合理范围并且有效个数达标时,采用计算所得均值代替原始值
                            if (avg.second > max(ncal / 5, 2)
                                && (it.factorData!! < min || it.factorData!! > max)
                                && (it.factorData!! < minValue || it.factorData!! > maxValue)
                            ) {
                                it.factorData = avg.first
                            }
                        }
                        // 判断量级是否在合理范围内以及变化倍率是否在合理范围内
                        else if (rangeTypes.contains(it.factorName)) {
                            if (isInRange(it) != true || excessiveChange(it) == true) {
                                // 采用计算所得均值代替原始值
                                it.factorData = avg.first
                            }
                        }
                    }
                }
            }
@@ -289,6 +306,6 @@
                break
            }
        }
        return m > multiplier
        return m > FactorType.getMultiplier(airData.factorName)
    }
}