Browse Source

修复一分一段及十分一段中不包含0.5分情况

ting.yin 6 years ago
parent
commit
6b689b93e5

+ 3 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/report/utils/module/SubjectQuestionOptionModule.java

@@ -36,6 +36,8 @@ public class SubjectQuestionOptionModule implements Module {
     private Map<String, Set<String>> optionMap;
 
     public static final String ANSWER_SPLIT = ",";
+    
+    public static final String ANSWER = "#";
 
     public SubjectQuestionOptionModule(ReportContext context) {
         this.counters = new HashMap<String, OptionCounter>();
@@ -104,6 +106,7 @@ public class SubjectQuestionOptionModule implements Module {
         for (String subjectCode : optionMap.keySet()) {
             ReportSubject r = subjectService.findOne(this.context.getExamId(), subjectCode);
             Set<String> options = optionMap.get(subjectCode);
+            options.remove(ANSWER);
             r.setOptions(StringUtils.join(options, ANSWER_SPLIT));
             subjectService.save(r);
         }

+ 3 - 1
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/report/utils/module/SubjectRangeModule.java

@@ -64,15 +64,17 @@ public class SubjectRangeModule implements Module {
             service.save(subjectRange);
 
             ReportSubjectService subjectService = SpringContextHolder.getBean(ReportSubjectService.class);
+//            ExamStudentService studentService = SpringContextHolder.getBean(ExamStudentService.class);
             ReportSubject subject = subjectService.findOne(this.context.getExamId(), subjectCode);
             JSONObject rangeLevel = new JSONObject();
+
             rangeLevel.accumulate("highScore", counter.countGeAndLt(100 - context.getHighValueConfig(), null));
             rangeLevel.accumulate("lowScore", counter.countGeAndLt(null, context.getLowValueConfig()));
             subject.setRangeLevel(rangeLevel.toString());
 
             JSONObject scoreRange = new JSONObject();
             for (int i = 0; i <= subject.getTotalScore(); i++) {
-                scoreRange.accumulate(String.valueOf(i), counter.countGeAndLt((double) i, (double) (i + 1)));
+                scoreRange.accumulate(String.valueOf(i), counter.countGtAndLe((double) (i - 1), (double) i));
             }
             subject.setScoreRange(scoreRange.toString());
             subjectService.save(subject);

+ 45 - 6
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/report/utils/unit/RangeCounter.java

@@ -10,27 +10,42 @@ public class RangeCounter {
 
     public double interval;
 
-    public Map<Double, Integer> map;
+    public Map<Double, Integer> GeAndLtMap;
+
+    public Map<Double, Integer> GtAndLeMap;
 
     public RangeCounter() {
         this.interval = 1;
-        this.map = new HashMap<Double, Integer>();
+        this.GeAndLtMap = new HashMap<Double, Integer>();
+        this.GtAndLeMap = new HashMap<Double, Integer>();
     }
 
     public void process(double score) {
         totalCount++;
         // 取最接近的分段起始分数
-        double min = Math.floor(score);
+        double min = score;
         while ((min + interval) < score) {
             min += interval;
         }
         // 以起始分数为key,累加计数结果
-        Integer count = map.get(min);
+        Integer count = GeAndLtMap.get(min);
         if (count == null) {
             count = 0;
         }
         count++;
-        map.put(min, count);
+        GeAndLtMap.put(min, count);
+
+        // 计算(s1, s2]
+        double max = score;
+        while ((max - interval) > score) {
+            max -= interval;
+        }
+        Integer count1 = GtAndLeMap.get(max);
+        if (count1 == null) {
+            count1 = 0;
+        }
+        count1++;
+        GtAndLeMap.put(max, count1);
     }
 
     /**
@@ -44,7 +59,7 @@ public class RangeCounter {
     public int countGeAndLt(Double s1, Double s2) {
         int count = 0;
         if (s1 != null || s2 != null) {
-            for (Entry<Double, Integer> entry : map.entrySet()) {
+            for (Entry<Double, Integer> entry : GeAndLtMap.entrySet()) {
                 Double key = entry.getKey();
                 if (s1 != null && key < s1) {
                     continue;
@@ -58,4 +73,28 @@ public class RangeCounter {
         return count;
     }
 
+    /**
+     * 获取在(s1, s2]分数范围内的数量<br>
+     * s1和s2可以有一个为null,不能全部为null
+     * 
+     * @param s1
+     * @param s2
+     * @return
+     */
+    public int countGtAndLe(Double s1, Double s2) {
+        int count = 0;
+        if (s1 != null || s2 != null) {
+            for (Entry<Double, Integer> entry : GtAndLeMap.entrySet()) {
+                Double key = entry.getKey();
+                if (s1 != null && key <= s1) {
+                    continue;
+                }
+                if (s2 != null && key > s2) {
+                    continue;
+                }
+                count += entry.getValue();
+            }
+        }
+        return count;
+    }
 }