From f026ad6337f4cbe4e1b628c6296a7a728350bb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 26 Aug 2014 00:05:28 +0200 Subject: Fix statistics --- app/views/stats.py | 11 +++++++---- 1 file 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 } -- cgit v1.2.3