2 var File = imports.File.File;
11 var home = GLib.get_home_dir();
13 var flines = File.read( home + '/.gitlog' + date.format('/Y/m/d') + '.log').split("\n");
14 // first just convert them..
15 // we had an old bug that did not put line breaks in there..
16 // however 00:00:00: is pretty distinct, so let'st try and split on it..
22 // read the lines, and fill in the 'spans'
24 for (var i = 0; i < flines.length; i++) {
25 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
26 //print(JSON.stringify(xl));
27 for (var ii=1; ii< xl.length; ii+=2) {
29 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
31 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
38 //print(JSON.stringify(lines,null,4));
42 for (var i = 0; i < lines.length; i++) {
44 var hour = line.start.format('H');
45 var project = line.project;
49 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
50 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
51 { total : 0, items : [] }
52 : hours[hour][project];
53 hours[hour][project].total += line.span;
54 hours[hour][project].items.push(line);
59 parseLine : function(l)
61 var ret = { cmd : false, line : l, span : 0 };
62 var ar = l.split(/\s+/);
63 //print(JSON.stringify(ar));
65 var time = ar.shift();
66 //print("time: " + time);
68 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
71 while (ret.cmd === false) {
74 if (ta[0] != '-') { //hopfully withc catch stuff.
79 // just assume it's the last bit..
81 throw "invalid line: " + l;
88 ret.title = ar.join(' ');
89 if (ret.title == 'IDLE') {
96 if (typeof(this[ret.cmd])=='undefined') {
97 ret.project = 'Unknown';
99 print( "Unknown application: " + ret.line);
100 throw { error : "TEST"};
102 if (typeof(this[ret.cmd])=='string') {
103 ret.project = this[ret.cmd]
114 '/usr/bin/perl' : function(ret) {
115 if (ret.title.match(/^PAC/)) {
116 ret.project = 'Unknown';
119 throw "Unknown match: " + ret.line;
121 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
122 '/usr/lib/chromium/chromium' : function (ret) {
126 case (ret.title.match(/Media Clipping Portal/)):
127 ret.project = 'Media Outreach';
131 ret.project = 'Browsing';
136 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
137 var l = ret.title.match(/Project\s+(^\)+)/);
139 ret.project="Unknown";
142 throw "Unknown match: " + ret.line;
144 'guake' : 'Local Terminal',
149 //print(Seed.argv[2]);Seed.quit();
150 if (typeof(Seed.argv[2]) == 'undefined') {
151 print("pick a date");
156 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
157 var totals = { work : 0 , idle: 0}
159 for (var p in res[h]) {
161 var idletime = Math.floor(res[h][p].total/60000) ;
162 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m IDLE' );
164 totals.idle += idletime;
169 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
170 totals.work += Math.floor(res[h][p].total/60000) ;
171 for (var k in res[h][p].items) {
173 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
181 print("\nIDLE : " +(totals.idle/60).toFixed(2) +"h" );
182 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
189 // summarize each hour
191 //convert line into 'Project / filename'