|  |  |  | 
|---|
|  |  |  | Date end = DateUtils.addDays(start, 7); | 
|---|
|  |  |  | //因子 | 
|---|
|  |  |  | QueryWrapper<Sensor> sensorQueryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | sensorQueryWrapper.select("code").eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | List<Object> sensorCodes = sensorService.listObjs(sensorQueryWrapper); | 
|---|
|  |  |  | sensorQueryWrapper.select("code", "lower", "upper").eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | List<Sensor> sensors = sensorService.list(sensorQueryWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取所有设备日数据 | 
|---|
|  |  |  | QueryWrapper<HistoryDaily> historyDailyQueryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | dataMap.put("time", start); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //风向均值计算并修约 | 
|---|
|  |  |  | Object windDirAvg = AmendUtils.getWindDirAvg(value); | 
|---|
|  |  |  | if (windDirAvg != null) { | 
|---|
|  |  |  | jsonMap.put(Constants.SENSOR_CODE_WIND_DIR, windDirAvg); | 
|---|
|  |  |  | Map<String, Object> params = new HashMap<>(); | 
|---|
|  |  |  | params.put("data", value); | 
|---|
|  |  |  | params.put("type", "week"); | 
|---|
|  |  |  | for (Sensor sensor : sensors) { | 
|---|
|  |  |  | String sensorCode = sensor.getCode(); | 
|---|
|  |  |  | if (sensorCode.equals(Constants.SENSOR_CODE_WIND_DIR)) { | 
|---|
|  |  |  | if (sensor.getUpper() != null) { | 
|---|
|  |  |  | params.put("windDirUpper", sensor.getUpper()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (sensor.getLower() != null) { | 
|---|
|  |  |  | params.put("windDirLower", sensor.getLower()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (sensorCode.equals(Constants.SENSOR_CODE_WIND_SPEED)) { | 
|---|
|  |  |  | if (sensor.getUpper() != null) { | 
|---|
|  |  |  | params.put("windSpeedUpper", sensor.getUpper()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (sensor.getLower() != null) { | 
|---|
|  |  |  | params.put("windSpeedLower", sensor.getLower()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (sensorCode.equals(Constants.SENSOR_CODE_CO)) { | 
|---|
|  |  |  | if (sensor.getUpper() != null) { | 
|---|
|  |  |  | params.put("coUpper", sensor.getUpper()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (sensor.getLower() != null) { | 
|---|
|  |  |  | params.put("coLower", sensor.getLower()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (sensorCode.equals(Constants.SENSOR_CODE_O3)) { | 
|---|
|  |  |  | if (sensor.getUpper() != null) { | 
|---|
|  |  |  | params.put("o3Upper", sensor.getUpper()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (sensor.getLower() != null) { | 
|---|
|  |  |  | params.put("o3Lower", sensor.getLower()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //风向计算 | 
|---|
|  |  |  | Map<String, Object> windDirAvg = AmendUtils.getWindDirAvg(params); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(windDirAvg)) { | 
|---|
|  |  |  | jsonMap.putAll(windDirAvg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //CO 95百分位计算并修约 | 
|---|
|  |  |  | Object coAvg = AmendUtils.getCOAvgOfWeekOrMonth(value); | 
|---|
|  |  |  | if (coAvg != null) { | 
|---|
|  |  |  | jsonMap.put(Constants.SENSOR_CODE_CO, coAvg); | 
|---|
|  |  |  | Map<String, Object> coAvgOfWeekOrMonth = AmendUtils.getCOAvgOfWeekOrMonth(params); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(coAvgOfWeekOrMonth)) { | 
|---|
|  |  |  | jsonMap.putAll(coAvgOfWeekOrMonth); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //O3 90百分位计算并修约 | 
|---|
|  |  |  | Object o3Avg = AmendUtils.getO3AvgOfWeekOrMonth(value); | 
|---|
|  |  |  | if (o3Avg != null) { | 
|---|
|  |  |  | jsonMap.put(Constants.SENSOR_CODE_O3, o3Avg); | 
|---|
|  |  |  | Map<String, Object> o3AvgOfWeekOrMonth = AmendUtils.getO3AvgOfWeekOrMonth(params); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(o3AvgOfWeekOrMonth)) { | 
|---|
|  |  |  | jsonMap.putAll(o3AvgOfWeekOrMonth); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sensorCodes.forEach(sensorCode -> { | 
|---|
|  |  |  | sensors.forEach(sensor -> { | 
|---|
|  |  |  | String sensorCode = sensor.getCode(); | 
|---|
|  |  |  | Double upper = sensor.getUpper(); | 
|---|
|  |  |  | Double lower = sensor.getLower(); | 
|---|
|  |  |  | OptionalDouble optionalDouble = value.parallelStream() | 
|---|
|  |  |  | .flatMapToDouble(v -> { | 
|---|
|  |  |  | Map<String, Object> dataValue = JSONObject.parseObject((String) v.get("value"), Map.class); | 
|---|
|  |  |  | Object sensorValue = dataValue.get(sensorCode.toString()); | 
|---|
|  |  |  | Object sensorValue = dataValue.get(sensorCode); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(sensorValue)) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //风向另外计算 | 
|---|
|  |  |  | //风向单独计算 | 
|---|
|  |  |  | if (Constants.SENSOR_CODE_WIND_DIR.equals(sensorCode)) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //CO另外计算 | 
|---|
|  |  |  | //CO单独计算 | 
|---|
|  |  |  | if (Constants.SENSOR_CODE_CO.equals(sensorCode)) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //O3另外计算 | 
|---|
|  |  |  | //O3单独计算 | 
|---|
|  |  |  | if (Constants.SENSOR_CODE_O3.equals(sensorCode)) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return DoubleStream.of(Double.parseDouble(sensorValue.toString())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //剔除数据超过上下限的数据 | 
|---|
|  |  |  | double aDouble = Double.parseDouble(sensorValue.toString()); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(upper)) { | 
|---|
|  |  |  | if (aDouble > upper) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(lower)) { | 
|---|
|  |  |  | if (aDouble < lower) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return DoubleStream.of(aDouble); | 
|---|
|  |  |  | }).average(); | 
|---|
|  |  |  | if (optionalDouble.isPresent()) { | 
|---|
|  |  |  | //银行家算法修约 | 
|---|
|  |  |  | double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 4); | 
|---|
|  |  |  | jsonMap.put(sensorCode.toString(), sciCal); | 
|---|
|  |  |  | jsonMap.put(sensorCode, sciCal); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | dataMap.put("value", JSONObject.toJSONString(jsonMap)); | 
|---|