2 var File = imports.File.File;
11 var home = GLib.get_home_dir();
12 print( "READING FILE");
13 var flines = File.read( home + '/.gitlog' + date.format('/Y/m/d') + '.log').split("\n");
15 // first just convert them..
16 // we had an old bug that did not put line breaks in there..
17 // however 00:00:00: is pretty distinct, so let'st try and split on it..
23 // read the lines, and fill in the 'spans'
25 for (var i = 0; i < flines.length; i++) {
27 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
29 //print(JSON.stringify(xl));
30 for (var ii=1; ii< xl.length; ii+=2) {
32 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
34 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
35 lines[p-1].spanMin = lines[p-1].span/60000;
45 //print(JSON.stringify(lines,null,4));
49 for (var i = 0; i < lines.length; i++) {
51 var hour = line.start.format('H');
53 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
54 line.project = 'LONGIDLE';
57 var project = line.project;
58 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
59 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
60 { total : 0, items : [] }
61 : hours[hour][project];
62 hours[hour][project].total += line.span;
63 hours[hour][project].items.push(line);
68 parseLine : function(l)
70 var ret = { cmd : false, line : l, span : 0 };
71 var ar = l.split(/\s+/);
72 print(JSON.stringify(ar));
74 var time = ar.shift();
75 //print("time: " + time);
77 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
80 while (ret.cmd === false) {
83 if (ta[0] != '-') { //hopfully withc catch stuff.
88 // just assume it's the last bit..
90 throw "invalid line: " + l;
97 ret.title = ar.join(' ');
98 if (ret.title == 'IDLE') {
105 if (typeof(this[ret.cmd])=='undefined') {
106 ret.project = 'Unknown';
108 print( "Unknown application: " + ret.line);
109 throw { error : "TEST"};
111 if (typeof(this[ret.cmd])=='string') {
112 ret.project = this[ret.cmd]
123 '/usr/bin/perl' : function(ret) {
124 if (ret.title.match(/^PAC/)) {
125 ret.project = 'Unknown';
128 throw "Unknown match: " + ret.line;
130 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
131 '/usr/lib/chromium/chromium' : function (ret) {
135 case (ret.title.match(/Media Clipping Portal/)):
136 ret.project = 'Media Outreach';
140 ret.project = 'Browsing';
145 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
146 var l = ret.title.match(/Project\s+(^\)+)/);
148 ret.project="Unknown";
151 throw "Unknown match: " + ret.line;
153 'guake' : 'Local Terminal',
158 //print(Seed.argv[2]);Seed.quit();
159 if (typeof(Seed.argv[2]) == 'undefined') {
160 print("pick a date");
165 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
166 var totals = { work : 0 , idle: 0, shortidle : 0}
168 for (var p in res[h]) {
169 if (p == 'LONGIDLE') {
170 var idletime = Math.floor(res[h][p].total/60000) ;
171 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
172 totals.idle += idletime;
178 var idletime = Math.floor(res[h][p].total/60000) ;
179 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
180 totals.shortidle += idletime;
187 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
188 totals.work += Math.floor(res[h][p].total/60000) ;
189 for (var k in res[h][p].items) {
191 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
199 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
200 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
202 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
209 // summarize each hour
211 //convert line into 'Project / filename'