【修改】mysql根据出题界面,考点加引号

This commit is contained in:
huababa1
2025-07-15 04:28:33 +08:00
parent a69cfac1bd
commit 3f4c7b6fa5
4 changed files with 147 additions and 76 deletions

View File

@@ -0,0 +1,24 @@
package com.example.exam.exam.dal;
import lombok.Data;
/**
* @author REN
*/
@Data
public class SourceAndTextAndTotal {
/**
* 分数
*/
private double score;
/**
* 文本
*/
private String text;
/**
* 考点正确数量
*/
private int total;
}

View File

@@ -3,6 +3,7 @@ package com.example.exam.exam.service.brower;
import com.example.exam.exam.dal.ExamQuestion;
import com.example.exam.exam.dal.ExamQuestionAnswer;
import com.example.exam.exam.dal.SourceAndText;
import com.example.exam.exam.dal.SourceAndTextAndTotal;
import com.example.exam.exam.mapper.ExamQuestionAnswerMapper;
import com.example.exam.exam.utils.HtmlAppender;
import com.example.exam.exam.utils.brower.BookmarkChecker;
@@ -53,7 +54,8 @@ public class JudgementBrowerServiceImpl implements JudgementBrowerService {
// }
// }
// }
int correctCount = 0; // 完全正确的题目数量
int totalQuestions = answerList.size(); // 总题目数量// 总题目数量
//分为两点1文件夹-- 去考生文件夹去找 文件名
@@ -77,8 +79,9 @@ public class JudgementBrowerServiceImpl implements JudgementBrowerService {
.mapToInt(a -> Integer.parseInt(a.getScoreRate()))
.sum();
//这里指挥判断存在文件夹的得分点
SourceAndText studentScorePojo = compareStuAndTestFiles(answerList, stuFiles,score,totalScore,judgementStr);
SourceAndTextAndTotal studentScorePojo = compareStuAndTestFiles(answerList, stuFiles,score,totalScore,judgementStr);
double studentScore = studentScorePojo.getScore();
correctCount= studentScorePojo.getTotal();
judgementStr = studentScorePojo.getText();
//判断收藏夹得分点
for (ExamQuestionAnswer examQuestionAnswer : answerList) {
@@ -91,7 +94,7 @@ public class JudgementBrowerServiceImpl implements JudgementBrowerService {
if (isCorrect) {
//如果有 +权值
studentScore += currentScore;
correctCount++;
// 计算该考点的权重得分并保留一位小数
double weightScore = ((double) currentScore / totalScore) * score;
@@ -114,18 +117,22 @@ public class JudgementBrowerServiceImpl implements JudgementBrowerService {
// 计算最终得分比例(保留两位小数)
double scoreRatio = totalScore == 0 ? 0 : (double) studentScore / totalScore;
double roundedScoreRatio = Math.round(scoreRatio * 100.0) / 100.0; // 四舍五入到2位小数
appendToFile(answerLogPath," 得分:"+roundedScoreRatio*score);
sourceAndText.setScore(roundedScoreRatio*score);
double roundedScoreRatio = Math.round(scoreRatio*score * 100.0) / 100.0; // 四舍五入到2位小数
if (correctCount == totalQuestions) {
roundedScoreRatio = score; // 全对,直接给满分
}
appendToFile(answerLogPath," 得分:"+roundedScoreRatio);
sourceAndText.setScore(roundedScoreRatio);
sourceAndText.setText(judgementStr);
return sourceAndText;
}
// 对比学生提交内容与试题得分点
static SourceAndText compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles,double score,int total, String judgementStr) {
static SourceAndTextAndTotal compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles,double score,int total, String judgementStr) {
int totalScore = 0; // 记录总得分
SourceAndText sourceAndText = new SourceAndText();
int correctCount = 0; // 完全正确的题目数量
SourceAndTextAndTotal sourceAndText = new SourceAndTextAndTotal();
for (ExamQuestionAnswer answer : answerList) {
if ("添加到文件夹".equals(answer.getContentIn())) {
String filePath = answer.getContent(); // 试题文件路径
@@ -136,6 +143,7 @@ public class JudgementBrowerServiceImpl implements JudgementBrowerService {
// 如果正确,则累加总分
if (isCorrect) {
totalScore += currentScore;
correctCount++;
// 计算该考点的权重得分并保留一位小数
double weightScore = ((double) currentScore / total) * score;
String formattedWeightScore = String.format("%.1f", weightScore);
@@ -150,6 +158,7 @@ public class JudgementBrowerServiceImpl implements JudgementBrowerService {
//返回累加的得分点
sourceAndText.setScore(totalScore);
sourceAndText.setText(judgementStr);
sourceAndText.setTotal(correctCount);
return sourceAndText;
}
/**

View File

@@ -67,6 +67,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
// 5.2、查询试题ID
List<ExamQuestionAnswer> examQuestionAnswers = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(examQuestion.getQuId());
int correctCount = 0; // 完全正确的题目数量
int totalQuestions = examQuestionAnswers.size(); // 总题目数量// 总题目数量
String totalKeyScore ="0";
//得出 这个题总共的权值点
totalKeyScore=examQuestionAnswerMapper.selectCountPointByQuId(examQuestion.getQuId());
@@ -243,6 +245,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
if (table1Columns.equals(table2Columns)) {
correctCount++; // 完全正确
appendToFile(answerLogPath, "【执行】"+""+showCreateTableSql+"】【验证】【表】【"+tableName+"】【√】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】"+""+showCreateTableSql+"】【验证】【表】【"+tableName+"】【✅】");
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSQL,totalKeyScore,score,answerId,scoreTotal,judgementStr);
@@ -259,83 +262,93 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
}
if (sql.trim().toUpperCase().startsWith("INSERT")) {
appendToFile(answerLogPath, "==================插入语句==================");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==================插入语句==================");
// 正则表达式匹配表名
Pattern pattern = Pattern.compile("INSERT INTO\\s+`?(\\w+)`?\\s*\\(");
Matcher matcher = pattern.matcher(sql);
// 匹配成功
if (sql.trim().toUpperCase().startsWith("INSERT")) {
appendToFile(answerLogPath, "==================插入语句==================");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==================插入语句==================");
// 正则表达式匹配表名
Pattern pattern = Pattern.compile(
"INSERT\\s+INTO\\s+`?(\\w+)`?",
Pattern.CASE_INSENSITIVE
);
Matcher matcher = pattern.matcher(sql);
// appendToFile(answerLogPath, "答案语句: " + sql);
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
if (matcher.find()) {
String tableName = matcher.group(1).replace("`", ""); // 获取表名
// 匹配成功
if (matcher.find()) {
String tableName = matcher.group(1);
String answerId= examQuestionAnswer.getAnswerId();
List<ExamMysqlKeyword> examMysqlKeywordList = examMysqlKeywordMapper.selectListByAnswerId(answerId);
// 传入 INSERT SQL 和主键字段
String yanzheng = convertInsertToSelect(sql);
String stuSql=null;
List<List<String>> answerList= new ArrayList<>();
List<List<String>> answerListStu = new ArrayList<>();
try (Connection connanswer = DriverManager.getConnection(newDbUrl, user, password);
Statement stmtan = connanswer.createStatement()) {
try (ResultSet answer = stmtan.executeQuery(yanzheng)) {
answerList = getAnswerList(answer);
String yanzheng = null;
try {
yanzheng = convertInsertToSelect(sql);
String stuSql=null;
List<List<String>> answerList= new ArrayList<>();
List<List<String>> answerListStu = new ArrayList<>();
try (Connection connanswer = DriverManager.getConnection(newDbUrl, user, password);
Statement stmtan = connanswer.createStatement()) {
try (ResultSet answer = stmtan.executeQuery(yanzheng)) {
answerList = getAnswerList(answer);
// appendToFile(answerLogPath, "查找语句标准答案");
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "查找语句标准答案");
// printResult(answerList,judgementStr);
}catch (SQLException e) {
}catch (SQLException e) {
// appendToFile(answerLogPath, "答案表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
e.printStackTrace();
e.printStackTrace();
}
}
}
try (Connection connstu = DriverManager.getConnection(stuDbUrl, user, password);
Statement stmtstu = connstu.createStatement()) {
try (ResultSet answer = stmtstu.executeQuery(yanzheng)) {
answerListStu = getAnswerList(answer);
//这里根据answerListStu 还原学生的sql语句
List<String> columnNames = getColumnNames(answer); // ← 获取字段名
try (Connection connstu = DriverManager.getConnection(stuDbUrl, user, password);
Statement stmtstu = connstu.createStatement()) {
try (ResultSet answer = stmtstu.executeQuery(yanzheng)) {
answerListStu = getAnswerList(answer);
//这里根据answerListStu 还原学生的sql语句
List<String> columnNames = getColumnNames(answer); // ← 获取字段名
String tName = extractTableNameFromInsert(sql);
String tName = extractTableNameFromInsert(sql);
//构建还原 SQL你可以自定义表名比如传 "student_table"
stuSql = generateInsertSQL(tName, columnNames, answerListStu);
//构建还原 SQL你可以自定义表名比如传 "student_table"
stuSql = generateInsertSQL(tName, columnNames, answerListStu);
// appendToFile(answerLogPath, "学生对"+tName+"插入的SQL:\n" + stuSql);
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生对"+tName+"+插入的SQL:" );
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, stuSql);
// appendToFile(answerLogPath, "学生语句答案");
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生语句答案");
// printResult(answerListStu,judgementStr);
} catch (SQLException e) {
} catch (SQLException e) {
// appendToFile(answerLogPath, "学生表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
}
}
}
boolean isEquivalent =false;
boolean isEquivalent =false;
if (answerListStu!=null&&answerListStu.size()>0){
isEquivalent = compareResultsSelect(answerList, answerListStu);
}
if (isEquivalent) {
correctCount++; // 完全正确
appendToFile(answerLogPath, "【执行】"+""+yanzheng+"】【验证】【表】【"+tableName+"】【√】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+""+yanzheng+"】【验证】【表】【"+tableName+"】【✅】");
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSql,totalKeyScore,score,answerId,scoreTotal,judgementStr);
scoreTotal += studentScorePojo.getScore();
judgementStr = studentScorePojo.getText();
} else {
appendToFile(answerLogPath, "【执行】"+""+yanzheng+"】【验证】【表】【"+tableName+"】【×】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+""+yanzheng+"】【验证】【表】【"+tableName+"】【❌】");
SourceAndText studentScorePojo= calculateTotalScoreRate(stuSql, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
scoreTotal += studentScorePojo.getScore();
judgementStr = studentScorePojo.getText();
}
} catch (Exception e) {
if (answerListStu!=null&&answerListStu.size()>0){
isEquivalent = compareResultsSelect(answerList, answerListStu);
}
if (isEquivalent) {
appendToFile(answerLogPath, "【执行】"+""+yanzheng+"】【验证】【表】【"+tableName+"】【√】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+""+yanzheng+"】【验证】【表】【"+tableName+"】【✅】");
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSql,totalKeyScore,score,answerId,scoreTotal,judgementStr);
scoreTotal += studentScorePojo.getScore();
judgementStr = studentScorePojo.getText();
} else {
appendToFile(answerLogPath, "【执行】"+""+yanzheng+"】【验证】【表】【"+tableName+"】【×】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+""+yanzheng+"】【验证】【表】【"+tableName+"】【❌】");
SourceAndText studentScorePojo= calculateTotalScoreRate(stuSql, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
scoreTotal += studentScorePojo.getScore();
judgementStr = studentScorePojo.getText();
}
}
}
@@ -347,7 +360,11 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
sql = sql.trim().replaceAll(";+\\s*$", "");
// 正则提取表名和 WHERE 条件
Pattern pattern = Pattern.compile("DELETE\\s+FROM\\s+(\\w+)\\s+WHERE\\s+(.+)", Pattern.CASE_INSENSITIVE);
Pattern pattern = Pattern.compile(
"DELETE\\s+FROM\\s+`?(\\w+)`?\\s+WHERE\\s+([^;]+);?",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL
);
Matcher matcher = pattern.matcher(sql);
// 匹配成功
String answerId = examQuestionAnswer.getAnswerId();
@@ -375,6 +392,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
if (rsstu.next()) {
int countstu = rsstu.getInt(1);
if (countstu == 0) {
correctCount++; // 完全正确
//累加删除语句的所有权值 examQuestionKeywords累加scorerate
// appendToFile(answerLogPath, "验证通过:符合 DELETE 条件的记录已删除。");
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "验证通过:符合 DELETE 条件的记录已删除。");
@@ -430,9 +448,10 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
String selectSql = convertUpdateToSelectWhere(sql);
// 提取表名和 WHERE 子句
Pattern pattern = Pattern.compile(
"UPDATE\\s+`?(\\w+)`?\\s+SET\\s+.+?\\s+WHERE\\s+(.+);?",
"UPDATE\\s+`?(\\w+)`?\\s+SET\\s+(.+?)\\s+WHERE\\s+(.+?);?$",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL
);
Matcher matcher = pattern.matcher(sql);
if (matcher.find()) {
@@ -486,6 +505,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
}
//
if (isEquivalent) {
correctCount++; // 完全正确
appendToFile(answerLogPath, "【执行】 "+""+selectSql+"】【验证】【表】【"+tableName+"】【√】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+""+selectSql+"】【验证】【表】【"+tableName+"】【✅】");
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSql,totalKeyScore,score,answerId,scoreTotal,judgementStr);
@@ -591,6 +611,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
}
if (isEquivalent) {
correctCount++; // 完全正确
appendToFile(answerLogPath, "执行"+sql+"验证文件【"+fileName.get()+"】【√】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"执行"+sql+"验证文件【"+fileName.get()+"】【✅】");
//todo 得分
@@ -684,6 +705,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
if (isEquivalent) {
correctCount++; // 完全正确
appendToFile(answerLogPath, "【执行】"+""+showCreateViewSql+"】【验证】【视图】【"+viewNam1+"】 【√】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】"+""+showCreateViewSql+"】【验证】【视图】【"+viewNam1+"】【✅】");
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSQL,totalKeyScore,score,answerId,scoreTotal,judgementStr);
@@ -798,7 +820,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
boolean flag= !hasError &&mysqlBooleanVo.isFlag();
if (flag) {
//todo 得分
correctCount++; // 完全正确
appendToFile(answerLogPath, "【执行】"+extractCallStatements+"【验证】【文件】【"+fileName.get()+"】【√】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【执行】"+extractCallStatements+"【验证】【文件】 【"+fileName.get()+"】【✅】");
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuAnswer.get(),totalKeyScore,score,answerId,scoreTotal,judgementStr);
@@ -937,6 +959,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
boolean equals = normalizedTriggerSql1.equals(normalizedTriggerSql2);
if (equals) {
correctCount++; // 完全正确
appendToFile(answerLogPath, "【文件】 【"+fileName.get()+"】【√】");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【文件】 【"+fileName.get()+"】【✅】");
//todo 得分
@@ -1025,7 +1048,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
}
//
if (isEquivalent) {
correctCount++; // 完全正确
appendToFile(answerLogPath, "【执行】 "+""+selectSql+"】 【验证】 【表】 【"+tableName+"】【√】");
@@ -1084,6 +1107,10 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "共得分:" + String.format("%.2f", scoreTotal));
folderzip.delete();
deleteFolder(folder);
// 全部题目处理完成后
if (correctCount == totalQuestions) {
scoreTotal = score; // 全对,直接给满分
}
//todo 删除学生答题的数据库连接 单独写一个接口
// deleteRegistryKey();
sourceAndText.setScore(scoreTotal);
@@ -1361,21 +1388,23 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
// 清理语句
updateSQL = updateSQL.trim().replaceAll(";\\s*$", "");
// 正则提取表名和 WHERE 条件
// 正则提取表名和 WHERE 条件(支持反引号)
Pattern pattern = Pattern.compile(
"UPDATE\\s+(\\w+)\\s+SET\\s+.+?\\s+WHERE\\s+(.+)",
"UPDATE\\s+`?(\\w+)`?\\s+SET\\s+.+?\\s+WHERE\\s+(.+)",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL
);
Matcher matcher = pattern.matcher(updateSQL);
if (matcher.find()) {
String tableName = matcher.group(1).trim();
String whereClause = matcher.group(2).trim();
return "SELECT * FROM " + tableName + " WHERE " + whereClause + ";";
return "SELECT * FROM `" + tableName + "` WHERE " + whereClause + ";";
} else {
return "-- 无法识别的 UPDATE 语句";
}
}
public static String extractTableNameFromInsert(String sql) {
Pattern pattern = Pattern.compile("INSERT\\s+INTO\\s+(\\w+)\\s*\\(", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(sql);
@@ -1747,7 +1776,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
System.out.println("========================================================= " );
Pattern p = Pattern.compile("UPDATE\\s+(\\w+)\\s+SET\\s+(.+?)\\s+WHERE\\s+(.+);?", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Pattern p = Pattern.compile("UPDATE\\s+`?(\\w+)`?\\s+SET\\s+(.+?)\\s+WHERE\\s+(.+);?", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(originalUpdateSql);
if (!m.find()) {
throw new IllegalArgumentException("无法解析原始 UPDATE 语句");
@@ -1794,6 +1823,9 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
return callStatements;
}
public static String convertInsertToSelect(String insertSql) {
Pattern pattern = Pattern.compile(
"INSERT INTO\\s+`?(\\w+)`?\\s*\\((.*?)\\)\\s*VALUES\\s*\\((.*?)\\)",
@@ -1842,8 +1874,6 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
/**
* 比较两个查询的结果
*/

View File

@@ -3,6 +3,7 @@ package com.example.exam.exam.service.winfile;
import com.example.exam.exam.dal.ExamQuestion;
import com.example.exam.exam.dal.ExamQuestionAnswer;
import com.example.exam.exam.dal.SourceAndText;
import com.example.exam.exam.dal.SourceAndTextAndTotal;
import com.example.exam.exam.mapper.ExamQuestionAnswerMapper;
import com.example.exam.exam.utils.HtmlAppender;
import com.example.exam.exam.utils.file.GetDifferencesBetweenFolders;
@@ -40,8 +41,8 @@ public class FileServericeImpl implements IFileServerice {
// answerList.add(new ExamQuestionAnswer("","","","","EDZK\\RONGHE.COM", "考察名称", "1", "4"));
// answerList.add(new ExamQuestionAnswer("","","","","HGACYL\\PLAY.MEM", "考察名称", "1", "5"));
// answerList.add(new ExamQuestionAnswer("","","","","WUE\\PB6.txt", "考察名称", "1", "6"));
int correctCount = 0; // 完全正确的题目数量
int totalQuestions = answerList.size(); // 总题目数量// 总题目数量
File stuPath = file;
// 设置日志文件路径为file所在目录下的answerLogFile.txt
@@ -62,26 +63,31 @@ public class FileServericeImpl implements IFileServerice {
appendToFile(answerLogPath,"=== 学生提交内容得分点 ===");
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "=== 学生提交内容得分点 ===");
// 对比学生提交内容与试题得分点
SourceAndText studentScorePojo = compareStuAndTestFiles(answerList, stuFiles,score,totalScore,judgementStr);
SourceAndTextAndTotal studentScorePojo = compareStuAndTestFiles(answerList, stuFiles,score,totalScore,judgementStr);
double studentScore = studentScorePojo.getScore();
judgementStr = studentScorePojo.getText();
//获取answerList里的所有sorcerate,和integer相除得到一个小于等于1的数
// 计算最终得分比例(保留两位小数)
double scoreRatio = totalScore == 0 ? 0 : (double) studentScore / totalScore;
double roundedScoreRatio = Math.round(scoreRatio * 100.0) / 100.0; // 四舍五入到2位小数
appendToFile(answerLogPath,"得分:"+roundedScoreRatio*score);
double roundedScoreRatio = Math.round(scoreRatio * 100.0*score) / 100.0; // 四舍五入到2位小数
if (correctCount == totalQuestions) {
roundedScoreRatio = score; // 全对,直接给满分
}
appendToFile(answerLogPath,"得分:"+roundedScoreRatio);
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "得分:"+roundedScoreRatio*score);
sourceAndText.setScore(roundedScoreRatio*score);
sourceAndText.setScore(roundedScoreRatio);
sourceAndText.setText(judgementStr);
return sourceAndText;
}
// 对比学生提交内容与试题得分点
static SourceAndText compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles,double score,int total, String judgementStr) {
SourceAndText sourceAndText = new SourceAndText();
int totalScore = 0; // 记录总得分
static SourceAndTextAndTotal compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles, double score, int total, String judgementStr) {
SourceAndTextAndTotal sourceAndText = new SourceAndTextAndTotal();
int correctCount = 0; // 完全正确的题目数量
int totalQuestions = answerList.size(); // 总题目数量// 总题目数量
double totalScore = 0; // 记录总得分
for (ExamQuestionAnswer answer : answerList) {
String filePath = answer.getContent(); // 试题文件路径
String checkType = answer.getContentIn(); // 考察类型(考察删除 / 考察名称 / 考察属性)
@@ -105,6 +111,7 @@ public class FileServericeImpl implements IFileServerice {
// 如果正确,则累加总分
if (isCorrect) {
totalScore += currentScore;
correctCount++; // 完全正确
// 计算该考点的权重得分并保留一位小数
double weightScore = ((double) currentScore / total) * score;
String formattedWeightScore = String.format("%.1f", weightScore);
@@ -117,6 +124,7 @@ public class FileServericeImpl implements IFileServerice {
}
sourceAndText.setText(judgementStr);
sourceAndText.setScore(totalScore);
sourceAndText.setTotal(correctCount);
//返回累加的总分
return sourceAndText;
}