【修改】操作题log文件格式

This commit is contained in:
YOHO\20373
2025-05-20 22:40:30 +08:00
parent 06dc46e10b
commit ca04a6f1bd
3 changed files with 94 additions and 68 deletions

View File

@@ -66,13 +66,16 @@ public class BrowserServericeImpl implements IBrowserServerice {
// 输出学生提交的内容
appendToFile(answerLogPath,"=== 学生提交内容stu 目录) ===");
stuFiles.forEach((key, value) -> appendToFile(answerLogPath,key + " -> " + value));
// appendToFile(answerLogPath,"=== 学生提交内容stu 目录) ===");
//
// stuFiles.forEach((key, value) -> appendToFile(answerLogPath,key + " -> " + value));
appendToFile(answerLogPath,"=== 学生提交内容得分点 ===");
// 对比学生提交内容与试题得分点
// 计算试题总分
int totalScore = answerList.stream()
.mapToInt(a -> Integer.parseInt(a.getScoreRate()))
.sum();
//这里指挥判断存在文件夹的得分点
Integer studentScore = compareStuAndTestFiles(answerList, stuFiles);
Integer studentScore = compareStuAndTestFiles(answerList, stuFiles,score,totalScore);
//判断收藏夹得分点
for (ExamQuestionAnswer examQuestionAnswer : answerList) {
@@ -85,31 +88,34 @@ public class BrowserServericeImpl implements IBrowserServerice {
if (isCorrect) {
//如果有 +权值
studentScore += currentScore;
appendToFile(answerLogPath,"考点"+bookmarkNameToDelete + " -> 得分权值:" + currentScore+"-> 是否得分:"+isCorrect+"");
// 计算该考点的权重得分并保留一位小数
double weightScore = ((double) currentScore / totalScore) * score;
String formattedWeightScore = String.format("%.1f", weightScore);
appendToFile(answerLogPath,"✅考点"+bookmarkNameToDelete + " -> 得分权值:" + currentScore+"-> 得分:"+formattedWeightScore);
//删除此书签
BookmarkDeleter.deleteBookmarkByName(chromeBookmarkPath, bookmarkNameToDelete);
}
else {
appendToFile(answerLogPath,"考点"+bookmarkNameToDelete + " -> 得分权值:" + currentScore+"-> 是否得分:"+isCorrect+"");
appendToFile(answerLogPath,"考点"+bookmarkNameToDelete + " -> 得分权值:" + currentScore+"-> 得分:0");
}
}
}
// 计算试题总分
int totalScore = answerList.stream()
.mapToInt(a -> Integer.parseInt(a.getScoreRate()))
.sum();
// 计算最终得分比例(保留两位小数)
double scoreRatio = totalScore == 0 ? 0 : (double) studentScore / totalScore;
double roundedScoreRatio = Math.round(scoreRatio * 100.0) / 100.0; // 四舍五入到2位小数
appendToFile(answerLogPath," 得分:"+roundedScoreRatio*score);
return roundedScoreRatio*score;
}
// 对比学生提交内容与试题得分点
static Integer compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles) {
static Integer compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles,double score,int total) {
int totalScore = 0; // 记录总得分
for (ExamQuestionAnswer answer : answerList) {
if ("添加到文件夹".equals(answer.getContentIn())) {
@@ -121,11 +127,13 @@ public class BrowserServericeImpl implements IBrowserServerice {
// 如果正确,则累加总分
if (isCorrect) {
totalScore += currentScore;
appendToFile(answerLogPath,"考点"+answer.getContent() + " -> 得分权值:" + answer.getScoreRate()+"-> 是否得分:"+isCorrect+"");
// 计算该考点的权重得分并保留一位小数
double weightScore = ((double) currentScore / total) * score;
String formattedWeightScore = String.format("%.1f", weightScore);
appendToFile(answerLogPath,"✅考点"+answer.getContent() + " -> 得分权值:" + answer.getScoreRate()+"-> 得分:"+weightScore);
}else {
appendToFile(answerLogPath,"考点"+answer.getContent() + " -> 得分权值:" + answer.getScoreRate()+"-> 是否得分:"+isCorrect+"");
appendToFile(answerLogPath,"考点"+answer.getContent() + " -> 得分权值:" + answer.getScoreRate()+"-> 得分:0");
}
}

View File

@@ -47,30 +47,30 @@ public class FileServericeImpl implements IFileServerice {
Map<String, String> stuFiles = GetDifferencesBetweenFolders.listFilesAndFoldersWithAttributes(stuPath.toPath());
// 输出学生提交的内容
appendToFile(answerLogPath,"=== 学生提交内容stu 目录) ===");
// appendToFile(answerLogPath,"=== 学生提交内容stu 目录) ===");
//
// stuFiles.forEach((key, value) -> appendToFile(answerLogPath,key + " -> " + value));
stuFiles.forEach((key, value) -> appendToFile(answerLogPath,key + " -> " + value));
appendToFile(answerLogPath,"=== 学生提交内容得分点 ===");
// 对比学生提交内容与试题得分点
Integer studentScore = compareStuAndTestFiles(answerList, stuFiles);
//获取answerList里的所有sorcerate,和integer相除得到一个小于等于1的数
// 计算试题总分
// 计算试题总分
int totalScore = answerList.stream()
.mapToInt(a -> Integer.parseInt(a.getScoreRate()))
.sum();
appendToFile(answerLogPath,"=== 学生提交内容得分点 ===");
// 对比学生提交内容与试题得分点
Integer studentScore = compareStuAndTestFiles(answerList, stuFiles,score,totalScore);
//获取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);
return roundedScoreRatio*score;
}
// 对比学生提交内容与试题得分点
static Integer compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles) {
static Integer compareStuAndTestFiles(List<ExamQuestionAnswer> answerList, Map<String, String> stuFiles,double score,int total) {
int totalScore = 0; // 记录总得分
for (ExamQuestionAnswer answer : answerList) {
String filePath = answer.getContent(); // 试题文件路径
@@ -95,9 +95,12 @@ public class FileServericeImpl implements IFileServerice {
// 如果正确,则累加总分
if (isCorrect) {
totalScore += currentScore;
appendToFile(answerLogPath,answer.getContent() + " -> " + answer.getContentIn() + " -> 得分权值:" + answer.getScoreRate()+"-> 是否得分:"+isCorrect+"");
// 计算该考点的权重得分并保留一位小数
double weightScore = ((double) currentScore / total) * score;
String formattedWeightScore = String.format("%.1f", weightScore);
appendToFile(answerLogPath,""+answer.getContent() + " -> " + answer.getContentIn() + " -> 得分权值:" + answer.getScoreRate()+"-> 得分:"+formattedWeightScore);
}else {
appendToFile(answerLogPath,answer.getContent() + " -> " + answer.getContentIn() + " -> 得分权值:" + answer.getScoreRate()+"-> 是否得分:"+isCorrect+"");
appendToFile(answerLogPath,""+answer.getContent() + " -> " + answer.getContentIn() + " -> 得分权值:" + answer.getScoreRate()+"-> 得分:0");
}
}

View File

@@ -56,7 +56,6 @@ public class MysqlServericeImpl implements IMysqlServerice {
//得到总计得分点
totalKeyScore=examMysqlKeywordMapper.selectByAnswerIds(answerIdList);
}
answerLogPath = filepath.getParent() + File.separator + "log.txt";
@@ -241,9 +240,9 @@ public class MysqlServericeImpl implements IMysqlServerice {
if (normalizedSql1.equals(normalizedSql2)) {
//
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2);
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score);
} else {
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList);
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score);
total.addAndGet(scoreAnswerNotAllTrue);
}
@@ -287,10 +286,10 @@ public class MysqlServericeImpl implements IMysqlServerice {
boolean equals = sql1.equals(sql2);
if (equals) {
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2);
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score);
} else {
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList);
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score);
total.addAndGet(scoreAnswerNotAllTrue);
}
@@ -345,11 +344,11 @@ public class MysqlServericeImpl implements IMysqlServerice {
//累加删除语句的所有权值 examQuestionKeywords累加scorerate
appendToFile(answerLogPath, "验证通过:符合 DELETE 条件的记录已删除。");
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2);
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score);
} else {
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList);
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score);
total.addAndGet(scoreAnswerNotAllTrue);
}
@@ -398,9 +397,9 @@ public class MysqlServericeImpl implements IMysqlServerice {
//
if (b) {
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2);
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score);
} else {
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList);
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score);
total.addAndGet(scoreAnswerNotAllTrue);
// appendToFile(answerLogPath,"语句"+sql2+"不正确,关键得分:"+scoreAnswerNotAllTrue+ "❌");
@@ -409,6 +408,7 @@ public class MysqlServericeImpl implements IMysqlServerice {
}
if (entry.getValue().trim().toUpperCase().startsWith("SELECT")) {
appendToFile(answerLogPath, "==================查找语句==================");
List<ExamMysqlKeyword> examMysqlKeywordList =new ArrayList<>();
for (ExamQuestionAnswer examQuestionAnswer : examQuestionAnswers) {
if (normalize(examQuestionAnswer.getContent()).equals(normalize(entry.getValue()))) {
@@ -452,11 +452,11 @@ public class MysqlServericeImpl implements IMysqlServerice {
if (isEquivalent) {
//todo 得分
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2);
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score);
} else {
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList);
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score);
total.addAndGet(scoreAnswerNotAllTrue);
// appendToFile(answerLogPath,"语句"+sql2+"不正确,关键得分:"+scoreAnswerNotAllTrue+ "❌");
@@ -535,10 +535,10 @@ public class MysqlServericeImpl implements IMysqlServerice {
stmt.execute("DROP VIEW IF EXISTS " + viewName1);
stmt.execute("DROP VIEW IF EXISTS " + viewName2);
if (isEquivalent) {
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2);
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score);
} else {
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList);
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score);
total.addAndGet(scoreAnswerNotAllTrue);
}
@@ -604,11 +604,11 @@ public class MysqlServericeImpl implements IMysqlServerice {
if (flag) {
//todo 得分
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2);
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score);
} else {
//得分
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList);
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score);
total.addAndGet(scoreAnswerNotAllTrue);
@@ -656,9 +656,9 @@ public class MysqlServericeImpl implements IMysqlServerice {
boolean equals = normalizedTriggerSql1.equals(normalizedTriggerSql2);
if (equals) {
//todo 得分
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2);
accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score);
} else {
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList);
int scoreAnswerNotAllTrue =calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score);
total.addAndGet(scoreAnswerNotAllTrue);
}
@@ -694,10 +694,15 @@ public class MysqlServericeImpl implements IMysqlServerice {
} catch (NumberFormatException e) {
System.out.println("无效的 totalKeyScore 值:" + totalKeyScore);
}
appendToFile(answerLogPath, "共得分:"+roundedResult);
return roundedResult;
}
public static void accumulateScoreAndLog(List<ExamMysqlKeyword> examMysqlKeywordList, AtomicInteger total, String answerLogPath, String sql2) {
AtomicInteger singleTotal = new AtomicInteger(); // 单独累加 scoreRateStr 的总和
private static void accumulateScoreAndLog(List<ExamMysqlKeyword> examMysqlKeywordList, AtomicInteger total, String answerLogPath, String sql2, String totalKeyScore, double score) {
AtomicInteger singleTotal = new AtomicInteger(); // 单独累加 scoreRateStr 的总和
for (ExamMysqlKeyword examMysqlKeyword : examMysqlKeywordList) {
String scoreRateStr = examMysqlKeyword.getScoreRate();
if (scoreRateStr != null && !scoreRateStr.trim().isEmpty()) {
@@ -711,10 +716,18 @@ public class MysqlServericeImpl implements IMysqlServerice {
}
}
}
appendToFile(answerLogPath, "语句" + sql2 + "正确,关键得分:" + singleTotal+ "");
try {
int totalKeyScoreInt = Integer.parseInt(totalKeyScore.trim());
double finalScore = ((double) singleTotal.get() / totalKeyScoreInt) * score;
String formattedScore = String.format("%.1f", finalScore);
appendToFile(answerLogPath, "✅语句" + sql2 + "正确,关键得分权值:" + singleTotal.get() + ",得分" + formattedScore);
} catch (NumberFormatException e) {
System.err.println("无效的totalKeyScore值" + totalKeyScore);
}
}
public static int calculateTotalScoreRate(String sql, List<ExamMysqlKeyword> examQuestionKeywords) {
public static int calculateTotalScoreRate(String sql, List<ExamMysqlKeyword> examQuestionKeywords, String totalKeyScore, double score) {
int totalScoreRate = 0;
Set<String> matchedKeywords = new HashSet<>();
for (ExamMysqlKeyword keyword : examQuestionKeywords) {
@@ -733,8 +746,10 @@ public class MysqlServericeImpl implements IMysqlServerice {
}
}
}
appendToFile(answerLogPath,"语句"+sql+"不正确,关键得分点:"+matchedKeywords+ ""+"关键得分"+totalScoreRate);
int totalKeyScoreInt = Integer.parseInt(totalKeyScore.trim());
double finalScore = ((double) totalScoreRate / totalKeyScoreInt) * score;
String formattedScore = String.format("%.1f", finalScore);
appendToFile(answerLogPath,"❌语句"+sql+"不正确,答对得分点为:"+matchedKeywords+"关键得分权值"+ totalScoreRate+ ",得分" + formattedScore);
return totalScoreRate;
}
@@ -986,21 +1001,21 @@ public class MysqlServericeImpl implements IMysqlServerice {
* 打印查询结果
*/
private static void printResult(List<List<String>> result) {
if (result.isEmpty()) {
appendToFile(answerLogPath,"查询结果为空");
} else {
// 打印每一行数据
for (int i = 0; i < result.size(); i++) {
List<String> row = result.get(i);
if (i == 0) { // 打印列名
appendToFile(answerLogPath,"列名:");
}
for (String value : row) {
appendToFile(answerLogPath,value + "\t");
}
System.out.println();
}
}
// if (result.isEmpty()) {
// appendToFile(answerLogPath,"查询结果为空");
// } else {
// // 打印每一行数据
// for (int i = 0; i < result.size(); i++) {
// List<String> row = result.get(i);
// if (i == 0) { // 打印列名
// appendToFile(answerLogPath,"列名:");
// }
// for (String value : row) {
// appendToFile(answerLogPath,value + "\t");
// }
// System.out.println();
// }
// }
}
/**
* 使用提供的正则表达式模式从给定的 SQL 语句中提取视图名称。