summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2014-01-17 00:36:10 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2014-01-17 00:36:10 +0100
commit7dc8868361e0f174e211c9a3d158082df5c21a3c (patch)
treedd3fe351f8c953fe4756a6774bed32fe7467e0de /app
parentf7d4c3c2c8bbcad07c41498e71c5a311f01e0f4b (diff)
downloadkosten-7dc8868361e0f174e211c9a3d158082df5c21a3c.tar.gz
kosten-7dc8868361e0f174e211c9a3d158082df5c21a3c.tar.bz2
kosten-7dc8868361e0f174e211c9a3d158082df5c21a3c.zip
First statistics :)
Diffstat (limited to 'app')
-rw-r--r--app/views/__init__.py8
-rw-r--r--app/views/stats.py36
2 files changed, 41 insertions, 3 deletions
diff --git a/app/views/__init__.py b/app/views/__init__.py
index b8ae6b3..4f079c3 100644
--- a/app/views/__init__.py
+++ b/app/views/__init__.py
@@ -50,14 +50,16 @@ def page_not_found (error):
return render_template('404.jinja', page = request.path), 404
# Now import the views
-from . import categories, consts, expenses, user, api
+from . import categories, consts, expenses, user, stats
+#from . import api
app.register_blueprint(expenses.mod)
app.register_blueprint(user.mod, url_prefix='/user')
app.register_blueprint(consts.mod, url_prefix='/const')
app.register_blueprint(categories.mod, url_prefix='/cat')
+app.register_blueprint(stats.mod, url_prefix='/stats')
-for m in api.mods:
- app.register_blueprint(m, url_prefix='/api')
+#for m in api.mods:
+# app.register_blueprint(m, url_prefix='/api')
app.add_url_rule('/', endpoint = 'index', build_only = True)
diff --git a/app/views/stats.py b/app/views/stats.py
new file mode 100644
index 0000000..b1e9b1a
--- /dev/null
+++ b/app/views/stats.py
@@ -0,0 +1,36 @@
+from . import Blueprint, flash, db, \
+ current_user, login_required, \
+ assert_authorisation, templated, redirect, request, \
+ today
+
+from .. import forms as F
+from ..model import ConstExpense
+import sqlalchemy as sql
+import time
+from collections import defaultdict
+
+mod = Blueprint('stats', __name__)
+
+def next_date(d):
+ if d.month == 12:
+ return d.replace(year = d.year + 1, month = 1)
+ else:
+ return d.replace(month = d.month + 1)
+
+@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))
+ 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
+ cur = next_date(cur)
+
+ expenses = list(sorted((int(k),v) for k,v in expenses.iteritems()))
+
+ return { 'consts': expenses }