Skip to content

Commit

Permalink
Merge pull request #59 from Killerrekt/master
Browse files Browse the repository at this point in the history
Added the no of testcases and passed in submission res and changed from req.body to params for code by round
  • Loading branch information
souvik150 authored Sep 23, 2023
2 parents 000a1ce + d20565e commit 81e6ddd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
17 changes: 14 additions & 3 deletions api/controllers/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require("dotenv").config();
const Judge0 = process.env.JUDGE_URI;

class submission {
async create(req, user, score, max, result, time) {
async create(req, user, score, max, result, time, passed) {
//console.log(result);
const { language_id, code, question_id } = req.body;
const check = await submission_db.findOne({
Expand All @@ -27,6 +27,7 @@ class submission {
max_score: max,
lastResults: result,
runtime: time,
testcases_passed: passed
},
)
.then(() => "Submission record has been updated")
Expand All @@ -42,6 +43,7 @@ class submission {
max_score: max,
lastResults: result,
runtime: time,
testcases_passed: passed
})
.then(() => "Submission record has been saved")
.catch((err) => "Error faced during creating the entry");
Expand Down Expand Up @@ -83,11 +85,14 @@ class submission {
//console.log(!check.allPassesAt);
if (check && check.code == code) {
await this.create_score(reg_no);
const max = await questiondb.findById(question_id,"testcases");
if (!check.lastResults[0]) {
res.status(201).json({
error: check.lastResults,
Sub_db: "No changes in source code",
Score: check.score,
test_passed : check.testcases_passed,
no_of_test : max.length
});
return;
}
Expand Down Expand Up @@ -206,6 +211,8 @@ class submission {
//[complilation error/runtime,time limit exceeded, O/P failed]
Sub_db: "",
Score: "",
test_passed : "",
no_of_test : ""
};
while (!completion) {
let runtime = 0;
Expand Down Expand Up @@ -327,12 +334,15 @@ class submission {
Object.keys(grp).length,
data_sent_back.error,
runtime,
(tests.length - failed.length)
);
await this.create_score(reg_no);
} else {
data_sent_back.Sub_db = "No changes in Sub DB";
await this.create_score(reg_no);
}
data_sent_back.test_passed = (tests.length - failed.length);
data_sent_back.no_of_test = tests.length;

//Creation of allPassesAt field when all testcases are passed
if (
Expand Down Expand Up @@ -501,8 +511,9 @@ class submission {
}

async get_round(req, res) {
const { regno,round } = req.body;
console.log(regno,round);
const { regno,round } = req.params;
//console.log(req.params);
//console.log(regno,round);
//console.log(regno);
const question = await questiondb.find(
{round : round},"_id name points"
Expand Down
3 changes: 2 additions & 1 deletion api/models/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const submission_schema = new Schema({
score: { type: Number },
lastResults: [{ type: Boolean }],
allPassesAt: { type: Date },
runtime: { type: Number, required: true }
runtime: {type: Number, required: true},
testcases_passed : {type:Number},
}, { timestamps: true });

const submission_db = model("Submissions", submission_schema);
Expand Down
2 changes: 1 addition & 1 deletion api/routes/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ router.get("/round_lb/:round", verifyAdminToken, (req, res)=> {
submit.round_lb(req,res);
});

router.get("/codes_by_round", verifyAdminToken, (req,res) =>{
router.get("/codes_by_round/:regno/:round", verifyAdminToken, (req,res) =>{
submit.get_round(req,res);
})

Expand Down

0 comments on commit 81e6ddd

Please sign in to comment.