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