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

Sign up
Appearance settings

Commit a403ca0

Browse files
Show reasonable AC count in stat -c.
Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent 32aa3da commit a403ca0

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

‎lib/commands/stat.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function showCal() {
150150
const graph = [];
151151
const stats = require('../cache').get(h.KEYS.stat) || {};
152152
for (let k of _.keys(stats)) {
153-
const v = stats[k].ac || 0;
153+
const v = (stats[k]['ac.set'] || []).length;
154154
if (v === 0) continue;
155155

156156
const d = moment(k, 'YYYY-MM-DD');

‎lib/commands/submit.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ cmd.handler = function(argv) {
6666

6767
if (result.ok) {
6868
session.updateStat('ac', 1);
69+
session.updateStat('ac.set', problem.id);
6970
core.getSubmission({id: result.id}, function(e, submission) {
7071
if (e || !submission || !submission.distributionChart)
7172
return log.warn('Failed to get submission beat ratio.');

‎lib/session.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ session.updateStat = function(k, v) {
3939
const today = moment().format('YYYY-MM-DD');
4040
const stats = cache.get(h.KEYS.stat) || {};
4141
const stat = stats[today] = stats[today] || {};
42-
stat[k] = stat[k] || 0;
43-
stat[k] += v;
42+
43+
if (k.endsWith('.set')) {
44+
const s = new Set(stat[k] || []);
45+
s.add(v);
46+
stat[k] = Array.from(s);
47+
} else {
48+
stat[k] = (stat[k] || 0) + v;
49+
}
50+
4451
cache.set(h.KEYS.stat, stats);
4552
};
4653

‎test/test_session.js‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ describe('session', function() {
2323
session.__set__('moment', moment);
2424
});
2525

26+
beforeEach(function() {
27+
stats = null;
28+
});
29+
2630
describe('#updateStat', function() {
27-
it('should ok', function() {
31+
it('should update number ok', function() {
2832
now = '2017年12月13日';
2933
session.updateStat('ac', 10);
30-
assert.deepEqual(stats, {
31-
'2017年12月13日': {ac: 10}
32-
});
34+
assert.deepEqual(stats, {'2017年12月13日': {ac: 10}});
3335

3436
session.updateStat('ac', 20);
35-
assert.deepEqual(stats, {
36-
'2017年12月13日': {ac: 30}
37-
});
37+
assert.deepEqual(stats, {'2017年12月13日': {ac: 30}});
3838

3939
now = '2017年12月14日';
4040
session.updateStat('ac', 40);
@@ -43,5 +43,15 @@ describe('session', function() {
4343
'2017年12月14日': {ac: 40}
4444
});
4545
});
46+
47+
it('should update set ok', function() {
48+
now = '2017年12月13日';
49+
session.updateStat('ac.set', 101);
50+
assert.deepEqual(stats, {'2017年12月13日': {'ac.set': [101]}});
51+
session.updateStat('ac.set', 100);
52+
assert.deepEqual(stats, {'2017年12月13日': {'ac.set': [101, 100]}});
53+
session.updateStat('ac.set', 101);
54+
assert.deepEqual(stats, {'2017年12月13日': {'ac.set': [101, 100]}});
55+
});
4656
});
4757
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /