From 7dc8868361e0f174e211c9a3d158082df5c21a3c Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 17 Jan 2014 00:36:10 +0100 Subject: First statistics :) --- app/views/__init__.py | 8 +++++--- app/views/stats.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 app/views/stats.py (limited to 'app') 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 } -- cgit v1.2.3-70-g09d2 20bcd82dd&follow=1'>.vim/after/ftplugin/python_pydiction.vim (unfollow)
Commit message (Expand)AuthorFilesLines
2010-04-09Add one more zsh optionRené 'Necoro' Neumann1-0/+1
2010-04-08screen stuffRené 'Necoro' Neumann2-1/+4
2010-04-07Fix mako.vimRené 'Necoro' Neumann1-2/+2
2010-04-07Another commit alias for gitRené 'Necoro' Neumann1-0/+1