WindowLog.js
[gitlive] / GitLogParser.js
index 7303093..fe6f0be 100644 (file)
@@ -32,15 +32,18 @@ GitLogParser = {
              
             
         };
+        //print(JSON.stringify(lines,null,4));
+        
         // summarize data...
         var hours = {};
         for (var i = 0; i < lines.length; i++) {
             var line = lines[i];
-            var hour = hours[line].start.format('H');
+            var hour = line.start.format('H');
+            var project = line.project;
             hours[hour] = (typeof(hours[hour]) == 'undefined') ? {} : hours[hour];
-            hours[hour][project] = (typeof(hours[project]) == 'undefined') ? 
+            hours[hour][project] = (typeof(hours[hour][project]) == 'undefined') ? 
                     { total : 0, items : [] } 
-                    : hours[project];
+                    : hours[hour][project];
             hours[hour][project].total += line.span;
             hours[hour][project].items.push(line);
         }
@@ -49,31 +52,31 @@ GitLogParser = {
     },
     parseLine : function(l) 
     {
-        var ret = { cmd : false,  line : l };
+        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);
+        //print("time: " + time);
         
         ret.start = xDate.Date.parseDate(this.date.format('Y-m-d') + ' ' + time, 'Y-m-d H:i:s');
         
 
         while (ret.cmd === false) {
             var ta = ar.pop();
-            print("TA:"+ta)
+            //print("TA:"+ta)
             if (ta[0] !=  '-') { //hopfully withc catch stuff.
                 ret.cmd = ta;
                 break;
             }
             if (!ar.length) {
                 // just assume it's the last bit..
-                print(line);
+                //print(line);
                 throw "invalid line: " + l;
             }
 
         }
-        print(ret.cmd);
+        //print(ret.cmd);
         
         
         ret.title = ar.join(' ');
@@ -85,6 +88,8 @@ GitLogParser = {
         
 
         if (typeof(this[ret.cmd])=='undefined') {
+             ret.project = 'Unknown';
+            return ret;
             print( "Unknown application: " + ret.line);
             throw { error : "TEST"};
         }
@@ -123,19 +128,39 @@ GitLogParser = {
 
     },
     '/usr/lib/Komodo-Edit-7/lib/mozilla/komodo' : function(ret) {
-          var l = ret.title.match(/Project\s+(^\)+)/);
-          print(l);
-              
-         throw "Unknown match: " + ret.line;
+        var l = ret.title.match(/Project\s+(^\)+)/);
+        if (!l) {
+            ret.project="Unknown";
+            return;
+        }
+        throw "Unknown match: " + ret.line;
     },
     'guake' : 'Local Terminal',
-    'mono' : 'mono?',
-
+    'mono' : 'mono?'
+    
 
 }
 
 var res = GitLogParser.parse(xDate.Date.parseDate('2012-07-31', 'Y-m-d'));
-print(JSON.stringify(res,null,4));
+for (var h in res) {
+    for (var p in res[h]) {
+        if (p == 'IDLE') {
+            print(h + ' ' + Math.floor(res[h][p].total/60000) +') IDLE' );
+            continue;
+        }
+        print(h + ' ' + Math.floor(res[h][p].total/60000) +'m ' + p );  
+       
+        for (var k in res[h][p].items) {
+             
+            print( '     ' + Math.floor(res[h][p].items[k].span/60000) +'m ' + res[h][p].items[k].line );
+                 
+        }
+        
+        
+    }
+    
+}
+//print(JSON.stringify(res,null,4));
 
 // open file..