|
@@ -7,10 +7,15 @@ import com.cpp.web.domain.enums.DataSourcesEnum;
|
|
import com.cpp.web.domain.enums.ForecastTypeEnum;
|
|
import com.cpp.web.domain.enums.ForecastTypeEnum;
|
|
import com.cpp.web.mapper.accuracy.AccuracyPassRateMapper;
|
|
import com.cpp.web.mapper.accuracy.AccuracyPassRateMapper;
|
|
import com.cpp.web.service.accuracy.AccuracyPassRateService;
|
|
import com.cpp.web.service.accuracy.AccuracyPassRateService;
|
|
|
|
+import com.cpp.web.utils.StartAndEndMonthUtil;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.function.Function;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* idp_forecast_power_short_term
|
|
* idp_forecast_power_short_term
|
|
@@ -60,4 +65,119 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
|
|
wrapper.eq("forecast_type","dq");
|
|
wrapper.eq("forecast_type","dq");
|
|
return list(wrapper);
|
|
return list(wrapper);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Double> findByMonthBetweenAndForecastTypeAndStationCode(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources,String stationCode) {
|
|
|
|
+
|
|
|
|
+ QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
|
|
|
|
+ if (stationCode != null && !stationCode.equals("")) {
|
|
|
|
+ wrapper.eq("station_code", stationCode);
|
|
|
|
+ }
|
|
|
|
+ if (startTime != null && endTime != null) {
|
|
|
|
+ wrapper.between("time", new Date(StartAndEndMonthUtil.getBeginAndEndMonth(startTime,1)), new Date(StartAndEndMonthUtil.getBeginAndEndMonth(endTime,2)));
|
|
|
|
+ }
|
|
|
|
+ if (forecastType != null && !forecastType.equals("")) {
|
|
|
|
+ wrapper.eq("forecast_type", forecastType);
|
|
|
|
+ }
|
|
|
|
+ if (dataSources != null && !dataSources.equals("")) {
|
|
|
|
+ wrapper.eq("data_sources", dataSources);
|
|
|
|
+ }
|
|
|
|
+ List<AccuracyPassRate> accuracyPassRateList = baseMapper.selectList(wrapper);
|
|
|
|
+
|
|
|
|
+ Map<String, Double> sortMap = new TreeMap<>();
|
|
|
|
+ if (null != accuracyPassRateList && accuracyPassRateList.size() > 0) {
|
|
|
|
+ accuracyPassRateList = accuracyPassRateList.stream().filter(f -> !"无可用数据计算".equals(f.getAccuracy()) && !"无计算公式".equals(f.getAccuracy())).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ Function<String, Double> stringToDouble = s -> {
|
|
|
|
+ String numberStr = s.replace("%", "");
|
|
|
|
+ return Double.parseDouble(numberStr);
|
|
|
|
+ };
|
|
|
|
+ Map<String, Double> averageByCategory = accuracyPassRateList.stream()
|
|
|
|
+ .filter(apr -> apr.getForecastModel()!=null)
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ AccuracyPassRate::getForecastModel,
|
|
|
|
+ Collectors.averagingDouble(apr -> stringToDouble.apply(apr.getAccuracy()))
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ sortMap = new TreeMap<>(new Comparator<String>() {
|
|
|
|
+ @Override
|
|
|
|
+ public int compare(String o1, String o2) {
|
|
|
|
+ return (int) (averageByCategory.get(o2) - averageByCategory.get(o1));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ sortMap.putAll(averageByCategory);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return sortMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Map<String,String>> finfBySingleMonthBetweenAndForecastTypeAndStationCode(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode,String stationName,String uploadDataSources) {
|
|
|
|
+ List<Map<String,String>> list = new ArrayList<>();
|
|
|
|
+ QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
|
|
|
|
+ QueryWrapper<AccuracyPassRate> wrapper2 = new QueryWrapper<>();
|
|
|
|
+ List<long[]> longs = StartAndEndMonthUtil.singleMonth(startTime, endTime);
|
|
|
|
+ Collections.reverse(longs);
|
|
|
|
+ if (stationCode != null && !stationCode.equals("")) {
|
|
|
|
+ wrapper.eq("station_code", stationCode);
|
|
|
|
+ wrapper2.eq("station_code", stationCode);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (forecastType != null && !forecastType.equals("")) {
|
|
|
|
+ wrapper.eq("forecast_type", forecastType);
|
|
|
|
+ wrapper2.eq("forecast_type", forecastType);
|
|
|
|
+ }
|
|
|
|
+ if (dataSources != null && !dataSources.equals("")) {
|
|
|
|
+ wrapper.eq("data_sources", dataSources);
|
|
|
|
+ wrapper2.eq("data_sources", uploadDataSources);
|
|
|
|
+ }
|
|
|
|
+ for (long[] aLong : longs) {
|
|
|
|
+ int count = 0;
|
|
|
|
+ if (startTime != null && endTime != null) {
|
|
|
|
+ wrapper.between("time", new Date(aLong[0]), new Date(aLong[1]));
|
|
|
|
+ wrapper.orderByDesc("time");
|
|
|
|
+ wrapper2.between("time", new Date(aLong[0]), new Date(aLong[1]));
|
|
|
|
+ wrapper2.orderByDesc("time");
|
|
|
|
+ }
|
|
|
|
+ List<AccuracyPassRate> accuracyPassRateList = baseMapper.selectList(wrapper);
|
|
|
|
+ List<AccuracyPassRate> accuracyPassRateList2 = baseMapper.selectList(wrapper2);
|
|
|
|
+
|
|
|
|
+ accuracyPassRateList = accuracyPassRateList.stream().filter(f -> !"无可用数据计算".equals(f.getAccuracy()) && !"无计算公式".equals(f.getAccuracy())).collect(Collectors.toList());
|
|
|
|
+ accuracyPassRateList2 = accuracyPassRateList2.stream().filter(f -> !"无可用数据计算".equals(f.getAccuracy()) && !"无计算公式".equals(f.getAccuracy())).collect(Collectors.toList());
|
|
|
|
+ BigDecimal collect = BigDecimal.valueOf(accuracyPassRateList2.stream().collect(Collectors.summingDouble(s -> Double.valueOf(s.getAccuracy().replace("%", ""))))/accuracyPassRateList2.size()).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
+
|
|
|
|
+ Function<String, Double> stringToDouble = s -> {
|
|
|
|
+ String numberStr = s.replace("%", "");
|
|
|
|
+ return Double.parseDouble(numberStr);
|
|
|
|
+ };
|
|
|
|
+ Map<String, Double> averageByCategory = accuracyPassRateList.stream()
|
|
|
|
+ .filter(apr -> apr.getForecastModel()!=null)
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ AccuracyPassRate::getForecastModel,
|
|
|
|
+ Collectors.averagingDouble(apr -> stringToDouble.apply(apr.getAccuracy()))
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ Map<String, Double> sortMap = new TreeMap<>();
|
|
|
|
+ sortMap = new TreeMap<>(new Comparator<String>() {
|
|
|
|
+ @Override
|
|
|
|
+ public int compare(String o1, String o2) {
|
|
|
|
+ return (int) (averageByCategory.get(o2) - averageByCategory.get(o1));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ sortMap.putAll(averageByCategory);
|
|
|
|
+
|
|
|
|
+ for (Map.Entry<String, Double> entry : sortMap.entrySet()) {
|
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
|
+ map.put("station",stationName);
|
|
|
|
+ map.put("month",new SimpleDateFormat("yyyy-MM").format(new Date(aLong[0])));
|
|
|
|
+ map.put("preModels",entry.getKey());
|
|
|
|
+ map.put("shortAccuracy",BigDecimal.valueOf(entry.getValue()).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
|
+ map.put("uploadShortAccuracy",collect.toString());
|
|
|
|
+ map.put("accuracyRanking",String.valueOf(++count));
|
|
|
|
+ list.add(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
}
|
|
}
|