Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Add beat ratio display after AC #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/commands/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ cmd.handler = function(argv) {
result.status_runtime);
log.info(INDENT + h.prettyText(line, ok));

// show beat ratio
if(ok) {
core.getSubmission({id: result.submission_id}, function(e, submission){
var beat_ratio = 0.0;
var chart = submission.distribution_chart.distribution;
var lang = submission.distribution_chart.lang;
for(i in chart) {
if (parseFloat(chart[i][0]) <= parseFloat(result.display_runtime)) {
continue;
} else {
beat_ratio += parseFloat(chart[i][1]);
}
}
line = util.format(' Your runtime beats %d %% of %s submissions',
beat_ratio.toFixed(2),
lang);
log.info(INDENT + h.prettyText(line, ok));
});
}

// show testcase
var testcase = result.input || result.last_testcase;
if (!ok && testcase) {
Expand Down
6 changes: 6 additions & 0 deletions lib/leetcode_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ leetcodeClient.getSubmission = function(submission, cb) {
if (re) {
submission.code = eval(re[1]);
}
re = body.match(/distribution_formatted:\s('[^']*')/);
if (re) {
var distributionChart = JSON.parse(eval(re[1]));
submission.distribution_chart = distributionChart;
}
return cb(null, submission);
});
};
Expand Down Expand Up @@ -273,6 +278,7 @@ function verifyResult(opts, jobs, results, cb) {
var result = JSON.parse(body);
if (result.state === 'SUCCESS') {
result.name = jobs[0].name;
result.submission_id = jobs[0].id;
results.push(result);
jobs.shift();
}
Expand Down