Browse Source

Merge remote-tracking branch 'origin/ywx' into wn_j

# Conflicts:
#	sexam/src/main/java/com/xhkjedu/sexam/service/report/EReportGenerateService.java
#	sexam/src/main/java/com/xhkjedu/sexam/utils/ExamUtil.java
tags/正式版本
王宁 2 years ago
parent
commit
27d9285556

+ 0
- 3
sexam/src/main/java/com/xhkjedu/sexam/model/reportclass/ERclass.java View File

37
     //班级平均分
37
     //班级平均分
38
     private Double classavgscore;
38
     private Double classavgscore;
39
 
39
 
40
-    //平均分排名
41
-    private Integer schoolrank;
42
-
43
     //校最高分
40
     //校最高分
44
     private Double schoolmaxscore;
41
     private Double schoolmaxscore;
45
 
42
 

+ 66
- 31
sexam/src/main/java/com/xhkjedu/sexam/service/report/EReportGenerateService.java View File

31
 import com.xhkjedu.sexam.vo.report.ERClassScoreVo;
31
 import com.xhkjedu.sexam.vo.report.ERClassScoreVo;
32
 import com.xhkjedu.sexam.vo.report.ERPaperVo;
32
 import com.xhkjedu.sexam.vo.report.ERPaperVo;
33
 import com.xhkjedu.utils.N_Utils;
33
 import com.xhkjedu.utils.N_Utils;
34
+
34
 import org.springframework.beans.BeanUtils;
35
 import org.springframework.beans.BeanUtils;
35
 import org.springframework.stereotype.Service;
36
 import org.springframework.stereotype.Service;
36
-
37
 import javax.annotation.Resource;
37
 import javax.annotation.Resource;
38
 import java.util.*;
38
 import java.util.*;
39
 import java.util.stream.Collectors;
39
 import java.util.stream.Collectors;
85
         int stunum = classes.stream().mapToInt(m -> (int) m.get("classnum")).sum();
85
         int stunum = classes.stream().mapToInt(m -> (int) m.get("classnum")).sum();
86
         int subjectnum = subjects.size();
86
         int subjectnum = subjects.size();
87
 
87
 
88
-        String subjectid = "zf";
89
-        String subjectname = "总分";
88
+        String subjectid;
89
+        String subjectname;
90
         Map<String, String> subjectMap = subjects.stream().collect(Collectors.toMap(m -> m.get("subjectid").toString(),
90
         Map<String, String> subjectMap = subjects.stream().collect(Collectors.toMap(m -> m.get("subjectid").toString(),
91
                 m -> m.get("subjectname").toString()));
91
                 m -> m.get("subjectname").toString()));
92
         Map<String, ERPaperVo> paperMap = papers.stream().collect(Collectors.toMap(m -> m.getSubjectid(), m -> m));
92
         Map<String, ERPaperVo> paperMap = papers.stream().collect(Collectors.toMap(m -> m.getSubjectid(), m -> m));
95
         List<ERstudent> schoolSubjectStudents = new ArrayList<>();//学校科目学生成绩
95
         List<ERstudent> schoolSubjectStudents = new ArrayList<>();//学校科目学生成绩
96
         List<ERstudent> classStudents = new ArrayList<>();//班级学生成绩
96
         List<ERstudent> classStudents = new ArrayList<>();//班级学生成绩
97
         List<ERstudent> classSubjectStudents = new ArrayList<>();//班级科目学生成绩
97
         List<ERstudent> classSubjectStudents = new ArrayList<>();//班级科目学生成绩
98
-        Map<String, Integer> schoolRank = new HashMap<>();//学校分数排名
99
-        Map<String, Integer> schoolSubjectRank = new HashMap<>();//学校科目分数排名
100
-        Map<String, Integer> classRank = new HashMap<>();//班级分数排名
101
-        Map<String, Integer> classSubjectRank = new HashMap<>();//班级科目分数排名
102
-
98
+        Map<String, Integer> schoolStuRank = new HashMap<>();//学校学生分数排名
99
+        Map<String, Integer> schoolSubStuRank = new HashMap<>();//学校科目学生分数排名
100
+        Map<String, Integer> classStuRank = new HashMap<>();//班级学生分数排名
101
+        Map<String, Integer> classSubStuRank = new HashMap<>();//班级科目学生分数排名
103
         List<ERstudent> students = ePaperStudentMapper.listByExamId(examid);
102
         List<ERstudent> students = ePaperStudentMapper.listByExamId(examid);
104
         Map<Integer, List<ERstudent>> schoolCollect = students.stream().collect(Collectors.groupingBy(s -> s.getStudentid()));
103
         Map<Integer, List<ERstudent>> schoolCollect = students.stream().collect(Collectors.groupingBy(s -> s.getStudentid()));
105
         for (Map.Entry<Integer, List<ERstudent>> entry : schoolCollect.entrySet()) {
104
         for (Map.Entry<Integer, List<ERstudent>> entry : schoolCollect.entrySet()) {
112
         Map<Integer, List<ERstudent>> cCollect = students.stream().collect(Collectors.groupingBy(s -> s.getClassid()));
111
         Map<Integer, List<ERstudent>> cCollect = students.stream().collect(Collectors.groupingBy(s -> s.getClassid()));
113
         for (Map.Entry<Integer, List<ERstudent>> entry : cCollect.entrySet()) {
112
         for (Map.Entry<Integer, List<ERstudent>> entry : cCollect.entrySet()) {
114
             Integer classid = entry.getKey();
113
             Integer classid = entry.getKey();
114
+            subjectid = "zf";
115
+            subjectname = "总分";
115
             List<ERstudent> studentList = entry.getValue();
116
             List<ERstudent> studentList = entry.getValue();
117
+
116
             Map<Integer, List<ERstudent>> sCollect = studentList.stream().collect(Collectors.groupingBy(s -> s.getStudentid()));
118
             Map<Integer, List<ERstudent>> sCollect = studentList.stream().collect(Collectors.groupingBy(s -> s.getStudentid()));
117
             for (Map.Entry<Integer, List<ERstudent>> csEntry : sCollect.entrySet()) {
119
             for (Map.Entry<Integer, List<ERstudent>> csEntry : sCollect.entrySet()) {
118
                 ERstudent cs = new ERstudent();
120
                 ERstudent cs = new ERstudent();
136
         }
138
         }
137
 
139
 
138
         DoubleSummaryStatistics schoolStatistics = schoolStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
140
         DoubleSummaryStatistics schoolStatistics = schoolStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
139
-        DoubleSummaryStatistics sSStatistics = schoolSubjectStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
140
         DoubleSummaryStatistics classStatistics = classStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
141
         DoubleSummaryStatistics classStatistics = classStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
141
         DoubleSummaryStatistics cSStatistics = classSubjectStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
142
         DoubleSummaryStatistics cSStatistics = classSubjectStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
142
         double schoolStatisticsMax = schoolStatistics.getMax();
143
         double schoolStatisticsMax = schoolStatistics.getMax();
192
             rs.setMaxscore(statistics.getMax());
193
             rs.setMaxscore(statistics.getMax());
193
             rs.setMinscore(statistics.getMin());
194
             rs.setMinscore(statistics.getMin());
194
             rs.setAvgscore(statistics.getAverage());
195
             rs.setAvgscore(statistics.getAverage());
195
-            rs.setStunum(list.stream().filter(l -> l.getSstate() == 2).collect(Collectors.toList()).size());
196
-            rs.setMissnum(list.stream().filter(l -> l.getSstate() == 3).collect(Collectors.toList()).size());
196
+            int yxnum = list.stream().filter(l -> l.getScore().compareTo(yxscore) != -1)
197
+                    .collect(Collectors.toList()).size();
198
+            int lhnum = list.stream().filter(l -> l.getScore().compareTo(lhscore) != -1)
199
+                    .collect(Collectors.toList()).size();
200
+            int jgnum = list.stream().filter(l -> l.getScore().compareTo(jgscore) != -1)
201
+                    .collect(Collectors.toList()).size();
202
+            int dfnum = list.stream().filter(l -> l.getScore().compareTo(dfscore) != 1)
203
+                    .collect(Collectors.toList()).size();
204
+            List<Double> scores = list.stream().map(l -> l.getScore()).collect(Collectors.toList());
205
+            rs.setYxrate(N_Utils.getIntegerDivideAndMulitiply(yxnum, stunum));
206
+            rs.setLhrate(N_Utils.getIntegerDivideAndMulitiply(lhnum, stunum));
207
+            rs.setJgrate(N_Utils.getIntegerDivideAndMulitiply(jgnum, stunum));
208
+            rs.setDfrate(N_Utils.getIntegerDivideAndMulitiply(dfnum, stunum));
209
+            rs.setBzc(ExamUtil.standardDiviation(scores));
210
+            int sknum = list.size();
211
+            rs.setStunum(sknum);//实考人数
212
+            rs.setMissnum(stunum - sknum);//缺考人数=计划人数-实考人数
197
             subjectList.add(rs);
213
             subjectList.add(rs);
198
 
214
 
199
             Map<Integer, List<ERstudent>> claCollect = list.stream().collect(Collectors.groupingBy(s -> s.getClassid()));
215
             Map<Integer, List<ERstudent>> claCollect = list.stream().collect(Collectors.groupingBy(s -> s.getClassid()));
200
             for (Map.Entry<Integer, List<ERstudent>> entry : claCollect.entrySet()) {
216
             for (Map.Entry<Integer, List<ERstudent>> entry : claCollect.entrySet()) {
201
                 Integer classid = entry.getKey();
217
                 Integer classid = entry.getKey();
202
                 List<ERstudent> rstudentList = entry.getValue();
218
                 List<ERstudent> rstudentList = entry.getValue();
203
-                statistics = rstudentList.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
219
+                DoubleSummaryStatistics claStatistics = rstudentList.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
204
                 ERclass rc = new ERclass();
220
                 ERclass rc = new ERclass();
205
                 rc.setExamid(examid);
221
                 rc.setExamid(examid);
206
                 rc.setClassid(classid);
222
                 rc.setClassid(classid);
207
                 rc.setSubjectid(subjectid);
223
                 rc.setSubjectid(subjectid);
208
                 rc.setSubjectname(subjectname);
224
                 rc.setSubjectname(subjectname);
209
                 rc.setAllscore(allscore);
225
                 rc.setAllscore(allscore);
210
-                rc.setClassmaxscore(statistics.getMax());
211
-                rc.setClassminscore(statistics.getMin());
212
-                rc.setClassavgscore(statistics.getAverage());
213
-                rc.setStunum(rstudentList.stream().filter(l -> l.getSstate() == 2).collect(Collectors.toList()).size());
214
-                rc.setMissnum(rstudentList.stream().filter(l -> l.getSstate() == 3).collect(Collectors.toList()).size());
226
+                rc.setClassmaxscore(claStatistics.getMax());
227
+                rc.setClassminscore(claStatistics.getMin());
228
+                rc.setClassavgscore(claStatistics.getAverage());
229
+                rc.setSchoolmaxscore(statistics.getMax());
230
+                rc.setSchoolavgscore(statistics.getAverage());
231
+                sknum = rstudentList.size();
232
+                rc.setStunum(sknum);//实考人数
233
+                rc.setMissnum(stunum - sknum);//缺考人数=计划人数-实考人数
234
+                yxnum = rstudentList.stream().filter(l -> l.getScore().compareTo(yxscore) != -1)
235
+                        .collect(Collectors.toList()).size();
236
+                lhnum = rstudentList.stream().filter(l -> l.getScore().compareTo(lhscore) != -1)
237
+                        .collect(Collectors.toList()).size();
238
+                jgnum = rstudentList.stream().filter(l -> l.getScore().compareTo(jgscore) != -1)
239
+                        .collect(Collectors.toList()).size();
240
+                dfnum = rstudentList.stream().filter(l -> l.getScore().compareTo(dfscore) != 1)
241
+                        .collect(Collectors.toList()).size();
242
+                scores = rstudentList.stream().map(l -> l.getScore()).collect(Collectors.toList());
243
+                rc.setYxrate(N_Utils.getIntegerDivideAndMulitiply(yxnum, stunum));
244
+                rc.setLhrate(N_Utils.getIntegerDivideAndMulitiply(lhnum, stunum));
245
+                rc.setJgrate(N_Utils.getIntegerDivideAndMulitiply(jgnum, stunum));
246
+                rc.setDfrate(N_Utils.getIntegerDivideAndMulitiply(dfnum, stunum));
247
+                rc.setBzc(ExamUtil.standardDiviation(scores));
215
                 classList.add(rc);
248
                 classList.add(rc);
216
                 List<EPaperQsVo> typelist = JSON.parseArray(rp.getQnumjson(), EPaperQsVo.class);
249
                 List<EPaperQsVo> typelist = JSON.parseArray(rp.getQnumjson(), EPaperQsVo.class);
217
                 for (EPaperQsVo t : typelist) {
250
                 for (EPaperQsVo t : typelist) {
243
         eRclassMapper.insertList(classList);
276
         eRclassMapper.insertList(classList);
244
         eRsubjectMapper.insertList(subjectList);
277
         eRsubjectMapper.insertList(subjectList);
245
 
278
 
246
-        setRank(schoolStudents, schoolRank, 1);//学校分数排名
247
-        setRank(schoolSubjectStudents, schoolSubjectRank, 2);//学校科目分数排名
248
-        setRank(classStudents, classRank, 3);//班级分数排名
249
-        setRank(classSubjectStudents, classSubjectRank, 4);//班级科目分数排名
279
+        setRank(schoolStudents, schoolStuRank, 1);//学校学生分数排名
280
+        setRank(schoolSubjectStudents, schoolSubStuRank, 2);//学校科目学生分数排名
281
+        setRank(classStudents, classStuRank, 3);//班级学生分数排名
282
+        setRank(classSubjectStudents, classSubStuRank, 4);//班级科目学生分数排名
250
 
283
 
251
         for (ERstudent cs : classStudents) {
284
         for (ERstudent cs : classStudents) {
252
             Integer studentid = cs.getStudentid();
285
             Integer studentid = cs.getStudentid();
253
-            cs.setClassrank(classRank.get(cs.getClassid() + "_" + studentid));
286
+            cs.setClassrank(classStuRank.get(cs.getClassid() + "_" + studentid));
254
             cs.setClassmaxscore(classStatistics.getMax());
287
             cs.setClassmaxscore(classStatistics.getMax());
255
             cs.setClassavgscore(classStatistics.getAverage());
288
             cs.setClassavgscore(classStatistics.getAverage());
256
-            cs.setSchoolrank(schoolRank.get(studentid));
289
+            cs.setSchoolrank(schoolStuRank.get(studentid));
257
             cs.setSchoolmaxscore(schoolStatisticsMax);
290
             cs.setSchoolmaxscore(schoolStatisticsMax);
258
             cs.setSchoolavgscore(schoolStatisticsAverage);
291
             cs.setSchoolavgscore(schoolStatisticsAverage);
259
         }
292
         }
260
         eRstudentMapper.insertList(classStudents);
293
         eRstudentMapper.insertList(classStudents);
261
 
294
 
295
+        DoubleSummaryStatistics sSStatistics = schoolSubjectStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
262
         for (ERstudent cs : classSubjectStudents) {
296
         for (ERstudent cs : classSubjectStudents) {
263
             Integer studentid = cs.getStudentid();
297
             Integer studentid = cs.getStudentid();
264
             Integer classid = cs.getClassid();
298
             Integer classid = cs.getClassid();
265
-            cs.setClassrank(classRank.get(classid + "_" + studentid));
266
-            cs.setClassmaxscore(classStatistics.getMax());
267
-            cs.setClassavgscore(classStatistics.getAverage());
268
-            cs.setSchoolrank(schoolSubjectRank.get(classid + "_" + cs.getSubjectid() + "_" + studentid));
299
+            subjectid = cs.getSubjectid();
300
+            cs.setClassrank(classSubStuRank.get(classid + "_" + subjectid + "_" + studentid));
301
+            cs.setClassmaxscore(cSStatistics.getMax());
302
+            cs.setClassavgscore(cSStatistics.getAverage());
303
+            cs.setSchoolrank(schoolSubStuRank.get(subjectid + "_" + studentid));
269
             cs.setSchoolmaxscore(sSStatistics.getMax());
304
             cs.setSchoolmaxscore(sSStatistics.getMax());
270
             cs.setSchoolavgscore(sSStatistics.getAverage());
305
             cs.setSchoolavgscore(sSStatistics.getAverage());
271
         }
306
         }
286
                 Integer studentid = cgs.getStudentid();
321
                 Integer studentid = cgs.getStudentid();
287
                 Integer classid = cgs.getClassid();
322
                 Integer classid = cgs.getClassid();
288
                 String subjectid = cgs.getSubjectid();
323
                 String subjectid = cgs.getSubjectid();
289
-                if (code == 1) {//学校
324
+                if (code == 1) {//学校学生
290
                     key = studentid.toString();
325
                     key = studentid.toString();
291
-                } else if (code == 2) {//学校科目
326
+                } else if (code == 2) {//学校科目学生
292
                     key = subjectid + "_" + studentid;
327
                     key = subjectid + "_" + studentid;
293
-                } else if (code == 3) {//班级
328
+                } else if (code == 3) {//班级学生
294
                     key = classid + "_" + studentid;
329
                     key = classid + "_" + studentid;
295
-                } else {//班级科目
330
+                } else {//班级科目学生
296
                     key = classid + "_" + subjectid + "_" + studentid;
331
                     key = classid + "_" + subjectid + "_" + studentid;
297
                 }
332
                 }
298
                 rank.put(key, index);
333
                 rank.put(key, index);

+ 23
- 2
sexam/src/main/java/com/xhkjedu/sexam/utils/ExamUtil.java View File

7
 import java.time.LocalDateTime;
7
 import java.time.LocalDateTime;
8
 import java.time.ZoneId;
8
 import java.time.ZoneId;
9
 import java.time.format.DateTimeFormatter;
9
 import java.time.format.DateTimeFormatter;
10
+import java.util.List;
10
 import java.util.Map;
11
 import java.util.Map;
11
 import java.util.concurrent.ConcurrentHashMap;
12
 import java.util.concurrent.ConcurrentHashMap;
12
 
13
 
113
     }
114
     }
114
 
115
 
115
     //两数相减
116
     //两数相减
116
-    public static long subtract(long a,long b){
117
+    public static long subtract(long a, long b) {
117
         BigInteger biginta = new BigInteger(a + "");
118
         BigInteger biginta = new BigInteger(a + "");
118
         BigInteger bigintb = new BigInteger(b + "");
119
         BigInteger bigintb = new BigInteger(b + "");
119
         return biginta.subtract(bigintb).longValue();
120
         return biginta.subtract(bigintb).longValue();
130
         BigDecimal b1 = new BigDecimal(Double.toString(v1));
131
         BigDecimal b1 = new BigDecimal(Double.toString(v1));
131
         BigDecimal b2 = new BigDecimal(Double.toString(v2));
132
         BigDecimal b2 = new BigDecimal(Double.toString(v2));
132
 
133
 
133
-        return b1.multiply(b2).setScale(0,BigDecimal.ROUND_HALF_UP).doubleValue();
134
+        return b1.multiply(b2).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
135
+    }
136
+
137
+    //方差s^2=[(x1-x)^2 +...(xn-x)^2]/n 或者s^2=[(x1-x)^2 +...(xn-x)^2]/(n-1)
138
+    public static double variance(List<Double> x) {
139
+        int m = x.size();
140
+        double sum = 0;
141
+        for (int i = 0; i < m; i++) {//求和
142
+            sum += x.get(i);
143
+        }
144
+        double dAve = sum / m;//求平均值
145
+        double dVar = 0;
146
+        for (int i = 0; i < m; i++) {//求方差
147
+            dVar += (x.get(i) - dAve) * (x.get(i) - dAve);
148
+        }
149
+        return dVar / m;
150
+    }
151
+
152
+    //标准差σ=sqrt(s^2)
153
+    public static double standardDiviation(List<Double> x) {
154
+        return Math.sqrt(variance(x));
134
     }
155
     }
135
 }
156
 }

+ 1
- 1
sexam/src/main/resources/mapper/paperstudent/EPaperStudentMapper.xml View File

190
 
190
 
191
     <select id="listByExamId" resultType="com.xhkjedu.sexam.model.reportstu.ERstudent">
191
     <select id="listByExamId" resultType="com.xhkjedu.sexam.model.reportstu.ERstudent">
192
         select classid,examid,subjectid,studentid,stuscore score,sstate
192
         select classid,examid,subjectid,studentid,stuscore score,sstate
193
-        from e_paper_student where examid=#{examid}
193
+        from e_paper_student where examid=#{examid} and sstate!=0
194
     </select>
194
     </select>
195
 </mapper>
195
 </mapper>

Loading…
Cancel
Save