diff options
Diffstat (limited to '')
-rw-r--r-- | app/views/stats.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/app/views/stats.py b/app/views/stats.py index b1e9b1a..90f1686 100644 --- a/app/views/stats.py +++ b/app/views/stats.py @@ -6,7 +6,7 @@ from . import Blueprint, flash, db, \ from .. import forms as F from ..model import ConstExpense import sqlalchemy as sql -import time +import calendar from collections import defaultdict mod = Blueprint('stats', __name__) @@ -17,20 +17,23 @@ def next_date(d): else: return d.replace(month = d.month + 1) +def date_to_ms(d): + return calendar.timegm(d.timetuple()) * 1000 + @mod.route('/') @login_required @templated def show(): # easy way: fetch them all and then do some computation expenses = defaultdict(int) - t = next_date (today().replace(day = 1)) + t = today().replace(day = 1) for e in ConstExpense.of(current_user): cur = e.start end = min(e.end, t) while cur <= end: - expenses[time.mktime(cur.timetuple()) * 1000] += e.monthly + expenses[date_to_ms(cur)] += e.monthly cur = next_date(cur) - expenses = list(sorted((int(k),v) for k,v in expenses.iteritems())) + expenses = list(sorted(expenses.iteritems())) return { 'consts': expenses } |