From 9485a0cb33bb4535bb553a5bf49debeadbe0c89d Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Wed, 03 Nov 2021 11:48:55 +0800 Subject: [PATCH] city_aqi o3_8h,综指,首要污染物计算 --- screen-common/src/main/java/com/moral/util/AQIUtils.java | 199 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 188 insertions(+), 11 deletions(-) diff --git a/screen-common/src/main/java/com/moral/util/AQIUtils.java b/screen-common/src/main/java/com/moral/util/AQIUtils.java index 70cddb2..d283d23 100644 --- a/screen-common/src/main/java/com/moral/util/AQIUtils.java +++ b/screen-common/src/main/java/com/moral/util/AQIUtils.java @@ -2,10 +2,7 @@ import org.springframework.util.ObjectUtils; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import com.moral.constant.Constants; @@ -54,13 +51,120 @@ } int AQIMAX = 0; if (!ObjectUtils.isEmpty(AQIList)) { - AQIMAX = Collections.max(AQIList); + if (AQIList.size() == 6) { + AQIMAX = Collections.max(AQIList); + } } return AQIMAX; } + /** + * @Description: ������AQI������������������map���key���sensorCode���value��������� + * @Param: [map] + * @return: java.util.Map<java.lang.String, java.lang.Object> + * @Author: ��������� + * @Date: 2021/10/29 + */ + public static Map<String, Object> hourlyAqi_pollutant(Map<String, Object> map) { + List<Integer> AQIList = new ArrayList<>(); + Map<String, Integer> AQIMap = new HashMap<>(); + for (Map.Entry<String, Object> entry : map.entrySet()) { + String key = entry.getKey(); + if (entry.getValue().toString().equals("")) { + continue; + } + int PM2_5AQI; + int PM10AQI; + int SO2AQI; + int NO2AQI; + int COAQI; + int O3AQI; + switch (key) { + case Constants.SENSOR_CODE_PM25: + PM2_5AQI = PM2_5AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(PM2_5AQI); + AQIMap.put("PM2.5", PM2_5AQI); + break; + case Constants.SENSOR_CODE_PM10: + PM10AQI = PM10AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(PM10AQI); + AQIMap.put("PM10", PM10AQI); + break; + case Constants.SENSOR_CODE_SO2: + SO2AQI = SO2AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(SO2AQI); + AQIMap.put("SO2", SO2AQI); + break; + case Constants.SENSOR_CODE_NO2: + NO2AQI = NO2AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(NO2AQI); + AQIMap.put("NO2", NO2AQI); + break; + case Constants.SENSOR_CODE_CO: + COAQI = COAQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(COAQI); + AQIMap.put("CO", COAQI); + break; + case Constants.SENSOR_CODE_O3: + O3AQI = O3AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(O3AQI); + AQIMap.put("O3", O3AQI); + break; + default: + break; + } + } + int AQIMAX = 0; + if (!ObjectUtils.isEmpty(AQIList)) { + AQIMAX = Collections.max(AQIList); + } + List<String> nameList = new ArrayList<>(); + for (String key : AQIMap.keySet()) { + if (AQIMap.get(key).equals(AQIMAX)) { + nameList.add(key); + } + } + Map<String, Object> resultMap = new HashMap<>(); + resultMap.put("aqi", AQIMAX); + if (AQIMAX > 50) + resultMap.put("pollutant", nameList); + return resultMap; + } + + public static void main(String[] args) { + Map<String, Object> map = new HashMap<>(); + map.put("a34004", 11.25); + map.put("a34002", 18.25); + map.put("a21026", 55); + map.put("a21004", 200.01); + map.put("a21005", 18.94); + map.put("a05024", 55); + System.out.println(hourlyAqi_pollutant(map)); + } + + /** + * @Description: ������AQI������������ + * @Param: + * @return: + * @Author: ��������� + * @Date: 2021/10/29 + */ + public static String classOfPollutionByAqi(Integer aqi) { + if (aqi > 300) + return Constants.SERVER; + if (aqi > 200) + return Constants.SERIOUS; + if (aqi > 150) + return Constants.MIDDLE; + if (aqi > 100) + return Constants.MILD; + if (aqi > 50) + return Constants.GOOD; + return Constants.EXCELLENT; + } + //PM2.5 IAQI - public static int PM2_5AQI(Double value) { + private static int PM2_5AQI(Double value) { double result; if (value <= 0) { result = 0; @@ -83,7 +187,7 @@ } //PM10 IAQI - public static int PM10AQI(Double value) { + private static int PM10AQI(Double value) { double result; if (value <= 0) { result = 0; @@ -106,7 +210,7 @@ } //SO2 IAQI - public static int SO2AQI(Double value) { + private static int SO2AQI(Double value) { double result; if (value <= 0) { result = 0; @@ -123,7 +227,7 @@ } //NO2 IAQI - public static int NO2AQI(Double value) { + private static int NO2AQI(Double value) { double result; if (value <= 0) { result = 0; @@ -146,7 +250,7 @@ } //CO IAQI - public static int COAQI(Double value) { + private static int COAQI(Double value) { double result; if (value <= 0) { result = 0; @@ -169,7 +273,7 @@ } //O3 IAQI - public static int O3AQI(Double value) { + private static int O3AQI(Double value) { double result; if (value <= 0) { result = 0; @@ -190,4 +294,77 @@ } return (int) Math.ceil(result); } + + /** + * @Description: ������AQI������������������map���key���sensorCode���value��������� + * @Param: [map] + * @return: java.util.Map<java.lang.String, java.lang.Object> + * @Author: ��������� + * @Date: 2021/10/29 + */ + public static Map<String, Object> cityAqiPollutant(Map<String, Object> map) { + List<Integer> AQIList = new ArrayList<>(); + Map<String, Integer> AQIMap = new HashMap<>(); + for (Map.Entry<String, Object> entry : map.entrySet()) { + String key = entry.getKey(); + if (entry.getValue().toString().equals("")) { + continue; + } + int PM2_5AQI; + int PM10AQI; + int SO2AQI; + int NO2AQI; + int COAQI; + int O3AQI; + switch (key) { + case "pm2_5": + PM2_5AQI = PM2_5AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(PM2_5AQI); + AQIMap.put("pm2_5", PM2_5AQI); + break; + case "pm10": + PM10AQI = PM10AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(PM10AQI); + AQIMap.put("pm10", PM10AQI); + break; + case Constants.SENSOR_CODE_SO2: + SO2AQI = SO2AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(SO2AQI); + AQIMap.put("so2", SO2AQI); + break; + case Constants.SENSOR_CODE_NO2: + NO2AQI = NO2AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(NO2AQI); + AQIMap.put("no2", NO2AQI); + break; + case Constants.SENSOR_CODE_CO: + COAQI = COAQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(COAQI); + AQIMap.put("co", COAQI); + break; + case Constants.SENSOR_CODE_O3: + O3AQI = O3AQI(Double.valueOf(entry.getValue().toString())); + AQIList.add(O3AQI); + AQIMap.put("o3", O3AQI); + break; + default: + break; + } + } + int AQIMAX = 0; + if (!ObjectUtils.isEmpty(AQIList)) { + AQIMAX = Collections.max(AQIList); + } + List<String> nameList = new ArrayList<>(); + for (String key : AQIMap.keySet()) { + if (AQIMap.get(key).equals(AQIMAX)) { + nameList.add(key); + } + } + Map<String, Object> resultMap = new HashMap<>(); + resultMap.put("aqi", AQIMAX); + if (AQIMAX > 50) + resultMap.put("pollutant", nameList); + return resultMap; + } } -- Gitblit v1.8.0