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';
25 print(File.read(filename));
26 var flines = File.read( filename ).split("\n");
28 // first just convert them..
29 // we had an old bug that did not put line breaks in there..
30 // however 00:00:00: is pretty distinct, so let'st try and split on it..
36 // read the lines, and fill in the 'spans'
38 for (var i = 0; i < flines.length; i++) {
40 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
42 //print(JSON.stringify(xl));
43 for (var ii=1; ii< xl.length; ii+=2) {
45 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
47 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
48 lines[p-1].spanMin = lines[p-1].span/60000;
58 //print(JSON.stringify(lines,null,4));
68 for (var i = 0; i < lines.length; i++) {
70 var hour = line.start.format('H');
72 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
73 line.project = 'LONGIDLE';
75 if (line.project == 'IDLE' || line.project == 'LONGIDLE') {
76 line.desc = line.project;
79 var project = line.project;
80 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
81 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
82 { total : 0, items : [] }
83 : hours[hour][project];
84 hours[hour][project].total += line.span;
85 hours[hour][project].items.push(line);
87 shours[hour] = (typeof(shours[hour]) == 'undefined') ? {} : shours[hour];
88 shours[hour][line.desc] = (typeof(shours[hour][line.desc] ) == 'undefined') ? 0 : shours[hour][line.desc] ;
89 shours[hour][line.desc] += line.span;
96 parseLine : function(l)
98 var ret = { cmd : false, line : l, span : 0 };
99 var ar = l.split(/\s+/);
100 //print(JSON.stringify(ar));
103 var time = ar.shift();
105 ret.desc = ar.join(' ');
107 //print("time: " + time);
109 //ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
110 ret.start = xDate.Date.parseDate(
111 (this.date ? this.date.format('Y-m-d') :'2013-01-01') +
112 ' ' + time, 'Y-m-d H:i:s');
114 while (ret.cmd === false) {
117 if (ta[0] != '-') { //hopfully withc catch stuff.
122 // just assume it's the last bit..
124 throw "invalid line: " + l;
131 ret.title = ar.join(' ');
132 if (ret.title == 'IDLE') {
133 ret.project = 'IDLE';
139 if (typeof(this[ret.cmd])=='undefined') {
140 ret.project = 'Unknown';
142 print( "Unknown application: " + ret.line);
143 throw { error : "TEST"};
148 if (typeof(this[ret.cmd])=='string') {
149 ret.project = this[ret.cmd]
160 '/usr/bin/perl' : function(ret) {
161 if (ret.title.match(/^PAC/)) {
162 ret.project = 'Unknown';
166 throw "Unknown match: " + ret.line;
168 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
169 '/usr/lib/chromium/chromium' : function (ret) {
173 case (ret.title.match(/Media Clipping Portal/)):
174 ret.project = 'Media Outreach';
178 ret.project = 'Browsing';
183 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
184 var l = ret.title.match(/Project\s+(^\)+)/);
186 ret.project="Unknown";
189 throw "Unknown match: " + ret.line;
191 'guake' : 'Local Terminal',
196 //print(Seed.argv[2]);Seed.quit();
197 if (typeof(Seed.argv[2]) == 'undefined') {
198 print("pick a date");
202 var res = GitLogParser.parse( Seed.argv[2][0] == '/' ? Seed.argv[2] : xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
203 var totals = { work : 0 , idle: 0, shortidle : 0}
205 for (var p in res[h]) {
206 if (p == 'LONGIDLE') {
207 var idletime = Math.floor(res[h][p].total/60000) ;
208 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
209 totals.idle += idletime;
215 var idletime = Math.floor(res[h][p].total/60000) ;
216 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
217 totals.shortidle += idletime;
224 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
225 totals.work += Math.floor(res[h][p].total/60000) ;
226 for (var k in res[h][p].items) {
228 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
238 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
239 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
241 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
245 for (var h in GitLogParser.shours) {
248 for (var desc in GitLogParser.shours[h]) {
249 htot += (GitLogParser.shours[h][desc]/60000).toFixed(2)*1;
250 hsum.push({ desc : desc, tot : (GitLogParser.shours[h][desc]/60000).toFixed(2)*1 })
252 hsum.sort(function(a,b) { if (a.tot == b.tot) { return 0; } return a.tot < b.tot ? 1 : -1 });
253 print("\n\n" + h+': Total (' + htot +')');
254 hsum.forEach(function(r) {
255 print (" " + r.tot + " : " + r.desc);
261 //print(JSON.stringify(GitLogParser.shours,null,4));
269 // summarize each hour
271 //convert line into 'Project / filename'