2 var File = imports.File.File;
12 parse : function(date)
15 var home = GLib.get_home_dir();
16 print( "READING FILE");
17 var flines = File.read( home + '/.gitlog' + date.format('/Y/m/d') + '.log').split("\n");
19 // first just convert them..
20 // we had an old bug that did not put line breaks in there..
21 // however 00:00:00: is pretty distinct, so let'st try and split on it..
27 // read the lines, and fill in the 'spans'
29 for (var i = 0; i < flines.length; i++) {
31 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
33 //print(JSON.stringify(xl));
34 for (var ii=1; ii< xl.length; ii+=2) {
36 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
38 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
39 lines[p-1].spanMin = lines[p-1].span/60000;
49 //print(JSON.stringify(lines,null,4));
59 for (var i = 0; i < lines.length; i++) {
61 var hour = line.start.format('H');
63 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
64 line.project = 'LONGIDLE';
66 if (line.project == 'IDLE' || line.project == 'LONGIDLE') {
67 line.desc = line.project;
70 var project = line.project;
71 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
72 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
73 { total : 0, items : [] }
74 : hours[hour][project];
75 hours[hour][project].total += line.span;
76 hours[hour][project].items.push(line);
78 shours[hour] = (typeof(shours[hour]) == 'undefined') ? {} : shours[hour];
79 shours[hour][line.desc] = (typeof(shours[hour][line.desc] ) == 'undefined') ? 0 : shours[hour][line.desc] ;
80 shours[hour][line.desc] += line.span;
87 parseLine : function(l)
89 var ret = { cmd : false, line : l, span : 0 };
90 var ar = l.split(/\s+/);
91 //print(JSON.stringify(ar));
94 var time = ar.shift();
96 ret.desc = ar.join(' ');
98 //print("time: " + time);
100 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
103 while (ret.cmd === false) {
106 if (ta[0] != '-') { //hopfully withc catch stuff.
111 // just assume it's the last bit..
113 throw "invalid line: " + l;
120 ret.title = ar.join(' ');
121 if (ret.title == 'IDLE') {
122 ret.project = 'IDLE';
128 if (typeof(this[ret.cmd])=='undefined') {
129 ret.project = 'Unknown';
131 print( "Unknown application: " + ret.line);
132 throw { error : "TEST"};
137 if (typeof(this[ret.cmd])=='string') {
138 ret.project = this[ret.cmd]
149 '/usr/bin/perl' : function(ret) {
150 if (ret.title.match(/^PAC/)) {
151 ret.project = 'Unknown';
155 throw "Unknown match: " + ret.line;
157 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
158 '/usr/lib/chromium/chromium' : function (ret) {
162 case (ret.title.match(/Media Clipping Portal/)):
163 ret.project = 'Media Outreach';
167 ret.project = 'Browsing';
172 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
173 var l = ret.title.match(/Project\s+(^\)+)/);
175 ret.project="Unknown";
178 throw "Unknown match: " + ret.line;
180 'guake' : 'Local Terminal',
185 //print(Seed.argv[2]);Seed.quit();
186 if (typeof(Seed.argv[2]) == 'undefined') {
187 print("pick a date");
192 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
193 var totals = { work : 0 , idle: 0, shortidle : 0}
195 for (var p in res[h]) {
196 if (p == 'LONGIDLE') {
197 var idletime = Math.floor(res[h][p].total/60000) ;
198 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
199 totals.idle += idletime;
205 var idletime = Math.floor(res[h][p].total/60000) ;
206 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
207 totals.shortidle += idletime;
214 //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
215 totals.work += Math.floor(res[h][p].total/60000) ;
216 for (var k in res[h][p].items) {
218 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
226 for (var h in GitLogParser.shours) {
228 for (var desc in GitLogParser.shours[h]) {
229 hsum.push({ desc : desc, tot : (GitLogParser.shours[h][desc]/60000).toFixed(2)*1 })
231 hsum.sort(function(a,b) { if (a.tot == b.tot) { return 0; } return a.tot > b.tot ? 1 : -1 });
233 hsum.forEach(function(r) {
234 print (" " + r.tot + " : " + r.desc);
240 //print(JSON.stringify(GitLogParser.shours,null,4));
244 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
245 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
247 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
254 // summarize each hour
256 //convert line into 'Project / filename'