优化代码

This commit is contained in:
Himit_ZH 2021-07-31 18:38:10 +08:00
parent a687678ec0
commit 8dab12a089
4 changed files with 22 additions and 19 deletions

View File

@ -13,7 +13,7 @@ public class SystemError extends Exception{
private String stderr;
public SystemError(String message, String stdout, String stderr ) {
super(message);
super(message+" "+stderr);
this.stdout = stdout;
this.stderr = stderr;
}

View File

@ -86,23 +86,26 @@ public class JudgeRun {
final Long testTime = time.longValue();
// 用户输出的文件夹
String runDir = Constants.JudgeDir.RUN_WORKPLACE_DIR.getContent() + "/" + submitId;
String runDir = Constants.JudgeDir.RUN_WORKPLACE_DIR.getContent() + File.separator + submitId;
for (int index = 0; index < testcaseList.size(); index++) {
JSONObject testcase = (JSONObject) testcaseList.get(index);
// 将每个需要测试的线程任务加入任务列表中
final int testCaseId = index;
// 测试样例的路径
final String testCaseInputPath = testCasesDir + "/" + ((JSONObject) testcaseList.get(index)).getStr("inputName");
// 数据库表的测试样例id
final Long caseId = ((JSONObject) testcaseList.get(index)).getLong("caseId");
// 该测试点的满分
final Integer score = ((JSONObject) testcaseList.get(index)).getInt("score", 0);
final Long maxOutputSize = Math.max(((JSONObject) testcaseList.get(index)).getLong("outputSize", 0L) * 2, 16 * 1024 * 1024L);
// 输入文件名
final String inputFileName = ((JSONObject) testcaseList.get(index)).getStr("inputName");
final String inputFileName = testcase.getStr("inputName");
// 输出文件名
final String outputFileName = ((JSONObject) testcaseList.get(index)).getStr("outputName");
final String outputFileName = testcase.getStr("outputName");
// 测试样例的路径
final String testCaseInputPath = testCasesDir + File.separator + inputFileName;
// 数据库表的测试样例id
final Long caseId = testcase.getLong("caseId",null);
// 该测试点的满分
final Integer score = testcase.getInt("score", 0);
final Long maxOutputSize = Math.max(testcase.getLong("outputSize", 0L) * 2, 16 * 1024 * 1024L);
if (!isSpj) {
futureTasks.add(new FutureTask<>(new Callable<JSONObject>() {
@Override
@ -125,7 +128,7 @@ public class JudgeRun {
}
}));
} else {
final String testCaseOutputPath = testCasesDir + "/" + ((JSONObject) testcaseList.get(index)).getStr("outputName");
final String testCaseOutputPath = testCasesDir + "/" + outputFileName;
futureTasks.add(new FutureTask<>(new Callable<JSONObject>() {
@Override
public JSONObject call() throws SystemError {

View File

@ -105,7 +105,7 @@ public class JudgeStrategy {
result.put("time", 0);
result.put("memory", 0);
log.error("题号为:" + problem.getId() + "的题目提交id为" + judge.getSubmitId() + "在评测过程中发生系统性的异常------------------->{}",
systemError.getMessage() + "\n" + systemError.getStderr());
systemError);
} catch (SubmitError submitError) {
result.put("code", Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus());
result.put("errMsg", submitError.getMessage() + ":" + submitError.getStderr());
@ -121,7 +121,7 @@ public class JudgeStrategy {
result.put("errMsg", "Oops, something has gone wrong with the judgeServer. Please report this to administrator.");
result.put("time", 0);
result.put("memory", 0);
log.error("题号为:" + problem.getId() + "的题目提交id为" + judge.getSubmitId() + "在评测过程中发生系统性的异常-------------------->{}", e.getMessage());
log.error("题号为:" + problem.getId() + "的题目提交id为" + judge.getSubmitId() + "在评测过程中发生系统性的异常-------------------->{}", e);
} finally {
// 删除tmpfs内存中的用户代码可执行文件
@ -185,7 +185,7 @@ public class JudgeStrategy {
Integer time = jsonObject.getLong("time").intValue();
Integer memory = jsonObject.getLong("memory").intValue();
Integer status = jsonObject.getInt("status");
Long caseId = jsonObject.getLong("caseId");
Long caseId = jsonObject.getLong("caseId",null);
String inputFileName = jsonObject.getStr("inputFileName");
String outputFileName = jsonObject.getStr("outputFileName");
JudgeCase judgeCase = new JudgeCase();

View File

@ -57,7 +57,7 @@ public class ProblemTestCaseUtils {
for (int index = 0; index < testCases.size(); index++) {
JSONObject jsonObject = new JSONObject();
String inputName = (index + 1) + ".in";
jsonObject.set("caseId", (long) testCases.get(index).get("caseId"));
jsonObject.set("caseId", testCases.get(index).get("caseId"));
jsonObject.set("score", testCases.get(index).getOrDefault("score", null));
jsonObject.set("inputName", inputName);
// 生成对应文件
@ -108,7 +108,7 @@ public class ProblemTestCaseUtils {
for (ProblemCase problemCase : problemCaseList) {
JSONObject jsonObject = new JSONObject();
jsonObject.set("caseId", null);
jsonObject.set("caseId", problemCase.getId());
jsonObject.set("score", problemCase.getScore());
jsonObject.set("inputName", problemCase.getInput());
jsonObject.set("outputName", problemCase.getOutput());