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..
22 // read the lines, and fill in the 'spans'
24 for (var i = 0; i < flines.length; i++) {
25 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
26 //print(JSON.stringify(xl));
27 for (var ii=1; ii< xl.length; ii+=2) {
29 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
31 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
32 lines[p-1].spanMin = lines[p-1].span/60000;
41 //print(JSON.stringify(lines,null,4));
45 for (var i = 0; i < lines.length; i++) {
47 var hour = line.start.format('H');
49 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
50 line.project = 'LONGIDLE';
53 var project = line.project;
54 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
55 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
56 { total : 0, items : [] }
57 : hours[hour][project];
58 hours[hour][project].total += line.span;
59 hours[hour][project].items.push(line);
64 parseLine : function(l)
66 var ret = { cmd : false, line : l, span : 0 };
67 var ar = l.split(/\s+/);
68 //print(JSON.stringify(ar));
70 var time = ar.shift();
71 //print("time: " + time);
73 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
76 while (ret.cmd === false) {
79 if (ta[0] != '-') { //hopfully withc catch stuff.
84 // just assume it's the last bit..
86 throw "invalid line: " + l;
93 ret.title = ar.join(' ');
94 if (ret.title == 'IDLE') {
101 if (typeof(this[ret.cmd])=='undefined') {
102 ret.project = 'Unknown';
104 print( "Unknown application: " + ret.line);
105 throw { error : "TEST"};
107 if (typeof(this[ret.cmd])=='string') {
108 ret.project = this[ret.cmd]
119 '/usr/bin/perl' : function(ret) {
120 if (ret.title.match(/^PAC/)) {
121 ret.project = 'Unknown';
124 throw "Unknown match: " + ret.line;
126 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
127 '/usr/lib/chromium/chromium' : function (ret) {
131 case (ret.title.match(/Media Clipping Portal/)):
132 ret.project = 'Media Outreach';
136 ret.project = 'Browsing';
141 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
142 var l = ret.title.match(/Project\s+(^\)+)/);
144 ret.project="Unknown";
147 throw "Unknown match: " + ret.line;
149 'guake' : 'Local Terminal',
154 //print(Seed.argv[2]);Seed.quit();
155 if (typeof(Seed.argv[2]) == 'undefined') {
156 print("pick a date");
161 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
162 var totals = { work : 0 , idle: 0}
164 for (var p in res[h]) {
166 var idletime = Math.floor(res[h][p].total/60000) ;
167 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m IDLE' );
169 totals.idle += idletime;
174 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
175 totals.work += Math.floor(res[h][p].total/60000) ;
176 for (var k in res[h][p].items) {
178 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
186 print("\nIDLE : " +(totals.idle/60).toFixed(2) +"h" );
187 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
194 // summarize each hour
196 //convert line into 'Project / filename'