2 var File = imports.File.File;
11 parse : function(date)
14 var home = GLib.get_home_dir();
15 print( "READING FILE");
16 var flines = File.read( home + '/.gitlog' + date.format('/Y/m/d') + '.log').split("\n");
18 // first just convert them..
19 // we had an old bug that did not put line breaks in there..
20 // however 00:00:00: is pretty distinct, so let'st try and split on it..
26 // read the lines, and fill in the 'spans'
28 for (var i = 0; i < flines.length; i++) {
30 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
32 //print(JSON.stringify(xl));
33 for (var ii=1; ii< xl.length; ii+=2) {
35 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
37 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
38 lines[p-1].spanMin = lines[p-1].span/60000;
48 //print(JSON.stringify(lines,null,4));
58 for (var i = 0; i < lines.length; i++) {
60 var hour = line.start.format('H');
62 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
63 line.project = 'LONGIDLE';
65 if (line.project == 'IDLE' || line.project == 'LONGIDLE') {
66 line.desc = line.project;
69 var project = line.project;
70 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
71 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
72 { total : 0, items : [] }
73 : hours[hour][project];
74 hours[hour][project].total += line.span;
75 hours[hour][project].items.push(line);
77 shours[hour] = (typeof(shours[hour]) == 'undefined') ? {} : shours[hour];
78 shours[hour][line.desc] = (typeof(shours[hour][line.desc] ) == 'undefined') ? 0 : shours[hour][line.desc] ;
79 shours[hour][line.desc] += line.span;
85 parseLine : function(l)
87 var ret = { cmd : false, line : l, span : 0 };
88 var ar = l.split(/\s+/);
89 //print(JSON.stringify(ar));
92 var time = ar.shift();
94 ret.desc = ar.join(' ');
96 //print("time: " + time);
98 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
101 while (ret.cmd === false) {
104 if (ta[0] != '-') { //hopfully withc catch stuff.
109 // just assume it's the last bit..
111 throw "invalid line: " + l;
118 ret.title = ar.join(' ');
119 if (ret.title == 'IDLE') {
120 ret.project = 'IDLE';
126 if (typeof(this[ret.cmd])=='undefined') {
127 ret.project = 'Unknown';
129 print( "Unknown application: " + ret.line);
130 throw { error : "TEST"};
135 if (typeof(this[ret.cmd])=='string') {
136 ret.project = this[ret.cmd]
147 '/usr/bin/perl' : function(ret) {
148 if (ret.title.match(/^PAC/)) {
149 ret.project = 'Unknown';
153 throw "Unknown match: " + ret.line;
155 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
156 '/usr/lib/chromium/chromium' : function (ret) {
160 case (ret.title.match(/Media Clipping Portal/)):
161 ret.project = 'Media Outreach';
165 ret.project = 'Browsing';
170 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
171 var l = ret.title.match(/Project\s+(^\)+)/);
173 ret.project="Unknown";
176 throw "Unknown match: " + ret.line;
178 'guake' : 'Local Terminal',
183 //print(Seed.argv[2]);Seed.quit();
184 if (typeof(Seed.argv[2]) == 'undefined') {
185 print("pick a date");
190 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
191 var totals = { work : 0 , idle: 0, shortidle : 0}
193 for (var p in res[h]) {
194 if (p == 'LONGIDLE') {
195 var idletime = Math.floor(res[h][p].total/60000) ;
196 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
197 totals.idle += idletime;
203 var idletime = Math.floor(res[h][p].total/60000) ;
204 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
205 totals.shortidle += idletime;
212 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
213 totals.work += Math.floor(res[h][p].total/60000) ;
214 for (var k in res[h][p].items) {
216 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
224 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
225 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
227 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
234 // summarize each hour
236 //convert line into 'Project / filename'