2 var File = imports.File.File;
12 parse : function(date)
15 if (typeof(date) == 'object') {
17 var home = GLib.get_home_dir();
18 //print( "READING FILE");
19 filename = home + '/.gitlog' + date.format('/Y/m/d') + '.log';
24 var flines = File.read( filename ).split("\n");
26 // first just convert them..
27 // we had an old bug that did not put line breaks in there..
28 // however 00:00:00: is pretty distinct, so let'st try and split on it..
34 // read the lines, and fill in the 'spans'
36 for (var i = 0; i < flines.length; i++) {
38 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
40 //print(JSON.stringify(xl));
41 for (var ii=1; ii< xl.length; ii+=2) {
43 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
45 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
46 lines[p-1].spanMin = lines[p-1].span/60000;
56 //print(JSON.stringify(lines,null,4));
66 for (var i = 0; i < lines.length; i++) {
68 var hour = line.start.format('H');
70 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
71 line.project = 'LONGIDLE';
73 if (line.project == 'IDLE' || line.project == 'LONGIDLE') {
74 line.desc = line.project;
77 var project = line.project;
78 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
79 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
80 { total : 0, items : [] }
81 : hours[hour][project];
82 hours[hour][project].total += line.span;
83 hours[hour][project].items.push(line);
85 hours[-1] = (typeof(hours[-1]) == 'undefined') ? {} : hours[-1];
86 hours[-1][project] = (typeof(hours[-1][project]) == 'undefined') ?
87 { total : 0, items : {} }
90 hours[-1][project].total += line.span;
91 hours[-1][project].items[line.desc] = (typeof(hours[-1][project].items[line.desc]) == 'undefined' ?
92 0 : hours[-1][project].items[line.desc]) + line.span;
94 shours[hour] = (typeof(shours[hour]) == 'undefined') ? {} : shours[hour];
95 shours[hour][line.desc] = (typeof(shours[hour][line.desc] ) == 'undefined') ? 0 : shours[hour][line.desc] ;
96 shours[hour][line.desc] += line.span;
101 this.shours = shours;
105 parseLine : function(l)
107 var ret = { cmd : false, line : l, span : 0 };
108 var ar = l.split(/\s+/);
109 //print(JSON.stringify(ar));
112 var time = ar.shift();
114 ret.desc = ar.join(' ');
116 //print("time: " + time);
118 //ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
119 ret.start = xDate.Date.parseDate(
120 (this.date ? this.date.format('Y-m-d') :'2013-01-01') +
121 ' ' + time, 'Y-m-d H:i:s');
123 while (ret.cmd === false) {
126 if (ta[0] != '-') { //hopfully withc catch stuff.
131 // just assume it's the last bit..
133 throw "invalid line: " + l;
140 ret.title = ar.join(' ');
141 if (ret.title == 'IDLE') {
142 ret.project = 'IDLE';
145 ret.project = 'Unknown';
147 for(var proj in this.regexes) {
148 for(var r in this.regexes[proj]) {
149 if (ret.line.match(this.regexes[proj][r])) {
150 //print("Match " + proj + " on " + r + ret.line + )
155 if (ret.project != 'Unknown') {
162 if (typeof(this[ret.cmd])=='undefined') {
163 ret.project = 'Unknown';
165 print( "Unknown application: " + ret.line);
166 throw { error : "TEST"};
171 if (typeof(this[ret.cmd])=='string') {
172 ret.project = this[ret.cmd]
185 'HPA' : [ /web.hpasite/, /Roo Application Builder - Site/ ],
186 'MediaOut' : [ /app\.WorkerBee/, /web.MediaOut/,
187 /media-outreach/ , /Press Release Image Portal/, /Media Outreach Feed/ , /PressRelease/],
188 'Habito' : [ /Interspire/ ],
189 'Hebe' :[ /web.hhyc_membership_system/ ]
195 '/usr/bin/perl' : function(ret) {
196 if (ret.title.match(/^PAC/)) {
197 ret.project = 'Unknown';
201 throw "Unknown match: " + ret.line;
203 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
204 '/usr/lib/chromium/chromium' : function (ret) {
208 case (ret.title.match(/Media Clipping Portal/)):
209 ret.project = 'Media Outreach';
213 ret.project = 'Browsing';
218 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
219 var l = ret.title.match(/Project\s+(^\)+)/);
221 ret.project="Unknown";
224 throw "Unknown match: " + ret.line;
226 'guake' : 'Local Terminal',
231 //print(Seed.argv[2]);Seed.quit();
232 if (typeof(Seed.argv[2]) == 'undefined') {
233 print("pick a date");
237 var res = GitLogParser.parse( Seed.argv[2][0] == '/' ? Seed.argv[2] : xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
238 var totals = { work : 0 , idle: 0, shortidle : 0};
241 for (var p in res[h]) {
242 if (p == 'LONGIDLE') {
243 var idletime = Math.floor(res[h][p].total/60000) ;
244 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
245 totals.idle += idletime;
251 var idletime = Math.floor(res[h][p].total/60000) ;
252 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
253 totals.shortidle += idletime;
260 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
261 totals.work += Math.floor(res[h][p].total/60000) ;
265 print( "\n" + p + ':' + Math.floor(res[h][p].total/60000) + 'm');
267 if (p != 'Unknown') {
269 for (var k in res[h][p].items) {
271 print( ' ' + Math.floor(res[h][p].items[k]/60000) +'m ' + k );
276 for (var k in res[h][p].items) {
277 unknown.push({ desc : k , tot : (res[h][p].items[k]/60000).toFixed(2)*1 }) ;
289 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
290 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
292 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
296 for (var h in GitLogParser.shours) {
299 for (var desc in GitLogParser.shours[h]) {
300 htot += (GitLogParser.shours[h][desc]/60000).toFixed(2)*1;
301 hsum.push({ desc : desc, tot : (GitLogParser.shours[h][desc]/60000).toFixed(2)*1 })
302 totals[desc] = (typeof(totals[desc]) == 'undefined' ? 0 : totals[desc]) + ((GitLogParser.shours[h][desc]/60000).toFixed(2)*1);
304 hsum.sort(function(a,b) { if (a.tot == b.tot) { return 0; } return a.tot < b.tot ? 1 : -1 });
305 print("\n\n" + h+': Total (' + htot +')');
306 hsum.forEach(function(r) {
307 print (" " + r.tot + " : " + r.desc);
312 unknown.sort(function(a,b) { if (a.tot == b.tot) { return 0; } return a.tot < b.tot ? 1 : -1 });
313 print("\n\nUnclassified");
314 unknown.forEach(function(r) {
315 print (" " + (r.tot.toFixed(2)*1) + " : " + r.desc);
318 //print(JSON.stringify(GitLogParser.shours,null,4));
326 // summarize each hour
328 //convert line into 'Project / filename'