From d672457aaf5c7a2b7429b4eef82d574009b01351 Mon Sep 17 00:00:00 2001 From: cjl <909710561@qq.com> Date: Fri, 29 Mar 2024 15:33:40 +0800 Subject: [PATCH] fix:盐城报告臭氧调整 --- screen-common/src/main/java/com/moral/util/AmendUtils.java | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 43 insertions(+), 7 deletions(-) diff --git a/screen-common/src/main/java/com/moral/util/AmendUtils.java b/screen-common/src/main/java/com/moral/util/AmendUtils.java index 7b7348d..ac3c4e0 100644 --- a/screen-common/src/main/java/com/moral/util/AmendUtils.java +++ b/screen-common/src/main/java/com/moral/util/AmendUtils.java @@ -57,6 +57,9 @@ List<Double> data = new ArrayList<>(); for (Map<String, Object> dataMap : list) { Map<String, Object> dataValue = JSONObject.parseObject((String) dataMap.get("value"), Map.class); + if (ObjectUtils.isEmpty(dataValue.get(Constants.SENSOR_CODE_O3))){ + continue; + } Double o3 = Double.parseDouble(dataValue.get(Constants.SENSOR_CODE_O3).toString()); //O3��������������� @@ -249,15 +252,12 @@ public static double percentile(List<Double> data, int p) { int n = data.size(); Collections.sort(data); - double v = n / (100 / p); - if (n % (100 / p) == 0) { - if (v == n) { - return data.get(n - 1); - } - return (data.get((int) v - 1) + data.get((int) v)) / 2; - } + double v = MathUtils.division(MathUtils.mul(n, p),100d,1); + v = Math.ceil(v)-1; return sciCal(data.get((int) v), 4); } + + //������������������������������ public static Map<String, Object> getCOAvgOfWeekOrMonth(Map<String, Object> params) { @@ -327,4 +327,40 @@ result.put(Constants.SENSOR_CODE_O3, percentile(data, 90)); return result; } + + //������������������������ + /** + * ��������������� + * PM2.5,PM10,CO,���������95��������� + * SO2,NO2,���������98��������� + * O3���������������90��������� + * + * @param list ������ + * @param sensorCode ������code + */ + public static Double getAvgOfYear(List<Map<String, Object>> list, String sensorCode) { + List<Double> data = new ArrayList<>(); + for (Map<String, Object> dataMap : list) { + Map<String, Object> dataValue = JSONObject.parseObject((String) dataMap.get("value"), Map.class); + Object o = dataValue.get(sensorCode); + if (ObjectUtils.isEmpty(o)) { + continue; + } + Double sensorValue = Double.parseDouble(o.toString()); + data.add(sensorValue); + } + if (data.size() == 0) { + return null; + } + + Double v = null; + if ("PM2_5".equals(sensorCode) || "PM10".equals(sensorCode) || "CO".equals(sensorCode)) { + v = percentile(data, 95); + } else if ("SO2".equals(sensorCode) || "NO2".equals(sensorCode)) { + v = percentile(data, 98); + } else if ("O3".equals(sensorCode)) { + v = percentile(data, 90); + } + return v; + } } -- Gitblit v1.8.0