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, Double> classScoreRates = new HashMap<>();
// 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) {
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());
// 获取班级所有学生的名单(来自 rMembers
Map<String, String> studentIdToName = new HashMap<>();
RGroupList groupList = rGroupList.stream().filter(rGroupList1 -> rGroupList1.getId().equals(classId)).findFirst().orElse(null);
if (groupList != null) {
for (RMember member : groupList.members) {
studentIdToName.put(member.getId(), member.getName());
}
}
// 初始化知识块列表(从 appraise 配置中提取)
Set<String> knowledgeBlocks = new HashSet<>();
for (AppraiseTreeNode node : appraise.getNodes()) {
if (node.getName().equals("劳育")) {
for (AppraiseTreeNode child : node.getChildren()) {
knowledgeBlocks.add(child.getName());
}
}
}
if (examResults != null && !examResults.isEmpty()) {
// 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) {
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. 融合主观和客观分数
Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>();
for (Map.Entry<String, Map<String, Double>> entry : studentScoreRates.entrySet()) {
String studentId = entry.getKey();
Map<String, Double> objective = entry.getValue();
for (String studentId : studentIdToName.keySet()) {
String studentName = studentIdToName.get(studentId);
Map<String, Double> objective = studentScoreRates.getOrDefault(studentName, new HashMap<>());
Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>());
// 计算综合得分
Map<String, Double> compositeScores = new HashMap<>();
for (Map.Entry<String, Double> objectiveEntry : objective.entrySet()) {
String block = objectiveEntry.getKey();
double objectiveScore = objectiveEntry.getValue();
for (String block : knowledgeBlocks) {
double objectiveScore = objective.getOrDefault(block, 0.0);
double subjectiveScore = subjective.getOrDefault(block, 0.0);
// 按6:4比例计算综合得分
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
compositeScores.put(block, compositeScore);
}
compositeStudentScores.put(studentId, compositeScores);
compositeStudentScores.put(studentName, compositeScores);
}
// 5. 计算班级整体得分率
int studentCount = compositeStudentScores.size();
Map<String, Double> compositeClassScoreRates = new HashMap<>();
for (Map<String, Double> studentScores : compositeStudentScores.values()) {
for (Map.Entry<String, Double> entry : studentScores.entrySet()) {
String block = entry.getKey();
double score = entry.getValue();
compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score);
if (studentCount > 0) {
for (Map<String, Double> studentScores : compositeStudentScores.values()) {
for (String block : knowledgeBlocks) {
double score = studentScores.getOrDefault(block, 0.0);
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. 初始化所有同层的父节点
for (AppraiseTreeNode node : appraise.getNodes()) {
if (node.getName().equals("德育")) {
if (node.getName().equals("育")) {
for (AppraiseTreeNode child : node.getChildren()) {
if (!compositeClassScoreRates.containsKey(child.getName())) {
compositeClassScoreRates.put(child.getName(), 0.0);
@ -677,6 +716,10 @@ public class LaborEducationServiceImpl implements LaborEducationService {
}
// 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<>();
Map<String, Object> classScore = new HashMap<>();
classScore.put("className", className); // 设置班级名称
@ -718,8 +761,6 @@ public class LaborEducationServiceImpl implements LaborEducationService {
}
private static List<KnowledgeScoreRate> calculateStudentScoreRates(
String studentId,
List<ExamClassResult> examResults,

@ -576,29 +576,67 @@ public class MoralEducationServiceImpl implements MoralEducationService {
Map<String, Map<String, Double>> studentScoreRates = new HashMap<>();
Map<String, Double> classScoreRates = new HashMap<>();
// 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) {
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());
// 获取班级所有学生的名单(来自 rMembers
Map<String, String> studentIdToName = new HashMap<>();
RGroupList groupList = rGroupList.stream().filter(rGroupList1 -> rGroupList1.getId().equals(classId)).findFirst().orElse(null);
if (groupList != null) {
for (RMember member : groupList.members) {
studentIdToName.put(member.getId(), member.getName());
}
}
// 初始化知识块列表(从 appraise 配置中提取)
Set<String> knowledgeBlocks = new HashSet<>();
for (AppraiseTreeNode node : appraise.getNodes()) {
if (node.getName().equals("劳育")) {
for (AppraiseTreeNode child : node.getChildren()) {
knowledgeBlocks.add(child.getName());
}
}
}
if (examResults != null && !examResults.isEmpty()) {
// 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) {
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. 融合主观和客观分数
Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>();
for (Map.Entry<String, Map<String, Double>> entry : studentScoreRates.entrySet()) {
String studentId = entry.getKey();
Map<String, Double> objective = entry.getValue();
for (String studentId : studentIdToName.keySet()) {
String studentName = studentIdToName.get(studentId);
Map<String, Double> objective = studentScoreRates.getOrDefault(studentName, new HashMap<>());
Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>());
// 计算综合得分
Map<String, Double> compositeScores = new HashMap<>();
for (Map.Entry<String, Double> objectiveEntry : objective.entrySet()) {
String block = objectiveEntry.getKey();
double objectiveScore = objectiveEntry.getValue();
for (String block : knowledgeBlocks) {
double objectiveScore = objective.getOrDefault(block, 0.0);
double subjectiveScore = subjective.getOrDefault(block, 0.0);
// 按6:4比例计算综合得分
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
compositeScores.put(block, compositeScore);
}
compositeStudentScores.put(studentId, compositeScores);
compositeStudentScores.put(studentName, compositeScores);
}
// 5. 计算班级整体得分率
int studentCount = compositeStudentScores.size();
Map<String, Double> compositeClassScoreRates = new HashMap<>();
for (Map<String, Double> studentScores : compositeStudentScores.values()) {
for (Map.Entry<String, Double> entry : studentScores.entrySet()) {
String block = entry.getKey();
double score = entry.getValue();
compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score);
if (studentCount > 0) {
for (Map<String, Double> studentScores : compositeStudentScores.values()) {
for (String block : knowledgeBlocks) {
double score = studentScores.getOrDefault(block, 0.0);
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. 初始化所有同层的父节点
for (AppraiseTreeNode node : appraise.getNodes()) {
@ -678,6 +717,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
// 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<>();
Map<String, Object> classScore = new HashMap<>();
classScore.put("className", className); // 设置班级名称
@ -719,8 +762,6 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
private static List<KnowledgeScoreRate> calculateStudentScoreRates(
String studentId,
List<ExamClassResult> examResults,

Loading…
Cancel
Save