Skip to content

Commit

Permalink
judger completed v0.1 finished!
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpwfloi committed Dec 7, 2014
1 parent 5c1df80 commit cb31a95
Show file tree
Hide file tree
Showing 52 changed files with 5,696 additions and 47 deletions.
173 changes: 138 additions & 35 deletions model/judger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,66 @@ var db = new mongo.Db('cboj', server, {safe: true});
var Step = require('step');
var fs = require('fs');
var cp = require('child_process');
var problemId, filelist = [], child, timer, flag, id, result = [];
var problemId, filelist = [], child, timer, flag, id, result = [], score;

db.open(function(err, db) {});

function endtle() {
function endwa(callback) {
db.collection('submissions', function(err, collection) {
if (err) return;
collection.update({submissionId: id}, {$set: {status: 2}}, function(err, doc) {
collection.update({submissionId: id}, {$set: {status: 1}}, function(err, doc) {
db.collection('core', function(err, collection) {
collection.update({name: 'completedTotal'}, {$inc: {value: 1}}, function(err, doc) {
callback();
});
});
});
});
db.collection('core', function(err, collection) {
if (err) return;
collection.update({name: 'completedTotal'}, {$inc: {value: 1}}, function(err, doc) {
doJudge();
}

function endre(callback) {
db.collection('submissions', function(err, collection) {
collection.update({submissionId: id}, {$set: {status: 3}}, function(err, doc) {
db.collection('core', function(err, collection) {
collection.update({name: 'completedTotal'}, {$inc: {value: 1}}, function(err, doc) {
callback();
});
});
});
});
}

function endtle(callback) {
db.collection('submissions', function(err, collection) {
collection.update({submissionId: id}, {$set: {status: 2}}, function(err, doc) {
db.collection('core', function(err, collection) {
collection.update({name: 'completedTotal'}, {$inc: {value: 1}}, function(err, doc) {
callback();
});
});
});
});
}

function endce() {
function endce(callback) {
db.collection('submissions', function(err, collection) {
if (err) return;
collection.update({submissionId: id}, {$set: {status: 4}}, function(err, doc) {
db.collection('core', function(err, collection) {
collection.update({name: 'completedTotal'}, {$inc: {value: 1}}, function(err, doc) {
callback();
});
});
});
});
db.collection('core', function(err, collection) {
if (err) return;
collection.update({name: 'completedTotal'}, {$inc: {value: 1}}, function(err, doc) {
doJudge();
}

function endac(callback) {
db.collection('submissions', function(err, collection) {
collection.update({submissionId: id}, {$set: {status: 0}}, function(err, doc) {
db.collection('core', function(err, collection) {
collection.update({name: 'completedTotal'}, {$inc: {value: 1}}, function(err, doc) {
callback();
});
});
});
});
}
Expand Down Expand Up @@ -76,7 +108,7 @@ function getSubmission(submissionId, callback) {
}

function endProgram() {
cp.exec('rm -f ' + __dirname + '/../../judger/judge.lock', function(err, stdout, stderr) {
cp.exec('rm -f ' + __dirname + '/../../judger/judge.lock ' + __dirname + '/../../judger/code.exe ' + __dirname + '/../../judger/code.cpp ' + __dirname + '/../../judger/code.pas', function(err, stdout, stderr) {
});
}

Expand Down Expand Up @@ -113,7 +145,9 @@ Step(
function(err, stdout, stderr) {
console.log(err, stdout, stderr);
if (err) {
endce();
endce(function() {
doJudge();
});
} else shit();
}
);
Expand All @@ -140,6 +174,7 @@ Step(
var datapath = __dirname + '/../../judger/data/' + String(problemId) + '/';
var files = fs.readdirSync(datapath);
var regin = /\.in/, regout = /\.out/;
filelist = [];
for (var i = 0; i < files.length; ++ i) {
var name = files[i];
if (regin.test(name)) {
Expand All @@ -153,32 +188,100 @@ Step(
var execpath = __dirname + '/../../judger/code.exe';
var outpath = __dirname + '/../../judger/tempout';
var datapath = __dirname + '/../../judger/data/' + String(problemId) + '/';
console.log(filelist, filelist.length);
result = [];
var shit = this;
function run(i) {
if (i >= filelist.length) return;
Step(
function() {
var inputpath = datapath + filelist[i] + '.in';
var anspath = datapath + filelist[i] + '.out';
child = cp.exec(execpath + ' < ' + inputpath + ' > ' + outpath, {timeout: 1000}, this);
},
function(err, stdout, stderr) {
//console.log(err, stdout, stderr);
if (err && err.killed && err.signal == 'SIGTERM') {
console.log('tle');
endtle();
return;
} else {
console.log('not tle');
this();
console.log('run', i);
if (i >= filelist.length) {
shit();
return;
} else {
var inputpath = datapath + filelist[i] + '.in';
var anspath = datapath + filelist[i] + '.out';
Step(
function() {
child = cp.exec(execpath + ' < ' + inputpath + ' > ' + outpath, {timeout: 1000}, this);
},
function(err, stdout, stderr) {
console.log(err, stdout, stderr);
if (err && err.killed && err.signal == 'SIGTERM') {
console.log('tle');
result.push(2);
run(i + 1);
return;
} else if (err && !err.killed && err.signal != 'SIGTERM') {
console.log('re');
result.push(3);
run(i + 1);
return;
} else {
console.log('not tle');
this();
}
}, function() {
cp.exec('diff -w -B -q ' + outpath + ' ' + anspath, this);
}, function(err, stdout, stderr) {
if (!err) {
result.push(0);
run(i + 1);
return;
} else {
result.push(1);
run(i + 1);
return;
}
}
}, function() {
}
);
);
}
}
run(0);
},
function() {
var shit = this;
var correctNum = 0;
for (var i = 0; i < result.length; ++ i) {
if (!result[i]) ++ correctNum;
}
if (result.length) score = Math.round(correctNum * 100 / result.length);
else score = 0;
if (score == 100) endac(shit);
else {
var tempnum = 0;
for (var i = 0; i < result.length; ++ i)
if (result[i]) {
tempnum = result[i];
break;
}
if (tempnum == 1) {
endwa(shit);
} else if (tempnum == 2) {
endtle(shit);
} else if (tempnum == 3) {
endre(shit);
} else {
endwa(shit);
}
}
},
function() {
giveResult(result, score, this);
},
function() {
doJudge();
}
);
}

function giveResult(result, score, callback) {
console.log(result, score);
db.collection('submissions', function(err, collection) {
collection.update({submissionId: id}, {$set: {result: result, score: score}}, function(err, doc) {
callback();
});
});
}

exports.doJudge = doJudge;
exports.getSubmission = getSubmission;

17 changes: 17 additions & 0 deletions public/sh/scripts/shAutoloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(2(){1 h=5;h.I=2(){2 n(c,a){4(1 d=0;d<c.9;d++)i[c[d]]=a}2 o(c){1 a=r.H("J"),d=3;a.K=c;a.M="L/t";a.G="t";a.u=a.v=2(){6(!d&&(!8.7||8.7=="F"||8.7=="z")){d=q;e[c]=q;a:{4(1 p y e)6(e[p]==3)B a;j&&5.C(k)}a.u=a.v=x;a.D.O(a)}};r.N.R(a)}1 f=Q,l=h.P(),i={},e={},j=3,k=x,b;5.T=2(c){k=c;j=q};4(b=0;b<f.9;b++){1 m=f[b].w?f[b]:f[b].S(/\\s+/),g=m.w();n(m,g)}4(b=0;b<l.9;b++)6(g=i[l[b].E.A]){e[g]=3;o(g)}}})();',56,56,'|var|function|false|for|SyntaxHighlighter|if|readyState|this|length|||||||||||||||||true|document||javascript|onload|onreadystatechange|pop|null|in|complete|brush|break|highlight|parentNode|params|loaded|language|createElement|autoloader|script|src|text|type|body|removeChild|findElements|arguments|appendChild|split|all'.split('|'),0,{}))
59 changes: 59 additions & 0 deletions public/sh/scripts/shBrushAS3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
;(function()
{
// CommonJS
typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;

function Brush()
{
// Created by Peter Atoria @ http://iAtoria.com

var inits = 'class interface function package';

var keywords = '-Infinity ...rest Array as AS3 Boolean break case catch const continue Date decodeURI ' +
'decodeURIComponent default delete do dynamic each else encodeURI encodeURIComponent escape ' +
'extends false final finally flash_proxy for get if implements import in include Infinity ' +
'instanceof int internal is isFinite isNaN isXMLName label namespace NaN native new null ' +
'Null Number Object object_proxy override parseFloat parseInt private protected public ' +
'return set static String super switch this throw true try typeof uint undefined unescape ' +
'use void while with'
;

this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' }, // one line comments
{ regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // double quoted strings
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // single quoted strings
{ regex: /\b([\d]+(\.[\d]+)?|0x[a-f0-9]+)\b/gi, css: 'value' }, // numbers
{ regex: new RegExp(this.getKeywords(inits), 'gm'), css: 'color3' }, // initializations
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' }, // keywords
{ regex: new RegExp('var', 'gm'), css: 'variable' }, // variable
{ regex: new RegExp('trace', 'gm'), css: 'color1' } // trace
];

this.forHtmlScript(SyntaxHighlighter.regexLib.scriptScriptTags);
};

Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases = ['actionscript3', 'as3'];

SyntaxHighlighter.brushes.AS3 = Brush;

// CommonJS
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})();
Loading

0 comments on commit cb31a95

Please sign in to comment.