summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2016-05-01 14:36:48 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2016-05-01 14:36:48 +0200
commit9771a7352e0eafb8ed011f1bee98a537e23ebaa5 (patch)
treed2c6f58dea7123a9197257e3f02f17d478441c53 /app
parent25f8a6e4ea76574e878c8513aa0a44e2af586040 (diff)
downloadkosten-9771a7352e0eafb8ed011f1bee98a537e23ebaa5.tar.gz
kosten-9771a7352e0eafb8ed011f1bee98a537e23ebaa5.tar.bz2
kosten-9771a7352e0eafb8ed011f1bee98a537e23ebaa5.zip
Add normale expenses to stats-page
Diffstat (limited to 'app')
-rw-r--r--app/views/stats.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/app/views/stats.py b/app/views/stats.py
index 83c8154..639f73b 100644
--- a/app/views/stats.py
+++ b/app/views/stats.py
@@ -4,10 +4,11 @@ from . import Blueprint, flash, db, \
today
from .. import forms as F
-from ..model import ConstExpense
+from ..model import ConstExpense, SingleExpense
import sqlalchemy as sql
import calendar
from collections import defaultdict
+from datetime import date
from flask import jsonify
mod = Blueprint('stats', __name__)
@@ -35,15 +36,21 @@ def const_dialog(year,month):
@templated
def show():
# easy way: fetch them all and then do some computation
- expenses = defaultdict(int)
+ consts = defaultdict(int)
t = today().replace(day = 1)
for e in ConstExpense.of(current_user):
cur = e.start
end = min(e.end, t)
while cur <= end:
- expenses[date_to_ms(cur)] += e.monthly
+ consts[date_to_ms(cur)] += e.monthly
cur = next_date(cur)
- expenses = list(sorted(expenses.iteritems()))
+ consts = list(sorted(consts.iteritems()))
- return { 'consts': expenses }
+ expQuery = SingleExpense.of(current_user)\
+ .group_by(SingleExpense.year, SingleExpense.month)\
+ .values(SingleExpense.year, SingleExpense.month, sql.func.sum(SingleExpense.expense))
+
+ expenses = list(sorted((date_to_ms(date(year,month,1)), exp) for (year, month, exp) in expQuery))
+
+ return { 'consts': consts, 'expenses' : expenses }