update 调整算法精度

develop
hhb@hotmail.com 1 month ago
parent c74df513b4
commit 7530edc04a

@ -223,10 +223,10 @@ public class LaborEducationServiceImpl implements LaborEducationService {
List<Exam> exams; List<Exam> exams;
List<RecordVo> res; List<RecordVo> res;
try { try {
exams = examRepository.findExamByClassId(String.format(PK.EXAM, findDto.getTmdId()), findDto.getClassId(), findDto.getPeriodId(), findDto.getSubjectId()); exams = examRepository.findExamByClassId(String.format(PK.EXAM, findDto.getTmdId()), findDto.getClassId(), findDto.getPeriodId(), findDto.getSubjectId());
res= appraiseRecordRepository.getRecords(String.format(PK.PK_APPRAISE_RECORD, findDto.getCode()),findDto.getAcademicYearId(), findDto.getClassId(), findDto.getStudentId()); res= appraiseRecordRepository.getRecords(String.format(PK.PK_APPRAISE_RECORD, findDto.getCode()),findDto.getAcademicYearId(), findDto.getClassId(), findDto.getStudentId());
resMap.put("exams",exams); resMap.put("exams",exams);
resMap.put("res", res); resMap.put("res", res);
}catch (Exception e){ }catch (Exception e){
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据查询异常"); throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据查询异常");
} }
@ -293,9 +293,6 @@ public class LaborEducationServiceImpl implements LaborEducationService {
// 获取对应知识块的客观成绩并转换为基于60分加分的分数 // 获取对应知识块的客观成绩并转换为基于60分加分的分数
double objectiveScore = knowledgeBlockScores.get(knowledgeBlock); double objectiveScore = knowledgeBlockScores.get(knowledgeBlock);
// 转换为正确率的小数形式(假设原始分是百分比)
double correctRate = objectiveScore / 100.0;
objectiveScore = 60.0 + correctRate * 40.0;
// 确保不超过100分 // 确保不超过100分
objectiveScore = Math.min(100.0, objectiveScore); objectiveScore = Math.min(100.0, objectiveScore);
// 保留两位小数 // 保留两位小数
@ -339,21 +336,22 @@ public class LaborEducationServiceImpl implements LaborEducationService {
return scores; return scores;
} }
private static @NotNull Map<String, Map<String, Double>> getStringMapMap(Map<String, List<String>> knowledgeBlockToPointsMap, Map<String, Map<String, Double>> studentKnowledgePointScores) { private static Map<String, Map<String, Double>> getStringMapMap(
Map<String, List<String>> knowledgeBlockToPointsMap,
Map<String, Map<String, Double>> studentKnowledgePointScores) {
Map<String, Map<String, Double>> studentKnowledgeBlockScores = new HashMap<>(); Map<String, Map<String, Double>> studentKnowledgeBlockScores = new HashMap<>();
for (Map.Entry<String, Map<String, Double>> entry : studentKnowledgePointScores.entrySet()) { for (Map.Entry<String, Map<String, Double>> entry : studentKnowledgePointScores.entrySet()) {
String studentId = entry.getKey(); String studentId = entry.getKey();
Map<String, Double> pointScores = entry.getValue(); Map<String, Double> pointScores = entry.getValue();
Map<String, Double> blockScores = studentKnowledgeBlockScores.computeIfAbsent(studentId, k -> new HashMap<>()); Map<String, Double> blockScores = studentKnowledgeBlockScores.computeIfAbsent(studentId, k -> new HashMap<>());
// 遍历知识块和知识点的映射关系
for (Map.Entry<String, List<String>> blockEntry : knowledgeBlockToPointsMap.entrySet()) { for (Map.Entry<String, List<String>> blockEntry : knowledgeBlockToPointsMap.entrySet()) {
String knowledgeBlock = blockEntry.getKey(); String knowledgeBlock = blockEntry.getKey();
List<String> knowledgePoints = blockEntry.getValue(); List<String> knowledgePoints = blockEntry.getValue();
// 计算该知识块的总得分和知识点数量
double totalScore = 0.0; double totalScore = 0.0;
int validPointCount = 0; // 有效知识点数量(有实际得分的知识点) int validPointCount = 0;
for (String knowledgePoint : knowledgePoints) { for (String knowledgePoint : knowledgePoints) {
if (pointScores.containsKey(knowledgePoint)) { if (pointScores.containsKey(knowledgePoint)) {
totalScore += pointScores.get(knowledgePoint); totalScore += pointScores.get(knowledgePoint);
@ -361,10 +359,14 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
} }
// 计算知识块的平均分 // 关键修改:统一分数转换逻辑
double averageScore = (validPointCount > 0) ? totalScore / validPointCount : 60.0; // 无有效知识点时默认60分 double averageScore = (validPointCount > 0) ? totalScore / validPointCount : 0.0; // 原始正确率
averageScore = Math.max(60.0, Math.min(100.0, averageScore)); // 确保得分在60-100之间 double correctRate = averageScore / 100.0;
blockScores.put(knowledgeBlock, averageScore); double convertedScore = 60.0 + (correctRate * 40.0);
convertedScore = Math.min(100.0, convertedScore);
convertedScore = Double.parseDouble(String.format("%.2f", convertedScore));
blockScores.put(knowledgeBlock, convertedScore);
} }
} }
return studentKnowledgeBlockScores; return studentKnowledgeBlockScores;
@ -520,13 +522,13 @@ public class LaborEducationServiceImpl implements LaborEducationService {
Map<String, Double> knowledgeTotalScore = new HashMap<>(); Map<String, Double> knowledgeTotalScore = new HashMap<>();
// 计算学生的知识点得分率 // 计算学生的知识点得分率
List<KnowledgeScoreRate> studentScoreRates = calculateStudentScoreRates(studentId, examResults, knowledgeMap, points, knowledgeTotalScore); List<LaborEducationServiceImpl.KnowledgeScoreRate> studentScoreRates = calculateStudentScoreRates(studentId, examResults, knowledgeMap, points, knowledgeTotalScore);
// 查找知识点对应的节点及其父节点 // 查找知识点对应的节点及其父节点
Map<String, Double> parentNodeScoreRates = new HashMap<>(); Map<String, Double> parentNodeScoreRates = new HashMap<>();
Map<String, Integer> parentNodeScoreCount = new HashMap<>(); // 记录每个父节点的知识点数量 Map<String, Integer> parentNodeScoreCount = new HashMap<>(); // 记录每个父节点的知识点数量
for (KnowledgeScoreRate scoreRate : studentScoreRates) { for (LaborEducationServiceImpl.KnowledgeScoreRate scoreRate : studentScoreRates) {
AppraiseTreeNode node = findKnowledgeNode(appraise.getNodes(), scoreRate.getKnowledge()); AppraiseTreeNode node = findKnowledgeNode(appraise.getNodes(), scoreRate.getKnowledge());
if (node != null) { if (node != null) {
AppraiseTreeNode parentNode = findParentNode(appraise.getNodes(), node.getId()); AppraiseTreeNode parentNode = findParentNode(appraise.getNodes(), node.getId());
@ -646,7 +648,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
if (examResults != null && !examResults.isEmpty()) { if (examResults != null && !examResults.isEmpty()) {
// 遍历班级中的每个学生 // 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) { for (ExamClassResult examResult : examResults) {
if (!examResult.getInfo().getId().equals(classId)) continue; // 过滤出该班级的考试 if (!examResult.getInfo().getId().equals(classId)) continue;
List<Integer> statuses = examResult.getStatus(); List<Integer> statuses = examResult.getStatus();
for (int i = 0; i < examResult.getStudentIds().size(); i++) { for (int i = 0; i < examResult.getStudentIds().size(); i++) {
String studentId = examResult.getStudentIds().get(i); String studentId = examResult.getStudentIds().get(i);
@ -656,15 +658,12 @@ public class LaborEducationServiceImpl implements LaborEducationService {
.map(RMember::getName) .map(RMember::getName)
.orElse("未知"); .orElse("未知");
int status = statuses.get(i); int status = statuses.get(i);
if (status == 1) continue; // 跳过 status 为 1 的记录 if (status == 1) continue;
// 计算父节点得分率(客观分数 // 正确获取已转换的客观分数(无需二次截断
Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent( Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points studentId, examResults, knowledgeMap, appraise, points
); );
scoreRates.replaceAll((k, v) ->
Math.min(100.0, Math.max(60.0, v)) // 60分打底最高100分
);
studentScoreRates.put(name, scoreRates); studentScoreRates.put(name, scoreRates);
// 累加班级整体得分率 // 累加班级整体得分率
@ -673,7 +672,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
} }
} }
} else { }else {
// 无考试数据时初始化所有学生的默认分数为60 // 无考试数据时初始化所有学生的默认分数为60
if (groupList != null) { if (groupList != null) {
for (RMember member : groupList.members) { for (RMember member : groupList.members) {
@ -821,7 +820,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
private static List<KnowledgeScoreRate> calculateStudentScoreRates( private static List<LaborEducationServiceImpl.KnowledgeScoreRate> calculateStudentScoreRates(
String studentId, String studentId,
List<ExamClassResult> examResults, List<ExamClassResult> examResults,
Map<String, List<List<String>>> knowledgeMap, Map<String, List<List<String>>> knowledgeMap,
@ -840,7 +839,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
knowledgeTotalScore.put(knowledge, 60.0); // 默认60分 knowledgeTotalScore.put(knowledge, 60.0); // 默认60分
} }
return knowledgeTotalScore.entrySet().stream() return knowledgeTotalScore.entrySet().stream()
.map(entry -> new KnowledgeScoreRate(entry.getKey(), entry.getValue())) .map(entry -> new LaborEducationServiceImpl.KnowledgeScoreRate(entry.getKey(), entry.getValue()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -921,7 +920,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
return knowledgeTotalScore.entrySet().stream() return knowledgeTotalScore.entrySet().stream()
.map(entry -> new KnowledgeScoreRate(entry.getKey(), entry.getValue())) .map(entry -> new LaborEducationServiceImpl.KnowledgeScoreRate(entry.getKey(), entry.getValue()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

@ -293,9 +293,6 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 获取对应知识块的客观成绩并转换为基于60分加分的分数 // 获取对应知识块的客观成绩并转换为基于60分加分的分数
double objectiveScore = knowledgeBlockScores.get(knowledgeBlock); double objectiveScore = knowledgeBlockScores.get(knowledgeBlock);
// 转换为正确率的小数形式(假设原始分是百分比)
double correctRate = objectiveScore / 100.0;
objectiveScore = 60.0 + correctRate * 40.0;
// 确保不超过100分 // 确保不超过100分
objectiveScore = Math.min(100.0, objectiveScore); objectiveScore = Math.min(100.0, objectiveScore);
// 保留两位小数 // 保留两位小数
@ -339,21 +336,22 @@ public class MoralEducationServiceImpl implements MoralEducationService {
return scores; return scores;
} }
private static @NotNull Map<String, Map<String, Double>> getStringMapMap(Map<String, List<String>> knowledgeBlockToPointsMap, Map<String, Map<String, Double>> studentKnowledgePointScores) { private static Map<String, Map<String, Double>> getStringMapMap(
Map<String, List<String>> knowledgeBlockToPointsMap,
Map<String, Map<String, Double>> studentKnowledgePointScores) {
Map<String, Map<String, Double>> studentKnowledgeBlockScores = new HashMap<>(); Map<String, Map<String, Double>> studentKnowledgeBlockScores = new HashMap<>();
for (Map.Entry<String, Map<String, Double>> entry : studentKnowledgePointScores.entrySet()) { for (Map.Entry<String, Map<String, Double>> entry : studentKnowledgePointScores.entrySet()) {
String studentId = entry.getKey(); String studentId = entry.getKey();
Map<String, Double> pointScores = entry.getValue(); Map<String, Double> pointScores = entry.getValue();
Map<String, Double> blockScores = studentKnowledgeBlockScores.computeIfAbsent(studentId, k -> new HashMap<>()); Map<String, Double> blockScores = studentKnowledgeBlockScores.computeIfAbsent(studentId, k -> new HashMap<>());
// 遍历知识块和知识点的映射关系
for (Map.Entry<String, List<String>> blockEntry : knowledgeBlockToPointsMap.entrySet()) { for (Map.Entry<String, List<String>> blockEntry : knowledgeBlockToPointsMap.entrySet()) {
String knowledgeBlock = blockEntry.getKey(); String knowledgeBlock = blockEntry.getKey();
List<String> knowledgePoints = blockEntry.getValue(); List<String> knowledgePoints = blockEntry.getValue();
// 计算该知识块的总得分和知识点数量
double totalScore = 0.0; double totalScore = 0.0;
int validPointCount = 0; // 有效知识点数量(有实际得分的知识点) int validPointCount = 0;
for (String knowledgePoint : knowledgePoints) { for (String knowledgePoint : knowledgePoints) {
if (pointScores.containsKey(knowledgePoint)) { if (pointScores.containsKey(knowledgePoint)) {
totalScore += pointScores.get(knowledgePoint); totalScore += pointScores.get(knowledgePoint);
@ -361,10 +359,14 @@ public class MoralEducationServiceImpl implements MoralEducationService {
} }
} }
// 计算知识块的平均分 // 关键修改:统一分数转换逻辑
double averageScore = (validPointCount > 0) ? totalScore / validPointCount : 60.0; // 无有效知识点时默认60分 double averageScore = (validPointCount > 0) ? totalScore / validPointCount : 0.0; // 原始正确率
averageScore = Math.max(60.0, Math.min(100.0, averageScore)); // 确保得分在60-100之间 double correctRate = averageScore / 100.0;
blockScores.put(knowledgeBlock, averageScore); double convertedScore = 60.0 + (correctRate * 40.0);
convertedScore = Math.min(100.0, convertedScore);
convertedScore = Double.parseDouble(String.format("%.2f", convertedScore));
blockScores.put(knowledgeBlock, convertedScore);
} }
} }
return studentKnowledgeBlockScores; return studentKnowledgeBlockScores;
@ -646,7 +648,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
if (examResults != null && !examResults.isEmpty()) { if (examResults != null && !examResults.isEmpty()) {
// 遍历班级中的每个学生 // 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) { for (ExamClassResult examResult : examResults) {
if (!examResult.getInfo().getId().equals(classId)) continue; // 过滤出该班级的考试 if (!examResult.getInfo().getId().equals(classId)) continue;
List<Integer> statuses = examResult.getStatus(); List<Integer> statuses = examResult.getStatus();
for (int i = 0; i < examResult.getStudentIds().size(); i++) { for (int i = 0; i < examResult.getStudentIds().size(); i++) {
String studentId = examResult.getStudentIds().get(i); String studentId = examResult.getStudentIds().get(i);
@ -656,15 +658,12 @@ public class MoralEducationServiceImpl implements MoralEducationService {
.map(RMember::getName) .map(RMember::getName)
.orElse("未知"); .orElse("未知");
int status = statuses.get(i); int status = statuses.get(i);
if (status == 1) continue; // 跳过 status 为 1 的记录 if (status == 1) continue;
// 计算父节点得分率(客观分数 // 正确获取已转换的客观分数(无需二次截断
Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent( Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points studentId, examResults, knowledgeMap, appraise, points
); );
scoreRates.replaceAll((k, v) ->
Math.min(100.0, Math.max(60.0, v)) // 60分打底最高100分
);
studentScoreRates.put(name, scoreRates); studentScoreRates.put(name, scoreRates);
// 累加班级整体得分率 // 累加班级整体得分率
@ -673,7 +672,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
} }
} }
} }
} else { }else {
// 无考试数据时初始化所有学生的默认分数为60 // 无考试数据时初始化所有学生的默认分数为60
if (groupList != null) { if (groupList != null) {
for (RMember member : groupList.members) { for (RMember member : groupList.members) {

Loading…
Cancel
Save