From 83e17542449efc8ccd5d9cc887031a0bd90d6e8e Mon Sep 17 00:00:00 2001 From: Aman L Date: Fri, 22 Sep 2023 12:51:17 +0530 Subject: [PATCH 1/3] attempt to solve merge conflicts --- api/controllers/submission.js | 46 +++++++++++++++++------------------ api/routes/submission.js | 5 ++++ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/api/controllers/submission.js b/api/controllers/submission.js index c7d7690..256cf20 100644 --- a/api/controllers/submission.js +++ b/api/controllers/submission.js @@ -26,7 +26,7 @@ class submission { score: score, max_score: max, lastResults: result, - }, + } ) .then(() => "Submission record has been updated") .catch(() => "Error faced during updating the sub DB"); @@ -76,7 +76,7 @@ class submission { } const check = await submission_db.findOne( { regNo: reg_no, question_id: question_id }, - "code score lastResults allPassesAt", + "code score lastResults allPassesAt" ); //console.log(!check.allPassesAt); if (check && check.code == code) { @@ -144,11 +144,10 @@ class submission { language_id: language_id, stdin: Buffer.from(current.input, "binary").toString("base64"), expected_output: Buffer.from(current.expectedOutput, "binary").toString( - "base64", + "base64" ), - cpu_time_limit: current.time * multipler < 15 - ? current.time * multipler - : 15, + cpu_time_limit: + current.time * multipler < 15 ? current.time * multipler : 15, //redirect_stderr_to_stdout: true, }); const group = current.group; @@ -176,7 +175,7 @@ class submission { header: { "Content-Type": "application/JSON", }, - }, + } ) .then((response) => response.data) .catch((err) => { @@ -192,7 +191,8 @@ class submission { tokens.forEach((element) => { str.push(element.token); }); - const url = Judge0 + + const url = + Judge0 + "/submissions/batch?tokens=" + str.toString() + "&base64_encoded=true&fields=status_id,stderr,compile_output,expected_output,stdout"; @@ -227,13 +227,13 @@ class submission { if ( Buffer.from(element.stdout, "base64").toString("utf-8") + "\n" == Buffer.from(element.expected_output, "base64").toString( - "utf-8", + "utf-8" ) || Buffer.from(element.stdout, "base64").toString("utf-8") == Buffer.from(element.expected_output, "base64").toString("utf-8") - ) { + ) continue; - } else { + else { data_sent_back.error[3] = true; failed.push(i); } @@ -269,11 +269,12 @@ class submission { //In case of complilation error the following code will run if (data_sent_back.error[0]) { - const msg = result[0].compile_output != null - ? Buffer.from(result[0].compile_output, "base64").toString( - "utf-8", - ) - : Buffer.from(result[0].stderr, "base64").toString("utf-8"); + const msg = + result[0].compile_output != null + ? Buffer.from(result[0].compile_output, "base64").toString( + "utf-8" + ) + : Buffer.from(result[0].stderr, "base64").toString("utf-8"); data_sent_back.Sub_db = "Not saved in Sub DB(complilation error)"; res.status(201).json({ error: data_sent_back.error, @@ -298,9 +299,8 @@ class submission { }); //comparing the score with the existing score and picking the best one - data_sent_back.Score = !check || score >= check.score - ? score - : check.score; + data_sent_back.Score = + !check || score >= check.score ? score : check.score; console.log(data_sent_back.Score, score); //If new score is higher or equal to the existing score, then sub DB is updated @@ -310,7 +310,7 @@ class submission { reg_no, score, Object.keys(grp).length, - data_sent_back.error, + data_sent_back.error ); await this.create_score(reg_no); } else { @@ -382,10 +382,10 @@ class submission { } async get_all(req, res) { - const { regno } = req.params; + const { regno } = req.body; const record = await submission_db.find( { regNo: regno }, - "code score question_id lastResults", + "code score question_id lastResults" ); console.log(record); if (record.length == 0) { @@ -424,7 +424,7 @@ class submission { regNo: user, question_id: question_id, }, - { allPassesAt: curr_time }, + { allPassesAt: curr_time } ) .then(() => "Updated all testcases timestamp") .catch(() => "Failed to update the timestamp"); diff --git a/api/routes/submission.js b/api/routes/submission.js index fabd679..c1539cb 100644 --- a/api/routes/submission.js +++ b/api/routes/submission.js @@ -29,4 +29,9 @@ router.get("/endtest", verifyAccessToken, (req, res) => { submit.endtest(req, res); }); +router.get("/finals", verifyAdminToken, (req, res)=> { + submit.third_round_lb(req,res); +}); + + module.exports = router; From 9f6db1b0f66f527cd82bcbc6369b7a5c45a2c625 Mon Sep 17 00:00:00 2001 From: Aman L Date: Fri, 22 Sep 2023 14:04:56 +0530 Subject: [PATCH 2/3] almost done with round leaderboard --- api/controllers/submission.js | 52 ++++++++++++++++++++++++++++++++--- api/models/submission.js | 1 + api/routes/submission.js | 4 +-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/api/controllers/submission.js b/api/controllers/submission.js index 256cf20..f554424 100644 --- a/api/controllers/submission.js +++ b/api/controllers/submission.js @@ -9,7 +9,7 @@ require("dotenv").config(); const Judge0 = process.env.JUDGE_URI; class submission { - async create(req, user, score, max, result) { + async create(req, user, score, max, result,time) { //console.log(result); const { language_id, code, question_id } = req.body; const check = await submission_db.findOne({ @@ -26,6 +26,7 @@ class submission { score: score, max_score: max, lastResults: result, + runtime : time } ) .then(() => "Submission record has been updated") @@ -40,6 +41,7 @@ class submission { score: score, max_score: max, lastResults: result, + runtime : time }) .then(() => "Submission record has been saved") .catch((err) => "Error faced during creating the entry"); @@ -195,7 +197,7 @@ class submission { Judge0 + "/submissions/batch?tokens=" + str.toString() + - "&base64_encoded=true&fields=status_id,stderr,compile_output,expected_output,stdout"; + "&base64_encoded=true&fields=status_id,stderr,compile_output,expected_output,stdout,time"; console.log(url); let completion = false; let data_sent_back = { @@ -205,6 +207,7 @@ class submission { Score: "", }; while (!completion) { + let runtime = 0; let score = 0; completion = true; let failed = []; @@ -220,6 +223,7 @@ class submission { break; case 3: //console.log(Buffer.from(element.expected_output,"base64").toString("utf-8")); + runtime += parseFloat(element.time); break; case 4: //console.log(Buffer.from(element.expected_output,"base64").toString("utf-8")); @@ -232,7 +236,7 @@ class submission { Buffer.from(element.stdout, "base64").toString("utf-8") == Buffer.from(element.expected_output, "base64").toString("utf-8") ) - continue; + runtime += parseFloat(element.time); else { data_sent_back.error[3] = true; failed.push(i); @@ -260,6 +264,11 @@ class submission { break; } } + //console.log(runtime); + runtime = runtime/(tests.length-failed.length); + //console.log(tests.length,failed.length); + runtime = runtime/multipler; + //console.log("runtime = ", runtime); if (completion) { //Checking whether complilation error or runtime error if (failed.length != tests.length && data_sent_back.error[0]) { @@ -310,7 +319,8 @@ class submission { reg_no, score, Object.keys(grp).length, - data_sent_back.error + data_sent_back.error, + runtime ); await this.create_score(reg_no); } else { @@ -447,5 +457,39 @@ class submission { return res.status(500).json({ status: false, error: error }); } } + + async round_lb(req,res){ + const {round} = req.body; + const QID = await questiondb.find({round : round},"_id"); + let question = []; + QID.forEach((ele) => question.push(ele._id.toString())); + const all_submit = await submission_db.find({question_id : {"$in" : question}} + ,"regNo score question_id runtime allPassesAt"); + let leaderboard = {}; + all_submit.forEach((ele) => { + if (ele.regNo in leaderboard) { + let data = leaderboard[ele.regNo]; + data[0] += ele.score; + data[1] = data[1]>ele.allPassesAt?ele.allPassesAt:data[1]; + data[2] += ele.runtime; + //console.log(data); + leaderboard[ele.regNo] = data; + } else { + leaderboard[ele.regNo] = [ele.score,ele.allPassesAt,ele.runtime]; + } + }); + let items = Object.keys(leaderboard).map(function(key) { + return [key, leaderboard[key]]; + }); + console.log(items); + items.sort(function(a,b){ + console.log(a[1][0]); + if(a[1][0]>b[1][0]) return -1; + if(a[1][0]b[1][1]) return -1; + if(a[1][1] { submit.endtest(req, res); }); -router.get("/finals", verifyAdminToken, (req, res)=> { - submit.third_round_lb(req,res); +router.get("/round_lb", verifyAdminToken, (req, res)=> { + submit.round_lb(req,res); }); From 9a21a0fe629774e34240b80b7deb0c618bc0f906 Mon Sep 17 00:00:00 2001 From: Aman L Date: Fri, 22 Sep 2023 14:11:29 +0530 Subject: [PATCH 3/3] Added runtime field in submission, leaderboard for any particular round --- api/controllers/submission.js | 9 ++++----- api/routes/submission.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/api/controllers/submission.js b/api/controllers/submission.js index f554424..39244b3 100644 --- a/api/controllers/submission.js +++ b/api/controllers/submission.js @@ -459,7 +459,7 @@ class submission { } async round_lb(req,res){ - const {round} = req.body; + const {round} = req.params; const QID = await questiondb.find({round : round},"_id"); let question = []; QID.forEach((ele) => question.push(ele._id.toString())); @@ -481,15 +481,14 @@ class submission { let items = Object.keys(leaderboard).map(function(key) { return [key, leaderboard[key]]; }); - console.log(items); items.sort(function(a,b){ console.log(a[1][0]); if(a[1][0]>b[1][0]) return -1; if(a[1][0]b[1][1]) return -1; - if(a[1][1]b[1][1]) return 1; + if(a[1][1] { submit.endtest(req, res); }); -router.get("/round_lb", verifyAdminToken, (req, res)=> { +router.get("/round_lb/:round", verifyAdminToken, (req, res)=> { submit.round_lb(req,res); });