2 var File = imports.File.File;
11 var home = GLib.get_home_dir();
12 print( "READING FILE");
13 var flines = File.read( home + '/.gitlog' + date.format('/Y/m/d') + '.log').split("\n");
15 // first just convert them..
16 // we had an old bug that did not put line breaks in there..
17 // however 00:00:00: is pretty distinct, so let'st try and split on it..
23 // read the lines, and fill in the 'spans'
25 for (var i = 0; i < flines.length; i++) {
27 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
29 //print(JSON.stringify(xl));
30 for (var ii=1; ii< xl.length; ii+=2) {
32 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
34 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
35 lines[p-1].spanMin = lines[p-1].span/60000;
44 //print(JSON.stringify(lines,null,4));
48 for (var i = 0; i < lines.length; i++) {
50 var hour = line.start.format('H');
52 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
53 line.project = 'LONGIDLE';
56 var project = line.project;
57 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
58 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
59 { total : 0, items : [] }
60 : hours[hour][project];
61 hours[hour][project].total += line.span;
62 hours[hour][project].items.push(line);
67 parseLine : function(l)
69 var ret = { cmd : false, line : l, span : 0 };
70 var ar = l.split(/\s+/);
71 //print(JSON.stringify(ar));
73 var time = ar.shift();
74 //print("time: " + time);
76 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
79 while (ret.cmd === false) {
82 if (ta[0] != '-') { //hopfully withc catch stuff.
87 // just assume it's the last bit..
89 throw "invalid line: " + l;
96 ret.title = ar.join(' ');
97 if (ret.title == 'IDLE') {
104 if (typeof(this[ret.cmd])=='undefined') {
105 ret.project = 'Unknown';
107 print( "Unknown application: " + ret.line);
108 throw { error : "TEST"};
110 if (typeof(this[ret.cmd])=='string') {
111 ret.project = this[ret.cmd]
122 '/usr/bin/perl' : function(ret) {
123 if (ret.title.match(/^PAC/)) {
124 ret.project = 'Unknown';
127 throw "Unknown match: " + ret.line;
129 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
130 '/usr/lib/chromium/chromium' : function (ret) {
134 case (ret.title.match(/Media Clipping Portal/)):
135 ret.project = 'Media Outreach';
139 ret.project = 'Browsing';
144 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
145 var l = ret.title.match(/Project\s+(^\)+)/);
147 ret.project="Unknown";
150 throw "Unknown match: " + ret.line;
152 'guake' : 'Local Terminal',
157 //print(Seed.argv[2]);Seed.quit();
158 if (typeof(Seed.argv[2]) == 'undefined') {
159 print("pick a date");
164 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
165 var totals = { work : 0 , idle: 0, shortidle : 0}
167 for (var p in res[h]) {
168 if (p == 'LONGIDLE') {
169 var idletime = Math.floor(res[h][p].total/60000) ;
170 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
171 totals.idle += idletime;
177 var idletime = Math.floor(res[h][p].total/60000) ;
178 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
179 totals.shortidle += idletime;
186 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
187 totals.work += Math.floor(res[h][p].total/60000) ;
188 for (var k in res[h][p].items) {
190 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
198 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
199 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
201 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
208 // summarize each hour
210 //convert line into 'Project / filename'