GitLogParser.js
[gitlive] / GitLogParser.js
index 2360973..fa43331 100644 (file)
@@ -3,15 +3,25 @@ var File = imports.File.File;
 xDate = imports.Date;
 
 
-GitLogParser = { 
 
+
+
+GitLogParser = {
+    shours : false,
+    date : false,
     parse : function(date)
     {
-        this.date  = date;        
-        var home  = GLib.get_home_dir();
-        print( "READING FILE");
-        var flines = File.read(  home + '/.gitlog' + date.format('/Y/m/d') + '.log').split("\n");
-        print("loaded");
+        var filename = date;
+        if (typeof(date) == 'object') {
+            this.date  = date;        
+            var home  = GLib.get_home_dir();
+            //print( "READING FILE");
+            filename = home + '/.gitlog' + date.format('/Y/m/d') + '.log';
+        
+        
+        }
+        var flines = File.read(  filename ).split("\n");        
+        //print("loaded");
         // first just convert them..
         // we had an old bug that did not put line breaks in there..
         // however 00:00:00: is pretty distinct, so let'st try and split on it..
@@ -46,6 +56,12 @@ GitLogParser = {
         
         // summarize data...
         var hours = {};
+        var shours = {};
+        
+        // shours should be:
+        // hour : [ ]
+        
+        
         for (var i = 0; i < lines.length; i++) {
             var line = lines[i];
             var hour = line.start.format('H');
@@ -53,6 +69,9 @@ GitLogParser = {
             if (line.project == 'IDLE' && line.spanMin >= 5 ) {
                 line.project = 'LONGIDLE';
             }
+            if (line.project == 'IDLE' || line.project == 'LONGIDLE') {
+                line.desc = line.project;
+            }
             
             var project = line.project;
             hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
@@ -61,7 +80,13 @@ GitLogParser = {
                     : hours[hour][project];
             hours[hour][project].total += line.span;
             hours[hour][project].items.push(line);
+            
+            shours[hour] = (typeof(shours[hour]) == 'undefined') ? {} : shours[hour];
+            shours[hour][line.desc] = (typeof(shours[hour][line.desc] ) == 'undefined') ? 0 : shours[hour][line.desc] ;
+            shours[hour][line.desc] += line.span;
+            
         }
+        this.shours = shours;
         return hours;
 
     },
@@ -69,13 +94,19 @@ GitLogParser = {
     {
         var ret = { cmd : false,  line : l, span : 0 };
         var ar = l.split(/\s+/);
-        print(JSON.stringify(ar));
+        //print(JSON.stringify(ar));
+        
             
         var time = ar.shift();
-        //print("time: " + time);
         
-        ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
+        ret.desc = ar.join(' ');
+        
+        //print("time: " + time);
         
+        //ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
+        ret.start = xDate.Date.parseDate((
+                            this.date ? this.date.format('Y-m-d')  : (new Date()).format('Y-m-d') +
+                            ' ' + time, 'Y-m-d H:i:s');
 
         while (ret.cmd === false) {
             var ta = ar.pop();
@@ -108,6 +139,9 @@ GitLogParser = {
             print( "Unknown application: " + ret.line);
             throw { error : "TEST"};
         }
+        
+        //print(ret.cmd);
+        //print(ret.title);
         if (typeof(this[ret.cmd])=='string') {
             ret.project = this[ret.cmd]  
         } else {
@@ -123,8 +157,9 @@ GitLogParser = {
     '/usr/bin/perl' : function(ret) {
         if (ret.title.match(/^PAC/)) {
             ret.project = 'Unknown';
-            return;
+            return  'Unknown';
         }
+        return 'Unknown';
         throw "Unknown match: " + ret.line;
     },
     '/usr/lib/icedove/icedove-bin' : 'Checking Mail',
@@ -160,15 +195,14 @@ if (typeof(Seed.argv[2]) == 'undefined') {
     print("pick a date");
     Seed.quit();
 }
-
-
-var res = GitLogParser.parse(xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
+var res = GitLogParser.parse( Seed.argv[2][0] == '/' ? Seed.argv[2] : xDate.Date.parseDate(Seed.argv[2], 'Y-m-d'));
 var totals = { work : 0 , idle: 0, shortidle : 0}
 for (var h in res) {
     for (var p in res[h]) {
         if (p == 'LONGIDLE') {
             var idletime = Math.floor(res[h][p].total/60000) ;
-            print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
+            //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m LONGIDLE' );
             totals.idle += idletime;
             
              
@@ -176,7 +210,7 @@ for (var h in res) {
         }
         if (p == 'IDLE') {
             var idletime = Math.floor(res[h][p].total/60000) ;
-            print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
+            //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m SHORT IDLE' );
             totals.shortidle += idletime;
             
              
@@ -184,7 +218,7 @@ for (var h in res) {
         }
         
         
-        print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );  
+        //print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );  
         totals.work += Math.floor(res[h][p].total/60000) ;
         for (var k in res[h][p].items) {
              
@@ -196,6 +230,26 @@ for (var h in res) {
     }
     
 }
+for (var h in GitLogParser.shours) {
+    var hsum = [];
+    var htot = 0;
+    for (var desc in GitLogParser.shours[h]) {
+        htot += (GitLogParser.shours[h][desc]/60000).toFixed(2)*1;
+        hsum.push({ desc : desc, tot : (GitLogParser.shours[h][desc]/60000).toFixed(2)*1 })
+    }
+    hsum.sort(function(a,b) { if (a.tot == b.tot) { return 0; } return a.tot < b.tot ? 1 : -1 });
+    print(h+': Total (' + htot +')');
+    hsum.forEach(function(r) {
+        print ("  " + r.tot + "   : " + r.desc);
+    });
+}
+
+
+
+//print(JSON.stringify(GitLogParser.shours,null,4));
+
+
+
 print("\nLONGIDLE : " +(totals.idle/60).toFixed(2) +"h" );
 print("\nShort Idle : " +(totals.shortidle/60).toFixed(2) +"h" );