2 var File = imports.File.File;
11 var home = GLib.get_home_dir();
13 var flines = File.read( home + '/.gitlog' + date.format('/Y/m/d') + '.log').split("\n");
14 // first just convert them..
15 // we had an old bug that did not put line breaks in there..
16 // however 00:00:00: is pretty distinct, so let'st try and split on it..
21 for (var i = 0; i < flines.length; i++) {
22 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
23 //print(JSON.stringify(xl));
24 for (var ii=1; ii< xl.length; ii+=2) {
26 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
28 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
37 for (var i = 0; i < lines.length; i++) {
39 var hour = hours[line].start.format('H');
40 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
41 hours[hour][project] = (typeof(hours[project]) == 'undefined') ?
42 { total : 0, items : [] }
44 hours[hour][project].total += line.span;
45 hours[hour][project].items.push(line);
50 parseLine : function(l)
52 var ret = { cmd : false, line : l };
53 var ar = l.split(/\s+/);
54 print(JSON.stringify(ar));
56 var time = ar.shift();
57 print("time: " + time);
59 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
62 while (ret.cmd === false) {
65 if (ta[0] != '-') { //hopfully withc catch stuff.
70 // just assume it's the last bit..
72 throw "invalid line: " + l;
79 ret.title = ar.join(' ');
80 if (ret.title == 'IDLE') {
87 if (typeof(this[ret.cmd])=='undefined') {
88 throw "Unknown application: " + ret.line;
90 if (typeof(this[ret.cmd])=='string') {
91 ret.project = this[ret.cmd]
102 '/usr/bin/perl' : function(ret) {
103 if (ret.title.match(/^PAC/)) {
104 ret.project = 'Unknown';
107 throw "Unknown match: " + ret.line;
109 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
110 '/usr/lib/chromium/chromium' : function (ret) {
114 case (ret.title.match(/Media Clipping Portal/)):
115 ret.project = 'Media Outreach';
119 ret.project = 'Browsing';
124 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
125 var l = ret.title.match(/Project\s+(^\)+)/);
128 throw "Unknown match: " + ret.line;
130 'guake' : 'Local Terminal',
135 var res = GitLogParser.parse(xDate.Date.parseDate('2012-07-31', 'Y-m-d'));
136 print(JSON.stringify(res,null,4));
142 // summarize each hour
144 //convert line into 'Project / filename'