forked from SuprDewd/uva-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.js
84 lines (74 loc) · 2.66 KB
/
adapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const colors = require('colors');
const fs = require('fs');
const path = require('path');
const util = require('./util');
// Maps from typeName to class function
var subClasses = {}; // private static field
var normNames = {}; // normalize the type name
module.exports = (function(){
// constructor
function cls(app, acct)
{
// public instance method
this.send = function(probNum, filePath, callback){
// suf includes the dot
var suf = path.extname(filePath);
if (suf.length <= 1)
{
callback({message: "Cannot auto-detect language"});
return;
}
suf = suf.substring(1).toLowerCase();
this._send(probNum, filePath, suf, callback);
};
this.account = function(){
return acct;
};
}
cls.normalizeType = function(s){
return normNames[s.toLowerCase()];
};
// public static method
cls.create = function(app, acct){
var clsFn = subClasses[acct.type().toLowerCase()];
if (clsFn) return new clsFn(app, acct);
return null;
};
const STATUSES = {
STATUS_ERROR : {label: "subm err", color: "red"},
STATUS_QUEUE_ERROR : {label: "can't queue", color: "red"},
STATUS_IN_QUEUE : {label: "in queue", color: "yellow"},
STATUS_COMPILE_ERROR : {label: "compile err", color: "yellow"},
STATUS_RESTRICTED_FN : {label: "restricted func", color: "yellow"},
STATUS_RUNTIME_ERROR : {label: "runtime err", color: "cyan"},
STATUS_OUTPUT_LIMIT : {label: "output limit", color: "yellow"},
STATUS_TIME_LIMIT : {label: "time limit", color: "blue"},
STATUS_MEM_LIMIT : {label: "mem limit", color: "yellow"},
STATUS_WRONG_ANS : {label: "wrong ans", color: "red"},
STATUS_PRESENTATION : {label: "presentation", color: "yellow"},
STATUS_ACCEPTED : {label: "accepted", color: "green"},
STATUS_UNKNOWN : {label: "?", color: "white"},
};
for (var key in STATUSES)
{
var status = STATUSES[key];
status.coloredLabel = status.label[status.color];
cls[key] = status;
}
return cls;
})();
/*
* Auto load the subclasses
*/
(function(){
var files = fs.readdirSync(__dirname);
for (var i=0; i < files.length; i++)
{
var match = /^adapter(\w+)/i.exec(files[i]);
if (!match) continue;
var modName = match[1];
var lower = modName.toLowerCase();
normNames[lower] = modName;
subClasses[lower] = require('./'+files[i]);
}
})();