From 30c76f1f25ddf6437014ea47bdc206cf0e288ec7 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Wed, 03 Nov 2021 14:23:09 +0800 Subject: [PATCH] screen-common 修改AQI工具类代码 --- screen-common/src/main/java/com/moral/util/AQIUtils.java | 646 ++++++++++++++++++++++++++++------------------------------ 1 files changed, 314 insertions(+), 332 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 2b29c63..4d843a4 100644 --- a/screen-common/src/main/java/com/moral/util/AQIUtils.java +++ b/screen-common/src/main/java/com/moral/util/AQIUtils.java @@ -1,370 +1,352 @@ package com.moral.util; -import org.springframework.util.ObjectUtils; +import com.moral.pojo.AQI; import java.util.*; import com.moral.constant.Constants; public class AQIUtils { - public static int hourlyAqi(Map<String, Object> map) { - List<Integer> AQIList = new ArrayList<>(); - 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); - break; - case Constants.SENSOR_CODE_PM10: - PM10AQI = PM10AQI(Double.valueOf(entry.getValue().toString())); - AQIList.add(PM10AQI); - break; - case Constants.SENSOR_CODE_SO2: - SO2AQI = SO2AQI(Double.valueOf(entry.getValue().toString())); - AQIList.add(SO2AQI); - break; - case Constants.SENSOR_CODE_NO2: - NO2AQI = NO2AQI(Double.valueOf(entry.getValue().toString())); - AQIList.add(NO2AQI); - break; - case Constants.SENSOR_CODE_CO: - COAQI = COAQI(Double.valueOf(entry.getValue().toString())); - AQIList.add(COAQI); - break; - case Constants.SENSOR_CODE_O3: - O3AQI = O3AQI(Double.valueOf(entry.getValue().toString())); - AQIList.add(O3AQI); - break; - default: - break; - } - } - int AQIMAX = 0; - if (!ObjectUtils.isEmpty(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; - } + /*24������������������*/ + private static Double[] SO2_Daily_Limit_Data = new Double[]{0d, 50d, 150d, 475d, 800d, 1600d, 2100d, 2620d}; + private static Double[] NO2_Daily_Limit_Data = new Double[]{0d, 40d, 80d, 180d, 280d, 565d, 750d, 940d}; + private static Double[] PM10_Daily_Limit_Data = new Double[]{0d, 50d, 150d, 250d, 350d, 420d, 500d, 600d}; + private static Double[] CO_Daily_Limit_Data = new Double[]{0d, 2d, 4d, 14d, 24d, 36d, 48d, 60d}; + private static Double[] PM2_5_Daily_Limit_Data = new Double[]{0d, 35d, 75d, 115d, 150d, 250d, 350d, 500d}; + private static Double[] O3_Daily_Limit_Data = new Double[]{0d, 100d, 160d, 215d, 265d, 800d}; + /*1������������������*/ + private static Double[] SO2_Hourly_Limit_Data = new Double[]{0d, 150d, 500d, 650d, 800d}; + private static Double[] NO2_Hourly_Limit_Data = new Double[]{0d, 100d, 200d, 700d, 1200d, 2340d, 3090d, 3840d}; + private static Double[] PM10_Hourly_Limit_Data = new Double[]{0d, 50d, 150d, 250d, 350d, 420d, 500d, 600d}; + private static Double[] CO_Hourly_Limit_Data = new Double[]{0d, 5d, 10d, 35d, 60d, 90d, 120d, 150d}; + private static Double[] PM2_5_Hourly_Limit_Data = new Double[]{0d, 35d, 75d, 115d, 150d, 250d, 350d, 500d}; + private static Double[] O3_Hourly_Limit_Data = new Double[]{0d, 160d, 200d, 300d, 400d, 800d, 1000d, 1200d}; + /*���������������������*/ + private static Double[] IAQI_Array = new Double[]{0d,50d,100d,150d,200d,300d,400d,500d}; 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)); + Map<String,Object> map = new HashMap<>(); + map.put("a34002",60); + map.put("a34004",56); + map.put("a21004",99); + map.put("a21005",0.54); + map.put("a21026",27); + map.put("a05024",72); + System.out.println(dailyAQI(map)); } /** - * @Description: ������AQI������������ - * @Param: - * @return: - * @Author: ��������� - * @Date: 2021/10/29 - */ - public static String classOfPollutionByAqi(Integer aqi) { - if (aqi > 300) + * @Description: ������AQI������������ + * @Param: + * @return: + * @Author: ��������� + * @Date: 2021/10/29 + */ + public static String classOfPollutionByAqi(Integer aqi){ + if(aqi>300) return Constants.SERVER; - if (aqi > 200) + if(aqi>200) return Constants.SERIOUS; - if (aqi > 150) + if(aqi>150) return Constants.MIDDLE; - if (aqi > 100) + if(aqi>100) return Constants.MILD; - if (aqi > 50) + if(aqi>50) return Constants.GOOD; return Constants.EXCELLENT; } - //PM2.5 IAQI - private static int PM2_5AQI(Double value) { - double result; - if (value <= 0) { - result = 0; - } else if (value <= 35) { - result = 50d / 35d * (value - 0) + 0; - } else if (value <= 75) { - result = 50d / 40d * (value - 35) + 50; - } else if (value <= 115) { - result = 50d / 40d * (value - 75) + 100; - } else if (value <= 150) { - result = 50d / 35d * (value - 115) + 150; - } else if (value <= 250) { - result = 100d / 100d * (value - 150) + 200; - } else if (value <= 350) { - result = 100d / 100d * (value - 250) + 300; - } else { - result = 100d / 150d * (value - 350) + 400; + /** + * @Description: 24������AQI + * @Param: [paramMap] + * @return: java.lang.Integer + * @Author: ��������� + * @Date: 2021/11/3 + */ + public static AQI dailyAQI(Map<String,Object> paramMap){ + if(paramMap==null) + return null; + List<Integer> IAQIList = new ArrayList<>(); + List<String> primaryPollutantNames = new ArrayList<>(); + List<String> primaryPollutantCodes = new ArrayList<>(); + Integer PM2_5IAQI; + Integer SO2IAQI; + Integer NO2IAQI; + Integer COIAQI; + Integer PM10IAQI; + Integer O3IAQI; + if(paramMap.get(Constants.SENSOR_CODE_PM25)!=null){ + Double PM2_5 = Double.valueOf(paramMap.get("a34004").toString()); + PM2_5IAQI = calculateIAQIUniversal(PM2_5,PM2_5_Daily_Limit_Data); + IAQIList.add(PM2_5IAQI); + if(PM2_5IAQI>50){ + primaryPollutantCodes.add(Constants.SENSOR_CODE_PM25); + primaryPollutantNames.add("PM2.5"); + } } - return (int) Math.ceil(result); - } - - //PM10 IAQI - private static int PM10AQI(Double value) { - double result; - if (value <= 0) { - result = 0; - } else if (value <= 50) { - result = 50d / 50d * (value - 0) + 0; - } else if (value <= 150) { - result = 50d / 100d * (value - 50) + 50; - } else if (value <= 250) { - result = 50d / 100d * (value - 150) + 100; - } else if (value <= 350) { - result = 50d / 100d * (value - 250) + 150; - } else if (value <= 420) { - result = 100d / 70d * (value - 350) + 200; - } else if (value <= 500) { - result = 100d / 80d * (value - 420) + 300; - } else { - result = 100d / 100d * (value - 500) + 400; + if(paramMap.get(Constants.SENSOR_CODE_SO2)!=null){ + Double SO2 = Double.valueOf(paramMap.get("a21026").toString()); + SO2IAQI = calculateIAQIUniversal(SO2,SO2_Daily_Limit_Data); + IAQIList.add(SO2IAQI); + if(SO2IAQI>50){ + primaryPollutantNames.add("SO2"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_SO2); + } } - return (int) Math.ceil(result); - } - - //SO2 IAQI - private static int SO2AQI(Double value) { - double result; - if (value <= 0) { - result = 0; - } else if (value <= 150) { - result = 50d / 150d * (value - 0) + 0; - } else if (value <= 500) { - result = 50d / 350d * (value - 150) + 50; - } else if (value <= 650) { - result = 50d / 150d * (value - 500) + 100; - } else { - result = 50d / 150d * (value - 650) + 150; + if(paramMap.get(Constants.SENSOR_CODE_NO2)!=null){ + Double NO2 = Double.valueOf(paramMap.get("a21004").toString()); + NO2IAQI = calculateIAQIUniversal(NO2,NO2_Daily_Limit_Data); + IAQIList.add(NO2IAQI); + if(NO2IAQI>50){ + primaryPollutantNames.add("NO2"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_NO2); + } } - return (int) Math.ceil(result); - } - - //NO2 IAQI - private static int NO2AQI(Double value) { - double result; - if (value <= 0) { - result = 0; - } else if (value <= 100) { - result = 50d / 100d * (value - 0) + 0; - } else if (value <= 200) { - result = 50d / 100d * (value - 100) + 50; - } else if (value <= 700) { - result = 50d / 500d * (value - 200) + 100; - } else if (value <= 1200) { - result = 50d / 500d * (value - 700) + 150; - } else if (value <= 2340) { - result = 100d / 1140d * (value - 1200) + 200; - } else if (value <= 3090) { - result = 100d / 750d * (value - 2340) + 300; - } else { - result = 100d / 750d * (value - 3090) + 400; + if(paramMap.get(Constants.SENSOR_CODE_CO)!=null){ + Double CO = Double.valueOf(paramMap.get("a21005").toString()); + COIAQI = calculateIAQIUniversal(CO,CO_Daily_Limit_Data); + IAQIList.add(COIAQI); + if(COIAQI>50){ + primaryPollutantNames.add("CO"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_CO); + } } - return (int) Math.ceil(result); - } - - //CO IAQI - private static int COAQI(Double value) { - double result; - if (value <= 0) { - result = 0; - } else if (value <= 5) { - result = 50d / 5d * (value - 0) + 0; - } else if (value <= 10) { - result = 50d / 5d * (value - 5) + 50; - } else if (value <= 35) { - result = 50d / 25d * (value - 10) + 100; - } else if (value <= 60) { - result = 50d / 25d * (value - 35) + 150; - } else if (value <= 90) { - result = 100d / 30d * (value - 60) + 200; - } else if (value <= 120) { - result = 100d / 30d * (value - 90) + 300; - } else { - result = 100d / 30d * (value - 120) + 400; + if(paramMap.get(Constants.SENSOR_CODE_PM10)!=null){ + Double PM10 = Double.valueOf(paramMap.get("a34002").toString()); + PM10IAQI = calculateIAQIUniversal(PM10,PM10_Daily_Limit_Data); + IAQIList.add(PM10IAQI); + if(PM10IAQI>50){ + primaryPollutantNames.add("PM10"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_PM10); + } } - return (int) Math.ceil(result); - } - - //O3 IAQI - private static int O3AQI(Double value) { - double result; - if (value <= 0) { - result = 0; - } else if (value <= 100) { - result = 50d / 100d * (value - 0) + 0; - } else if (value <= 160) { - result = 50d / 60d * (value - 100) + 50; - } else if (value <= 215) { - result = 50d / 55d * (value - 160) + 100; - } else if (value <= 265) { - result = 50d / 150d * (value - 215) + 150; - } else if (value <= 800) { - result = 100d / 535d * (value - 265) + 200; - } else if (value <= 2100) { - result = 100d / 12d * (value - 800) + 300; - } else { - result = 100d / 12d * (value - 48) + 400; + if(paramMap.get(Constants.SENSOR_CODE_O3)!=null){ + Double O3 = Double.valueOf(paramMap.get("a05024").toString()); + O3IAQI = calculateO3DailyIAQI(O3); + IAQIList.add(O3IAQI); + if(O3IAQI>50){ + primaryPollutantNames.add("O3"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_O3); + } } - return (int) Math.ceil(result); + AQI aqi= new AQI(); + aqi.setAQIValue(getAQIByIAQIs(IAQIList)); + aqi.setPrimaryPollutantCodes(primaryPollutantCodes); + aqi.setPrimaryPollutantNames(primaryPollutantNames); + return aqi; } /** - * @Description: ������AQI������������������map���key���pm2_5,pm10,so2,no2,co,o3���value��������� - * @Param: [map] - * @return: java.util.Map<java.lang.String, java.lang.Object> + * @Description: 1������AQI + * @Param: [paramMap] + * @return: java.lang.Integer * @Author: ��������� - * @Date: 2021/10/29 + * @Date: 2021/11/3 */ - 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; + public static AQI hourlyAQI(Map<String,Object> paramMap){ + if(paramMap==null) + return null; + List<Integer> IAQIList = new ArrayList<>(); + List<String> primaryPollutantNames = new ArrayList<>(); + List<String> primaryPollutantCodes = new ArrayList<>(); + Integer PM2_5IAQI; + Integer SO2IAQI; + Integer NO2IAQI; + Integer COIAQI; + Integer PM10IAQI; + Integer O3IAQI; + if(paramMap.get("a34004")!=null){ + Double PM2_5 = Double.valueOf(paramMap.get("a34004").toString()); + PM2_5IAQI = calculateIAQIUniversal(PM2_5,PM2_5_Hourly_Limit_Data); + IAQIList.add(PM2_5IAQI); + if(PM2_5IAQI>50){ + primaryPollutantCodes.add(Constants.SENSOR_CODE_PM25); + primaryPollutantNames.add("PM2.5"); } } - 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); + if(paramMap.get("a21026")!=null){ + Double SO2 = Double.valueOf(paramMap.get("a21026").toString()); + SO2IAQI = calculateSO2HourlyIAQI(SO2); + IAQIList.add(SO2IAQI); + if(SO2IAQI>50){ + primaryPollutantNames.add("SO2"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_SO2); } } - Map<String, Object> resultMap = new HashMap<>(); - resultMap.put("aqi", AQIMAX); - if (AQIMAX > 50) - resultMap.put("pollutant", nameList); - return resultMap; + if(paramMap.get("a21004")!=null){ + Double NO2 = Double.valueOf(paramMap.get("a21004").toString()); + NO2IAQI = calculateIAQIUniversal(NO2,NO2_Hourly_Limit_Data); + IAQIList.add(NO2IAQI); + if(NO2IAQI>50){ + primaryPollutantNames.add("NO2"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_NO2); + } + } + if(paramMap.get("a21005")!=null){ + Double CO = Double.valueOf(paramMap.get("a21005").toString()); + COIAQI = calculateIAQIUniversal(CO,CO_Hourly_Limit_Data); + IAQIList.add(COIAQI); + if(COIAQI>50){ + primaryPollutantNames.add("CO"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_CO); + } + } + if(paramMap.get("a34002")!=null){ + Double PM10 = Double.valueOf(paramMap.get("a34002").toString()); + PM10IAQI = calculateIAQIUniversal(PM10,PM10_Hourly_Limit_Data); + IAQIList.add(PM10IAQI); + if(PM10IAQI>50){ + primaryPollutantNames.add("PM10"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_PM10); + } + } + if(paramMap.get("a05024")!=null){ + Double O3 = Double.valueOf(paramMap.get("a05024").toString()); + O3IAQI = calculateIAQIUniversal(O3,O3_Hourly_Limit_Data); + IAQIList.add(O3IAQI); + if(O3IAQI>50) { + primaryPollutantNames.add("O3"); + primaryPollutantCodes.add(Constants.SENSOR_CODE_O3); + } + } + AQI aqi= new AQI(); + aqi.setAQIValue(getAQIByIAQIs(IAQIList)); + aqi.setPrimaryPollutantCodes(primaryPollutantCodes); + aqi.setPrimaryPollutantNames(primaryPollutantNames); + return aqi; } + + + /** + * @Description: ������IAQI������AQI + * @Param: [IAQIs] + * @return: int + * @Author: ��������� + * @Date: 2021/11/3 + */ + private static Integer getAQIByIAQIs(List<Integer> IAQIs){ + if(IAQIs.size()==0) + return null; + Optional<Integer> max = IAQIs.stream().max(Comparator.comparing(Integer::intValue)); + return max.get(); + } + + + /** + * @Description: ������so2���������IAQI���O3������IAQI������IAQI������������ + * @Param: [Cp, limitData] + * @return: java.lang.Integer + * @Author: ��������� + * @Date: 2021/11/2 + */ + private static Integer calculateIAQIUniversal(Double Cp,Double[] limitData){ + int index = getStartIndexFromArray(Cp, limitData); + Double BPHi; + Double BPLo; + Double IAQIHi; + Double IAQILo; + if(index==limitData.length-1){ + return 500; + }else{ + BPHi = limitData[index+1]; + BPLo = limitData[index]; + IAQIHi = IAQI_Array[index+1]; + IAQILo = IAQI_Array[index]; + } + return calculateIAQIFormula(Cp,BPHi,BPLo,IAQIHi,IAQILo); + } + + /** + * @Description: ������so2���������IAQI + * @Param: [Cp, limitData] + * @return: java.lang.Integer + * @Author: ��������� + * @Date: 2021/11/2 + */ + private static Integer calculateSO2HourlyIAQI(Double Cp){ + Double BPHi; + Double BPLo; + Double IAQIHi; + Double IAQILo; + Double[] limitData = SO2_Hourly_Limit_Data; + int index = getStartIndexFromArray(Cp, limitData); + //������so2���������������������������������������24������������������������������������������ + if(index ==SO2_Hourly_Limit_Data.length-1){ + limitData = SO2_Daily_Limit_Data; + index = getStartIndexFromArray(Cp,limitData); + } + if(index==limitData.length-1){ + return 500; + }else{ + BPHi = limitData[index+1]; + BPLo = limitData[index]; + IAQIHi = IAQI_Array[index+1]; + IAQILo = IAQI_Array[index]; + } + return calculateIAQIFormula(Cp,BPHi,BPLo,IAQIHi,IAQILo); + } + + /** + * @Description: ������O3������IAQI + * @Param: [Cp] + * @return: java.lang.Integer + * @Author: ��������� + * @Date: 2021/11/3 + */ + private static Integer calculateO3DailyIAQI(Double Cp){ + Double BPHi; + Double BPLo; + Double IAQIHi; + Double IAQILo; + Double[] limitData = O3_Daily_Limit_Data; + int index = getStartIndexFromArray(Cp, limitData); + //������so2���������������������������������������24������������������������������������������ + if(index ==O3_Daily_Limit_Data.length-1){ + limitData = O3_Hourly_Limit_Data; + index = getStartIndexFromArray(Cp,limitData); + } + if(index==limitData.length-1){ + return 500; + }else{ + BPHi = limitData[index+1]; + BPLo = limitData[index]; + IAQIHi = IAQI_Array[index+1]; + IAQILo = IAQI_Array[index]; + } + return calculateIAQIFormula(Cp,BPHi,BPLo,IAQIHi,IAQILo); + } + + /** + * @Description: ������IAQI��������� + * @Param: [Cp, BPHi, BPLo, IAQIHi, IAQILo] + * @return: java.lang.Integer + * @Author: ��������� + * @Date: 2021/11/3 + */ + private static Integer calculateIAQIFormula(Double Cp, Double BPHi, Double BPLo, Double IAQIHi, Double IAQILo) { + Double tmp1 = MathUtils.sub(IAQIHi, IAQILo); + Double tmp2 = MathUtils.sub(BPHi, BPLo); + Double tmp3 = MathUtils.sub(Cp, BPLo); + + Double tmp4 = MathUtils.division(tmp1, tmp2, 2); + Double tmp5 = MathUtils.mul(tmp4, tmp3); + Double IAQI = MathUtils.add(tmp5, IAQILo); + return new Double(AmendUtils.sciCal(IAQI, 0)).intValue(); + } + + /*������������������������������������������������������ + * ������������������5 10 + * ���������[0,5,15,20] [0,5,8,12] + * ���������1(������������) 2 + * */ + private static int getStartIndexFromArray(Double num, Double[] array) { + for (int i = 0; i < array.length - 1; i++) { + if (num >= array[i] && num < array[i + 1]) + return i; + if (i == array.length - 2) + return i + 1; + } + return 0; + } + } -- Gitblit v1.8.0