Browse Source

Merge branch 'master' of zhaojunzhe/fair-web into master

pull/31/head
richie 5 years ago committed by Gogs
parent
commit
fd734035a7
  1. 33
      libs/judger.js

33
libs/judger.js

@ -5,6 +5,7 @@ const msgPack = require('msgpack-lite');
const fs = require('fs-extra');
const interface = require('./judger_interfaces');
const judgeResult = require('./judgeResult');
let Problem = syzoj.model('problem');
const judgeStateCache = new Map();
const progressPusher = require('../modules/socketio');
@ -158,7 +159,6 @@ async function connect() {
}
const result = msgPack.decode(payload);
console.log(result);
winston.verbose('Received report for task ' + result.taskId);
const judge_state = await JudgeState.findOne({
@ -171,9 +171,36 @@ async function connect() {
const convertedResult = judgeResult.convertResult(result.taskId, result.progress);
winston.verbose('Reporting report finished: ' + result.taskId);
progressPusher.cleanupProgress(result.taskId);
console.log(convertedResult);
if (!judge_state) return;
judge_state.score = convertedResult.score;
const problemId = judge_state.problem_id;
let problemQuery = await Problem.createQueryBuilder();
const problemInfo = await problemQuery.where("id = :id", { id: problemId }).getOne();
const problem_time_limit = problemInfo.time_limit;
const subtasksArray = convertedResult.result.judge.subtasks;
const timeArray = subtasksArray.map((subtasksItem) => {
return subtasksItem.cases.map((subtasksItemCases) => {
return subtasksItemCases.result.time
})
});
function flat(array, result=[]){
for (let i=0;i<array.length;i++){
if (Array.isArray(array[i])){
flat(array[i], result);
} else {
result.push(array[i]);
}
}
return result;
}
const flatTimeArray = flat(timeArray);
const maxItemTime = Math.max.apply(this, flatTimeArray);
if (judge_state.type_info && convertedResult.statusString === 'Accepted' && maxItemTime < problem_time_limit * 0.9) {
const beyondTime = problem_time_limit - maxItemTime;
const extraScore = (beyondTime / problem_time_limit).toString().slice(0,3)*100;
judge_state.score = convertedResult.score + extraScore;
} else {
judge_state.score = convertedResult.score;
}
judge_state.pending = false;
judge_state.status = convertedResult.statusString;
judge_state.total_time = convertedResult.time;

Loading…
Cancel
Save