Skip to content

Commit c038b47

Browse files
committed
Merge pull request #9 from radify/handle-untagged-entries
Handle untagged entries
2 parents f93c723 + ef3268e commit c038b47

File tree

4 files changed

+136
-13
lines changed

4 files changed

+136
-13
lines changed

fixtures/mostly-untagged.ics

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
BEGIN:VCALENDAR
2+
PRODID:-//Google Inc//Google Calendar 70.9054//EN
3+
VERSION:2.0
4+
CALSCALE:GREGORIAN
5+
METHOD:PUBLISH
6+
X-WR-CALNAME:Gavin Test Time Tracking
7+
X-WR-TIMEZONE:Europe/London
8+
X-WR-CALDESC:To test my ical software
9+
BEGIN:VEVENT
10+
DTSTART:20150506T113000Z
11+
DTEND:20150506T173000Z
12+
DTSTAMP:20150601T214818Z
13+
UID:jaf9dur4v611bg5oci2nrime3g@google.com
14+
CREATED:20150508T084343Z
15+
DESCRIPTION:
16+
LAST-MODIFIED:20150508T084343Z
17+
LOCATION:
18+
SEQUENCE:0
19+
STATUS:CONFIRMED
20+
SUMMARY:notags
21+
TRANSP:OPAQUE
22+
END:VEVENT
23+
BEGIN:VEVENT
24+
DTSTART:20150506T073000Z
25+
DTEND:20150506T110000Z
26+
DTSTAMP:20150601T214818Z
27+
UID:na28627isf4g647eqlf7tn6n78@google.com
28+
CREATED:20150508T084332Z
29+
DESCRIPTION:
30+
LAST-MODIFIED:20150508T084333Z
31+
LOCATION:
32+
SEQUENCE:0
33+
STATUS:CONFIRMED
34+
SUMMARY:meeting and emails
35+
TRANSP:OPAQUE
36+
END:VEVENT
37+
BEGIN:VEVENT
38+
DTSTART:20150504T130000Z
39+
DTEND:20150504T170000Z
40+
DTSTAMP:20150601T214818Z
41+
UID:pi8ddn7ag9lokp472k7645813c@google.com
42+
CREATED:20150508T084323Z
43+
DESCRIPTION:
44+
LAST-MODIFIED:20150508T084323Z
45+
LOCATION:
46+
SEQUENCE:0
47+
STATUS:CONFIRMED
48+
SUMMARY:sprint planning
49+
TRANSP:OPAQUE
50+
END:VEVENT
51+
BEGIN:VEVENT
52+
DTSTART:20150504T080000Z
53+
DTEND:20150504T123000Z
54+
DTSTAMP:20150601T214818Z
55+
UID:9kf9tfbhmt5720ksai6pa99ps0@google.com
56+
CREATED:20150506T155217Z
57+
DESCRIPTION:
58+
LAST-MODIFIED:20150508T084314Z
59+
LOCATION:
60+
SEQUENCE:1
61+
STATUS:CONFIRMED
62+
SUMMARY:Refactoring
63+
TRANSP:OPAQUE
64+
END:VEVENT
65+
BEGIN:VEVENT
66+
DTSTART:20150505T120000Z
67+
DTEND:20150505T163000Z
68+
DTSTAMP:20150601T214818Z
69+
UID:45g3cidmcdgjh7tms6kop0dp94@google.com
70+
CREATED:20150506T155212Z
71+
DESCRIPTION:
72+
LAST-MODIFIED:20150508T084258Z
73+
LOCATION:
74+
SEQUENCE:3
75+
STATUS:CONFIRMED
76+
SUMMARY:[project-a] debugging
77+
TRANSP:OPAQUE
78+
END:VEVENT
79+
BEGIN:VEVENT
80+
DTSTART:20150505T073000Z
81+
DTEND:20150505T110000Z
82+
DTSTAMP:20150601T214818Z
83+
UID:6j8qt69apv47f4c5a274kfnmtk@google.com
84+
CREATED:20150506T155207Z
85+
DESCRIPTION:
86+
LAST-MODIFIED:20150508T084257Z
87+
LOCATION:
88+
SEQUENCE:2
89+
STATUS:CONFIRMED
90+
SUMMARY:[project-a] Updating documentation
91+
TRANSP:OPAQUE
92+
END:VEVENT
93+
END:VCALENDAR

icalstats.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@ function dateFromUTC() {
66
return new Date(utcDate);
77
}
88

9+
describe('handling of untagged elements', function() {
10+
11+
var fixture;
12+
13+
// applied before each nested describe()
14+
beforeEach(function() {
15+
fixture = ical.parseFile('./fixtures/mostly-untagged.ics');
16+
iCalStats.load(fixture, '2015-05-01', '2015-06-05');
17+
});
18+
19+
describe('getHighLevelBreakdown()', function() {
20+
it('groups untagged elements into an untagged collection', function() {
21+
var hlb = iCalStats.getHighLevelBreakdown();
22+
23+
expect(hlb.untagged).toEqual(18);
24+
expect(hlb.project).toEqual(8);
25+
26+
});
27+
});
28+
29+
describe('getTree()', function() {
30+
it('groups all untagged elements into a high level collection', function() {
31+
var tree = iCalStats.getTree();
32+
expect(tree.untagged.value).toEqual(18);
33+
expect(tree.untagged.notags.value).toEqual(6);
34+
35+
expect(tree.untagged['meeting_and_emails'].value).toEqual(3.5);
36+
expect(tree.untagged['sprint_planning'].value).toEqual(4);
37+
});
38+
});
39+
});
40+
941
describe('iCalStats Library Test Suite:', function() {
1042

1143
var fixture;

src/icalstats.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
var _ = require('lodash');
44

55
function extractTags(event) {
6-
if (!event.summary || event.summary === '') {
7-
return ['no-tags'];
6+
var summary = event.summary.replace(/ /g, '_');
7+
if (!summary || summary === '') {
8+
return ['untagged-' + summary];
89
}
910

10-
var regex = /\[([a-zA-Z\.\s\-]*?)\]/g;
11-
var tags = event.summary.match(regex);
11+
// get everything that looks like a tag
12+
var tags = summary.match(/\[([a-zA-Z0-9\_\.\s\-]*?)\]/g);
1213

13-
if (!tags || tags.length === 0) {
14-
return ['no-tags'];
14+
if (_.isEmpty(tags)) {
15+
tags = ['untagged-' + summary];
1516
}
1617

17-
for (var i = 0; i < tags.length; i++) {
18-
tags[i] = tags[i].toLowerCase().replace('[', '').replace(']', '');
19-
}
20-
21-
return tags;
18+
return _(tags).map(function(tag) {
19+
return tag.toLowerCase().replace('[', '').replace(']', '').replace(/ /g, '_');
20+
}).value();
2221
}
2322

2423
function getLengthInHours(event) {
@@ -65,7 +64,6 @@
6564
}
6665
}
6766

68-
6967
function inDateRange(ev) {
7068
if (ev.start < filterStartDate) {
7169
return false;

0 commit comments

Comments
 (0)