Skip to content

Commit

Permalink
Merge pull request #55 from Killerrekt/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Emerald-Wolf authored Sep 23, 2023
2 parents c60cbb2 + 8f9a0c3 commit 04faef6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion api/controllers/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function getByRound(req, res) {
async function deleteQuestion(req, res) {
try {
const deletedItem = await ques.findByIdAndDelete(req.params.id);
console.log(req.body.id);
//console.log(req.body.id);

const testCases = await TestCaseModel.find()
.where(`_id: ${req.params.id}`)
Expand Down
36 changes: 18 additions & 18 deletions api/controllers/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ class submission {
expected_output: Buffer.from(current.expectedOutput, "binary").toString(
"base64",
),
cpu_time_limit: current.time * multipler < 15
? current.time * multipler
: 15,
cpu_time_limit:
current.time * multipler < 15 ? current.time * multipler : 15,
memory:
current.memory * multipler<2048 ? 2048 : current.memory*multipler
//redirect_stderr_to_stdout: true,
});
const group = current.group;
Expand Down Expand Up @@ -198,7 +199,7 @@ class submission {
"/submissions/batch?tokens=" +
str.toString() +
"&base64_encoded=true&fields=status_id,stderr,compile_output,expected_output,stdout,time";
console.log(url);
//console.log(url);
let completion = false;
let data_sent_back = {
error: [false, false, false, false], //false means it passed that grp
Expand Down Expand Up @@ -308,10 +309,9 @@ 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;
console.log(data_sent_back.Score, 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
if (data_sent_back.Score == score) {
Expand All @@ -326,6 +326,7 @@ class submission {
await this.create_score(reg_no);
} else {
data_sent_back.Sub_db = "No changes in Sub DB";
await this.create_score(reg_no);
}

//Creation of allPassesAt field when all testcases are passed
Expand Down Expand Up @@ -366,8 +367,7 @@ class submission {
]);
const score = ele[0].total;
return User.updateOne({ regNo: user }, { score: score })
.then(() => console.log("Score = " + score))
.catch(() => console.error("Error occured while saving scores"));
.catch(() => console.error("Error occured while saving scores \nRegno :"+regNo+"\tScore :"+score));
}

async get_reg_no(req, res) {
Expand All @@ -394,12 +394,12 @@ class submission {

async get_all(req, res) {
const { regno } = req.params;
console.log(regno);
//console.log(regno);
const record = await submission_db.find(
{ regNo: regno },
"code score question_id lastResults language_id",
);
console.log(record);
//console.log(record);
if (record.length == 0) {
res.status(400).json({
Error: "Invalid regNo",
Expand Down Expand Up @@ -485,12 +485,12 @@ class submission {
let items = Object.keys(leaderboard).map(function (key) {
return [key, leaderboard[key]];
});
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][0]) return 1;
if (a[1][1] > b[1][1]) return 1;
if (a[1][1] < b[1][1]) return -1;
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][0]) return 1;
if(a[1][1]>b[1][1]) return 1;
if(a[1][1]<b[1][1]) return -1;
});
res.status(200).json(items);
}
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/testCasesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const updateTestCase = async (req, res) => {
}

const updated = await QuestionModel.findById(question);
console.log(updated);
//console.log(updated);
updated.testCases.push(testCase._id);
await updated.save();

Expand Down
2 changes: 1 addition & 1 deletion api/middleware/jwtMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async function verifyQuestion(req, res, next) {
try {
const user = await User.findOne({ regNo: req.user.regNo });
const ques = await Ques.findOne({ _id: question_id });
console.log(ques);
//console.log(ques);
if (!ques) {
return res.status(400).json({ message: "Question not found" });
}
Expand Down

0 comments on commit 04faef6

Please sign in to comment.