From 5158c660013d52524559d4435f27b5e63d3221b7 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Wed, 17 Nov 2021 13:54:25 +0800 Subject: [PATCH] screen-api 更改饼状图接口 --- screen-common/src/main/java/com/moral/util/AmendUtils.java | 67 ++++++++++++++------------------- 1 files changed, 29 insertions(+), 38 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 4ed255f..7b7348d 100644 --- a/screen-common/src/main/java/com/moral/util/AmendUtils.java +++ b/screen-common/src/main/java/com/moral/util/AmendUtils.java @@ -53,7 +53,7 @@ Object lower = params.get("o3Lower"); double max; List<Double> avgs = new ArrayList<>(); - for (int i = 8; i <= 24; i++) { + for (int i = 7; i <= 23; i++) { List<Double> data = new ArrayList<>(); for (Map<String, Object> dataMap : list) { Map<String, Object> dataValue = JSONObject.parseObject((String) dataMap.get("value"), Map.class); @@ -79,9 +79,6 @@ } int hour = DateUtils.getHour((Date) dataMap.get("time")); - if (hour == 0) { - hour = 24; - } if (hour <= i && hour >= i - 7) { data.add(o3); } @@ -93,7 +90,6 @@ avgs.add(average); } max = avgs.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getMax(); - System.out.println(avgs.size()); if (avgs.size() < 14) { if (max < 160d) { return result; @@ -103,38 +99,38 @@ return result; } + //������aqi��������� + public static Double o3OfDay(List<Map<String, Object>> value) { + List<Map<String, Object>> o3_8H = getO3_8H(value); + if (!ObjectUtils.isEmpty(o3_8H)) { + double o3 = 0d; + for (Map<String, Object> o : o3_8H) { + double temp = (double) o.get("O3"); + if (temp > o3) { + o3 = temp; + } + } + return sciCal(o3, 0); + } + return null; + } + /** - * @param data ������ time:Date������ + * @param data ������ time:Date������,������key:o3 * @return ���������������8��������������������� */ public static List<Map<String, Object>> getO3_8H(List<Map<String, Object>> data) { - Date time1 = null; - Date time2 = null; - for (Map<String, Object> datum : data) { - Date time = (Date) datum.get("time"); - if (DateUtils.getHour(time) == 0) { - time2 = DateUtils.getDate(DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_EN)); - } else { - time1 = DateUtils.getDate(DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_EN)); - } - } - + Date date = (Date) data.get(0).get("time"); List<Map<String, Object>> result = new ArrayList<>(); - for (int i = 8; i <= 24; i++) { + for (int i = 7; i <= 23; i++) { Map<String, Object> map = new HashMap<>(); - if (i < 24) { - map.put("time", ObjectUtils.isEmpty(time1) ? null : DateUtils.addHours(time1, i)); - } else { - map.put("time", ObjectUtils.isEmpty(time2) ? null : time2); - } + map.put("time", DateUtils.addHours(date, i)); List<Double> value = new ArrayList<>(); for (Map<String, Object> dataMap : data) { - Double o3 = Double.parseDouble(dataMap.get(Constants.SENSOR_CODE_O3).toString()); + Map<String, Object> sensorValue = JSONObject.parseObject((String) dataMap.get("value"), Map.class); + Double o3 = Double.parseDouble(sensorValue.get("O3").toString()); Date time = (Date) dataMap.get("time"); int hour = DateUtils.getHour(time); - if (hour == 0) { - hour = 24; - } if (hour <= i && hour >= i - 7) { value.add(o3); } @@ -143,7 +139,7 @@ continue; } double average = value.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage(); - map.put(Constants.SENSOR_CODE_O3, average); + map.put("O3", sciCal(average, 0)); result.add(map); } return result; @@ -172,8 +168,11 @@ Object speed = dataValue.get(Constants.SENSOR_CODE_WIND_SPEED); Object flagDir = dataValue.get(Constants.SENSOR_CODE_WIND_DIR + "-" + Constants.MARKER_BIT_KEY); Object flagSpeed = dataValue.get(Constants.SENSOR_CODE_WIND_SPEED + "-" + Constants.MARKER_BIT_KEY); - if (!Constants.MARKER_BIT_TRUE.equals(flagDir) || !Constants.MARKER_BIT_TRUE.equals(flagSpeed)) { - continue; + + if (!ObjectUtils.isEmpty(flagDir) && !ObjectUtils.isEmpty(flagSpeed)) { + if (!Constants.MARKER_BIT_TRUE.equals(flagDir) || !Constants.MARKER_BIT_TRUE.equals(flagSpeed)) { + continue; + } } if (ObjectUtils.isEmpty(wind) || ObjectUtils.isEmpty(speed)) { @@ -271,10 +270,6 @@ for (Map<String, Object> dataMap : list) { Map<String, Object> dataValue = JSONObject.parseObject((String) dataMap.get("value"), Map.class); Object o = dataValue.get(Constants.SENSOR_CODE_CO); - Object flag = dataValue.get(Constants.SENSOR_CODE_CO + "-" + Constants.MARKER_BIT_KEY); - if (!Constants.MARKER_BIT_TRUE.equals(flag)) { - continue; - } if (ObjectUtils.isEmpty(o)) { continue; } @@ -309,10 +304,6 @@ for (Map<String, Object> dataMap : list) { Map<String, Object> dataValue = JSONObject.parseObject((String) dataMap.get("value"), Map.class); Object o = dataValue.get(Constants.SENSOR_CODE_O3); - Object flag = dataValue.get(Constants.SENSOR_CODE_O3 + "-" + Constants.MARKER_BIT_KEY); - if (!Constants.MARKER_BIT_TRUE.equals(flag)) { - continue; - } if (ObjectUtils.isEmpty(o)) { continue; } -- Gitblit v1.8.0