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