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);
84 parseLine : function(l)
86 var ret = { cmd : false, line : l, span : 0 };
87 var ar = l.split(/\s+/);
88 //print(JSON.stringify(ar));
91 var time = ar.shift();
93 ret.desc = ar.join(' ');
95 //print("time: " + time);
97 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
100 while (ret.cmd === false) {
103 if (ta[0] != '-') { //hopfully withc catch stuff.
108 // just assume it's the last bit..
110 throw "invalid line: " + l;
117 ret.title = ar.join(' ');
118 if (ret.title == 'IDLE') {
119 ret.project = 'IDLE';
125 if (typeof(this[ret.cmd])=='undefined') {
126 ret.project = 'Unknown';
128 print( "Unknown application: " + ret.line);
129 throw { error : "TEST"};
134 if (typeof(this[ret.cmd])=='string') {
135 ret.project = this[ret.cmd]
146 '/usr/bin/perl' : function(ret) {
147 if (ret.title.match(/^PAC/)) {
148 ret.project = 'Unknown';
152 throw "Unknown match: " + ret.line;
154 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
155 '/usr/lib/chromium/chromium' : function (ret) {
159 case (ret.title.match(/Media Clipping Portal/)):
160 ret.project = 'Media Outreach';
164 ret.project = 'Browsing';
169 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
170 var l = ret.title.match(/Project\s+(^\)+)/);
172 ret.project="Unknown";
175 throw "Unknown match: " + ret.line;
177 'guake' : 'Local Terminal',
182 //print(Seed.argv[2]);Seed.quit();
183 if (typeof(Seed.argv[2]) == 'undefined') {
184 print("pick a date");
189 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
190 var totals = { work : 0 , idle: 0, shortidle : 0}
192 for (var p in res[h]) {
193 if (p == 'LONGIDLE') {
194 var idletime = Math.floor(res[h][p].total/60000) ;
195 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
196 totals.idle += idletime;
202 var idletime = Math.floor(res[h][p].total/60000) ;
203 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
204 totals.shortidle += idletime;
211 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
212 totals.work += Math.floor(res[h][p].total/60000) ;
213 for (var k in res[h][p].items) {
215 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
223 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
224 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
226 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
233 // summarize each hour
235 //convert line into 'Project / filename'