| | |
| | | private val tmpVehicleDataList = mutableListOf<BaseRealTimeData>() |
| | | |
| | | // 走航监测校准系数 |
| | | private val calibrationMap = mutableMapOf<String, MutableMap<Int, Float>>() |
| | | private val calibrationMap = mutableMapOf<String?, MutableMap<Int, Float>>() |
| | | // 走航监测校准系数更新时间 |
| | | private var cUpdateTime = LocalDateTime.now() |
| | | // 走航监测校准系数更新时间间隔(分钟) |
| | | private val cInterval = 5L |
| | | private val cInterval = 1L |
| | | |
| | | override fun saveAirData(dataPackage: AirDataPackage): Int { |
| | | val data = RealTimeData().apply { |
| | |
| | | val d = vo.toBaseRealTimeData(RealTimeDataVehicle::class.java) |
| | | /***************************************************************************************************/ |
| | | // FIXME: 2021/10/27 车载监测部分因子量级调整 |
| | | calibration(d, UWDeviceType.VEHICLE) |
| | | calibration(d, d.deviceCode) |
| | | /***************************************************************************************************/ |
| | | realTimeDataVehicleMapper.insert(d) |
| | | res.add(d) |
| | |
| | | } |
| | | } |
| | | |
| | | private fun calibration(data: BaseRealTimeData, type: UWDeviceType) { |
| | | private fun calibration(data: BaseRealTimeData, deviceCode: String?) { |
| | | //1. 校准系数按照一定时间间隔进行刷新 |
| | | val now = LocalDateTime.now() |
| | | if (calibrationMap.isEmpty() || now.minusMinutes(cInterval).isAfter(cUpdateTime)) { |
| | | if (calibrationMap[deviceCode].isNullOrEmpty() || now.minusMinutes(cInterval).isAfter(cUpdateTime)) { |
| | | cUpdateTime = now |
| | | calibrationMap[type.value] = mutableMapOf() |
| | | calibrationMap[deviceCode] = mutableMapOf() |
| | | factorCalibrationMapper.selectByExample(Example(FactorCalibration::class.java).apply { |
| | | createCriteria().andEqualTo("deviceType", type.value) |
| | | createCriteria().andEqualTo("deviceType", deviceCode) |
| | | }).forEach { |
| | | calibrationMap[type.value]?.put(it.factorId, it.factorScale) |
| | | calibrationMap[deviceCode]?.put(it.factorId, it.factorScale) |
| | | } |
| | | } |
| | | //2. 根据校准系数计算 |
| | | calibrationMap[type.value]?.let{ |
| | | calibrationMap[deviceCode]?.let { |
| | | data.voc = data.voc?.times(it[FactorType.VOC.value] ?: 1f) |
| | | data.co = data.co?.times(it[FactorType.CO.value] ?: 1f) |
| | | data.pm25 = data.pm25?.times(it[FactorType.PM25.value] ?: 1f) |