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 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
60 while (ret.cmd !== false) {
62 if (ta == 'false' || ta[0] == '/') {
67 throw "invalid line: " + l;
71 ret.title = ar.join(' ');
72 if (ret.title == 'IDLE') {
79 if (typeof(this[ret.cmd])=='undefined') {
80 throw "Unknown application: " + ret.line;
82 if (typeof(this[ret.cmd])=='string') {
83 ret.project = this[ret.cmd]
94 '/usr/bin/perl' : function(ret) {
95 if (ret.title.match(/^PAC/)) {
96 ret.project = 'Unknown';
99 throw "Unknown match: " + ret.line;
101 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
102 '/usr/lib/chromium/chromium' : function (ret) {
106 case (ret.title.match(/Media Clipping Portal/)):
107 ret.project = 'Media Outreach';
111 ret.project = 'Browsing';
116 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
117 var l = ret.title.match(/Project\s+(^\)+)/);
120 throw "Unknown match: " + ret.line;
122 'guake' : 'Local Terminal',
127 var res = GitLogParser.parse(xDate.Date.parseDate('2012-07-31', 'Y-m-d'));
128 print(JSON.stringify(res,null,4));
134 // summarize each hour
136 //convert line into 'Project / filename'