Skip to content

Commit dfe8fb4

Browse files
committed
Added working Ranking code
1 parent 5b11647 commit dfe8fb4

63 files changed

Lines changed: 704 additions & 457 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contest/models/contest/contest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const mongoose = require('mongoose');
2-
const {Problem} = require('./../problem/problem')
2+
const Problem = require('./../problem/problem')
33

44
var contestSchema = new mongoose.Schema({
55
'name':{
66
type:String,
7-
required:true
7+
required:true,
88
},
99
'id':{
1010
type:String,
@@ -23,8 +23,8 @@ var contestSchema = new mongoose.Schema({
2323
type:String
2424
},
2525
'questions':[{
26-
type: mongoose.Schema.Types.Object,
27-
ref:Problem
26+
type: mongoose.Schema.Types.ObjectId,
27+
ref:'Problem'
2828
}]
2929
})
3030

contest/models/contest/contest.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

contest/models/problem/problem.js

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,76 @@
1-
const mongoose = require('mongoose')
2-
const ProblemJson = require('./problem.json')
1+
const mongoose = require('mongoose');
2+
const Contest = require('./../contest/contest')
3+
const User = require('./../../../server/models/user/user')
34

4-
const ProblemSchema = new mongoose.Schema(ProblemJson)
5+
const ProblemSchema = new mongoose.Schema({
6+
code:{
7+
type:String,
8+
required:true,
9+
unique:true
10+
},
11+
name:{
12+
type:String
13+
},
14+
level:{
15+
type:String
16+
},
17+
description:{
18+
type:String,
19+
default:""
20+
},
21+
successfulSubmission:{
22+
type:Number,
23+
default:0
24+
},
25+
input_format:{
26+
type:String
27+
},
28+
output_format:{
29+
type:String
30+
},
31+
constraints:{
32+
type:String
33+
},
34+
input_example:{
35+
type:String
36+
},
37+
output_example:{
38+
type:String
39+
},
40+
explanation_example:{
41+
type:String,
42+
default:""
43+
},
44+
date_added:{
45+
type:Date
46+
},
47+
timelimit:{
48+
type:Number
49+
},
50+
sourcelimit:{
51+
type:Number
52+
},
53+
score:{
54+
type:Number
55+
},
56+
users:[{
57+
type:mongoose.Schema.Types.String,
58+
refs:'User'
59+
}],
60+
author:{
61+
type:String
62+
},
63+
testCaseInput:{
64+
type:String,
65+
default:""
66+
},
67+
testCaseOutput:{
68+
type:String,
69+
},
70+
contest:{
71+
type:mongoose.Schema.Types.String,
72+
refs:'Contest'
73+
}
74+
} )
575

676
module.exports=mongoose.model('Problem',ProblemSchema)

contest/models/problem/problem.json

Lines changed: 0 additions & 58 deletions
This file was deleted.

contest/models/ranking/rank.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

contest/models/ranking/ranking.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const mongoose = require('mongoose');
2+
const Schema = mongoose.Schema;
3+
4+
const User = require('./../../../server/models/user/user');
5+
const Problem = require('./../problem/problem');
6+
const Contest = require('./../contest/contest');
7+
8+
const RankingSchema = new Schema({
9+
username:{
10+
type:Schema.Types.String,
11+
refs:'User'
12+
},
13+
score:{
14+
type:Number,
15+
default:0
16+
},
17+
submissionTime:{
18+
type:Date
19+
},
20+
WA:{
21+
type:Number,
22+
default:0
23+
},
24+
problemSolved:[{
25+
type:Schema.Types.String,
26+
refs:'Problem'
27+
}],
28+
contest:{
29+
type:Schema.Types.String,
30+
refs:'Contest'
31+
}
32+
33+
})
34+
35+
module.exports = mongoose.model('Ranking',RankingSchema);

judge/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ if (cluster.isMaster) {
2828
const flash = require('connect-flash')
2929
const app = express();
3030

31+
32+
const mongoose = require('mongoose')
33+
34+
mongoose.Promise = global.Promise
35+
mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/OnlineJudge')
36+
3137
const bodyParser = require('body-parser');
3238
app.use( bodyParser.json() );
3339
app.use(bodyParser.urlencoded({

judge/compileProblem.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ const path = require('path');
44
const fs = require('fs')
55
const buffer = require('buffer')
66

7-
async function lsExample() {
8-
const { stdout, stderr } = await exec('ls');
9-
console.log('stdout:', stdout);
10-
console.log('stderr:', stderr);
11-
}
127

138
//Compile program and check for error if okay the run it
149

@@ -17,12 +12,11 @@ const compileProblem= async (lang , filename)=>{
1712
switch(lang){
1813
case "c":
1914
file = path.basename(filename,'.c') +".out ";
20-
cmd="cd "+ path.join(__dirname,"result/source") && "gcc -o " +path.join(__dirname,"result/binary/") +file + " " + filename;
15+
cmd="cd "+ path.join(__dirname,"result/source").toString() +" && gcc -o " +path.join(__dirname,"result/binary/") +file + " " + filename;
2116
break;
2217
case "c++":
2318
case "cpp":
2419
file = path.basename(filename,'.cpp')+".out";
25-
console.log(file)
2620
cmd="cd "+ path.join(__dirname,"result/source") + " && g++ -o " + path.join(__dirname,"result/binary/")+file + " " +filename;
2721
break;
2822
case "java":
@@ -42,7 +36,7 @@ const compileProblem= async (lang , filename)=>{
4236

4337
//Run Compiled if okay the check result
4438

45-
async function runCompiled(lang,file,contest,problem){
39+
async function runCompiled(lang,file,contest,problem,option){
4640

4741
var cmd;
4842
switch(lang){
@@ -58,13 +52,13 @@ async function runCompiled(lang,file,contest,problem){
5852
}
5953

6054
return new Promise((resolve,reject)=>{
61-
exec(cmd, {timeout:100000,maxBuffer:2147483647,encoding:'utf8'},(error, stdout, stderr) => {
55+
exec(cmd,option,(error, stdout, stderr) => {
6256
if (error) {
6357
//console.log(error)
6458
reject(error);
6559
}
6660
var res=stdout;
67-
console.log(res)
61+
6862
resolve(res);
6963
});
7064
})
@@ -76,9 +70,9 @@ const checkResult=async (UserResult,serverResult)=>{
7670
// UserResult = fs.readFileSync(UserResult,'utf16le')
7771
return new Promise((resolve,reject)=>{
7872
if(UserResult===serverResult){
79-
resolve('Correct answer')
73+
resolve(true)
8074
}else{
81-
resolve('wrong answer')
75+
resolve(false)
8276
}
8377
})
8478
}
@@ -109,10 +103,10 @@ const base64tofile = async (base64,lang)=>{
109103
})
110104
}
111105

112-
async function compileAndRunProblem(contest,problem,id,lang ,description){
106+
async function compileAndRunProblem(contest,problem,id,lang ,description,option){
113107
const filename= await base64tofile(description,lang);
114108
const file = await compileProblem(lang,filename);
115-
const result= await runCompiled(lang,file,contest,problem);
109+
const result= await runCompiled(lang,file,contest,problem,option);
116110
const serverRes= await serverResult(contest,problem);
117111
const Result = await checkResult(result,serverRes);
118112
return Result;

judge/models/solution/solution.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
1-
const mongoose = require('mongoose')
2-
const SolutionJson = require('./solution.json')
1+
const mongoose = require('mongoose')
2+
const Schema = mongoose.Schema;
33

4-
const SolutionSchema = new mongoose.Schema(SolutionJson);
4+
const SolutionSchema = new mongoose.Schema({
5+
id:{
6+
type:String,
7+
required:true,
8+
9+
},
10+
problemCode:{
11+
type: Schema.Types.ObjectId, ref: 'Problem'
12+
},
13+
username:{
14+
type:Schema.Types.ObjectId,ref:'User',
15+
required:true
16+
},
17+
submitted_on:{
18+
type:Date,
19+
default:Date()
20+
},
21+
language:{
22+
type:String
23+
},
24+
result:{
25+
type:String
26+
},
27+
score:{
28+
type:Number,
29+
default:0
30+
},
31+
status:{
32+
type:String,
33+
default:""
34+
},
35+
description:{
36+
type:String,
37+
default:""
38+
}
39+
});
540
module.exports= mongoose.model('Solution',SolutionSchema)

judge/models/solution/solution.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)