From 6cc2a1d726e1019079b6d3fa74599426a359c001 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Tue, 02 Nov 2021 14:55:24 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev_ --- screen-common/src/main/java/com/moral/util/AQIUtils.java | 125 ++++++++++++++++++++++++++++++++++++++--- 1 files changed, 114 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..a55c8f5 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,119 @@ } 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 +186,7 @@ } //PM10 IAQI - public static int PM10AQI(Double value) { + private static int PM10AQI(Double value) { double result; if (value <= 0) { result = 0; @@ -106,7 +209,7 @@ } //SO2 IAQI - public static int SO2AQI(Double value) { + private static int SO2AQI(Double value) { double result; if (value <= 0) { result = 0; @@ -123,7 +226,7 @@ } //NO2 IAQI - public static int NO2AQI(Double value) { + private static int NO2AQI(Double value) { double result; if (value <= 0) { result = 0; @@ -146,7 +249,7 @@ } //CO IAQI - public static int COAQI(Double value) { + private static int COAQI(Double value) { double result; if (value <= 0) { result = 0; @@ -169,7 +272,7 @@ } //O3 IAQI - public static int O3AQI(Double value) { + private static int O3AQI(Double value) { double result; if (value <= 0) { result = 0; -- Gitblit v1.8.0