From 52fc99187771247b58ecf52e1fcd390bfe7ed3d9 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Tue, 02 Nov 2021 11:21:41 +0800 Subject: [PATCH] screen-api 增加获取累计AQI和首要污染物接口 --- screen-common/src/main/java/com/moral/util/AmendUtils.java | 135 ++++++++++++++++++++++++++++++++------------ 1 files changed, 98 insertions(+), 37 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 f49e3a9..4218796 100644 --- a/screen-common/src/main/java/com/moral/util/AmendUtils.java +++ b/screen-common/src/main/java/com/moral/util/AmendUtils.java @@ -60,7 +60,7 @@ Double o3 = Double.parseDouble(dataValue.get(Constants.SENSOR_CODE_O3).toString()); //O3��������������� - Object flag = dataValue.get(Constants.SENSOR_CODE_O3 + Constants.MARKER_BIT_KEY); + Object flag = dataValue.get(Constants.SENSOR_CODE_O3 + "-" + Constants.MARKER_BIT_KEY); //������������������������������ if (!Constants.MARKER_BIT_TRUE.equals(flag)) { continue; @@ -68,12 +68,12 @@ //������������������������������ if (!ObjectUtils.isEmpty(upper)) { - if (o3 < (Double) upper) { + if (o3 > (Double) upper) { continue; } } if (!ObjectUtils.isEmpty(lower)) { - if (o3 > (Double) upper) { + if (o3 < (Double) lower) { continue; } } @@ -102,6 +102,69 @@ 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������,������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)); + } + } + + List<Map<String, Object>> result = new ArrayList<>(); + for (int i = 8; i <= 24; 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); + } + List<Double> value = new ArrayList<>(); + for (Map<String, Object> dataMap : data) { + 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); + } + } + if (value.size() < 6) { + continue; + } + double average = value.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage(); + map.put("o3", average); + result.add(map); + } + return result; + } + /** * @param params ������ * @return ��������������������������� @@ -115,18 +178,21 @@ Object windSpeedUpper = params.get("windSpeedUpper"); Object windSpeedLower = params.get("windSpeedLower"); - double avgDir; - double sumSin = 0d; - double sumCos = 0d; - int size = 0; + Double avgDir = null; + Double sumSin = 0d; + Double sumCos = 0d; + Integer size = 0; for (Map<String, Object> map : data) { Map<String, Object> dataValue = JSONObject.parseObject((String) map.get("value"), Map.class); Object wind = dataValue.get(Constants.SENSOR_CODE_WIND_DIR); 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; + 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 (!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)) { @@ -137,25 +203,25 @@ //��������������������������������������������������� if (!ObjectUtils.isEmpty(windDirUpper)) { - if (windDir < (Double) windDirUpper) { + if (windDir > (Double) windDirUpper) { continue; } } if (!ObjectUtils.isEmpty(windDirLower)) { - if (windDir > (Double) windDirLower) { + if (windDir < (Double) windDirLower) { continue; } } if (!ObjectUtils.isEmpty(windSpeedUpper)) { - if (windSpeed < (Double) windSpeedUpper) { + if (windSpeed > (Double) windSpeedUpper) { continue; } } if (!ObjectUtils.isEmpty(windSpeedLower)) { - if (windSpeed > (Double) windSpeedLower) { + if (windSpeed < (Double) windSpeedLower) { continue; } } @@ -172,21 +238,24 @@ double avgSin = sumSin / size; double avgCos = sumCos / size; + if (avgSin > 0 && avgCos > 0) { avgDir = Math.atan(avgSin / avgCos) * 180 / Math.PI; - } else if (avgCos < 0) { + } else if ((avgSin > 0 && avgCos < 0) || (avgSin < 0 && avgCos < 0)) { avgDir = Math.atan(avgSin / avgCos) * 180 / Math.PI + 180; - } else { + } else if (avgSin < 0 && avgCos > 0) { avgDir = Math.atan(avgSin / avgCos) * 180 / Math.PI + 360; } - double v = sciCal(avgDir, 4); - result.put(Constants.SENSOR_CODE_WIND_DIR, v); - if ("hour".equals(type)) { - //���������>=45���,������������ N,<45���H H:��������������� - if (size >= 45) { - result.put(Constants.SENSOR_CODE_WIND_DIR + Constants.MARKER_BIT_KEY, Constants.MARKER_BIT_TRUE); - } else { - result.put(Constants.SENSOR_CODE_WIND_DIR + Constants.MARKER_BIT_KEY, Constants.MARKER_BIT_FALSE); + if (!ObjectUtils.isEmpty(avgDir)) { + double v = sciCal(avgDir, 4); + result.put(Constants.SENSOR_CODE_WIND_DIR, v); + if ("hour".equals(type)) { + //���������>=45���,������������ N,<45���H H:��������������� + if (size >= 45) { + result.put(Constants.SENSOR_CODE_WIND_DIR + "-" + Constants.MARKER_BIT_KEY, Constants.MARKER_BIT_TRUE); + } else { + result.put(Constants.SENSOR_CODE_WIND_DIR + "-" + Constants.MARKER_BIT_KEY, Constants.MARKER_BIT_FALSE); + } } } return result; @@ -221,22 +290,18 @@ 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; } Double co = Double.parseDouble(o.toString()); //������������������������������ if (!ObjectUtils.isEmpty(upper)) { - if (co < (Double) upper) { + if (co > (Double) upper) { continue; } } if (!ObjectUtils.isEmpty(lower)) { - if (co > (Double) upper) { + if (co < (Double) lower) { continue; } } @@ -259,22 +324,18 @@ 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; } Double o3 = Double.parseDouble(o.toString()); //������������������������������ if (!ObjectUtils.isEmpty(upper)) { - if (o3 < (Double) upper) { + if (o3 > (Double) upper) { continue; } } if (!ObjectUtils.isEmpty(lower)) { - if (o3 > (Double) upper) { + if (o3 < (Double) lower) { continue; } } -- Gitblit v1.8.0