Skip to content

Commit 4ce4b78

Browse files
committed
Add heatmap graph for 'stat' command.
Signed-off-by: Eric Wang <[email protected]>
1 parent acf5570 commit 4ce4b78

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

lib/commands/stat.js

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var log = require('loglevel');
22
var sprintf = require('sprintf-js').sprintf;
3+
var _ = require('underscore');
34

45
var chalk = require('../chalk');
56
var core = require('../core');
@@ -8,6 +9,12 @@ var cmd = {
89
command: 'stat',
910
desc: 'show statistics',
1011
builder: {
12+
graph: {
13+
alias: 'g',
14+
type: 'boolean',
15+
default: false,
16+
describe: 'Show graphic statistics'
17+
}
1118
}
1219
};
1320

@@ -53,11 +60,47 @@ function showSummary(problems) {
5360
log.info(prettyLine('Hard', statsNoLock.acHard, statsNoLock.allHard));
5461
}
5562

63+
function showGraph(problems) {
64+
var graph = [];
65+
_.each(problems, function(problem) {
66+
if (problem.state === 'ac') {
67+
graph[problem.id] = chalk.green('█');
68+
} else if (problem.state === 'notac') {
69+
graph[problem.id] = chalk.red('▓');
70+
} else {
71+
graph[problem.id] = '░';
72+
}
73+
});
74+
75+
log.info(sprintf('%13d%13d%13d%13d%13d', 10, 20, 30, 40, 50));
76+
77+
var line = [sprintf(' %03d ', 1)];
78+
for (var i = 1, n = graph.length; i < n; ++i) {
79+
line.push(graph[i] || ' ');
80+
if (i % 10 === 0) line.push(' ');
81+
if (i % 50 === 0 || i === n) {
82+
log.info(line.join(''));
83+
line = [sprintf(' %03d ', i)];
84+
}
85+
}
86+
87+
log.info();
88+
log.info(sprintf('%7s%s%3s%s%3s%s',
89+
' ', chalk.green('█ Accepted'),
90+
' ', chalk.red('▓ Not Accepted'),
91+
' ', '░ Remaining'));
92+
log.info();
93+
}
94+
5695
cmd.handler = function(argv) {
5796
core.getProblems(function(e, problems) {
5897
if (e) return log.fail(e);
5998

60-
showSummary(problems);
99+
if (argv.graph) {
100+
showGraph(problems);
101+
} else {
102+
showSummary(problems);
103+
}
61104
});
62105
};
63106

0 commit comments

Comments
 (0)