| | |
| | | import com.moral.api.service.HistoryMinutelyService; |
| | | import com.moral.api.service.SensorService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.AmendUtils; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | @Service |
| | |
| | | |
| | | //获取所有设备的5分钟数据 |
| | | List<Map<String, Object>> fiveMinutelyData = historyMinutelyService.getHistoryFiveMinutelyData(params); |
| | | if (fiveMinutelyData.size() == 0) { |
| | | return; |
| | | } |
| | | |
| | | //按mac分组 |
| | | Map<String, List<Map<String, Object>>> data = fiveMinutelyData.parallelStream() |
| | | .collect(Collectors.groupingBy(o -> (String) o.get("mac"))); |
| | |
| | | |
| | | data.forEach((key, value) -> { |
| | | Map<String, Object> dataMap = new HashMap<>(); |
| | | Map<String, Object> jsonMap = new HashMap<>(); |
| | | dataMap.put("mac", key); |
| | | dataMap.put("time", end); |
| | | Map<String, Object> jsonMap = new HashMap<>(); |
| | | |
| | | //风向均值计算并修约 |
| | | Object windDirAvg = AmendUtils.getWindDirAvg(value); |
| | | if (windDirAvg != null) { |
| | | jsonMap.put(Constants.SENSOR_CODE_WIND_DIR, windDirAvg); |
| | | } |
| | | |
| | | //除风向外其他因子均值计算 |
| | | sensorCodes.forEach(sensorCode -> { |
| | | OptionalDouble optionalDouble = value.parallelStream() |
| | | .flatMapToDouble(v -> { |
| | |
| | | if (ObjectUtils.isEmpty(sensorValue)) { |
| | | return null; |
| | | } |
| | | //风向另外计算 |
| | | if (Constants.SENSOR_CODE_WIND_DIR.equals(sensorCode)) { |
| | | return null; |
| | | } |
| | | return DoubleStream.of(Double.parseDouble(sensorValue.toString())); |
| | | }).average(); |
| | | if (optionalDouble.isPresent()) { |
| | | jsonMap.put(sensorCode.toString(), Double.parseDouble(String.format("%.4f", optionalDouble.getAsDouble()))); |
| | | //银行家算法修约 |
| | | double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 4); |
| | | jsonMap.put(sensorCode.toString(), sciCal); |
| | | } |
| | | }); |
| | | dataMap.put("value", JSONObject.toJSONString(jsonMap)); |
| | |
| | | |
| | | //5分钟表后缀 |
| | | String insertTimeUnits = DateUtils.dateToDateString(now, DateUtils.yyyyMM_EN); |
| | | //存入数据库 |
| | | historyFiveMinutelyMapper.insertHistoryFiveMinutely(insertData, insertTimeUnits); |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | //模拟数据 |
| | | /* //模拟数据 |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | Map<String, Object> map1 = new HashMap<>(); |
| | | map1.put("mac", "p5dnd1234567"); |
| | |
| | | }); |
| | | |
| | | |
| | | System.out.println("666==" + insertData); |
| | | System.out.println("666==" + insertData);*/ |
| | | |
| | | double a = 5.5d; |
| | | System.out.println(Math.round(a)); |
| | | } |
| | | } |