Selaa lähdekoodia

模型准确率统计改

yl 6 kuukautta sitten
vanhempi
commit
80f010f406

+ 5 - 7
cpp-admin/src/main/java/com/cpp/web/controller/accuracy/AccuracyPassRateController.java

@@ -31,18 +31,16 @@ public class AccuracyPassRateController {
         List<AccuracyPassRate> accuracyPassRateList = accuracyPassRateService.findByTimeBetweenAndForecastTypeAndDataSourcesAndAgoAndForecastModelAndStationCode(new Date(startTime), new Date(endTime), forecastType, dataSources, ago, forecastModel, stationCode);
         return R.ok(accuracyPassRateList);
     }
-
-    @GetMapping("/getByMonthBetweenAndForecastTypeAndStationCode")
-    public R getByMonthBetweenAndForecastTypeAndStationCode(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode) {
-        Map<String, Double> map = accuracyPassRateService.findByMonthBetweenAndForecastTypeAndStationCode(startTime, endTime, forecastType, dataSources, stationCode);
-        return R.ok(map);
-    }
-
     @GetMapping("/getBySingleMonthBetweenAndForecastTypeAndStationCode")
     public R getBySingleMonthBetweenAndForecastTypeAndStationCode(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode, String stationName, String uploadDataSources) {
         List<Map<String, String>> accuracyPassRateList = accuracyPassRateService.finfBySingleMonthBetweenAndForecastTypeAndStationCode(startTime, endTime, forecastType, dataSources, stationCode, stationName, uploadDataSources);
         return R.ok(accuracyPassRateList);
     }
+    @GetMapping("/getEchart")
+    public R getEchart(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode, String stationName, String uploadDataSources) {
+        Map<String,List<Object>> endMap = accuracyPassRateService.echarts(startTime, endTime, forecastType, dataSources, stationCode, stationName, uploadDataSources);
+        return R.ok(endMap);
+    }
 
     @GetMapping("/export")
     public void export(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode, String stationName, String uploadDataSources, HttpServletResponse response) {

+ 2 - 2
cpp-admin/src/main/java/com/cpp/web/service/accuracy/AccuracyPassRateService.java

@@ -20,7 +20,7 @@ public interface AccuracyPassRateService extends IService<AccuracyPassRate> {
 
     List<AccuracyPassRate> findByTimeBetweenAndStationCode(Date startTime,Date endTime,String stationCode);
 
-    Map<String, Double> findByMonthBetweenAndForecastTypeAndStationCode(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode);
-
     List<Map<String,String>> finfBySingleMonthBetweenAndForecastTypeAndStationCode(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode,String stationName,String uploadDataSources);
+
+    Map<String,List<Object>> echarts(Long startTime, Long endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, String stationCode, String stationName, String uploadDataSources);
 }

+ 77 - 51
cpp-admin/src/main/java/com/cpp/web/service/accuracy/impl/AccuracyPassRateServiceImpl.java

@@ -70,61 +70,15 @@ public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMap
     }
 
     @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()))
-                    ));
-            Map<String, Double> updatedAverageByCategory = averageByCategory.entrySet().stream()
-                    .collect(Collectors.toMap(
-                            entry->dictDataService.selectDictLabel("forecast_model",entry.getKey())==null?entry.getKey():dictDataService.selectDictLabel("forecast_model",entry.getKey()),
-                            entry->entry.getValue()
-                    ));
-            sortMap = new TreeMap<>(new Comparator<String>() {
-                @Override
-                public int compare(String o1, String o2) {
-                    return updatedAverageByCategory.get(o2).compareTo(updatedAverageByCategory.get(o1));
-                }
-            });
-
-            sortMap.putAll(updatedAverageByCategory);
-
-        }
-        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<>();
         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<>();
         for (long[] aLong : longs) {
             QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
             QueryWrapper<AccuracyPassRate> wrapper2 = new QueryWrapper<>();
@@ -192,4 +146,76 @@ 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){
+        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){
+            for (int i = 0; i < 6; i++) {
+                longsSix.add(longs.get(i));
+            }
+        }else {
+            longsSix = longs;
+        }
+        List<Map<String, String>> singleMonthList = getSingleMonthList(longsSix, startTime, endTime, forecastType, dataSources, stationCode, stationName, uploadDataSources);
+
+        Map<String, Map<String, Double>> groupedData = new HashMap<>();
+        // 根据 preModels 和 month 分组
+        for (Map<String, String> data : singleMonthList) {
+            String preModels = data.get("preModels");
+            String month = data.get("month");
+            double shortAccuracy = Double.parseDouble(data.get("shortAccuracy"));
+
+            groupedData
+                    .computeIfAbsent(preModels, k -> new HashMap<>())
+                    .put(month, shortAccuracy);
+        }
+
+        // 用于生成 ECharts 数据
+        Set<String> allMonths = new TreeSet<>();
+        List<String> preModels = new ArrayList<>(groupedData.keySet());
+        Collections.sort(preModels);
+
+        // 收集所有出现过的月份
+        for (Map<String, Double> monthData : groupedData.values()) {
+            allMonths.addAll(monthData.keySet());
+        }
+        List<String> months = new ArrayList<>(allMonths);
+
+        // 构建 ECharts xAxis 数据
+        List<String> xAxis = preModels;  // xAxis 就是模型名称列表
+        List<List<Double>> seriesData = new ArrayList<>();
+
+        // 为每个 month 构建对应的 shortAccuracy 数据
+        for (String month : months) {
+            List<Double> monthData = new ArrayList<>();
+            for (String preModel : preModels) {
+                monthData.add(groupedData.get(preModel).getOrDefault(month, 0.0));
+            }
+            seriesData.add(monthData);
+        }
+
+        Map<String, String> result = new TreeMap<>();
+
+
+        for (Map<String, String> entry : singleMonthList) {
+            String month = entry.get("month");
+            String uploadShortAccuracy = entry.get("uploadShortAccuracy");
+            result.put(month, uploadShortAccuracy);
+        }
+        List<String> uploadShortAccuracyList = new ArrayList<>();
+
+        for (Map.Entry<String, String> entry : result.entrySet()) {
+            uploadShortAccuracyList.add(entry.getValue());
+        }
+
+        Map<String,List<Object>> endMap = new HashMap<>();
+
+        endMap.put("uploadShortAccuracyList", Collections.singletonList(uploadShortAccuracyList));
+        endMap.put("xAxis", Collections.singletonList(xAxis));
+        endMap.put("seriesData", Collections.singletonList(seriesData));
+        endMap.put("monthData", Collections.singletonList(months));
+        return endMap;
+    }
 }

+ 61 - 38
cpp-ui/src/views/regulation/modelAccuracyStatistics/index.vue

@@ -117,6 +117,7 @@ export default {
       },
       loading: false,
       xData:[],
+      xAxis:[],
       yData:[],
       tableData: [],
       dataS:'E2',
@@ -180,6 +181,10 @@ export default {
       })
     },
     dataQuery(){
+      if (this.chart){
+        this.chart.clear()
+      }
+      this.loading = true
       if (!this.ifclick){
         return;
       }
@@ -199,17 +204,60 @@ export default {
         "stationName":this.stationName
       }
       this.ifclick = false
-      const accuracyPassRateByMonthPromise = new Promise((resolve,reject)=>{
-        this.$axios.get('/accuracyPassRate/getByMonthBetweenAndForecastTypeAndStationCode', {params: queryParams}).then(response => {
-          if (response.data){
-            for (const [key,value] of Object.entries(response.data)){
-              this.xData.push(key)
-              this.yData.push(value.toFixed(2))
+      let series = []
+      let colors = [ "#ff8200", "#EE82EE", "#00FF00", "#00BFFF", "#FF0000", "#FFFF33"  ]
+      const chartData =new Promise((resolve,reject)=>{
+        this.$axios.get('/accuracyPassRate/getEchart', {params: queryParams}).then(response => {
+          let monthData = response.data.monthData;
+          if (response.data.seriesData[0].length>0){
+            for (let i = 0; i <response.data.seriesData[0].length ; i++) {
+              series.push({
+                // name: 'Direct',
+                type: 'bar',
+                barMaxWidth: 60,
+                itemStyle: {
+                  normal: {
+                    show: true,
+                    color: colors[i]
+                  }
+                },
+                markLine: {
+                  silent: true,
+                  itemStyle: {
+                    normal: {
+                      show: true,
+                      color: colors[i]
+                    }
+                  },
+                  data: [{
+                    label: {
+                      fontSize:10,
+                      position: 'start',
+                      formatter: (params)=>{
+                        return params.value+'('+(params.value == 0 ?'':monthData[0][i].substring(2,4)+'/'+monthData[0][i].substring(5,7))+')';
+                      }
+                    },
+                    yAxis: response.data.uploadShortAccuracyList[0][i]
+                  }]
+                },
+                label: {
+                  show: true,
+                  position: 'top',
+                  formatter: (params) => {
+                    return params.value == 0 ?'':monthData[0][i];
+                  }
+                },
+                data: response.data.seriesData[0][i],
+              })
             }
+            this.xAxis = response.data.xAxis[0]
+          }else {
+            series = []
+            this.xAxis = []
           }
           resolve();
         }).catch(() => {}).finally(()=>{
-          this.initChart()
+          this.initChart(this.xAxis,series)
         })
       })
       const accuracyPassRateSingleMonthPromise = new Promise((resolve,reject)=>{
@@ -218,10 +266,11 @@ export default {
             this.tableData = response.data || []
             this.total = response.data.length
           }
+          this.loading = false
           resolve();
         })
       })
-      Promise.all([accuracyPassRateByMonthPromise,accuracyPassRateSingleMonthPromise]).then(()=>{
+      Promise.all([accuracyPassRateSingleMonthPromise,chartData]).then(()=>{
         this.ifclick = true
       })
     },
@@ -234,7 +283,7 @@ export default {
         this.dataQuery()
       })
     },
-    initChart() {
+    initChart(xAxis,series) {
       var chartDom = document.getElementById('masChart');
       this.chart = echarts.init(chartDom);
       this.chart.setOption({
@@ -254,7 +303,7 @@ export default {
           }
         },
         grid: {
-          left: '3%',
+          left: '4%',
           right: '4%',
           bottom: '3%',
           containLabel: true
@@ -262,7 +311,7 @@ export default {
         xAxis: [
           {
             type: 'category',
-            data: this.xData,
+            data: xAxis,
             axisTick: {
               alignWithLabel: true
             },
@@ -293,33 +342,7 @@ export default {
             },
           }
         ],
-        series: [
-          {
-            // name: 'Direct',
-            type: 'bar',
-            data: this.yData,
-            barMaxWidth: 60,
-            itemStyle: {color: '#e098c7'},
-            markLine:{
-              data:[
-                {
-                  silent:true,
-                  yAxis:65,
-                  label:{
-                    position:'end',
-                    formatter:'65',
-                    color:'#ff8200',
-                  },
-                  lineStyle:{
-                    type:'dashed',
-                    color:'#ff8200',
-                    width:1
-                  }
-                },
-              ]
-            },
-          }
-        ]
+        series: series
       })
     },
   }