| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | |
| | | //明日此小时风向 |
| | | String windDir = nextDayMap.get("windDir").toString(); |
| | | //风级 |
| | | String windScale = nextDayMap.get("windScale").toString(); |
| | | int windScale = Integer.parseInt(nextDayMap.get("windScale").toString()); |
| | | String time = nextDayMap.remove("time").toString(); |
| | | //当前小时 |
| | | hours.add(time.substring(11, 13)); |
| | |
| | | } |
| | | List<Integer> years = new ArrayList<>(); |
| | | Collections.addAll(years, timeUnits1, timeUnits2, timeUnits3, timeUnits4); |
| | | List<String> O3Samples = getSample(hashMap, years); |
| | | //根据天气筛选 |
| | | List<Map<String, Object>> O3Samples = getSample(hashMap, years); |
| | | if (O3Samples.size() > 100) { |
| | | hashMap.put("startTemp", temp - 1); |
| | | hashMap.put("endTemp", temp + 1); |
| | | O3Samples = getSample(hashMap, years); |
| | | O3Samples = O3Samples.parallelStream() |
| | | .filter(sample -> Integer.parseInt(sample.get("temp").toString()) >= temp - 1 && Integer.parseInt(sample.get("temp").toString()) <= temp + 1) |
| | | .collect(Collectors.toList()); |
| | | if (O3Samples.size() > 100) { |
| | | hashMap.put("startPressure", pressure - 5); |
| | | hashMap.put("endPressure", pressure + 5); |
| | | O3Samples = getSample(hashMap, years); |
| | | O3Samples = O3Samples.parallelStream() |
| | | .filter(sample -> Integer.parseInt(sample.get("pressure").toString()) >= pressure - 5 && Integer.parseInt(sample.get("pressure").toString()) <= pressure + 5) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | } |
| | | |
| | | hashMap.put("slicedTime1", slicedTime1); |
| | | hashMap.put("slicedTime2", slicedTime2); |
| | | hashMap.put("nowTemp", temp); |
| | | hashMap.put("sHour", sHour); |
| | | hashMap.put("eHour", eHour); |
| | | Map<String, List<String>> sectionTimesMap = getSectionTimes(hashMap, O3Samples, years); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("cityCode", cityCode); |
| | |
| | | Double O3Avg1 = getAvg(params, times1); |
| | | Double O3Avg2 = getAvg(params, times2); |
| | | Double O3Avg3 = getAvg(params, times3); |
| | | Double resultO3 = O3Avg1 * 0.7 + O3Avg2 * 0.15 + O3Avg3 * 0.15; |
| | | double resultO3 = O3Avg1 * 0.7 + O3Avg2 * 0.15 + O3Avg3 * 0.15; |
| | | nextDayMap.put("O3C", String.valueOf(Math.round(resultO3))); |
| | | //pm2.5,pm10颗粒物预测,温度,风向风级,气压 |
| | | Map<String, Object> hashMap1 = new HashMap<>(); |
| | |
| | | hashMap1.put("typeFormat", "%Y-%m-%d %H:%i:%s"); |
| | | hashMap1.put("startTemp", temp - 1); |
| | | hashMap1.put("endTemp", temp + 1); |
| | | List<String> pmSamples = getSample(hashMap1, years); |
| | | List<Map<String, Object>> pmSamples = getSample(hashMap1, years); |
| | | if (pmSamples.size() > 100) { |
| | | hashMap1.put("windScale", windScale); |
| | | pmSamples = getSample(hashMap1, years); |
| | | pmSamples = pmSamples.parallelStream() |
| | | .filter(sample -> Integer.parseInt(sample.get("windScale").toString()) == windScale) |
| | | .collect(Collectors.toList()); |
| | | if (pmSamples.size() > 100) { |
| | | hashMap1.put("windDir", windDir); |
| | | pmSamples = getSample(hashMap1, years); |
| | | pmSamples = pmSamples.parallelStream() |
| | | .filter(sample -> sample.get("windDir").toString().replace("\"", "").equals(windDir)) |
| | | .collect(Collectors.toList()); |
| | | if (pmSamples.size() > 100) { |
| | | hashMap1.put("startPressure", pressure - 5); |
| | | hashMap1.put("endPressure", pressure + 5); |
| | | pmSamples = getSample(hashMap1, years); |
| | | pmSamples = pmSamples.parallelStream() |
| | | .filter(sample -> Integer.parseInt(sample.get("pressure").toString()) >= pressure - 5 && Integer.parseInt(sample.get("pressure").toString()) <= pressure + 5) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | } |
| | | } |
| | |
| | | Double PM10Avg1 = getAvg(params1, times4); |
| | | Double PM10Avg2 = getAvg(params1, times5); |
| | | Double PM10Avg3 = getAvg(params1, times6); |
| | | Double resultPM25 = PM25Avg1 * 0.7 + PM25Avg2 * 0.15 + PM25Avg3 * 0.15; |
| | | double resultPM25 = PM25Avg1 * 0.7 + PM25Avg2 * 0.15 + PM25Avg3 * 0.15; |
| | | nextDayMap.put("PM25C", String.valueOf(Math.round(resultPM25))); |
| | | Double resultPM10 = PM10Avg1 * 0.7 + PM10Avg2 * 0.15 + PM10Avg3 * 0.15; |
| | | double resultPM10 = PM10Avg1 * 0.7 + PM10Avg2 * 0.15 + PM10Avg3 * 0.15; |
| | | nextDayMap.put("PM10C", String.valueOf(Math.round(resultPM10))); |
| | | params.put("time", time); |
| | | String beam = weatherMapper.getBeam(params); |
| | |
| | | return count; |
| | | } |
| | | |
| | | private List<String> getSample(Map<String, Object> params, List<Integer> years) { |
| | | List<String> samples = new ArrayList<>(); |
| | | private List<Map<String, Object>> getSample(Map<String, Object> params, List<Integer> years) { |
| | | List<Map<String, Object>> samples = new ArrayList<>(); |
| | | if (years.size() > 0) { |
| | | for (Integer year : years) { |
| | | params.put("timeUnits", year); |
| | |
| | | values.add(value.replace("\"", "")); |
| | | } |
| | | } |
| | | Double sum = 0.0; |
| | | double sum = 0.0; |
| | | for (String v : values) { |
| | | sum += Double.valueOf(v); |
| | | sum += Double.parseDouble(v); |
| | | } |
| | | return sum / values.size(); |
| | | } |
| | | |
| | | private Map<String, List<String>> getSectionTimes(Map<String, Object> params, List<String> samples, List<Integer> years) throws ParseException { |
| | | private Map<String, List<String>> getSectionTimes(Map<String, Object> params, List<Map<String, Object>> samples, List<Integer> years) throws ParseException { |
| | | Map<String, List<String>> hashMap = new HashMap<>(); |
| | | //当天前15天 |
| | | List<String> times1 = new ArrayList<>(); |
| | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date slicedTime1 = (Date) (params.get("slicedTime1")); |
| | | Date slicedTime2 = (Date) (params.get("slicedTime2")); |
| | | for (String sample : samples) { |
| | | Date samTime = sdf.parse(sample); |
| | | for (Map<String, Object> sample : samples) { |
| | | String time = sample.get("time").toString(); |
| | | Date samTime = sdf.parse(time); |
| | | if (samTime.getTime() >= slicedTime1.getTime()) { |
| | | times1.add(sample); |
| | | times1.add(time); |
| | | } else if (samTime.getTime() >= slicedTime2.getTime()) { |
| | | times2.add(sample); |
| | | times2.add(time); |
| | | } else { |
| | | times3.add(sample); |
| | | times3.add(time); |
| | | } |
| | | } |
| | | |
| | | hashMap.put("times1", times1); |
| | | hashMap.put("times2", times2); |
| | | hashMap.put("times3", times3); |
| | | |
| | | if (params.get("nowTemp") != null && params.get("hours") != null) { |
| | | Double nowTemp = Double.valueOf(params.get("nowTemp").toString()); |
| | | ArrayList<String> hours = (ArrayList<String>) params.get("hours"); |
| | | for (String key : hashMap.keySet()) { |
| | | List<String> values = hashMap.get(key); |
| | | if (values.size() == 0) { |
| | | params.put("startTemp", nowTemp - 2.0); |
| | | params.put("endTemp", nowTemp + 2.0); |
| | | if ("times1".equals(key) || "times2".equals(key)) { |
| | | years = new ArrayList<>(); |
| | | values = getSample(params, years); |
| | | } else { |
| | | values = getSample(params, years); |
| | | } |
| | | if (values.size() == 0) { |
| | | hours.add(params.get("sHour").toString()); |
| | | hours.add(params.get("eHour").toString()); |
| | | params.put("hours", hours); |
| | | if ("times1".equals(key) || "times2".equals(key)) { |
| | | years = new ArrayList<>(); |
| | | values = getSample(params, years); |
| | | } else { |
| | | values = getSample(params, years); |
| | | } |
| | | } |
| | | hashMap.put(key, values); |
| | | } |
| | | } |
| | | } |
| | | return hashMap; |
| | | } |
| | | |