README.txt
[gitlive] / GitLogParser.js
1
2 var File = imports.File.File;
3 xDate = imports.Date;
4
5
6 GitLogParser = { 
7
8     parse : function(date)
9     {
10         this.date  = date;        
11         var home  = GLib.get_home_dir();
12         
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..
17         
18         
19         
20         lines = [];
21         
22         // read the lines, and fill in the 'spans'
23         
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) {
28                 var p = lines.length;
29                 lines.push( this.parseLine(xl[ii] + ' ' + xl[ii+1])); 
30                 if (p > 0) {
31                     lines[p-1].span = lines[p].start - lines[p-1].start; // should be seconds..?
32                     lines[p-1].spanMin = lines[p-1].span/60000;
33                     
34                     
35                 }
36             
37             }
38              
39             
40         };
41         //print(JSON.stringify(lines,null,4));
42         
43         // summarize data...
44         var hours = {};
45         for (var i = 0; i < lines.length; i++) {
46             var line = lines[i];
47             var hour = line.start.format('H');
48             
49             if (line.project == 'IDLE' && line.spanMin >= 5 ) {
50                 line.project = 'LONGIDLE';
51             }
52             
53             var project = line.project;
54             hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
55             hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ? 
56                     { total : 0, items : [] } 
57                     : hours[hour][project];
58             hours[hour][project].total += line.span;
59             hours[hour][project].items.push(line);
60         }
61         return hours;
62
63     },
64     parseLine : function(l) 
65     {
66         var ret = { cmd : false,  line : l, span : 0 };
67         var ar = l.split(/\s+/);
68         //print(JSON.stringify(ar));
69             
70         var time = ar.shift();
71         //print("time: " + time);
72         
73         ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
74         
75
76         while (ret.cmd === false) {
77             var ta = ar.pop();
78             //print("TA:"+ta)
79             if (ta[0] !=  '-') { //hopfully withc catch stuff.
80                 ret.cmd = ta;
81                 break;
82             }
83             if (!ar.length) {
84                 // just assume it's the last bit..
85                 //print(line);
86                 throw "invalid line: " + l;
87             }
88
89         }
90         //print(ret.cmd);
91         
92         
93         ret.title = ar.join(' ');
94         if (ret.title == 'IDLE') {
95             ret.project = 'IDLE';
96             return ret;        
97         }
98                 
99         
100
101         if (typeof(this[ret.cmd])=='undefined') {
102              ret.project = 'Unknown';
103             return ret;
104             print( "Unknown application: " + ret.line);
105             throw { error : "TEST"};
106         }
107         if (typeof(this[ret.cmd])=='string') {
108             ret.project = this[ret.cmd]  
109         } else {
110
111             this[ret.cmd](ret);
112         }
113
114
115         return ret;
116
117     },
118  
119     '/usr/bin/perl' : function(ret) {
120         if (ret.title.match(/^PAC/)) {
121             ret.project = 'Unknown';
122             return;
123         }
124         throw "Unknown match: " + ret.line;
125     },
126     '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
127     '/usr/lib/chromium/chromium' : function (ret) {
128
129           switch(true) {
130
131                 case (ret.title.match(/Media Clipping Portal/)):
132                     ret.project = 'Media Outreach';
133                     return;
134                 
135                 default:
136                     ret.project = 'Browsing';
137                     return;
138           }
139
140     },
141     '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
142         var l = ret.title.match(/Project\s+(^\)+)/);
143         if (!l) {
144             ret.project="Unknown";
145             return;
146         }
147         throw "Unknown match: " + ret.line;
148     },
149     'guake' : 'Local Terminal',
150     'mono' : 'mono?'
151     
152
153 }
154 //print(Seed.argv[2]);Seed.quit();
155 if (typeof(Seed.argv[2]) == 'undefined') {
156     print("pick a date");
157     Seed.quit();
158 }
159
160
161 var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
162 var totals = { work : 0 , idle: 0}
163 for (var h in res) {
164     for (var p in res[h]) {
165         if (p == 'LONGIDLE') {
166             var idletime = Math.floor(res[h][p].total/60000) ;
167             print(h + ' ' + Math.floor(res[h][p].total/60000) +'m IDLE' );
168             totals.idle += idletime;
169             
170              
171             continue;
172         }
173         print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );  
174         totals.work += Math.floor(res[h][p].total/60000) ;
175         for (var k in res[h][p].items) {
176              
177             //print( '     ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
178                  
179         }
180         
181         
182     }
183     
184 }
185 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
186 print("Worked: " + (totals.work/60).toFixed(2) +"h\n" );
187  
188
189 // open file..
190
191 // read lines
192
193 // summarize each hour
194
195 //convert line into 'Project / filename'
196
197