Browse Source

考试报告计算最大值、最小值完善

tags/正式3.13.3
雍文秀 1 year ago
parent
commit
a4077da87a

+ 19
- 1
scommons/src/main/java/com/xhkjedu/utils/N_Utils.java View File

@@ -25,6 +25,8 @@ import java.util.regex.Pattern;
25 25
 import java.util.stream.Collectors;
26 26
 import java.util.stream.IntStream;
27 27
 
28
+import static jdk.nashorn.internal.objects.Global.Infinity;
29
+
28 30
 /**
29 31
  * @author WN
30 32
  * @className N_Utils
@@ -660,13 +662,29 @@ public class N_Utils {
660 662
      * @return java.lang.Double
661 663
      **/
662 664
     public static Double formatDouble(Double num,Integer decimalNum) {
663
-        if (num == null) num = 0.0;
665
+        if (num == null || num == Double.NEGATIVE_INFINITY || num == Double.POSITIVE_INFINITY) return 0.0;
664 666
         if (isEmptyInteger(decimalNum)) return num;
665 667
         BigDecimal bg = new BigDecimal(num);
666 668
         double num2 = bg.setScale(decimalNum, BigDecimal.ROUND_DOWN).doubleValue();
667 669
         return num2;
668 670
     }
669 671
 
672
+    /**
673
+     * @Description DoubleSummaryStatistics获取最大值有可能为(-Infinity)、最小值有可能为(Infinity);
674
+     * 检查Double类型的值是否为-Infinity或Infinity,并在是的情况下返回0
675
+     * @Date 2023/12/28 16:30
676
+     * @Author YWX
677
+     * @Param [value]
678
+     * @Return double
679
+     **/
680
+    public static double handleInfinity(double value) {
681
+        if (value == Double.NEGATIVE_INFINITY || value == Double.POSITIVE_INFINITY) {
682
+            return 0;
683
+        } else {
684
+            return value;
685
+        }
686
+    }
687
+
670 688
     /**
671 689
      * @Description  格式化double类型,如果未小数点后为0反正整式,
672 690
      * @Param [score]

+ 7
- 6
sexam/src/main/java/com/xhkjedu/sexam/service/report/EReportGenerateService.java View File

@@ -187,10 +187,10 @@ public class EReportGenerateService {
187 187
             schoolStudents2 = schoolStudents;
188 188
         }
189 189
         DoubleSummaryStatistics schoolStatistics = schoolStudents2.stream().filter(s -> s.getScore() > 0).mapToDouble(s -> s.getScore()).summaryStatistics();
190
-        double schoolStatisticsMax = schoolStatistics.getMax();
190
+        double schoolStatisticsMax = N_Utils.handleInfinity(schoolStatistics.getMax());
191 191
         double schoolStatisticsAverage = N_Utils.formatDouble(schoolStatistics.getAverage(), 2);
192 192
         //最低分均不包括0分
193
-        double schoolStatisticsMin = schoolStudents.stream().filter(s -> s.getScore() > 0).mapToDouble(s -> s.getScore()).summaryStatistics().getMin();
193
+        double schoolStatisticsMin = N_Utils.handleInfinity(schoolStudents.stream().filter(s -> s.getScore() > 0).mapToDouble(s -> s.getScore()).summaryStatistics().getMin());
194 194
         if (N_Utils.isListEmpty(students)) {
195 195
             schoolStatisticsMax = 0;
196 196
             schoolStatisticsMin = 0;
@@ -404,8 +404,8 @@ public class EReportGenerateService {
404 404
         }
405 405
 
406 406
         DoubleSummaryStatistics statistics = list2.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
407
-        double maxscore = statistics.getMax();
408
-        double minscore = list.stream().mapToDouble(s -> s.getScore()).summaryStatistics().getMin();
407
+        double maxscore = N_Utils.handleInfinity(statistics.getMax());
408
+        double minscore = N_Utils.handleInfinity(list.stream().mapToDouble(s -> s.getScore()).summaryStatistics().getMin());
409 409
         double avgscore = N_Utils.formatDouble(statistics.getAverage(), 2);
410 410
         if (N_Utils.isListEmpty(list)) {
411 411
             maxscore = 0;
@@ -453,8 +453,8 @@ public class EReportGenerateService {
453 453
                 rstudentList2 = list;
454 454
             }
455 455
             DoubleSummaryStatistics claStatistics = rstudentList2.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
456
-            double clamaxscore = claStatistics.getMax();
457
-            double claminscore = rstudentList.stream().mapToDouble(s -> s.getScore()).summaryStatistics().getMin();
456
+            double clamaxscore = N_Utils.handleInfinity(claStatistics.getMax());
457
+            double claminscore = N_Utils.handleInfinity(rstudentList.stream().mapToDouble(s -> s.getScore()).summaryStatistics().getMin());
458 458
             double claavgscore = N_Utils.formatDouble(claStatistics.getAverage(), 2);
459 459
             if (N_Utils.isListEmpty(list)) {
460 460
                 clamaxscore = 0;
@@ -1527,6 +1527,7 @@ public class EReportGenerateService {
1527 1527
 
1528 1528
     //获取最高分
1529 1529
     private Double getMaxScore(List<ERstudent> cstudents, Integer linescore) {
1530
+        if(N_Utils.isListEmpty(cstudents)) return 0.0;
1530 1531
         List<Double> cScore = cstudents.stream().map(s -> s.getScore()).distinct().sorted().collect(Collectors.toList());
1531 1532
         int rnum = cScore.size();//排名数量
1532 1533
         if (linescore > rnum) linescore = rnum;

Loading…
Cancel
Save