8000 Implement 'user -s'. · Johnsonys/leetcode-cli@f5a534b · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f5a534b

Browse files
committed
Implement 'user -s'.
Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent 090b22b commit f5a534b

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

lib/commands/user.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var chalk = require('chalk');
22
var prompt = require('prompt');
3+
var sprintf = require('sprintf-js').sprintf;
34

45
var core = require('../core');
56

@@ -9,15 +10,35 @@ var cmd = {
910
builder: {
1011
login: {
1112
alias: 'l',
13+
type: 'boolean',
1214
describe: 'Login leetcode.'
1315
},
1416
logout: {
1517
alias: 'L',
18+
type: 'boolean',
1619
describe: 'Logout leetcode.'
20+
},
21+
stat: {
22+
alias: 's',
23+
type: 'boolean',
24+
describe: 'Show user stats.'
1725
}
1826
}
1927
};
2028

29+
function bar(c, n) {
30+
return new Buffer(n).fill(c).toString();
31+
}
8000 32+
33+
function prettyLine(key, done, all) {
34+
var n = 30;
35+
var x = Math.ceil(n * done / all);
36+
return sprintf('%-8s %3d/%-3d (%.2f%%)\t%s%s',
37+
key, done, all, done * 100 / all,
38+
chalk.green('[' + bar(chalk.enabled ? '.' : '+', x)),
39+
chalk.red(bar('.', n - x) + ']'));
40+
}
41+
2142
cmd.handler = function(argv) {
2243
var user = null;
2344
if (argv.login) {
@@ -50,7 +71,26 @@ cmd.handler = function(argv) {
5071
if (user)
5172
console.log('You are now login as', chalk.yellow(user.name));
5273
else
53-
console.log('You are not login yet?');
74+
return console.log('You are not login yet?');
75+
76+
if (argv.stat) {
77+
core.getProblems(function(e, problems) {
78+
if (e) return console.log('Get stats failed:', e);
79+
80+
var stats = {};
81+
problems.forEach(function(problem) {
82+
var keyAll = 'all' + problem.level;
83+
var keyAC = problem.state + problem.level;
84+
stats[keyAll] = (stats[keyAll] || 0) + 1;
85+
stats[keyAC] = (stats[keyAC] || 0) + 1;
86+
});
87+
88+
console.log();
89+
console.log(prettyLine('Easy', stats.acEasy, stats.allEasy));
90+
console.log(prettyLine('Medium', stats.acMedium, stats.allMedium));
91+
console.log(prettyLine('Hard', stats.acHard, stats.allHard));
92+
});
93+
}
5494
}
5595
};
5696

0 commit comments

Comments
 (0)
0