~ubuntu-branches/ubuntu/lucid/hamster-applet/lucid-proposed

« back to all changes in this revision

Viewing changes to src/hamster/overview_totals.py

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2010-09-06 01:31:34 UTC
  • mfrom: (1.2.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100906013134-wtzn81wdx5en03cn
Tags: 2.30.2-0ubuntu1
* New upstream release. (LP: #629609)
* Fixes a bug that made hamster-applet always use some of the CPU,
  draining battery. (LP: #620113)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
from configuration import runtime, dialogs
34
34
 
35
35
from hamster.i18n import C_
 
36
import locale
36
37
from collections import defaultdict
37
38
 
38
39
 
111
112
        self.do_charts()
112
113
 
113
114
 
114
 
    def on_reports_box_expose_event(self, box, someth):
115
 
        self.do_charts()
116
 
 
117
115
    def search(self, start_date, end_date, facts):
118
116
        self.facts = facts
119
117
        self.category_sums, self.activity_sums, self.tag_sums = [], [], []
141
139
    def do_charts(self):
142
140
        if not self.facts:
143
141
            return
144
 
 
145
 
        import copy
146
 
        facts = copy.deepcopy(self.facts)
147
 
 
148
 
        total_hours = sum([stuff.duration_minutes(fact["delta"]) for fact in facts])
149
 
        total_label = _("%s hours tracked total") % ("%.1f" % (total_hours / 60.0))
150
 
        self.get_widget("total_hours").set_text(total_label)
 
142
        facts = self.facts
 
143
 
 
144
        total_hours = dt.timedelta()
 
145
 
151
146
 
152
147
 
153
148
        category_sums, activity_sums, tag_sums = defaultdict(dt.timedelta), defaultdict(dt.timedelta), defaultdict(dt.timedelta),
154
149
 
155
150
        for fact in facts:
 
151
            total_hours += fact["delta"]
 
152
 
156
153
            if self.selected_categories and fact["category"] not in self.selected_categories:
157
154
                continue
158
155
            if self.selected_activities and fact["name"] not in self.selected_activities:
165
162
            for tag in fact["tags"]:
166
163
                tag_sums[tag] += fact["delta"]
167
164
 
 
165
        total_label = _("%s hours tracked total") % locale.format("%.1f", stuff.duration_minutes(total_hours) / 60.0)
 
166
        self.get_widget("total_hours").set_text(total_label)
 
167
 
168
168
 
169
169
        for key in category_sums:
170
170
            category_sums[key] = stuff.duration_minutes(category_sums[key]) / 60.0