update 调整无数据时 初始化结构返回

develop
hhb@hotmail.com 2 months ago
parent fb2e273060
commit 0523d7c774

@ -575,29 +575,67 @@ public class LaborEducationServiceImpl implements LaborEducationService {
Map<String, Map<String, Double>> studentScoreRates = new HashMap<>(); Map<String, Map<String, Double>> studentScoreRates = new HashMap<>();
Map<String, Double> classScoreRates = new HashMap<>(); Map<String, Double> classScoreRates = new HashMap<>();
// 遍历班级中的每个学生 // 获取班级所有学生的名单(来自 rMembers
for (ExamClassResult examResult : examResults) { Map<String, String> studentIdToName = new HashMap<>();
if (!examResult.getInfo().getId().equals(classId)) continue; // 过滤出该班级的考试 RGroupList groupList = rGroupList.stream().filter(rGroupList1 -> rGroupList1.getId().equals(classId)).findFirst().orElse(null);
List<Integer> statuses = examResult.getStatus(); if (groupList != null) {
for (int i = 0; i < examResult.getStudentIds().size(); i++) { for (RMember member : groupList.members) {
String studentId = examResult.getStudentIds().get(i); studentIdToName.put(member.getId(), member.getName());
String name = rMembers.stream() }
.filter(member -> member.getId().equals(studentId)) }
.findFirst()
.map(RMember::getName) // 初始化知识块列表(从 appraise 配置中提取)
.orElse("未知"); Set<String> knowledgeBlocks = new HashSet<>();
int status = statuses.get(i); for (AppraiseTreeNode node : appraise.getNodes()) {
if (status == 1) continue; // 跳过 status 为 1 的记录 if (node.getName().equals("劳育")) {
for (AppraiseTreeNode child : node.getChildren()) {
// 计算父节点得分率(客观分数) knowledgeBlocks.add(child.getName());
Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent( }
studentId, examResults, knowledgeMap, appraise, points }
); }
studentScoreRates.put(name, scoreRates);
if (examResults != null && !examResults.isEmpty()) {
// 累加班级整体得分率 // 遍历班级中的每个学生
for (Map.Entry<String, Double> entry : scoreRates.entrySet()) { for (ExamClassResult examResult : examResults) {
classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue()); if (!examResult.getInfo().getId().equals(classId)) continue; // 过滤出该班级的考试
List<Integer> statuses = examResult.getStatus();
for (int i = 0; i < examResult.getStudentIds().size(); i++) {
String studentId = examResult.getStudentIds().get(i);
String name = rMembers.stream()
.filter(member -> member.getId().equals(studentId))
.findFirst()
.map(RMember::getName)
.orElse("未知");
int status = statuses.get(i);
if (status == 1) continue; // 跳过 status 为 1 的记录
// 计算父节点得分率(客观分数)
Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points
);
studentScoreRates.put(name, scoreRates);
// 累加班级整体得分率
for (Map.Entry<String, Double> entry : scoreRates.entrySet()) {
classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue());
}
}
}
}else {
// 无考试数据时初始化所有学生的默认分数为0
if (groupList != null) {
for (RMember member : groupList.members) {
String studentId = member.getId();
String studentName = studentIdToName.getOrDefault(studentId, "未知学生");
Map<String, Double> defaultScores = new HashMap<>();
for (String block : knowledgeBlocks) {
defaultScores.put(block, 0.0);
}
studentScoreRates.put(studentName, defaultScores);
// 初始化班级得分率
for (String block : knowledgeBlocks) {
classScoreRates.put(block, 0.0);
}
} }
} }
} }
@ -632,42 +670,43 @@ public class LaborEducationServiceImpl implements LaborEducationService {
// 4. 融合主观和客观分数 // 4. 融合主观和客观分数
Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>(); Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>();
for (Map.Entry<String, Map<String, Double>> entry : studentScoreRates.entrySet()) { for (String studentId : studentIdToName.keySet()) {
String studentId = entry.getKey(); String studentName = studentIdToName.get(studentId);
Map<String, Double> objective = entry.getValue(); Map<String, Double> objective = studentScoreRates.getOrDefault(studentName, new HashMap<>());
Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>()); Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>());
// 计算综合得分
Map<String, Double> compositeScores = new HashMap<>(); Map<String, Double> compositeScores = new HashMap<>();
for (Map.Entry<String, Double> objectiveEntry : objective.entrySet()) { for (String block : knowledgeBlocks) {
String block = objectiveEntry.getKey(); double objectiveScore = objective.getOrDefault(block, 0.0);
double objectiveScore = objectiveEntry.getValue();
double subjectiveScore = subjective.getOrDefault(block, 0.0); double subjectiveScore = subjective.getOrDefault(block, 0.0);
// 按6:4比例计算综合得分
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4); double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore)); compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
compositeScores.put(block, compositeScore); compositeScores.put(block, compositeScore);
} }
compositeStudentScores.put(studentName, compositeScores);
compositeStudentScores.put(studentId, compositeScores);
} }
// 5. 计算班级整体得分率 // 5. 计算班级整体得分率
int studentCount = compositeStudentScores.size(); int studentCount = compositeStudentScores.size();
Map<String, Double> compositeClassScoreRates = new HashMap<>(); Map<String, Double> compositeClassScoreRates = new HashMap<>();
for (Map<String, Double> studentScores : compositeStudentScores.values()) { if (studentCount > 0) {
for (Map.Entry<String, Double> entry : studentScores.entrySet()) { for (Map<String, Double> studentScores : compositeStudentScores.values()) {
String block = entry.getKey(); for (String block : knowledgeBlocks) {
double score = entry.getValue(); double score = studentScores.getOrDefault(block, 0.0);
compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score); compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score);
}
}
compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount)));
} else {
// 无学生时初始化空值
for (String block : knowledgeBlocks) {
compositeClassScoreRates.put(block, 0.0);
} }
} }
compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount))); // 保留小数点后两位
// 6. 初始化所有同层的父节点 // 6. 初始化所有同层的父节点
for (AppraiseTreeNode node : appraise.getNodes()) { for (AppraiseTreeNode node : appraise.getNodes()) {
if (node.getName().equals("德育")) { if (node.getName().equals("育")) {
for (AppraiseTreeNode child : node.getChildren()) { for (AppraiseTreeNode child : node.getChildren()) {
if (!compositeClassScoreRates.containsKey(child.getName())) { if (!compositeClassScoreRates.containsKey(child.getName())) {
compositeClassScoreRates.put(child.getName(), 0.0); compositeClassScoreRates.put(child.getName(), 0.0);
@ -677,6 +716,10 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
// 7. 转换 classScoreRates 和 studentScoreRates 为新的数据结构 // 7. 转换 classScoreRates 和 studentScoreRates 为新的数据结构
return getResult(className, compositeClassScoreRates, compositeStudentScores);
}
private static @NotNull Map<String, Object> getResult(String className, Map<String, Double> compositeClassScoreRates, Map<String, Map<String, Double>> compositeStudentScores) {
List<Map<String, Object>> adjustedClassScoreRates = new ArrayList<>(); List<Map<String, Object>> adjustedClassScoreRates = new ArrayList<>();
Map<String, Object> classScore = new HashMap<>(); Map<String, Object> classScore = new HashMap<>();
classScore.put("className", className); // 设置班级名称 classScore.put("className", className); // 设置班级名称
@ -718,8 +761,6 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
private static List<KnowledgeScoreRate> calculateStudentScoreRates( private static List<KnowledgeScoreRate> calculateStudentScoreRates(
String studentId, String studentId,
List<ExamClassResult> examResults, List<ExamClassResult> examResults,

@ -576,29 +576,67 @@ public class MoralEducationServiceImpl implements MoralEducationService {
Map<String, Map<String, Double>> studentScoreRates = new HashMap<>(); Map<String, Map<String, Double>> studentScoreRates = new HashMap<>();
Map<String, Double> classScoreRates = new HashMap<>(); Map<String, Double> classScoreRates = new HashMap<>();
// 遍历班级中的每个学生 // 获取班级所有学生的名单(来自 rMembers
for (ExamClassResult examResult : examResults) { Map<String, String> studentIdToName = new HashMap<>();
if (!examResult.getInfo().getId().equals(classId)) continue; // 过滤出该班级的考试 RGroupList groupList = rGroupList.stream().filter(rGroupList1 -> rGroupList1.getId().equals(classId)).findFirst().orElse(null);
List<Integer> statuses = examResult.getStatus(); if (groupList != null) {
for (int i = 0; i < examResult.getStudentIds().size(); i++) { for (RMember member : groupList.members) {
String studentId = examResult.getStudentIds().get(i); studentIdToName.put(member.getId(), member.getName());
String name = rMembers.stream() }
.filter(member -> member.getId().equals(studentId)) }
.findFirst()
.map(RMember::getName) // 初始化知识块列表(从 appraise 配置中提取)
.orElse("未知"); Set<String> knowledgeBlocks = new HashSet<>();
int status = statuses.get(i); for (AppraiseTreeNode node : appraise.getNodes()) {
if (status == 1) continue; // 跳过 status 为 1 的记录 if (node.getName().equals("劳育")) {
for (AppraiseTreeNode child : node.getChildren()) {
// 计算父节点得分率(客观分数) knowledgeBlocks.add(child.getName());
Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent( }
studentId, examResults, knowledgeMap, appraise, points }
); }
studentScoreRates.put(name, scoreRates);
if (examResults != null && !examResults.isEmpty()) {
// 累加班级整体得分率 // 遍历班级中的每个学生
for (Map.Entry<String, Double> entry : scoreRates.entrySet()) { for (ExamClassResult examResult : examResults) {
classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue()); if (!examResult.getInfo().getId().equals(classId)) continue; // 过滤出该班级的考试
List<Integer> statuses = examResult.getStatus();
for (int i = 0; i < examResult.getStudentIds().size(); i++) {
String studentId = examResult.getStudentIds().get(i);
String name = rMembers.stream()
.filter(member -> member.getId().equals(studentId))
.findFirst()
.map(RMember::getName)
.orElse("未知");
int status = statuses.get(i);
if (status == 1) continue; // 跳过 status 为 1 的记录
// 计算父节点得分率(客观分数)
Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points
);
studentScoreRates.put(name, scoreRates);
// 累加班级整体得分率
for (Map.Entry<String, Double> entry : scoreRates.entrySet()) {
classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue());
}
}
}
}else {
// 无考试数据时初始化所有学生的默认分数为0
if (groupList != null) {
for (RMember member : groupList.members) {
String studentId = member.getId();
String studentName = studentIdToName.getOrDefault(studentId, "未知学生");
Map<String, Double> defaultScores = new HashMap<>();
for (String block : knowledgeBlocks) {
defaultScores.put(block, 0.0);
}
studentScoreRates.put(studentName, defaultScores);
// 初始化班级得分率
for (String block : knowledgeBlocks) {
classScoreRates.put(block, 0.0);
}
} }
} }
} }
@ -633,38 +671,39 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 4. 融合主观和客观分数 // 4. 融合主观和客观分数
Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>(); Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>();
for (Map.Entry<String, Map<String, Double>> entry : studentScoreRates.entrySet()) { for (String studentId : studentIdToName.keySet()) {
String studentId = entry.getKey(); String studentName = studentIdToName.get(studentId);
Map<String, Double> objective = entry.getValue(); Map<String, Double> objective = studentScoreRates.getOrDefault(studentName, new HashMap<>());
Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>()); Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>());
// 计算综合得分
Map<String, Double> compositeScores = new HashMap<>(); Map<String, Double> compositeScores = new HashMap<>();
for (Map.Entry<String, Double> objectiveEntry : objective.entrySet()) { for (String block : knowledgeBlocks) {
String block = objectiveEntry.getKey(); double objectiveScore = objective.getOrDefault(block, 0.0);
double objectiveScore = objectiveEntry.getValue();
double subjectiveScore = subjective.getOrDefault(block, 0.0); double subjectiveScore = subjective.getOrDefault(block, 0.0);
// 按6:4比例计算综合得分
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4); double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore)); compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
compositeScores.put(block, compositeScore); compositeScores.put(block, compositeScore);
} }
compositeStudentScores.put(studentName, compositeScores);
compositeStudentScores.put(studentId, compositeScores);
} }
// 5. 计算班级整体得分率 // 5. 计算班级整体得分率
int studentCount = compositeStudentScores.size(); int studentCount = compositeStudentScores.size();
Map<String, Double> compositeClassScoreRates = new HashMap<>(); Map<String, Double> compositeClassScoreRates = new HashMap<>();
for (Map<String, Double> studentScores : compositeStudentScores.values()) { if (studentCount > 0) {
for (Map.Entry<String, Double> entry : studentScores.entrySet()) { for (Map<String, Double> studentScores : compositeStudentScores.values()) {
String block = entry.getKey(); for (String block : knowledgeBlocks) {
double score = entry.getValue(); double score = studentScores.getOrDefault(block, 0.0);
compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score); compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score);
}
}
compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount)));
} else {
// 无学生时初始化空值
for (String block : knowledgeBlocks) {
compositeClassScoreRates.put(block, 0.0);
} }
} }
compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount))); // 保留小数点后两位
// 6. 初始化所有同层的父节点 // 6. 初始化所有同层的父节点
for (AppraiseTreeNode node : appraise.getNodes()) { for (AppraiseTreeNode node : appraise.getNodes()) {
@ -678,6 +717,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
} }
// 7. 转换 classScoreRates 和 studentScoreRates 为新的数据结构 // 7. 转换 classScoreRates 和 studentScoreRates 为新的数据结构
return getResult(className, compositeClassScoreRates, compositeStudentScores);
}
private static @NotNull Map<String, Object> getResult(String className, Map<String, Double> compositeClassScoreRates, Map<String, Map<String, Double>> compositeStudentScores) {
List<Map<String, Object>> adjustedClassScoreRates = new ArrayList<>(); List<Map<String, Object>> adjustedClassScoreRates = new ArrayList<>();
Map<String, Object> classScore = new HashMap<>(); Map<String, Object> classScore = new HashMap<>();
classScore.put("className", className); // 设置班级名称 classScore.put("className", className); // 设置班级名称
@ -719,8 +762,6 @@ public class MoralEducationServiceImpl implements MoralEducationService {
} }
private static List<KnowledgeScoreRate> calculateStudentScoreRates( private static List<KnowledgeScoreRate> calculateStudentScoreRates(
String studentId, String studentId,
List<ExamClassResult> examResults, List<ExamClassResult> examResults,

Loading…
Cancel
Save