|
@@ -11,6 +11,7 @@ import com.xhkjedu.smarking.vo.report.reportother.RankGroupVo;
|
11
|
11
|
import com.xhkjedu.smarking.vo.report.reportother.SzJsonVo;
|
12
|
12
|
import com.xhkjedu.smarking.vo.report.reportsubject.SectionScoreVo;
|
13
|
13
|
import com.xhkjedu.utils.N_Utils;
|
|
14
|
+import com.xhkjedu.vo.PageResult;
|
14
|
15
|
import com.xhkjedu.vo.ResultVo;
|
15
|
16
|
import lombok.extern.slf4j.Slf4j;
|
16
|
17
|
|
|
@@ -458,7 +459,7 @@ public class MarkingUtil {
|
458
|
459
|
}
|
459
|
460
|
|
460
|
461
|
//计算占比,保留4为小数,乘以100后2位小数
|
461
|
|
- public static double calculateRate(Object v1,Object v2){
|
|
462
|
+ public static double calculateRate(Object v1, Object v2) {
|
462
|
463
|
BigDecimal b1 = new BigDecimal(v1.toString());
|
463
|
464
|
BigDecimal b2 = new BigDecimal(v2.toString());
|
464
|
465
|
|
|
@@ -549,7 +550,7 @@ public class MarkingUtil {
|
549
|
550
|
}
|
550
|
551
|
|
551
|
552
|
//排名分组计算 参数[总名次,分组数] 如:第一组(第1-10名)
|
552
|
|
- public static List<RankGroupVo> rankGroup(Integer total,Integer groupNum) {
|
|
553
|
+ public static List<RankGroupVo> rankGroup(Integer total, Integer groupNum) {
|
553
|
554
|
List<RankGroupVo> rtnList = new ArrayList<>();
|
554
|
555
|
if (groupNum > total) groupNum = total;
|
555
|
556
|
|
|
@@ -586,7 +587,7 @@ public class MarkingUtil {
|
586
|
587
|
}
|
587
|
588
|
|
588
|
589
|
//分数排名
|
589
|
|
- public static Map<Double,Integer> fspm(List<Double> scores) {
|
|
590
|
+ public static Map<Double, Integer> fspm(List<Double> scores) {
|
590
|
591
|
//倒序排
|
591
|
592
|
scores.sort(Collections.reverseOrder());
|
592
|
593
|
// 创建一个地图来存储分数和出现次数
|
|
@@ -603,7 +604,7 @@ public class MarkingUtil {
|
603
|
604
|
}
|
604
|
605
|
|
605
|
606
|
//人数排名
|
606
|
|
- public static Map<Integer,Integer> rspm(List<Integer> nums) {
|
|
607
|
+ public static Map<Integer, Integer> rspm(List<Integer> nums) {
|
607
|
608
|
//倒序排
|
608
|
609
|
nums.sort(Collections.reverseOrder());
|
609
|
610
|
// 创建一个地图来存储分数和出现次数
|
|
@@ -676,16 +677,16 @@ public class MarkingUtil {
|
676
|
677
|
}
|
677
|
678
|
|
678
|
679
|
// 分数段 分数分段
|
679
|
|
- public static List<RankGroupVo> fdScore(Double totalScore,int fdscore){
|
|
680
|
+ public static List<RankGroupVo> fdScore(Double totalScore, int fdscore) {
|
680
|
681
|
List<RankGroupVo> rtnList = new ArrayList<>();
|
681
|
682
|
for (int i = 0; i < totalScore; i += fdscore) {
|
682
|
683
|
int end = (int) Math.min(i + fdscore, totalScore);
|
683
|
684
|
|
684
|
685
|
String groupname = "[" + i + "~" + end;
|
685
|
|
- if(end == totalScore){
|
686
|
|
- groupname+="]";
|
687
|
|
- }else {
|
688
|
|
- groupname+=")";
|
|
686
|
+ if (end == totalScore) {
|
|
687
|
+ groupname += "]";
|
|
688
|
+ } else {
|
|
689
|
+ groupname += ")";
|
689
|
690
|
}
|
690
|
691
|
|
691
|
692
|
RankGroupVo rgvo = new RankGroupVo();
|
|
@@ -696,11 +697,12 @@ public class MarkingUtil {
|
696
|
697
|
}
|
697
|
698
|
return rtnList;
|
698
|
699
|
}
|
|
700
|
+
|
699
|
701
|
//分数分段 试题1分1段
|
700
|
|
- public static List<SectionScoreVo> fdScoreForOne(Double totalScore){
|
|
702
|
+ public static List<SectionScoreVo> fdScoreForOne(Double totalScore) {
|
701
|
703
|
List<SectionScoreVo> rtnList = new ArrayList<>();
|
702
|
|
- for (int i = 0; i < totalScore; i ++) {
|
703
|
|
- double end = Math.min(i+1, totalScore);
|
|
704
|
+ for (int i = 0; i < totalScore; i++) {
|
|
705
|
+ double end = Math.min(i + 1, totalScore);
|
704
|
706
|
SectionScoreVo rgvo = new SectionScoreVo();
|
705
|
707
|
rgvo.setSectionname("[" + i + "~" + end + ")");
|
706
|
708
|
rgvo.setMinvalue(i);
|
|
@@ -735,6 +737,7 @@ public class MarkingUtil {
|
735
|
737
|
}
|
736
|
738
|
|
737
|
739
|
private static int index = 0;
|
|
740
|
+
|
738
|
741
|
//根据表达式计算
|
739
|
742
|
public static double evaluate(String expression) {
|
740
|
743
|
index = 0;
|
|
@@ -826,7 +829,7 @@ public class MarkingUtil {
|
826
|
829
|
|
827
|
830
|
//获取报告参数
|
828
|
831
|
public static List<MsrReportparam> getMsrReportParams(MsrReportparamMapper msrReportparamMapper
|
829
|
|
- ,Integer examid, String rpbelong, String reportcode) {
|
|
832
|
+ , Integer examid, String rpbelong, String reportcode) {
|
830
|
833
|
List<MsrReportparam> list = msrReportparamMapper.listReportparamByRpbelong(examid, rpbelong, reportcode);
|
831
|
834
|
if (N_Utils.isListEmpty(list) && !"all".equals(reportcode)) {
|
832
|
835
|
list = msrReportparamMapper.listReportparamByRpbelong(examid, rpbelong, "all");
|
|
@@ -834,11 +837,74 @@ public class MarkingUtil {
|
834
|
837
|
return list;
|
835
|
838
|
}
|
836
|
839
|
|
|
840
|
+ // 获取指定字段的值
|
|
841
|
+ public static double getFieldValueAsDouble(Map<String, Object> subject, String field) {
|
|
842
|
+ Object value = subject.get(field);
|
|
843
|
+ if (value instanceof Number) {
|
|
844
|
+ return ((Number) value).doubleValue();
|
|
845
|
+ } else if (value instanceof String && isNumeric((String) value)) {
|
|
846
|
+ return Double.parseDouble((String) value);
|
|
847
|
+ }
|
|
848
|
+ throw new IllegalArgumentException("Unknown or non-numeric field: " + field);
|
|
849
|
+ }
|
|
850
|
+
|
|
851
|
+ // 判断字符串是否为数字
|
|
852
|
+ public static boolean isNumeric(String strNum) {
|
|
853
|
+ if (strNum == null) {
|
|
854
|
+ return false;
|
|
855
|
+ }
|
|
856
|
+ try {
|
|
857
|
+ Double.parseDouble(strNum);
|
|
858
|
+ } catch (NumberFormatException nfe) {
|
|
859
|
+ return false;
|
|
860
|
+ }
|
|
861
|
+ return true;
|
|
862
|
+ }
|
|
863
|
+
|
|
864
|
+ // 根据指定科目字段排序
|
|
865
|
+ public static List<Map<String, Object>> sortBySubjectField(List<Map<String, Object>> students
|
|
866
|
+ , String subjectid, String field, Integer od) {
|
|
867
|
+ if ("classname".equals(field)) {
|
|
868
|
+ if (od.equals(2)) {//降序
|
|
869
|
+ return students.stream().sorted(Comparator.comparing(student -> student.get("classname").toString(), Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList());
|
|
870
|
+ } else {//升序
|
|
871
|
+ return students.stream().sorted(Comparator.comparing(student -> student.get("classname").toString(), Comparator.nullsLast(Comparator.naturalOrder()))).collect(Collectors.toList());
|
|
872
|
+ }
|
|
873
|
+ }
|
|
874
|
+ Comparator<Map<String, Object>> studentComparator = Comparator.comparingDouble((Map<String, Object> student) -> {
|
|
875
|
+ // 获取并转换subjectList为List<Map<String, Object>>
|
|
876
|
+ @SuppressWarnings("unchecked")
|
|
877
|
+ List<Map<String, Object>> subjectList = (List<Map<String, Object>>) student.get("subjectList");
|
|
878
|
+
|
|
879
|
+ // 查找与subjectid匹配的第一个科目,并根据field获取其值
|
|
880
|
+ return subjectList.stream()
|
|
881
|
+ .filter(subject -> subjectid.equals(subject.get("subjectid")))
|
|
882
|
+ .mapToDouble(subject -> MarkingUtil.getFieldValueAsDouble(subject, field))
|
|
883
|
+ .findFirst().orElse(Double.NaN);
|
|
884
|
+ }); // 如果是数值型字段,通常希望降序排列
|
|
885
|
+ if (od.equals(2)) {
|
|
886
|
+ studentComparator = studentComparator.reversed();
|
|
887
|
+ }
|
|
888
|
+
|
|
889
|
+ // 对学生列表进行排序
|
|
890
|
+ return students.stream().sorted(studentComparator).collect(Collectors.toList());
|
|
891
|
+ }
|
|
892
|
+
|
|
893
|
+ //分页
|
|
894
|
+ public static PageResult getPageResult(Integer page, Integer pageSize, List<?> list) {
|
|
895
|
+ int start = (page - 1) * pageSize;
|
|
896
|
+ PageResult pageResult = new PageResult();
|
|
897
|
+ pageResult.setTotal(list.size());
|
|
898
|
+ list = list.stream().skip(start).limit(pageSize).collect(Collectors.toList());
|
|
899
|
+ pageResult.setList(list);
|
|
900
|
+ return pageResult;
|
|
901
|
+ }
|
|
902
|
+
|
837
|
903
|
public static void main(String[] args) {
|
838
|
|
- List<RankGroupVo> list = fdScore(1.0,5);
|
839
|
|
- for (RankGroupVo rgvo : list) {
|
840
|
|
- System.out.println(rgvo.getGroupname() + ";" + rgvo.getMinvalue() + "-" + rgvo.getMaxvalue());
|
|
904
|
+ List<RankGroupVo> list = fdScore(1.0, 5);
|
|
905
|
+ for (RankGroupVo rgvo : list) {
|
|
906
|
+ System.out.println(rgvo.getGroupname() + ";" + rgvo.getMinvalue() + "-" + rgvo.getMaxvalue());
|
841
|
907
|
|
842
|
|
- }
|
|
908
|
+ }
|
843
|
909
|
}
|
844
|
910
|
}
|