Skip to content

Commit

Permalink
Refactor runtime and memory percentile logic for fixing issue #114 and
Browse files Browse the repository at this point in the history
  • Loading branch information
smrook committed Feb 6, 2019
1 parent 8dc0b2a commit 1e269fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
25 changes: 9 additions & 16 deletions lib/commands/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,16 @@ cmd.handler = function(argv) {
if (result.ok) {
session.updateStat('ac', 1);
session.updateStat('ac.set', problem.fid);
core.getSubmission({id: result.id}, function(e, submission) {
if (e || !submission || !submission.distributionChart)
return log.warn('Failed to get submission beat ratio.');

const lang = submission.distributionChart.lang;
const scores = submission.distributionChart.distribution;
const myRuntime = parseFloat(result.runtime);

let ratio = 0.0;
for (let score of scores) {
if (parseFloat(score[0]) > myRuntime)
ratio += parseFloat(score[1]);
}

if (result.runtime_percentile)
printLine(result, 'Your runtime beats %d %% of %s submissions',
ratio.toFixed(2), lang);
});
result.runtime_percentile.toFixed(2), result.lang);
else
return log.warn('Failed to get runtime percentile.');
if (result.memory && result.memory_percentile)
printLine(result, 'Your memory usage beats %d %% of %s submissions (%s)',
result.memory_percentile.toFixed(2), result.lang, result.memory);
else
return log.warn('Failed to get memory percentile.');
} else {
printResult(result, 'error');
printResult(result, 'testcase');
Expand Down
20 changes: 12 additions & 8 deletions lib/plugins/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,17 @@ function verifyResult(task, queue, cb) {

function formatResult(result) {
const x = {
ok: result.run_success,
answer: result.code_answer || '',
runtime: result.status_runtime || '',
state: h.statusToName(result.status_code),
testcase: util.inspect(result.input || result.last_testcase || ''),
passed: result.total_correct || 0,
total: result.total_testcases || 0
ok: result.run_success,
answer: result.code_answer || '',
lang: result.lang,
runtime: result.status_runtime || '',
runtime_percentile: result.runtime_percentile || '',
memory: result.status_memory || '',
memory_percentile: result.memory_percentile || '',
state: h.statusToName(result.status_code),
testcase: util.inspect(result.input || result.last_testcase || ''),
passed: result.total_correct || 0,
total: result.total_testcases || 0
};

x.error = _.chain(result)
Expand Down Expand Up @@ -336,7 +340,7 @@ plugin.getSubmission = function(submission, cb) {
let re = body.match(/submissionCode:\s('[^']*')/);
if (re) submission.code = eval(re[1]);

re = body.match(/distribution_formatted:\s('[^']+')/);
re = body.match(/runtimeDistributionFormatted:\s('[^']+')/);
if (re) submission.distributionChart = JSON.parse(eval(re[1]));
return cb(null, submission);
});
Expand Down

0 comments on commit 1e269fe

Please sign in to comment.