use of top.hcode.hoj.pojo.entity.judge.JudgeCase in project HOJ by HimitZH.
the class JudgeController method getALLCaseResult.
/**
* @MethodName getJudgeCase
* @Params * @param null
* @Description 获得指定提交id的测试样例结果,暂不支持查看测试数据,只可看测试点结果,时间,空间,或者IO得分
* @Return
* @Since 2020/10/29
*/
@GetMapping("/get-all-case-result")
public CommonResult getALLCaseResult(@RequestParam(value = "submitId", required = true) Long submitId, HttpServletRequest request) {
Judge judge = judgeService.getById(submitId);
if (judge == null) {
return CommonResult.errorResponse("此提交数据不存在!");
}
Problem problem = problemService.getById(judge.getPid());
// 如果该题不支持开放测试点结果查看
if (!problem.getOpenCaseResult()) {
return CommonResult.successResponse(null, "对不起,该题测试样例详情不支持开放!");
}
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 是否为超级管理员
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (judge.getCid() != 0 && userRolesVo != null && !isRoot) {
Contest contest = contestService.getById(judge.getCid());
// 如果不是比赛管理员 比赛封榜不能看
if (!contest.getUid().equals(userRolesVo.getUid())) {
// 当前是比赛期间 同时处于封榜时间
if (contest.getSealRank() && contest.getStatus().intValue() == Constants.Contest.STATUS_RUNNING.getCode() && contest.getSealRankTime().before(new Date())) {
return CommonResult.successResponse(null, "对不起,该题测试样例详情不能查看!");
}
// 若是比赛题目,只支持OI查看测试点情况,ACM强制禁止查看,比赛管理员除外
if (problem.getType().intValue() == Constants.Contest.TYPE_ACM.getCode()) {
return CommonResult.successResponse(null, "对不起,该题测试样例详情不能查看!");
}
}
}
QueryWrapper<JudgeCase> wrapper = new QueryWrapper<>();
if (userRolesVo == null || (!isRoot && !SecurityUtils.getSubject().hasRole("admin") && !SecurityUtils.getSubject().hasRole("problem_admin"))) {
wrapper.select("time", "memory", "score", "status", "user_output");
}
wrapper.eq("submit_id", submitId).last("order by length(input_data) asc,input_data asc");
// 当前所有测试点只支持 空间 时间 状态码 IO得分 输出文件名 输入文件名和错误信息提示查看而已
List<JudgeCase> judgeCaseList = judgeCaseService.list(wrapper);
if (judgeCaseList.isEmpty()) {
// 未查询到一条数据
return CommonResult.successResponse(null, "暂无数据");
} else {
return CommonResult.successResponse(judgeCaseList, "获取成功");
}
}
use of top.hcode.hoj.pojo.entity.judge.JudgeCase in project HOJ by HimitZH.
the class JudgeManager method getALLCaseResult.
/**
* @MethodName getJudgeCase
* @Description 获得指定提交id的测试样例结果,暂不支持查看测试数据,只可看测试点结果,时间,空间,或者IO得分
* @Since 2020/10/29
*/
@GetMapping("/get-all-case-result")
public List<JudgeCase> getALLCaseResult(Long submitId) throws StatusNotFoundException, StatusForbiddenException {
Judge judge = judgeEntityService.getById(submitId);
if (judge == null) {
throw new StatusNotFoundException("此提交数据不存在!");
}
Problem problem = problemEntityService.getById(judge.getPid());
// 如果该题不支持开放测试点结果查看
if (!problem.getOpenCaseResult()) {
return null;
}
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
QueryWrapper<JudgeCase> wrapper = new QueryWrapper<>();
if (judge.getCid() == 0) {
// 非比赛提交
if (userRolesVo == null) {
// 没有登录
wrapper.select("time", "memory", "score", "status", "user_output");
} else {
// 是否为超级管理员
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (!isRoot && !SecurityUtils.getSubject().hasRole("admin") && !SecurityUtils.getSubject().hasRole("problem_admin")) {
// 不是管理员
wrapper.select("time", "memory", "score", "status", "user_output");
}
}
} else {
// 比赛提交
if (userRolesVo == null) {
throw new StatusForbiddenException("您还未登录!不可查看比赛提交的测试点详情!");
}
// 是否为超级管理员
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (!isRoot) {
Contest contest = contestEntityService.getById(judge.getCid());
// 如果不是比赛管理员 需要受到规则限制
if (!contest.getUid().equals(userRolesVo.getUid()) || (contest.getIsGroup() && !groupValidator.isGroupRoot(userRolesVo.getUid(), contest.getGid()))) {
// ACM比赛期间强制禁止查看,比赛管理员除外(赛后恢复正常)
if (contest.getType().intValue() == Constants.Contest.TYPE_ACM.getCode()) {
if (contest.getStatus().intValue() == Constants.Contest.STATUS_RUNNING.getCode()) {
return null;
}
} else {
// 当前是oi比赛期间 同时处于封榜时间
if (contest.getSealRank() && contest.getStatus().intValue() == Constants.Contest.STATUS_RUNNING.getCode() && contest.getSealRankTime().before(new Date())) {
return null;
}
}
wrapper.select("time", "memory", "score", "status", "user_output");
}
}
}
wrapper.eq("submit_id", submitId);
if (!problem.getIsRemote()) {
wrapper.last("order by length(input_data) asc,input_data asc");
}
// 当前所有测试点只支持 空间 时间 状态码 IO得分 和错误信息提示查看而已
return judgeCaseEntityService.list(wrapper);
}
use of top.hcode.hoj.pojo.entity.judge.JudgeCase in project HOJ by HimitZH.
the class JudgeStrategy method computeResultInfo.
// 获取判题的运行时间,运行空间,OI得分
public HashMap<String, Object> computeResultInfo(List<JudgeCase> allTestCaseResultList, Boolean isACM, Integer errorCaseNum, Integer totalScore, Integer problemDiffculty) {
HashMap<String, Object> result = new HashMap<>();
// 用时和内存占用保存为多个测试点中最长的
allTestCaseResultList.stream().max(Comparator.comparing(t -> t.getTime())).ifPresent(t -> result.put("time", t.getTime()));
allTestCaseResultList.stream().max(Comparator.comparing(t -> t.getMemory())).ifPresent(t -> result.put("memory", t.getMemory()));
// OI题目计算得分
if (!isACM) {
// 全对的直接用总分*0.1+2*题目难度
if (errorCaseNum == 0) {
int oiRankScore = (int) Math.round(totalScore * 0.1 + 2 * problemDiffculty);
result.put("score", totalScore);
result.put("oiRankScore", oiRankScore);
} else {
int sumScore = 0;
for (JudgeCase testcaseResult : allTestCaseResultList) {
sumScore += testcaseResult.getScore();
}
// 测试点总得分*0.1+2*题目难度*(测试点总得分/题目总分)
int oiRankScore = (int) Math.round(sumScore * 0.1 + 2 * problemDiffculty * (sumScore * 1.0 / totalScore));
result.put("score", sumScore);
result.put("oiRankScore", oiRankScore);
}
}
return result;
}
use of top.hcode.hoj.pojo.entity.judge.JudgeCase in project HOJ by HimitZH.
the class CodeForcesJudge method result.
@Override
public RemoteJudgeRes result() {
// 清除当前线程的cookies缓存
HttpRequest.getCookieManager().getCookieStore().removeAll();
RemoteJudgeDTO remoteJudgeDTO = getRemoteJudgeDTO();
if (remoteJudgeDTO.getCookies() == null) {
login();
}
HttpRequest homeRequest = HttpUtil.createGet(HOST + MY_SUBMISSION);
homeRequest.cookie(remoteJudgeDTO.getCookies());
HttpResponse homeResponse = homeRequest.execute();
String csrfToken = ReUtil.get("data-csrf='(\\w+)'", homeResponse.body(), 1);
HttpRequest httpRequest = HttpUtil.createPost(HOST + CE_INFO_URL).cookie(remoteJudgeDTO.getCookies()).timeout(30000);
httpRequest.form(MapUtil.builder(new HashMap<String, Object>()).put("csrf_token", csrfToken).put("submissionId", remoteJudgeDTO.getSubmitId()).map());
HttpResponse httpResponse = httpRequest.execute();
RemoteJudgeRes remoteJudgeRes = RemoteJudgeRes.builder().status(Constants.Judge.STATUS_JUDGING.getStatus()).build();
if (httpResponse.getStatus() == 200) {
JSONObject submissionInfoJson = JSONUtil.parseObj(httpResponse.body());
String compilationError = submissionInfoJson.getStr("compilationError");
if ("true".equals(compilationError)) {
remoteJudgeRes.setMemory(0).setTime(0).setStatus(Constants.Judge.STATUS_COMPILE_ERROR.getStatus());
String CEMsg = submissionInfoJson.getStr("checkerStdoutAndStderr#1");
if (StringUtils.isEmpty(CEMsg)) {
remoteJudgeRes.setErrorInfo("Oops! Because Codeforces does not provide compilation details, it is unable to provide the reason for compilation failure!");
} else {
remoteJudgeRes.setErrorInfo(CEMsg);
}
return remoteJudgeRes;
}
Integer testcaseNum = remoteJudgeDTO.getTestcaseNum();
Integer maxTime = remoteJudgeDTO.getMaxTime();
Integer maxMemory = remoteJudgeDTO.getMaxMemory();
if (testcaseNum == null) {
testcaseNum = 1;
maxTime = 0;
maxMemory = 0;
}
List<JudgeCase> judgeCaseList = new ArrayList<>();
String testCountStr = submissionInfoJson.getStr("testCount");
int testCount = Integer.parseInt(testCountStr);
for (; testcaseNum <= testCount; testcaseNum++) {
String verdict = submissionInfoJson.getStr("verdict#" + testcaseNum);
if (StringUtils.isEmpty(verdict)) {
continue;
}
Constants.Judge judgeRes = statusMap.get(verdict);
Integer time = Integer.parseInt(submissionInfoJson.getStr("timeConsumed#" + testcaseNum));
Integer memory = Integer.parseInt(submissionInfoJson.getStr("memoryConsumed#" + testcaseNum)) / 1024;
String msg = submissionInfoJson.getStr("checkerStdoutAndStderr#" + testcaseNum);
judgeCaseList.add(new JudgeCase().setSubmitId(remoteJudgeDTO.getJudgeId()).setPid(remoteJudgeDTO.getPid()).setUid(remoteJudgeDTO.getUid()).setTime(time).setMemory(memory).setStatus(judgeRes.getStatus()).setUserOutput(msg));
if (time > maxTime) {
maxTime = time;
}
if (memory > maxMemory) {
maxMemory = memory;
}
}
remoteJudgeDTO.setTestcaseNum(testcaseNum);
remoteJudgeDTO.setMaxMemory(maxMemory);
remoteJudgeDTO.setMaxTime(maxTime);
remoteJudgeRes.setJudgeCaseList(judgeCaseList);
if ("true".equals(submissionInfoJson.getStr("waiting"))) {
return remoteJudgeRes;
}
Constants.Judge finalJudgeRes = statusMap.get(submissionInfoJson.getStr("verdict#" + testCount));
remoteJudgeRes.setStatus(finalJudgeRes.getStatus()).setTime(maxTime).setMemory(maxMemory);
return remoteJudgeRes;
} else {
remoteJudgeRes.setStatus(Constants.Judge.STATUS_SYSTEM_ERROR.getStatus()).setMemory(0).setTime(0).setErrorInfo("Oops! Error in obtaining the judging result. The status code returned by the interface is " + httpResponse.getStatus() + ".");
return remoteJudgeRes;
}
}
use of top.hcode.hoj.pojo.entity.judge.JudgeCase in project HOJ by HimitZH.
the class RejudgeServiceImpl method rejudgeContestProblem.
@Override
@Transactional(rollbackFor = Exception.class)
public CommonResult rejudgeContestProblem(Long cid, Long pid) {
QueryWrapper<Judge> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("cid", cid).eq("pid", pid);
List<Judge> rejudgeList = judgeService.list(queryWrapper);
if (rejudgeList.size() == 0) {
return CommonResult.errorResponse("当前该题目无提交,不可重判!");
}
List<Long> submitIdList = new LinkedList<>();
HashMap<Long, Integer> idMapStatus = new HashMap<>();
// 全部设置默认值
for (Judge judge : rejudgeList) {
idMapStatus.put(judge.getSubmitId(), judge.getStatus());
// 开始进入判题队列
judge.setStatus(Constants.Judge.STATUS_PENDING.getStatus());
judge.setVersion(judge.getVersion() + 1);
judge.setJudger("").setTime(null).setMemory(null).setErrorMessage(null).setOiRankScore(null).setScore(null);
submitIdList.add(judge.getSubmitId());
}
boolean resetJudgeResult = judgeService.updateBatchById(rejudgeList);
// 清除每个提交对应的测试点结果
QueryWrapper<JudgeCase> judgeCaseQueryWrapper = new QueryWrapper<>();
judgeCaseQueryWrapper.in("submit_id", submitIdList);
judgeCaseService.remove(judgeCaseQueryWrapper);
// 将对应比赛记录设置成默认值
UpdateWrapper<ContestRecord> updateWrapper = new UpdateWrapper<>();
updateWrapper.in("submit_id", submitIdList).setSql("status=null,score=null");
boolean resetContestRecordResult = contestRecordService.update(updateWrapper);
if (resetContestRecordResult && resetJudgeResult) {
// 调用重判服务
Problem problem = problemService.getById(pid);
if (problem.getIsRemote()) {
// 如果是远程oj判题
for (Judge judge : rejudgeList) {
// 进入重判队列,等待调用判题服务
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(), judge.getCid() != 0, isHasSubmitIdRemoteRejudge(judge.getVjudgeSubmitId(), idMapStatus.get(judge.getSubmitId())));
}
} else {
for (Judge judge : rejudgeList) {
// 进入重判队列,等待调用判题服务
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() != 0);
}
}
return CommonResult.successResponse(null, "重判成功!该题目对应的全部提交已进入判题队列!");
} else {
return CommonResult.errorResponse("重判失败!请重新尝试!");
}
}
Aggregations