[hamster-applet] rudimentar totals for the reports view



commit f893fd340107852a63d50cae56618e3f37188286
Author: Toms Bauģis <toms baugis gmail com>
Date:   Sun Dec 6 00:58:14 2009 +0000

    rudimentar totals for the reports view

 data/stats_reports.ui       |    2 +-
 hamster/stats_reports.py    |   52 +++++++++++++++++++++++++++++++++++++-----
 hamster/stats_stats.py      |   13 +---------
 hamster/widgets/facttree.py |    4 +-
 4 files changed, 50 insertions(+), 21 deletions(-)
---
diff --git a/data/stats_reports.ui b/data/stats_reports.ui
index c70339f..284cfae 100644
--- a/data/stats_reports.ui
+++ b/data/stats_reports.ui
@@ -161,7 +161,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="position">400</property>
+                <property name="position">500</property>
                 <property name="position_set">True</property>
                 <child>
                   <object class="GtkScrolledWindow" id="totals_tree_box">
diff --git a/hamster/stats_reports.py b/hamster/stats_reports.py
index 442157e..d624dfd 100644
--- a/hamster/stats_reports.py
+++ b/hamster/stats_reports.py
@@ -155,9 +155,47 @@ class ReportsBox(gtk.VBox):
             totals.append(group)
 
         self.totals_tree.clear()
+        
         # second iteration - group the interim result by category
+        i = 0
         for category, totals in groupby(totals, lambda total:total[0]):
-            self.totals_tree.add_group(category, list(totals))
+            i+=1
+            totals = list(totals)
+
+
+            category_duration = sum([stuff.duration_minutes(total[3]) for total in totals])
+            category_occurences = sum([total[4] for total in totals])
+    
+            
+            # adds group of facts with the given label
+            category_row = self.totals_tree.model.append(None,
+                                                         [category,
+                                                          None,
+                                                          stuff.format_duration(category_duration),
+                                                          str(category_occurences)])
+
+            #now group by activity too
+            for group, totals in groupby(totals, lambda total:(total[0], total[1])):
+                totals = list(totals)
+    
+                if len(totals) > 1:
+                    activity_duration = sum([stuff.duration_minutes(total[3]) for total in totals])
+                    activity_occurences = sum([total[4] for total in totals])
+                    
+            
+                    # adds group of facts with the given label
+                    activity_row = self.totals_tree.model.append(category_row,
+                                                                 [group[1],
+                                                                  None,
+                                                                  stuff.format_duration(activity_duration),
+                                                                  str(activity_occurences)])
+                    
+                    for total in totals:
+                        self.totals_tree.add_total(total, activity_row)
+                else:
+                    self.totals_tree.add_total(totals[0], category_row)
+            
+            self.totals_tree.expand_row((i-1,), False)
 
 
     def on_graph_frame_size_allocate(self, widget, new_size):
@@ -239,7 +277,7 @@ class ReportsBox(gtk.VBox):
             start_date_str = self.view_date.strftime(C_("single day overview",
                                                         "%B %d, %Y"))
             # Overview label if looking on single day
-            overview_label = _(u"Overview for %(date)s") % \
+            overview_label = _(u"Totals for %(date)s") % \
                                                       ({"date": start_date_str})
         else:
             dates_dict = stuff.dateDict(self.start_date, "start_")
@@ -250,19 +288,19 @@ class ReportsBox(gtk.VBox):
                 # letter after prefixes (start_, end_) is the one of
                 # standard python date formatting ones- you can use all of them
                 # see http://docs.python.org/library/time.html#time.strftime
-                overview_label = _(u"Overview for %(start_B)s %(start_d)s, %(start_Y)s â?? %(end_B)s %(end_d)s, %(end_Y)s") % dates_dict
+                overview_label = _(u"Totals for %(start_B)s %(start_d)s, %(start_Y)s â?? %(end_B)s %(end_d)s, %(end_Y)s") % dates_dict
             elif self.start_date.month != self.end_date.month:
                 # overview label if start and end month do not match
                 # letter after prefixes (start_, end_) is the one of
                 # standard python date formatting ones- you can use all of them
                 # see http://docs.python.org/library/time.html#time.strftime
-                overview_label = _(u"Overview for %(start_B)s %(start_d)s â?? %(end_B)s %(end_d)s, %(end_Y)s") % dates_dict
+                overview_label = _(u"Totals for %(start_B)s %(start_d)s â?? %(end_B)s %(end_d)s, %(end_Y)s") % dates_dict
             else:
                 # overview label for interval in same month
                 # letter after prefixes (start_, end_) is the one of
                 # standard python date formatting ones- you can use all of them
                 # see http://docs.python.org/library/time.html#time.strftime
-                overview_label = _(u"Overview for %(start_B)s %(start_d)s â?? %(end_d)s, %(end_Y)s") % dates_dict
+                overview_label = _(u"Totals for %(start_B)s %(start_d)s â?? %(end_d)s, %(end_Y)s") % dates_dict
 
         if self.week_view.get_active():
             dayview_caption = _("Week")
@@ -570,7 +608,7 @@ class TotalsTree(gtk.TreeView):
         return self.get_model()
         
     def add_total(self, total, parent = None):
-        duration = 24 * 60 * total[3].days + total[3].seconds / 60
+        duration = stuff.duration_minutes(total[3])
 
 
         self.model.append(parent, [total[1],
@@ -579,7 +617,7 @@ class TotalsTree(gtk.TreeView):
                                    str(total[4])])
 
     def add_group(self, group_label, totals):
-        total_duration = sum([total[3].seconds for total in totals]) / 60.0
+        total_duration = sum([stuff.duration_minutes(total[3]) for total in totals])
         total_occurences = sum([total[4] for total in totals])
 
         
diff --git a/hamster/stats_stats.py b/hamster/stats_stats.py
index 3653993..eca6880 100644
--- a/hamster/stats_stats.py
+++ b/hamster/stats_stats.py
@@ -63,7 +63,7 @@ class StatsBox(gtk.VBox):
         self.get_widget("explore_everything").add(self.timeline)
         self.get_widget("explore_everything").show_all()
 
-        runtime.dispatcher.add_handler('activity_updated', self.after_activity_update)
+        runtime.dispatcher.add_handler('activity_updated', self.after_fact_update)
         runtime.dispatcher.add_handler('day_updated', self.after_fact_update)
 
         self.init_stats()
@@ -411,22 +411,13 @@ than 15 minutes you seem to be a busy bee." % ("<b>%d</b>" % short_percent))
 
     def after_fact_update(self, event, date):
         self.stat_facts = runtime.storage.get_facts(dt.date(1970, 1, 1), dt.date.today())
-        self.popular_categories = [cat[0] for cat in runtime.storage.get_popular_categories()]
-        
-        if self.get_widget("pages").get_current_page() == 0:
-            self.do_graph()
-        else:
-            self.stats()
-        
-
+        self.stats()
 
     def get_widget(self, name):
         """ skip one variable (huh) """
         return self._gui.get_object(name)
 
 
-
-
 if __name__ == "__main__":
     gtk.window_set_default_icon_name("hamster-applet")
     
diff --git a/hamster/widgets/facttree.py b/hamster/widgets/facttree.py
index bd99fc8..d5a80ce 100644
--- a/hamster/widgets/facttree.py
+++ b/hamster/widgets/facttree.py
@@ -122,7 +122,7 @@ class FactTree(gtk.TreeView):
         return self.get_model()
         
     def add_fact(self, fact, parent = None):
-        duration = 24 * 60 * fact["delta"].days + fact["delta"].seconds / 60
+        duration = stuff.duration_minutes(fact["delta"]) / 60
 
         if fact["end_time"]:
             fact_time = "%s - %s " % (fact["start_time"].strftime("%H:%M"),
@@ -139,7 +139,7 @@ class FactTree(gtk.TreeView):
                                    fact])
 
     def add_group(self, group_label, facts):
-        total = sum([fact["delta"].seconds for fact in facts]) / 60.0
+        total = sum([stuff.duration_minutes(fact["delta"]) for fact in facts])
         
         # adds group of facts with the given label
         group_row = self.model.append(None,



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