creados los script ejecutables
authorDaniel Garcia Moreno <dgarcia@emergya.es>
Wed, 24 Sep 2008 06:49:59 +0000 (08:49 +0200)
committerDaniel Garcia Moreno <dgarcia@emergya.es>
Wed, 24 Sep 2008 06:49:59 +0000 (08:49 +0200)
show.py [new file with mode: 0755]
ttt.py [changed mode: 0644->0755]

diff --git a/show.py b/show.py
new file mode 100755 (executable)
index 0000000..3c620a2
--- /dev/null
+++ b/show.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python
+
+# Author: Daniel Garcia <dani@danigm.net>
+# License: GPLv3
+
+import sys
+import ttt
+
+if __name__ == '__main__':
+    args = sys.argv[1:]
+    if '-g' in args:
+        ttt.show_today_grouped()
+    else:
+        ttt.show_today()
diff --git a/ttt.py b/ttt.py
old mode 100644 (file)
new mode 100755 (executable)
index dbe7af8..f62178b
--- a/ttt.py
+++ b/ttt.py
@@ -48,13 +48,34 @@ def track(task, project='', ticket=0):
                 end=end)
 
 def show(trackers):
-    for i in today_trackers:
+    grouped = {}
+    total = 0
+    for i in trackers:
         diff = i.end - i.start
-        diff = parse_time(diff.seconds)
+        total += diff
+        time_passed = parse_time(diff.seconds)
+
+        key = (i.task, i.project)
+        if grouped.has_key(key):
+            grouped[key] += diff.seconds
+            
+        else:
+            grouped[key] = diff.seconds
+        
         to_show = '%-20s | %-40s | #%-6d | %s | %s | %s'
-        print to_show % (i.project, i.task, i.ticket, i.start, i.end, diff)
+        print to_show % (i.project, i.task, i.ticket, i.start, i.end,
+                                                            time_passed)
+    
+    print ''
+    for k,v in grouped.items():
+        task, project = k
+        time_passed = parse_time(v)
+        print 'Tiempo para "%s": %s' % (task, time_passed)
+
+    print '\nTotal para hoy: %s' % parse_time(total)
 
 def show_today(delta=1):
+    # TODO yesterday no es real, hay que mirar desde las 00 del mismo dia
     yesterday = datetime.datetime.now() - datetime.timedelta(delta)
     today_trackers = Tracker.select(Tracker.q.start > yesterday)
     show(today_trackers)
@@ -77,8 +98,10 @@ def show_today_grouped(delta=1):
 
 def show_grouped(trackers):
     projects = {}
+    total = 0
     for i in trackers:
         diff = (i.end - i.start).seconds
+        total += diff
         if projects.has_key(i.project):
             projects[i.project] += diff
         else:
@@ -86,3 +109,17 @@ def show_grouped(trackers):
 
     for k,v in projects.items():
         print 'Tiempo para %-50s: %s' % (k, parse_time(v))
+
+    print '\nTotal para hoy: %s' % parse_time(total)
+
+if __name__ == '__main__':
+    task, project, ticket = '','',0
+    args = sys.argv[1:]
+    if len(args) >= 1:
+        task = args[0]
+    if len(args) >= 2:
+        project = args[1]
+    if len(args) >= 3:
+        ticket = int(args[2])
+
+    track(task, project, ticket)