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