[billreminder] More work done to wire in new chart widget.



commit 45d6800e501b1631eaaf6915fdf11327f6232c38
Author: Og B. Maciel <ogmaciel gnome org>
Date:   Wed Nov 25 07:31:25 2009 -0500

    More work done to wire in new chart widget.

 src/gui/maindialog.py          |   17 ++++++++++-------
 src/gui/widgets/chartwidget.py |    2 +-
 src/lib/actions.py             |   10 ++++------
 3 files changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/src/gui/maindialog.py b/src/gui/maindialog.py
index ca2885f..076cf16 100644
--- a/src/gui/maindialog.py
+++ b/src/gui/maindialog.py
@@ -265,7 +265,7 @@ class MainDialog:
         # Update status bar
         self.update_statusbar()
         # populate chart
-        #self._populate_chart(status, first, last)
+        self._populate_chart(status, first, last)
 
         return len(records)
 
@@ -305,12 +305,15 @@ class MainDialog:
 
     def _populate_chart(self, status, start, end):
         chartdata = []
-        #records = self.actions.get_interval_totals(start, end, status)
-        records = []
-        for rec in records:
-            chartdata.append([field for field in rec])
-        if chartdata:
-            self.chart.plot(chartdata)
+        records = self.actions.get_monthly_totals(start, end)
+        #records = []
+        #for rec in records:
+        #    chartdata.append([field for field in rec])
+        #if chartdata:
+        print records
+        if records:
+            records = [(c,float(t)) for c,t in records]
+            self.chart.plot(records)
 
     def _populate_menubar(self):
         # Create a UIManager instance
diff --git a/src/gui/widgets/chartwidget.py b/src/gui/widgets/chartwidget.py
index 1257253..d55a578 100644
--- a/src/gui/widgets/chartwidget.py
+++ b/src/gui/widgets/chartwidget.py
@@ -24,7 +24,7 @@ class ChartWidget(gtk.HBox):
         surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 200)
 
         dataSet = (
-            ('data', [(i, l[1]) for i, l in enumerate(data)]),
+            ('data', [(i, float(l[1])) for i, l in enumerate(data)]),
 
         )
 
diff --git a/src/lib/actions.py b/src/lib/actions.py
index 537a729..2abfcee 100644
--- a/src/lib/actions.py
+++ b/src/lib/actions.py
@@ -8,7 +8,8 @@ import dal
 import time
 import datetime
 from db.entities import Bill, Category
-from sqlalchemy.orm import eagerload
+from sqlalchemy.sql import func
+from sqlalchemy.orm import eagerload, outerjoin
 from lib import common, scheduler
 from lib.utils import force_string
 from lib.utils import verify_dbus_service
@@ -43,20 +44,17 @@ class Actions(object):
 
         return records
 
-    def get_monthly_totals(self, month, year, paid=None):
+    def get_monthly_totals(self, start, end, paid=None):
         """
         Return a list of categories and totals for the given month
         """
 
         records = []
 
-        firstDay = scheduler.first_of_month(month, year)
-        lastDay = scheduler.last_of_month(month, year)
-
         try:
             session = self.dal.Session()
             # records is a tuple of Category.name and total as type Decimal
-            q = session.query(Category.name, func.sum(Bill.amount)).select_from(outerjoin(Bill, Category)).filter(Bill.dueDate >= dt).filter(Bill.dueDate <= to).group_by(Category.name)
+            q = session.query(Category.name, func.sum(Bill.amount)).select_from(outerjoin(Bill, Category)).filter(Bill.dueDate >= start).filter(Bill.dueDate <= end).group_by(Category.name)
 
             if paid:
                 q = q.filter(Bill.paid == paid)



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