screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java
@@ -89,7 +89,7 @@ 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); @@ -104,7 +104,7 @@ 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); screen-job/src/main/java/com/moral/api/service/impl/CityAqiDailyServiceImpl.java
@@ -8,6 +8,8 @@ import com.moral.api.service.CityAqiDailyService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.api.service.CityAqiService; import com.moral.pojo.AQI; import com.moral.util.AQIUtils; import com.moral.util.AmendUtils; import com.moral.util.ComprehensiveIndexUtils; import com.moral.util.DateUtils; @@ -45,7 +47,7 @@ @Override public void insertCityAqiDaily() { List<String> sensors = Arrays.asList("pm2_5", "pm10", "so2", "no2", "co", "o3", "aqi"); List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2", "CO", "O3", "AQI"); String format = DateUtils.yyyy_MM_dd_EN; Date now = new Date(); //开始时间,昨日 @@ -77,10 +79,12 @@ //移除第一天数据(0点的),O3滑动值第一条数据是从1点-8点 value.removeIf(map -> ((Date) map.get("time")).getTime() == start.getTime()); //臭氧日均值计算,滑动值算法 Double o3OfDay = AmendUtils.o3OfDay(value); if (o3OfDay != null) { jsonMap.put("o3", o3OfDay); jsonMap.put("O3", o3OfDay); } //除臭氧外其他因子均值计算 tempValue.removeIf(o -> ((Date) o.get("time")).getTime() == end.getTime()); @@ -88,7 +92,12 @@ OptionalDouble optionalDouble = tempValue.parallelStream().flatMapToDouble(v -> { Map<String, Object> dataValue = JSONObject.parseObject((String) v.get("value"), Map.class); //臭氧单独计算 if ("o3".equals(sensor)) { if ("O3".equals(sensor)) { return null; } //aqi单独计算 if ("AQI".equals(sensor)) { return null; } @@ -102,7 +111,7 @@ if (optionalDouble.isPresent()) { //银行家算法修约 double sciCal; if ("co".equals(sensor)) { if ("CO".equals(sensor)) { sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 1); } else { sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0); @@ -111,10 +120,17 @@ } }); //日aqi计算 AQI aqi = AQIUtils.dailyAQI(jsonMap); jsonMap.put("AQI", aqi.getAQIValue()); //日综合指数计算 Double compositeIndex = ComprehensiveIndexUtils.dailyData(jsonMap); jsonMap.put("compositeIndex", compositeIndex); //首要污染物计算 jsonMap.put("primaryPollutant", aqi.getPrimaryPollutantNames()); cityAqiDaily.setValue(JSONObject.toJSONString(jsonMap)); cityAqiDailyMapper.insert(cityAqiDaily); }); screen-job/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java
@@ -110,19 +110,19 @@ if (cityAqis.size() >= 6) { OptionalDouble average = cityAqis.parallelStream().flatMapToDouble(v -> { Map<String, Object> dataValue = JSONObject.parseObject((String) v.get("value"), Map.class); double o3 = Double.parseDouble(dataValue.get("o3").toString()); double o3 = Double.parseDouble(dataValue.get("O3").toString()); return DoubleStream.of(o3); }).average(); if (average.isPresent()) { double o3_8h = AmendUtils.sciCal(average.getAsDouble(), 0); aqi.put("o3_8h", o3_8h); double O3_8H = AmendUtils.sciCal(average.getAsDouble(), 0); aqi.put("O3_8H", O3_8H); } } } //综合指数计算 Map<String, Object> temp = new HashMap<>(aqi); temp.put("o3", temp.get("o3_8h")); temp.put("O3", temp.get("O3_8H")); Double compositeIndex = ComprehensiveIndexUtils.dailyData(temp); aqi.put("compositeIndex", compositeIndex); @@ -136,7 +136,7 @@ sixParamMap.put("a21026",aqi.get("SO2")); AQI aqiAndPollutant = AQIUtils.hourlyAQI(sixParamMap); if (!ObjectUtils.isEmpty(aqiAndPollutant.getPrimaryPollutantNames())) { aqi.put("pollutant",aqiAndPollutant.getPrimaryPollutantNames()); aqi.put("primaryPollutant", aqiAndPollutant.getPrimaryPollutantNames()); } CityAqi cityAqi = new CityAqi();