sistema inicial
authordanigm <dani@danigm.net>
Wed, 24 Sep 2008 06:16:58 +0000 (08:16 +0200)
committerdanigm <dani@danigm.net>
Wed, 24 Sep 2008 06:16:58 +0000 (08:16 +0200)
ttt.py [new file with mode: 0644]
tttdb.py [new file with mode: 0644]

diff --git a/ttt.py b/ttt.py
new file mode 100644 (file)
index 0000000..dbe7af8
--- /dev/null
+++ b/ttt.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+
+# Author: Daniel Garcia <dani@danigm.net>
+# License: GPLv3
+
+import datetime
+import time
+import sys
+import tttdb as db
+from tttdb import Tracker
+
+sqlhub = db.get_hub()
+
+def parse_time(time_seconds):
+    hour = 0
+    min = 0
+    sec = time_seconds
+    while sec >= 60:
+        min += 1
+        sec -= 60
+    while min >= 60:
+        hour += 1
+        min -= 60
+    time_str = '%02d:%02d:%02d' % (hour, min, sec)
+    return time_str
+
+def track(task, project='', ticket=0):
+    today = datetime.datetime.now()
+    tick = time.time()
+    time_pass = 0
+    try:
+        while True:
+            tick2 = time.time()
+            time_pass = tick2 - tick
+            cadena = '\rtracking: %(task)s %(project)s %(ticket)s %(time)s' % \
+                {'time':parse_time(time_pass),
+                 'task':task,
+                 'project':project,
+                 'ticket':ticket}
+            sys.stdout.write(cadena)
+    except:
+        print '\n', 'Finalizando'
+        end = datetime.datetime.now()
+        db.Tracker(project=project,
+                task=task,
+                ticket=ticket,
+                start=today,
+                end=end)
+
+def show(trackers):
+    for i in today_trackers:
+        diff = i.end - i.start
+        diff = parse_time(diff.seconds)
+        to_show = '%-20s | %-40s | #%-6d | %s | %s | %s'
+        print to_show % (i.project, i.task, i.ticket, i.start, i.end, diff)
+
+def show_today(delta=1):
+    yesterday = datetime.datetime.now() - datetime.timedelta(delta)
+    today_trackers = Tracker.select(Tracker.q.start > yesterday)
+    show(today_trackers)
+
+def show_project(project):
+    project_trackers = Tracker.select(Tracker.q.project == project)
+    sum = 0
+    for i in project_trackers:
+        sum += (i.end - i.start).seconds
+
+    print 'Tiempo para %s: %s' % (project, parse_time(sum))
+
+def show_sem():
+    show_today(7)
+
+def show_today_grouped(delta=1):
+    yesterday = datetime.datetime.now() - datetime.timedelta(delta)
+    today_trackers = Tracker.select(Tracker.q.start > yesterday)
+    show_grouped(today_trackers)
+
+def show_grouped(trackers):
+    projects = {}
+    for i in trackers:
+        diff = (i.end - i.start).seconds
+        if projects.has_key(i.project):
+            projects[i.project] += diff
+        else:
+            projects[i.project] = diff
+
+    for k,v in projects.items():
+        print 'Tiempo para %-50s: %s' % (k, parse_time(v))
diff --git a/tttdb.py b/tttdb.py
new file mode 100644 (file)
index 0000000..ecf4403
--- /dev/null
+++ b/tttdb.py
@@ -0,0 +1,25 @@
+# Author: Daniel Garcia <dani@danigm.net>
+# License: GPLv3
+
+from sqlobject import *
+import os
+
+class Tracker(SQLObject):
+    project = StringCol()
+    task = StringCol()
+    ticket = IntCol()
+    start = DateTimeCol()
+    end = DateTimeCol()
+
+def get_hub():
+    connection_string = 'sqlite://%s/devdata.sqlite' % os.getcwd()
+    connection = connectionForURI(connection_string)
+    sqlhub.processConnection = connection
+
+    return sqlhub
+
+def create_db():
+    # You need to create the database before.
+    sqlhub = get_hub()
+
+    Tracker.createTable()