update testlib res

This commit is contained in:
Himit_ZH 2022-01-05 12:53:28 +08:00
parent e965aaa366
commit 64f899021e
6 changed files with 63 additions and 19 deletions

View File

@ -74,10 +74,11 @@ int main(int argc, char *args[]){
#include<iostream>
#include<cstdio>
#define AC 100
#define PE 101
#define WA 102
#define ERROR 103
#define PC 99 // 部分正确
#define AC 100 // 全部正确
#define PE 101 // 格式错误
#define WA 102 // 答案错误
#define ERROR 103 // 系统错误
using namespace std;

View File

@ -1,8 +1,10 @@
package top.hcode.hoj.judge;
import cn.hutool.core.util.ReUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import top.hcode.hoj.common.exception.SystemError;
import top.hcode.hoj.judge.entity.JudgeDTO;
import top.hcode.hoj.judge.entity.JudgeGlobalDTO;
@ -21,6 +23,8 @@ import java.util.List;
*/
public abstract class AbstractJudge {
protected static final int SPJ_PC = 99;
protected static final int SPJ_AC = 100;
protected static final int SPJ_PE = 101;
@ -117,6 +121,29 @@ public abstract class AbstractJudge {
} else if (err.startsWith("wrong output format ")) {
res.set("code", SPJ_WA);
res.set("errMsg", "May be output presentation error. " + err.split("wrong output format")[1]);
} else if (err.startsWith("partially correct ")) {
res.set("errMsg", err.split("partially correct ")[1]);
String numStr = ReUtil.get("partially correct \\(([\\s\\S]*?)\\) ", err, 1);
double percentage = 0.0;
if (!StringUtils.isEmpty(numStr)) {
percentage = Integer.parseInt(numStr) * 1.0 / 100;
}
res.set("percentage", percentage);
res.set("code", SPJ_PC);
} else if (err.startsWith("points ")) {
res.set("code", SPJ_PC);
String numStr = err.split("points ")[1].split(" ")[0];
double percentage = 0.0;
if (!StringUtils.isEmpty(numStr)) {
percentage = Double.parseDouble(numStr) / 100;
}
if (percentage == 1) {
res.set("code", SPJ_AC);
} else {
res.set("percentage", percentage);
}
String tmp = err.split("points ")[1];
res.set("errMsg", tmp.substring(0, Math.min(1024, tmp.length())));
} else if (err.startsWith("FAIL ")) {
res.set("code", SPJ_ERROR);
res.set("errMsg", err.split("FAIL ")[1]);

View File

@ -174,13 +174,13 @@ public class JudgeStrategy {
result.put("score", totalScore);
result.put("oiRankScore", oiRankScore);
} else {
int score = 0;
int sumScore = 0;
for (JudgeCase testcaseResult : allTestCaseResultList) {
score += testcaseResult.getScore();
sumScore += testcaseResult.getScore();
}
//测试点总得分*0.1+2*题目难度*测试点总得分/题目总分
int oiRankScore = (int) Math.round(score * 0.1 + 2 * problemDiffculty * (score * 1.0 / totalScore));
result.put("score", score);
int oiRankScore = (int) Math.round(sumScore * 0.1 + 2 * problemDiffculty * (sumScore * 1.0 / totalScore));
result.put("score", sumScore);
result.put("oiRankScore", oiRankScore);
}
}
@ -201,6 +201,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", null);
String inputFileName = jsonObject.getStr("inputFileName");
String outputFileName = jsonObject.getStr("outputFileName");
@ -219,17 +220,29 @@ public class JudgeStrategy {
judgeCase.setUserOutput(msg);
}
// 过滤出结果不是AC的测试点结果 同时如果是IO题目 则得分为0
if (jsonObject.getInt("status").intValue() != Constants.Judge.STATUS_ACCEPTED.getStatus()) {
errorTestCaseList.add(jsonObject);
if (!isACM) {
if (isACM) {
if (status != Constants.Judge.STATUS_ACCEPTED.getStatus()) {
errorTestCaseList.add(jsonObject);
}
} else {
int oiScore = jsonObject.getInt("score").intValue();
if (status == Constants.Judge.STATUS_ACCEPTED.getStatus()) {
judgeCase.setScore(oiScore);
} else if (status == Constants.Judge.STATUS_PARTIAL_ACCEPTED.getStatus()) {
errorTestCaseList.add(jsonObject);
Double percentage = jsonObject.getDouble("percentage");
if (percentage != null) {
int score = (int) Math.floor(percentage * oiScore);
judgeCase.setScore(score);
} else {
judgeCase.setScore(0);
}
} else {
errorTestCaseList.add(jsonObject);
judgeCase.setScore(0);
}
} else { // 如果是AC同时为IO题目测试点则获得该点的得分
if (!isACM) {
judgeCase.setScore(jsonObject.getInt("score").intValue());
}
}
allCaseResList.add(judgeCase);
});

View File

@ -489,7 +489,7 @@ public class SandboxRun {
/**
* 注意用户源代码需要先编译若是通过编译需要先将文件存入内存再利用管道判题同时特殊判题程序必须已编译且存在否则判题失败系统错误
*/
JSONObject pipeInputCmd = new JSONObject();
pipeInputCmd.set("args", args);
pipeInputCmd.set("env", envs);

View File

@ -86,6 +86,9 @@ public class InteractiveJudge extends AbstractJudge {
result.set("status", Constants.Judge.STATUS_ACCEPTED.getStatus());
} else if (code == SPJ_PE) {
result.set("status", Constants.Judge.STATUS_PRESENTATION_ERROR.getStatus());
} else if (code == SPJ_PC){
result.set("status", Constants.Judge.STATUS_PARTIAL_ACCEPTED.getStatus());
result.set("percentage", interactiveCheckRes.getDouble("percentage"));
} else {
result.set("status", Constants.Judge.STATUS_SYSTEM_ERROR.getStatus());
}
@ -145,7 +148,7 @@ public class InteractiveJudge extends AbstractJudge {
result.set("code", exitCode);
}
} else if (interactiveSandBoxRes.getStatus().equals(Constants.Judge.STATUS_RUNTIME_ERROR.getStatus())) {
if (exitCode == SPJ_WA || exitCode == SPJ_ERROR || exitCode == SPJ_AC || exitCode == SPJ_PE) {
if (exitCode == SPJ_WA || exitCode == SPJ_ERROR || exitCode == SPJ_AC || exitCode == SPJ_PE || exitCode == SPJ_PC) {
result.set("code", exitCode);
} else {
if (!StringUtils.isEmpty(interactiveSandBoxRes.getStderr())) {

View File

@ -177,7 +177,7 @@ public class SpecialJudge extends AbstractJudge {
result.set("code", exitCode);
}
} else if (spjJudgeResult.getInt("status").intValue() == Constants.Judge.STATUS_RUNTIME_ERROR.getStatus()) {
if (exitCode == SPJ_WA || exitCode == SPJ_ERROR || exitCode == SPJ_AC || exitCode == SPJ_PE) {
if (exitCode == SPJ_WA || exitCode == SPJ_ERROR || exitCode == SPJ_AC || exitCode == SPJ_PE || exitCode == SPJ_PC) {
result.set("code", exitCode);
} else {
if (!StringUtils.isEmpty(spjErrOut)) {