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';
23 var flines = File.read( filename ).split("\n");
25 // first just convert them..
26 // we had an old bug that did not put line breaks in there..
27 // however 00:00:00: is pretty distinct, so let'st try and split on it..
33 // read the lines, and fill in the 'spans'
35 for (var i = 0; i < flines.length; i++) {
37 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
39 //print(JSON.stringify(xl));
40 for (var ii=1; ii< xl.length; ii+=2) {
42 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
44 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
45 lines[p-1].spanMin = lines[p-1].span/60000;
55 //print(JSON.stringify(lines,null,4));
65 for (var i = 0; i < lines.length; i++) {
67 var hour = line.start.format('H');
69 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
70 line.project = 'LONGIDLE';
72 if (line.project == 'IDLE' || line.project == 'LONGIDLE') {
73 line.desc = line.project;
76 var project = line.project;
77 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
78 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
79 { total : 0, items : [] }
80 : hours[hour][project];
81 hours[hour][project].total += line.span;
82 hours[hour][project].items.push(line);
84 shours[hour] = (typeof(shours[hour]) == 'undefined') ? {} : shours[hour];
85 shours[hour][line.desc] = (typeof(shours[hour][line.desc] ) == 'undefined') ? 0 : shours[hour][line.desc] ;
86 shours[hour][line.desc] += line.span;
93 parseLine : function(l)
95 var ret = { cmd : false, line : l, span : 0 };
96 var ar = l.split(/\s+/);
97 //print(JSON.stringify(ar));
100 var time = ar.shift();
102 ret.desc = ar.join(' ');
104 //print("time: " + time);
106 //ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
107 ret.start = xDate.Date.parseDate(
108 (this.date ? this.date.format('Y-m-d') :'2013-01-01') +
109 ' ' + time, 'Y-m-d H:i:s');
111 while (ret.cmd === false) {
114 if (ta[0] != '-') { //hopfully withc catch stuff.
119 // just assume it's the last bit..
121 throw "invalid line: " + l;
128 ret.title = ar.join(' ');
129 if (ret.title == 'IDLE') {
130 ret.project = 'IDLE';
136 if (typeof(this[ret.cmd])=='undefined') {
137 ret.project = 'Unknown';
139 print( "Unknown application: " + ret.line);
140 throw { error : "TEST"};
145 if (typeof(this[ret.cmd])=='string') {
146 ret.project = this[ret.cmd]
157 '/usr/bin/perl' : function(ret) {
158 if (ret.title.match(/^PAC/)) {
159 ret.project = 'Unknown';
163 throw "Unknown match: " + ret.line;
165 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
166 '/usr/lib/chromium/chromium' : function (ret) {
170 case (ret.title.match(/Media Clipping Portal/)):
171 ret.project = 'Media Outreach';
175 ret.project = 'Browsing';
180 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
181 var l = ret.title.match(/Project\s+(^\)+)/);
183 ret.project="Unknown";
186 throw "Unknown match: " + ret.line;
188 'guake' : 'Local Terminal',
193 //print(Seed.argv[2]);Seed.quit();
194 if (typeof(Seed.argv[2]) == 'undefined') {
195 print("pick a date");
199 var res = GitLogParser.parse( Seed.argv[2][0] == '/' ? Seed.argv[2] : xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
200 var totals = { work : 0 , idle: 0, shortidle : 0}
202 for (var p in res[h]) {
203 if (p == 'LONGIDLE') {
204 var idletime = Math.floor(res[h][p].total/60000) ;
205 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
206 totals.idle += idletime;
212 var idletime = Math.floor(res[h][p].total/60000) ;
213 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
214 totals.shortidle += idletime;
221 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
222 totals.work += Math.floor(res[h][p].total/60000) ;
223 for (var k in res[h][p].items) {
225 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
235 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
236 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
238 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
242 for (var h in GitLogParser.shours) {
245 for (var desc in GitLogParser.shours[h]) {
246 htot += (GitLogParser.shours[h][desc]/60000).toFixed(2)*1;
247 hsum.push({ desc : desc, tot : (GitLogParser.shours[h][desc]/60000).toFixed(2)*1 })
249 hsum.sort(function(a,b) { if (a.tot == b.tot) { return 0; } return a.tot < b.tot ? 1 : -1 });
250 print("\n\n" + h+': Total (' + htot +')');
251 hsum.forEach(function(r) {
252 print (" " + r.tot + " : " + r.desc);
258 //print(JSON.stringify(GitLogParser.shours,null,4));
266 // summarize each hour
268 //convert line into 'Project / filename'