1. Wayne Werner
  2. Boog Slayer

Commits

Wayne Werner  committed 6943bec

Added reduction of time already spend on project.

  • Participants
  • Parent commits d891386
  • Branches default

Comments (0)

Files changed (1)

File slayer.py

View file
     assigned_to = relationship("User", backref=backref('tasks', order_by=id))
     project = relationship("Project", backref=backref('tasks', order_by=id))
 
+    @property
+    def is_open(self):
+        return self.status in ('New', 'Open', 'In Progress')
+
     def make_dict(self):
         return {'id': self.id,
                 'desc': self.desc,
 
 USAGE = 'slayer.py task [add | list | update task_id]'
 
+def time_spent(user, project=None, task=None):
+    if project:
+        if task:
+            intervals = session.query(Interval).filter_by(user_id=user,
+                                                       project_id=project,
+                                                       task_id=task).all()
+        else:
+            intervals = session.query(Interval).filter_by(user_id=user,
+                                                       project_id=project).all()
+    else:
+        intervals = session.query(Interval).filter_by(user_id=user).all()
+
+    intervals = filter(lambda x: x.task.is_open, intervals)
+    times_spent = map(lambda x: (x.end - x.start).total_seconds()/60/60, intervals)
+    return sum(times_spent)
 
 def ebs(user_id, project=None):
     conn = engine.connect()
 
     estimates =  [e[0] for e in conn.execute(text(query), user_id=user_id, project_id=project).fetchall()]
     totals = []
+    completed = time_spent(user_id, project)
     for _ in range(100):
         total = 0
         for e in estimates:
-            total += e/(random.choice(standard))
-        totals.append(total)
+            total += e/(random.choice(standard)) 
+        print(total, completed)
+        totals.append(total-completed)
     totals.sort()
     totals = [[x[0], len(list(x[1]))] for x in itertools.groupby(totals, lambda x: int(x))]
     total = 0
 
 
 if __name__ == "__main__":
-    print(main(sys.argv[1:]))
+    print(time_spent('wayne', 'Sandbox'))