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++) {
26 var xl = flines[i].split(/([0-9]{2}:[0-9]{2}:[0-9]{2})/);
27 //print(JSON.stringify(xl));
28 for (var ii=1; ii< xl.length; ii+=2) {
30 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1]));
32 lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
33 lines[p-1].spanMin = lines[p-1].span/60000;
42 //print(JSON.stringify(lines,null,4));
46 for (var i = 0; i < lines.length; i++) {
48 var hour = line.start.format('H');
50 if (line.project == 'IDLE' && line.spanMin >= 5 ) {
51 line.project = 'LONGIDLE';
54 var project = line.project;
55 hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
56 hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ?
57 { total : 0, items : [] }
58 : hours[hour][project];
59 hours[hour][project].total += line.span;
60 hours[hour][project].items.push(line);
65 parseLine : function(l)
67 var ret = { cmd : false, line : l, span : 0 };
68 var ar = l.split(/\s+/);
69 //print(JSON.stringify(ar));
71 var time = ar.shift();
72 //print("time: " + time);
74 ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
77 while (ret.cmd === false) {
80 if (ta[0] != '-') { //hopfully withc catch stuff.
85 // just assume it's the last bit..
87 throw "invalid line: " + l;
94 ret.title = ar.join(' ');
95 if (ret.title == 'IDLE') {
102 if (typeof(this[ret.cmd])=='undefined') {
103 ret.project = 'Unknown';
105 print( "Unknown application: " + ret.line);
106 throw { error : "TEST"};
108 if (typeof(this[ret.cmd])=='string') {
109 ret.project = this[ret.cmd]
120 '/usr/bin/perl' : function(ret) {
121 if (ret.title.match(/^PAC/)) {
122 ret.project = 'Unknown';
125 throw "Unknown match: " + ret.line;
127 '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
128 '/usr/lib/chromium/chromium' : function (ret) {
132 case (ret.title.match(/Media Clipping Portal/)):
133 ret.project = 'Media Outreach';
137 ret.project = 'Browsing';
142 '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
143 var l = ret.title.match(/Project\s+(^\)+)/);
145 ret.project="Unknown";
148 throw "Unknown match: " + ret.line;
150 'guake' : 'Local Terminal',
155 //print(Seed.argv[2]);Seed.quit();
156 if (typeof(Seed.argv[2]) == 'undefined') {
157 print("pick a date");
162 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
163 var totals = { work : 0 , idle: 0, shortidle : 0}
165 for (var p in res[h]) {
166 if (p == 'LONGIDLE') {
167 var idletime = Math.floor(res[h][p].total/60000) ;
168 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
169 totals.idle += idletime;
175 var idletime = Math.floor(res[h][p].total/60000) ;
176 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
177 totals.shortidle += idletime;
184 print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );
185 totals.work += Math.floor(res[h][p].total/60000) ;
186 for (var k in res[h][p].items) {
188 //print( ' ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
196 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
197 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );
199 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
206 // summarize each hour
208 //convert line into 'Project / filename'