[hamster-applet] bug 624873. trying to avoid rounding error in totals - duration_minutes now accepts lists too to mov



commit da27a98cd21750eecf1b017adede8e169248c56f
Author: Toms Bauģis <toms baugis gmail com>
Date:   Wed Jul 21 12:38:30 2010 +0100

    bug 624873. trying to avoid rounding error in totals - duration_minutes now accepts lists too to move all the logic in single place and avoid duplicate code

 src/hamster/overview_totals.py  |    8 +-------
 src/hamster/reports.py          |    3 +--
 src/hamster/stuff.py            |   11 ++++++++++-
 src/hamster/widgets/facttree.py |    2 +-
 4 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/src/hamster/overview_totals.py b/src/hamster/overview_totals.py
index 766a3b2..9263a5a 100644
--- a/src/hamster/overview_totals.py
+++ b/src/hamster/overview_totals.py
@@ -143,15 +143,9 @@ class TotalsBox(gtk.VBox):
             return
         facts = self.facts
 
-        total_hours = dt.timedelta()
-
-
-
         category_sums, activity_sums, tag_sums = defaultdict(dt.timedelta), defaultdict(dt.timedelta), defaultdict(dt.timedelta),
 
         for fact in facts:
-            total_hours += fact["delta"]
-
             if self.selected_categories and fact["category"] not in self.selected_categories:
                 continue
             if self.selected_activities and fact["name"] not in self.selected_activities:
@@ -164,7 +158,7 @@ class TotalsBox(gtk.VBox):
             for tag in fact["tags"]:
                 tag_sums[tag] += fact["delta"]
 
-        total_label = _("%s hours tracked total") % locale.format("%.1f", stuff.duration_minutes(total_hours) / 60.0)
+        total_label = _("%s hours tracked total") % locale.format("%.1f", stuff.duration_minutes([fact["delta"] for fact in facts]) / 60.0)
         self.get_widget("total_hours").set_text(total_label)
 
 
diff --git a/src/hamster/reports.py b/src/hamster/reports.py
index fdcf2c6..5ae8709 100644
--- a/src/hamster/reports.py
+++ b/src/hamster/reports.py
@@ -150,8 +150,7 @@ class XMLWriter(ReportWriter):
         activity.setAttribute("name", fact["name"])
         activity.setAttribute("start_time", fact["start_time"])
         activity.setAttribute("end_time", fact["end_time"])
-        delta = fact["delta"].seconds / 60 + fact["delta"].days * 24 * 60
-        activity.setAttribute("duration_minutes", delta)
+        activity.setAttribute("duration_minutes", stuff.duration_minutes(fact["delta"]))
         activity.setAttribute("category", fact["category"])
         activity.setAttribute("description", fact["description"])
         activity.setAttribute("tags", fact["tags"])
diff --git a/src/hamster/stuff.py b/src/hamster/stuff.py
index d8b1cad..0029d46 100644
--- a/src/hamster/stuff.py
+++ b/src/hamster/stuff.py
@@ -118,7 +118,16 @@ def month(view_date):
 
 def duration_minutes(duration):
     """returns minutes from duration, otherwise we keep bashing in same math"""
-    return duration.seconds / 60 + duration.days * 24 * 60
+    if isinstance(duration, list):
+        res = dt.timedelta()
+        for entry in duration:
+            res += entry
+
+        return duration_minutes(res)
+    elif isinstance(duration, dt.timedelta):
+        return duration.seconds / 60 + duration.days * 24 * 60
+    else:
+        return duration
 
 
 def load_ui_file(name):
diff --git a/src/hamster/widgets/facttree.py b/src/hamster/widgets/facttree.py
index 798e7db..12351b6 100644
--- a/src/hamster/widgets/facttree.py
+++ b/src/hamster/widgets/facttree.py
@@ -138,7 +138,7 @@ class FactTree(gtk.TreeView):
 
 
     def add_group(self, group_label, group_date, facts):
-        total = sum([stuff.duration_minutes(fact["delta"]) for fact in facts])
+        total = stuff.duration_minutes([fact["delta"] for fact in facts])
 
         # adds group of facts with the given label
         self.store_model.append([None, dict(date = group_date,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]