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..?
35 //print(JSON.stringify(lines,null,4));
39 for (var i = 0; i < lines.length; i++) {
41 var hour = line.start.format('H');
42 var project = line.project;
43 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
44 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
45 { total : 0, items : [] }
46 : hours[hour][project];
47 hours[hour][project].total += line.span;
48 hours[hour][project].items.push(line);
53 parseLine : function(l)
55 var ret = { cmd : false, line : l, span : 0 };
56 var ar = l.split(/\s+/);
57 //print(JSON.stringify(ar));
59 var time = ar.shift();
60 //print("time: " + time);
62 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
65 while (ret.cmd === false) {
68 if (ta[0] != '-') { //hopfully withc catch stuff.
73 // just assume it's the last bit..
75 throw "invalid line: " + l;
82 ret.title = ar.join(' ');
83 if (ret.title == 'IDLE') {
90 if (typeof(this[ret.cmd])=='undefined') {
91 ret.project = 'Unknown';
93 print( "Unknown application: " + ret.line);
94 throw { error : "TEST"};
96 if (typeof(this[ret.cmd])=='string') {
97 ret.project = this[ret.cmd]
108 '/usr/bin/perl' : function(ret) {
109 if (ret.title.match(/^PAC/)) {
110 ret.project = 'Unknown';
113 throw "Unknown match: " + ret.line;
115 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
116 '/usr/lib/chromium/chromium' : function (ret) {
120 case (ret.title.match(/Media Clipping Portal/)):
121 ret.project = 'Media Outreach';
125 ret.project = 'Browsing';
130 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
131 var l = ret.title.match(/Project\s+(^\)+)/);
133 ret.project="Unknown";
136 throw "Unknown match: " + ret.line;
138 'guake' : 'Local Terminal',
144 var res = GitLogParser.parse(xDate.Date.parseDate('2012-07-31', 'Y-m-d'));
146 for (var p in res[h]) {
148 print(h + ' ' + Math.floor(res[h][p].total/60000) +') IDLE' );
151 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
153 for (var k in res[h][p].items) {
155 print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
163 //print(JSON.stringify(res,null,4));
169 // summarize each hour
171 //convert line into 'Project / filename'