Skip to content

Commit ee0ded4

Browse files
committed
Update stat.ac when submit succeed.
Signed-off-by: Eric Wang <[email protected]>
1 parent b8d7e90 commit ee0ded4

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/commands/stat.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ var cmd = {
4343
.example(chalk.yellow('leetcode stat'), 'Show progress status')
4444
.example(chalk.yellow('leetcode stat --no-lock'), 'Show progress status without locked questions')
4545
.example(chalk.yellow('leetcode stat -t algorithms'), 'Show progress status of algorithms questions')
46-
.example(chalk.yellow('leetcode stat -g'), 'Show detailed status in graph');
46+
.example(chalk.yellow('leetcode stat -g'), 'Show detailed status in graph')
47+
.example(chalk.yellow('leetcode stat -c'), 'Show accepted status in calendar');
4748
}
4849
};
4950

lib/commands/submit.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function printLine() {
4444

4545
cmd.handler = function(argv) {
4646
session.argv = argv;
47-
4847
if (!fs.existsSync(argv.filename))
4948
return log.error('File ' + argv.filename + ' not exist!');
5049

@@ -66,8 +65,8 @@ cmd.handler = function(argv) {
6665
printLine(result, '%d/%d cases passed (%s)',
6766
result.passed, result.total, result.runtime);
6867

69-
// show beat ratio
7068
if (result.ok) {
69+
session.updateStat('ac', 1);
7170
core.getSubmission({id: result.id}, function(e, submission) {
7271
if (e || !submission || !submission.distributionChart)
7372
return log.warn('Failed to get submission beat ratio.');

lib/session.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var moment = require('moment');
12
var _ = require('underscore');
23

34
var cache = require('./cache');
@@ -32,4 +33,14 @@ session.isLogin = function() {
3233
return this.getUser() !== null;
3334
};
3435

36+
session.updateStat = function(k, v) {
37+
// TODO: use other storage if too many stat data
38+
var today = moment().format('YYYY-MM-DD');
39+
var stats = cache.get(h.KEYS.stat) || {};
40+
var stat = stats[today] = stats[today] || {};
41+
stat[k] = stat[k] || 0;
42+
stat[k] += v;
43+
cache.set(h.KEYS.stat, stats);
44+
};
45+
3546
module.exports = session;

0 commit comments

Comments
 (0)