【修改】 判分逻辑修改(文件夹路径补全),GCC逻辑判分修改,Word判分修改

This commit is contained in:
RENWEIBING\letre
2025-05-06 15:07:05 +08:00
parent ef83662910
commit 4b962fa609
8 changed files with 51 additions and 26 deletions

View File

@@ -33,8 +33,8 @@ public class WpsWordController {
* @return 判分 * @return 判分
*/ */
@GetMapping("/run_wps_word") @GetMapping("/run_wps_word")
public CommonResult<List<WordVO>> run_wps_word() throws Exception { public CommonResult<List<WordVO>> run_wps_word(String path) throws Exception {
return CommonResult.success(judgementWpsWordService.ProgrammingWpsWord("1")); return CommonResult.success(judgementWpsWordService.ProgrammingWpsWord(path));
} }
} }

View File

@@ -20,7 +20,7 @@ public class AutoToolsController {
private AutoToolsService autoToolsService; private AutoToolsService autoToolsService;
@GetMapping("/get") @GetMapping("/get")
public CommonResult<Double> get(StuPaperReqVo stuPaperReqVo) { public CommonResult<Double> get(StuPaperReqVo stuPaperReqVo) throws Exception {
return autoToolsService.judgementScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId()); return autoToolsService.judgementScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId());
} }
} }

View File

@@ -32,5 +32,5 @@ public interface AutoToolsService {
* @param paperId 试卷ID * @param paperId 试卷ID
* @return 分数 * @return 分数
*/ */
CommonResult<Double> judgementScore(Long stuId, String paperId); CommonResult<Double> judgementScore(Long stuId, String paperId) throws Exception;
} }

View File

@@ -11,8 +11,10 @@ import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService;
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO; import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
import pc.exam.pp.module.infra.service.config.ConfigService; import pc.exam.pp.module.infra.service.config.ConfigService;
import pc.exam.pp.module.judgement.service.c_programming.JudgementService; import pc.exam.pp.module.judgement.service.c_programming.JudgementService;
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
import java.io.*; import java.io.*;
import java.math.BigDecimal;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
@@ -29,6 +31,8 @@ public class AutoToolsServiceImpl implements AutoToolsService{
IExamQuestionService examQuestionService; IExamQuestionService examQuestionService;
@Resource @Resource
JudgementService judgementService; JudgementService judgementService;
@Resource
JudgementWpsWordService judgementWpsWordService;
@Override @Override
public String downloadStudentFile(String fileUrl, String filePath) { public String downloadStudentFile(String fileUrl, String filePath) {
@@ -114,7 +118,7 @@ public class AutoToolsServiceImpl implements AutoToolsService{
} }
@Override @Override
public CommonResult<Double> judgementScore(Long stuId, String paperId) { public CommonResult<Double> judgementScore(Long stuId, String paperId) throws Exception {
double score = 0; double score = 0;
// 1、通过学号,试卷ID查询文件路径 // 1、通过学号,试卷ID查询文件路径
StuPaperFileDO stuPaperFileDO = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId); StuPaperFileDO stuPaperFileDO = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId);
@@ -145,7 +149,7 @@ public class AutoToolsServiceImpl implements AutoToolsService{
if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传目录不正确"); if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传目录不正确");
if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传目录不正确"); if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传目录不正确");
// 判断学号是否正确 // 判断学号是否正确
if (!files[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常"); if (!filess[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常");
// 5.3、查询出来所有试题 // 5.3、查询出来所有试题
File qu_files = new File(filess[0].getPath()); File qu_files = new File(filess[0].getPath());
// 所有试题文件夹 // 所有试题文件夹
@@ -157,7 +161,7 @@ public class AutoToolsServiceImpl implements AutoToolsService{
// 7、进行对应得判分 // 7、进行对应得判分
// --- 7.1、查询试题文件 // --- 7.1、查询试题文件
File qu_file = new File(file.getPath()); File qu_file = new File(file.getPath());
File[] qu_file_list = qu_files.listFiles(); File[] qu_file_list = qu_file.listFiles();
if (qu_file_list == null) continue; if (qu_file_list == null) continue;
// --- 7.2、通过文件名称进行判分 // --- 7.2、通过文件名称进行判分
for (File file_one : qu_file_list) { for (File file_one : qu_file_list) {
@@ -168,10 +172,19 @@ public class AutoToolsServiceImpl implements AutoToolsService{
break; break;
} }
// wps 类型存在多级文文件夹,需要个性化设置 // wps 类型存在多级文文件夹,需要个性化设置
// if () if (file_one.getName().equals("结果")) {
// 进入到学生作答得文件,直接判断文件是否存在
File wps_file = new File(file_one.getPath());
File[] wps_file_list = wps_file.listFiles();
if (wps_file_list == null) break;
if (wps_file_list[0].getName().equals("结果.docx")) {
// 开始调用wps_word判分
double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, wps_file_list[0].getPath(), examQuestion);
score += wps_word_score;
}
}
} }
} }
return CommonResult.success(score); return CommonResult.success(score);
} }
} }

View File

@@ -65,7 +65,7 @@ public class JudgementServiceImpl implements JudgementService
LogFileUtils.createFile(pathC + "/log.txt"); LogFileUtils.createFile(pathC + "/log.txt");
String code = JudgementCUtils.readFile(pathC, fileName); String code = JudgementCUtils.readFile(pathC, fileName);
LogFileUtils.writeLine("✅ 系统开始读取文件:" + code); LogFileUtils.writeLine("✅ 系统开始读取文件:" + code);
if (code == null) { if (code == "") {
// 如果没有读到源码 // 如果没有读到源码
LogFileUtils.writeLine("❌ 系统没有读取到文件。"); LogFileUtils.writeLine("❌ 系统没有读取到文件。");
LogFileUtils.close(); LogFileUtils.close();

View File

@@ -31,5 +31,5 @@ public interface JudgementWpsWordService {
* @return 得分 * @return 得分
* @throws Exception 异常 * @throws Exception 异常
*/ */
public BigDecimal judgementWpsWord(BigDecimal sorce, String path, ExamQuestion examQuestion) throws Exception; public double judgementWpsWord(double sorce, String path, ExamQuestion examQuestion) throws Exception;
} }

View File

@@ -51,8 +51,8 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
} }
@Override @Override
public BigDecimal judgementWpsWord(BigDecimal sorce, String path, ExamQuestion examQuestion) throws Exception { public double judgementWpsWord(double sorce, String path, ExamQuestion examQuestion) throws Exception {
BigDecimal wps_word_sorce = new BigDecimal(0); double wps_word_sorce = 0;
// 1、查询Word考点tree // 1、查询Word考点tree
WordListReqVO wordListReqVO = new WordListReqVO(); WordListReqVO wordListReqVO = new WordListReqVO();
wordListReqVO.setBelongTo(0); wordListReqVO.setBelongTo(0);
@@ -64,11 +64,21 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
// 4、进行关联判断 // 4、进行关联判断
for (ExamQuestionAnswer examQuestionAnswer : answerList) { for (ExamQuestionAnswer examQuestionAnswer : answerList) {
for (WordVO wordVO : margins1) { for (WordVO wordVO : margins1) {
if (wordVO.getExamKeynote() != null) {
for (String str : wordVO.getExamKeynote()) { for (String str : wordVO.getExamKeynote()) {
if (str.equals(examQuestionAnswer.getContent())) { int index = 0;
if ((index+str).equals(examQuestionAnswer.getContent())) {
double one_sorce = 0;
// 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重 // 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重
BigDecimal one_sorce = sorce.multiply(new BigDecimal(examQuestionAnswer.getScoreRate())).setScale(2, RoundingMode.HALF_UP); if (examQuestionAnswer.getScoreRate().equals("1")) {
wps_word_sorce = wps_word_sorce.add(one_sorce); // 说明权重相等,直接平分分数
one_sorce = sorce / answerList.size();
} else {
one_sorce = sorce * Double.parseDouble(examQuestionAnswer.getScoreRate());
}
wps_word_sorce += one_sorce;
break;
}
} }
} }
} }

View File

@@ -1,6 +1,8 @@
package pc.exam.pp.module.judgement.utils; package pc.exam.pp.module.judgement.utils;
import pc.exam.pp.module.exam.utils.file.LogFileUtils;
import javax.swing.*; import javax.swing.*;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -67,7 +69,7 @@ public class JudgementCUtils
public static String run_code(String code, String input, String standard, String text) { public static String run_code(String code, String input, String standard, String text) {
try { try {
boolean hasInput = code.contains("scanf") || code.contains("fgets") || code.contains("getchar"); boolean hasInput = code.contains("scanf") || code.contains("fgets") || code.contains("getchar");
System.out.println(System.getenv("PATH"));
// 写入 C 源码到文件 // 写入 C 源码到文件
File file = new File("program.c"); File file = new File("program.c");
try (FileWriter writer = new FileWriter(file)) { try (FileWriter writer = new FileWriter(file)) {
@@ -232,7 +234,7 @@ public class JudgementCUtils
// 判断路径是否存在 // 判断路径是否存在
if (!Files.exists(folderPath)) { if (!Files.exists(folderPath)) {
// LogFileUtils.writeLine("❗ 文件夹路径不存在: " + folderPath.toString()); LogFileUtils.writeLine("❗ 文件夹路径不存在: " + folderPath.toString());
return null; // 或者 return null或者 throw new RuntimeException(...),看你的函数定义 return null; // 或者 return null或者 throw new RuntimeException(...),看你的函数定义
} }
@@ -241,9 +243,9 @@ public class JudgementCUtils
try (Stream<Path> paths = Files.walk(folderPath)) { try (Stream<Path> paths = Files.walk(folderPath)) {
paths.filter(Files::isRegularFile) paths.filter(Files::isRegularFile)
.filter(path -> path.toString().toLowerCase().endsWith(fileName)) .filter(path -> path.getFileName().toString().equalsIgnoreCase(fileName))
.forEach(path -> { .forEach(path -> {
// LogFileUtils.writeLine("📄 文件: " + path); LogFileUtils.writeLine("📄 文件: " + path);
try { try {
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8); List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
for (String line : lines) { for (String line : lines) {
@@ -251,7 +253,7 @@ public class JudgementCUtils
System.out.println(" " + line); System.out.println(" " + line);
} }
} catch (IOException e) { } catch (IOException e) {
// LogFileUtils.writeLine("❗ 无法读取文件: " + path); LogFileUtils.writeLine("❗ 无法读取文件: " + path);
} }
}); });
} catch (IOException e) { } catch (IOException e) {