| | |
| | | import kotlin.math.min |
| | | import kotlin.math.round |
| | | import kotlin.math.sqrt |
| | | import kotlin.time.times |
| | | |
| | | /** |
| | | * 数据平滑预处理 |
| | |
| | | i = 0 |
| | | } |
| | | while (i < mDataList.size) { |
| | | // 针对每个监测因子,分别做数据平滑处理 |
| | | for (y in mDataList[i].values?.indices ?: 0..0) { |
| | | val it = mDataList[i].values?.get(y) ?: continue |
| | | val vMax = FactorType.getVMin(it.factorName) ?: continue |
| | |
| | | } |
| | | } |
| | | |
| | | // 根据物理规律,剔除或修正不合理的数据 |
| | | val data = mDataList[i] |
| | | // 1. PM2.5 应该始终小于PM10 |
| | | val pm25 = data.getFactorData(FactorType.PM25) |
| | | val pm10 = data.getFactorData(FactorType.PM10) |
| | | if (pm25 != null && pm10 != null) { |
| | | // 若pm2.5大于pm10 |
| | | if (pm25 >= pm10){ |
| | | val lastIndex = i - 1 |
| | | // 则将pm2.5修改为前一个数据的值 |
| | | if (lastIndex >= 0) { |
| | | data.setFactorData(FactorType.PM25, mDataList[lastIndex].getFactorData(FactorType.PM25)) |
| | | } else { |
| | | if (lastData.isEmpty()) { |
| | | // 没有历史数据时,修改为pm10的80%(后续待优化比例 2026.3.6) |
| | | data.setFactorData(FactorType.PM25, data.getFactorData(FactorType.PM10)?.times(.8)) |
| | | } else { |
| | | data.setFactorData(FactorType.PM25, lastData.last().getFactorData(FactorType.PM25)) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | i++ |
| | | } |
| | | |