| | |
| | | import com.moral.api.service.SysAreaService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.pojo.AQI; |
| | | import com.moral.util.AQIUtils; |
| | | import com.moral.util.AmendUtils; |
| | | import com.moral.util.DateUtils; |
| | |
| | | Date date = (Date) forecastDatum.get("time"); |
| | | String value = forecastDatum.get("value").toString(); |
| | | Map<String, Object> data = JSONObject.parseObject(value, Map.class); |
| | | Object o3 = data.get("o3"); |
| | | Object o3 = data.get("O3"); |
| | | if (i == DateUtils.getHour(date) * 2) { |
| | | if (!ObjectUtils.isEmpty(o3)) { |
| | | map.put("O3", o3); |
| | |
| | | Date date = (Date) measuredDatum.get("time"); |
| | | String value = measuredDatum.get("value").toString(); |
| | | Map<String, Object> data = JSONObject.parseObject(value, Map.class); |
| | | Object o3 = data.get("o3"); |
| | | Object o3 = data.get("O3"); |
| | | if (i == (DateUtils.getHour(date) * 2 + 1)) { |
| | | if (!ObjectUtils.isEmpty(o3)) { |
| | | map.put("O3", o3); |
| | |
| | | if (value == null) |
| | | value = queryCityAqiByRegionCodeFromDB(regionCode); |
| | | //根据AQI计算污染等级 |
| | | if (value == null || value.get("aqi") == null) |
| | | if (value == null || value.get("AQI") == null) |
| | | return null; |
| | | Integer aqi = Integer.parseInt(value.get("aqi").toString()); |
| | | Integer aqi = Integer.parseInt(value.get("AQI").toString()); |
| | | String category = AQIUtils.classOfPollutionByAqi(aqi); |
| | | value.put("category", category); |
| | | return value; |
| | |
| | | continue; |
| | | } |
| | | Map<String, Object> allDataMap = JSON.parseObject(allDataJson, Map.class); |
| | | Object aqiData = allDataMap.get("aqi"); |
| | | Object aqiData = allDataMap.get("AQI"); |
| | | if (aqiData == null) |
| | | result.put(key, ""); |
| | | else |
| | |
| | | //计算平均数 |
| | | Map<String, Object> sixParamAvg = calculate6ParamAvg(cityAqis); |
| | | //计算累计aqi和首要污染物 |
| | | Map<String, Object> result = AQIUtils.hourlyAqi_pollutant(sixParamAvg); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | AQI aqi = AQIUtils.hourlyAQI(sixParamAvg); |
| | | result.put("aqi",aqi.getAQIValue()); |
| | | result.put("pollutant",aqi.getPrimaryPollutantNames()); |
| | | //结果集添加时间 |
| | | CityAqi lastCityAqi = cityAqis.get(cityAqis.size() - 1); |
| | | String time = DateUtils.dateToDateString(lastCityAqi.getTime(), "HH:mm"); |
| | |
| | | * @Date: 2021/11/2 |
| | | */ |
| | | private Map<String, Object> calculate6ParamAvg(List<CityAqi> cityAqiList) { |
| | | Double co = calculateSensorAvg(cityAqiList, "co"); |
| | | Double pm2_5 = calculateSensorAvg(cityAqiList, "pm2_5"); |
| | | Double pm10 = calculateSensorAvg(cityAqiList, "pm10"); |
| | | Double so2 = calculateSensorAvg(cityAqiList, "so2"); |
| | | Double no2 = calculateSensorAvg(cityAqiList, "no2"); |
| | | Double o3 = calculateSensorAvg(cityAqiList, "o3"); |
| | | Double co = calculateSensorAvg(cityAqiList, "CO"); |
| | | Double pm2_5 = calculateSensorAvg(cityAqiList, "PM2_5"); |
| | | Double pm10 = calculateSensorAvg(cityAqiList, "PM10"); |
| | | Double so2 = calculateSensorAvg(cityAqiList, "SO2"); |
| | | Double no2 = calculateSensorAvg(cityAqiList, "NO2"); |
| | | Double o3 = calculateSensorAvg(cityAqiList, "O3"); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put(Constants.SENSOR_CODE_CO, co); |
| | | result.put(Constants.SENSOR_CODE_NO2, no2); |
| | |
| | | if (!ObjectUtils.isEmpty(one)) { |
| | | String value = one.getValue(); |
| | | Map<String, Object> valueMap = JSONObject.parseObject(value, Map.class); |
| | | rankMap.put("aqi", valueMap.get("aqi")); |
| | | rankMap.put("AQI", valueMap.get("AQI")); |
| | | } |
| | | |
| | | |
| | | //2.本月累计综合指数计算,截止到昨日 |
| | | queryWrapper.clear(); |
| | |
| | | } |
| | | |
| | | //日排名,按aqi排序 |
| | | ranks.removeIf(o -> o.get("aqi") == null); |
| | | sortByField(ranks, "aqi"); |
| | | ranks.removeIf(o -> o.get("AQI") == null); |
| | | sortByField(ranks, "AQI"); |
| | | //日排名结果 |
| | | Map<String, Object> dayMap = rankByField(ranks, cityCode, "aqi", cityCodes.size()); |
| | | if (!ObjectUtils.isEmpty(dayMap)) { |
| | | dayMap.put("aqi", dayMap.remove("value")); |
| | | Map<String, Object> dayMap = rankByField(ranks, cityCode, "AQI", cityCodes.size()); |
| | | if (ObjectUtils.isEmpty(dayMap)) { |
| | | dayMap.put("rank", null); |
| | | dayMap.put("size", null); |
| | | } |
| | | dayMap.put("AQI", dayMap.remove("value")); |
| | | result.put("day", dayMap); |
| | | |
| | | //月排名,按累计综指排 |
| | |
| | | sortByField(ranks, "compositeIndexMonth"); |
| | | //月排名结果 |
| | | Map<String, Object> monthMap = rankByField(ranks, cityCode, "compositeIndexMonth", cityCodes.size()); |
| | | if (!ObjectUtils.isEmpty(monthMap)) { |
| | | monthMap.put("compositeIndex", monthMap.remove("value")); |
| | | if (ObjectUtils.isEmpty(monthMap)) { |
| | | monthMap.put("rank", null); |
| | | monthMap.put("size", null); |
| | | } |
| | | monthMap.put("compositeIndex", monthMap.remove("value")); |
| | | result.put("month", monthMap); |
| | | |
| | | //年排名,按累计综指排 |
| | |
| | | //年排名结果 |
| | | sortByField(ranks, "compositeIndexYear"); |
| | | Map<String, Object> yearMap = rankByField(ranks, cityCode, "compositeIndexYear", cityCodes.size()); |
| | | if(!ObjectUtils.isEmpty(yearMap)){ |
| | | yearMap.put("compositeIndex", yearMap.remove("value")); |
| | | if (ObjectUtils.isEmpty(yearMap)) { |
| | | yearMap.put("rank", null); |
| | | yearMap.put("size", null); |
| | | } |
| | | yearMap.put("compositeIndex", yearMap.remove("value")); |
| | | result.put("year", yearMap); |
| | | |
| | | //时间,昨日 |