| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.HistoryDaily; |
| | | import com.moral.api.entity.HistoryHourly; |
| | | import com.moral.api.entity.Sensor; |
| | | import com.moral.api.mapper.HistoryDailyMapper; |
| | | import com.moral.api.service.HistoryDailyService; |
| | |
| | | List<Sensor> sensors = sensorService.list(sensorQueryWrapper); |
| | | |
| | | //获取所有设备小时数据 |
| | | QueryWrapper<HistoryHourly> historyHourlyQueryWrapper = new QueryWrapper<>(); |
| | | historyHourlyQueryWrapper.ge("time", DateUtils.dateToDateString(start)).le("time", DateUtils.dateToDateString(end)); |
| | | List<Map<String, Object>> dailyData = historyHourlyService.listMaps(historyHourlyQueryWrapper); |
| | | Map<String, Object> prop = new HashMap<>(); |
| | | String timeUnits = DateUtils.dateToDateString(start, DateUtils.yyyyMM_EN); |
| | | prop.put("timeUnits", timeUnits); |
| | | prop.put("start", DateUtils.dateToDateString(start)); |
| | | prop.put("end", DateUtils.dateToDateString(end)); |
| | | List<Map<String, Object>> dailyData = historyHourlyService.selectDailyData(prop); |
| | | |
| | | if (dailyData.size() == 0) { |
| | | return; |
| | | } |
| | |
| | | //存入数据库的结果集 |
| | | List<Map<String, Object>> insertData = new ArrayList<>(); |
| | | |
| | | data.forEach((key, value) -> { |
| | | data.forEach((mac, value) -> { |
| | | Map<String, Object> dataMap = new HashMap<>(); |
| | | Map<String, Object> jsonMap = new HashMap<>(); |
| | | dataMap.put("mac", key); |
| | | dataMap.put("mac", mac); |
| | | dataMap.put("time", start); |
| | | |
| | | //中间变量,用于计算除臭氧外其它因子 |
| | | List<Map<String, Object>> tempValue = new ArrayList<>(value); |
| | | |
| | | //移除第一天数据(0点的),O3滑动值第一天数据是从1点-8点 |
| | | value.removeIf(map -> ((Date) map.get("time")).getTime() == start.getTime()); |
| | | |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("data", value); |
| | |
| | | if (!ObjectUtils.isEmpty(o3AvgOfDay)) { |
| | | jsonMap.putAll(o3AvgOfDay); |
| | | } |
| | | //除臭氧外其他因子均值计算 |
| | | tempValue.removeIf(o -> ((Date) o.get("time")).getTime() == end.getTime()); |
| | | |
| | | //风向均值计算并修约 |
| | | params.put("data", tempValue); |
| | | |
| | | Map<String, Object> windDirAvg = AmendUtils.getWindDirAvg(params); |
| | | if (!ObjectUtils.isEmpty(windDirAvg)) { |
| | | jsonMap.putAll(windDirAvg); |
| | |
| | | String sensorCode = sensor.getCode(); |
| | | Double upper = sensor.getUpper(); |
| | | Double lower = sensor.getLower(); |
| | | OptionalDouble optionalDouble = tempValue.parallelStream() |
| | | OptionalDouble optionalDouble = value.parallelStream() |
| | | .flatMapToDouble(v -> { |
| | | Map<String, Object> dataValue = JSONObject.parseObject((String) v.get("value"), Map.class); |
| | | Object sensorValue = dataValue.get(sensorCode); |
| | | //数据有效性标记位 |
| | | Object flag = dataValue.get(sensorCode + Constants.MARKER_BIT_KEY); |
| | | Object flag = dataValue.get(sensorCode + "-" + Constants.MARKER_BIT_KEY); |
| | | if (!Constants.MARKER_BIT_TRUE.equals(flag)) { |
| | | return null; |
| | | } |
| | | |
| | | if (ObjectUtils.isEmpty(sensorValue)) { |
| | | System.out.println(456); |
| | | return null; |
| | | } |
| | | |
| | |
| | | //剔除数据超过上下限的数据 |
| | | double aDouble = Double.parseDouble(sensorValue.toString()); |
| | | if (!ObjectUtils.isEmpty(upper)) { |
| | | if (aDouble < upper) { |
| | | if (aDouble > upper) { |
| | | return null; |
| | | } |
| | | } |
| | | if (!ObjectUtils.isEmpty(lower)) { |
| | | if (aDouble > lower) { |
| | | if (aDouble < lower) { |
| | | return null; |
| | | } |
| | | } |
| | | if ("a00e12".equals(sensorCode)) { |
| | | System.out.println(key + "==" + sensorCode + "==" + v.get("time") + "==" + aDouble); |
| | | } |
| | | |
| | | return DoubleStream.of(aDouble); |
| | | }).average(); |
| | | if (optionalDouble.isPresent()) { |