Browse Source

修复超短期准确率不显示问题

fanxiaoyu 2 tháng trước cách đây
mục cha
commit
d6b5301fbc

+ 39 - 31
cpp-admin/src/main/java/com/cpp/web/service/accuracy/impl/AccuracyPassRateServiceImpl.java

@@ -36,9 +36,10 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
     private ISysDictDataService dictDataService;
 
     private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
     @Override
     public List<AccuracyPassRate> findByTimeBetweenAndForecastTypeAndDataSourcesAndAgoAndForecastModelAndStationCode(Date startTime, Date endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, Integer ago, String forecastModel, String stationCode) {
-            QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
+        QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
         if (stationCode != null && !stationCode.equals("")) {
             wrapper.eq("station_code", stationCode);
         }
@@ -61,15 +62,20 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
         // 根据要求进行调整,过滤脏数据,如果所查天数为空,则显示"",而不是直接就是不展示了
         // 过滤掉单点平均偏差大于100的
         List<AccuracyPassRate> glList = list.stream().filter(f -> !"无可用数据计算".equals(f.getDeviationSum()) && !"无计算公式".equals(f.getDeviationSum())).collect(Collectors.toList());
-        List<AccuracyPassRate> filterList = glList.stream().filter(f -> null != f.getDeviationSum() && Double.valueOf(f.getDeviationSum().replace("%","")) <=100 && !"无可用数据计算".equals(f.getDeviationSum()) && !"无计算公式".equals(f.getDeviationSum())).collect(Collectors.toList());
-        List<String> timeList = getDatesInRange(startTime,endTime);
+        List<AccuracyPassRate> filterList = new ArrayList<>();
+        if ("dq".equals(forecastType)) {
+            filterList = glList.stream().filter(f -> null != f.getDeviationSum() && Double.valueOf(f.getDeviationSum().replace("%", "")) <= 100 && !"无可用数据计算".equals(f.getDeviationSum()) && !"无计算公式".equals(f.getDeviationSum())).collect(Collectors.toList());
+        } else {
+            filterList.addAll(glList);
+        }
+        List<String> timeList = getDatesInRange(startTime, endTime);
         try {
             for (String s : timeList) {
 //                if (s.equals(dateFormat.format(new Date()))){
 //                    continue;
 //                }
                 List<AccuracyPassRate> collectList = filterList.stream().filter(f -> dateFormat.format(f.getTime()).equals(s)).collect(Collectors.toList());
-                if (collectList.size() == 0 ){
+                if (collectList.size() == 0) {
                     AccuracyPassRate accuracyPassRate = new AccuracyPassRate();
                     accuracyPassRate.setTime(dateFormat.parse(s));
                     accuracyPassRate.setDeviationSum("");
@@ -87,28 +93,28 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
     @Override
     public List<AccuracyPassRate> findByTimeBetweenAndStationCode(Date startTime, Date endTime, String stationCode) {
         QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
-        if (null != startTime && null != endTime){
-            wrapper.between("time",startTime,endTime);
+        if (null != startTime && null != endTime) {
+            wrapper.between("time", startTime, endTime);
         }
-        if (null != stationCode && !"".equals(stationCode)){
-            wrapper.eq("station_code",stationCode);
+        if (null != stationCode && !"".equals(stationCode)) {
+            wrapper.eq("station_code", stationCode);
         }
-        wrapper.eq("data_sources","E2");
-        wrapper.eq("forecast_how_long_ago",1);
-        wrapper.eq("forecast_type","dq");
+        wrapper.eq("data_sources", "E2");
+        wrapper.eq("forecast_how_long_ago", 1);
+        wrapper.eq("forecast_type", "dq");
         return list(wrapper);
     }
 
     @Override
-    public List<Map<String,String>> finfBySingleMonthBetweenAndForecastTypeAndStationCode(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode,String stationName,String uploadDataSources) {
+    public List<Map<String, String>> finfBySingleMonthBetweenAndForecastTypeAndStationCode(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode, String stationName, String uploadDataSources) {
         List<long[]> longs = StartAndEndMonthUtil.singleMonth(startTime, endTime);
         Collections.reverse(longs);
         List<Map<String, String>> singleMonthList = getSingleMonthList(longs, startTime, endTime, forecastType, dataSources, stationCode, stationName, uploadDataSources);
         return singleMonthList;
     }
 
-    public List<Map<String,String>> getSingleMonthList(List<long[]> longs,Long startTime, Long endTime,ForecastTypeEnum forecastType, DataSourcesEnum dataSources,String stationCode,String stationName,String uploadDataSources){
-        List<Map<String,String>> list = new ArrayList<>();
+    public List<Map<String, String>> getSingleMonthList(List<long[]> longs, Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode, String stationName, String uploadDataSources) {
+        List<Map<String, String>> list = new ArrayList<>();
         for (long[] aLong : longs) {
             QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
             QueryWrapper<AccuracyPassRate> wrapper2 = new QueryWrapper<>();
@@ -139,15 +145,15 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
             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.ZERO;
-            if (accuracyPassRateList2.size()>0){
-                collect = BigDecimal.valueOf(accuracyPassRateList2.stream().collect(Collectors.summingDouble(s -> Double.valueOf(s.getAccuracy().replace("%", ""))))/accuracyPassRateList2.size()).setScale(2, RoundingMode.HALF_UP);
+            if (accuracyPassRateList2.size() > 0) {
+                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)
+                    .filter(apr -> apr.getForecastModel() != null)
                     .collect(Collectors.groupingBy(
                             AccuracyPassRate::getForecastModel,
                             Collectors.averagingDouble(apr -> stringToDouble.apply(apr.getAccuracy()))
@@ -162,16 +168,16 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
             });
             sortMap.putAll(averageByCategory);
 
-            List<String> modelList =  DictUtils.getDictCache("forecast_model").stream().map(SysDictData::getDictValue).collect(Collectors.toList());
+            List<String> modelList = DictUtils.getDictCache("forecast_model").stream().map(SysDictData::getDictValue).collect(Collectors.toList());
 
             for (String s : modelList) {
-                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",dictDataService.selectDictLabel("forecast_model",s));
-                map.put("shortAccuracy",sortMap.get(s) == null? "" : BigDecimal.valueOf(sortMap.get(s)).setScale(2, RoundingMode.HALF_UP).toString());
-                map.put("uploadShortAccuracy",collect.toString());
-                map.put("accuracyRanking",String.valueOf(++count));
+                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", dictDataService.selectDictLabel("forecast_model", s));
+                map.put("shortAccuracy", sortMap.get(s) == null ? "" : BigDecimal.valueOf(sortMap.get(s)).setScale(2, RoundingMode.HALF_UP).toString());
+                map.put("uploadShortAccuracy", collect.toString());
+                map.put("accuracyRanking", String.valueOf(++count));
                 list.add(map);
             }
 //            for (Map.Entry<String, Double> entry : sortMap.entrySet()) {
@@ -188,17 +194,18 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
         }
         return list;
     }
+
     @Override
-    public Map<String,List<Object>> echarts(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode,String stationName,String uploadDataSources){
+    public Map<String, List<Object>> echarts(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode, String stationName, String uploadDataSources) {
         // 注释掉无用代码
 //        List<Map<String, String>> list = finfBySingleMonthBetweenAndForecastTypeAndStationCode(startTime, endTime, forecastType, dataSources, stationCode, stationName, uploadDataSources);
         List<long[]> longs = StartAndEndMonthUtil.singleMonth(startTime, endTime);
         List<long[]> longsSix = new ArrayList<>();
-        if (longs.size()>=6){
+        if (longs.size() >= 6) {
             for (int i = 0; i < 6; i++) {
                 longsSix.add(longs.get(i));
             }
-        }else {
+        } else {
             longsSix = longs;
         }
         List<Map<String, String>> singleMonthList = getSingleMonthList(longsSix, startTime, endTime, forecastType, dataSources, stationCode, stationName, uploadDataSources);
@@ -208,12 +215,12 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
         for (Map<String, String> data : singleMonthList) {
             String preModels = data.get("preModels");
             String month = data.get("month");
-            if (data.get("shortAccuracy") != ""){
+            if (data.get("shortAccuracy") != "") {
                 double shortAccuracy = Double.parseDouble(data.get("shortAccuracy"));
                 groupedData
                         .computeIfAbsent(preModels, k -> new HashMap<>())
                         .put(month, shortAccuracy);
-            }else {
+            } else {
                 groupedData
                         .computeIfAbsent(preModels, k -> new HashMap<>())
                         .put(month, "");
@@ -258,7 +265,7 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
             uploadShortAccuracyList.add(entry.getValue());
         }
 
-        Map<String,List<Object>> endMap = new HashMap<>();
+        Map<String, List<Object>> endMap = new HashMap<>();
 
         endMap.put("uploadShortAccuracyList", Collections.singletonList(uploadShortAccuracyList));
         endMap.put("xAxis", Collections.singletonList(xAxis));
@@ -266,6 +273,7 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
         endMap.put("monthData", Collections.singletonList(months));
         return endMap;
     }
+
     public List<String> getDatesInRange(Date startTime, Date endTime) {
         List<String> dateList = new ArrayList<>();
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");