diff --git a/app/__init__.pyc b/app/__init__.pyc index fd48e13..ad59d38 100644 Binary files a/app/__init__.pyc and b/app/__init__.pyc differ diff --git a/app/check_rights.pyc b/app/check_rights.pyc index 0be638b..abac51b 100644 Binary files a/app/check_rights.pyc and b/app/check_rights.pyc differ diff --git a/app/consumption.pyc b/app/consumption.pyc index 11a3bdd..ec3c676 100644 Binary files a/app/consumption.pyc and b/app/consumption.pyc differ diff --git a/app/database.pyc b/app/database.pyc index 89eeda7..0185dd7 100644 Binary files a/app/database.pyc and b/app/database.pyc differ diff --git a/app/gui.pyc b/app/gui.pyc index 7ff6a8e..50cf307 100644 Binary files a/app/gui.pyc and b/app/gui.pyc differ diff --git a/app/plot.py b/app/plot.py new file mode 100644 index 0000000..7c3fcd3 --- /dev/null +++ b/app/plot.py @@ -0,0 +1,77 @@ +from matplotlib import pyplot as plt +from matplotlib.dates import WeekdayLocator, DayLocator, HourLocator, DateFormatter, drange, MONDAY +import numpy as np +from user import User +from database import * + +def plot_total(user = None): + + today = datetime.date.today() + delta = datetime.timedelta(days=1) + begin = datetime.date.today() - datetime.timedelta(weeks=4) + dates = drange(begin, today, delta) + +# all_consumptions = list(10) + # for consumptions in all_consumptions: #todo fix + consumptions = np.zeros(len(dates)) + + #print consumptions + + consumed = get_consumed() + for consumption in consumed: + if consumption.prodnr == 1: + if user == None or consumption.consumer == user.id: + if consumption.time.date() > begin: + consumptions[(consumption.time.date() - begin).days - 1] += 1 + plt.xkcd() + + + fig, ax = plt.subplots() + + ax.plot(dates, consumptions, linestyle='-', marker='') + + # ax.axes.margins = 1 # x margin. See `axes.Axes.margins` + # ax.axes.ymargin = 1 # y margin See `axes.Axes.margins` + + plt.xticks(rotation='vertical') + + ax.spines['right'].set_visible(False) + ax.spines['top'].set_visible(False) + + ax.yaxis.set_ticks_position('left') + ax.xaxis.set_ticks_position('bottom') + + plt.tick_params(which='minor', length=4) + plt.tick_params(which='major', length=5) + + #ax.xaxis.set_major_locator(WeekdayLocator(MONDAY)) + #ax.xaxis.set_major_locator(DayLocator()) + ax.xaxis.set_major_formatter(DateFormatter('%d.%m')) + #ax.xaxis.set_minor_formatter(DateFormatter('%d.%m')) + + #ax.fmt_xdata = DateFormatter('%d.%m') + fig.autofmt_xdate() + + plt.annotate( + 'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED', + xy=(30, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10)) + + plt.xlabel('Datum') + plt.ylabel('Halbe') + + if user == None: + tit = "Bierkonsum FET" + fils = "app/static/total.png" + fill = "app/static/total_big.png" + else: + tit = "Bierkonsum %s" % user.name + fils = "app/static/total%03d.png" % user.id + fill = "app/static/total%03d_big.png" % user.id + plt.title(tit) + + #480x320 + fig.set_size_inches(4.8, 3.2) + plt.savefig(fils, dpi=100) + + fig.set_size_inches(4.8, 3.2) + plt.savefig(fill, dpi=400) diff --git a/app/product.pyc b/app/product.pyc index 7c051e7..fd78f30 100644 Binary files a/app/product.pyc and b/app/product.pyc differ diff --git a/app/templates/base.html b/app/templates/base.html index 2260046..ab4a708 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -29,9 +29,8 @@ {% endif %} {% if user %} - Du bist eingeloggt als {{user.longname}}. + Du bist eingeloggt als {{user.longname}} {% endif %} - {% block content %}{% endblock %} diff --git a/app/templates/index.html b/app/templates/index.html index e115bff..8246e16 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -4,6 +4,12 @@

TODO:

Bierliste

diff --git a/app/user.pyc b/app/user.pyc index eefeaab..cce4fd7 100644 Binary files a/app/user.pyc and b/app/user.pyc differ diff --git a/app/views.py b/app/views.py index 49d0da1..ac22164 100644 --- a/app/views.py +++ b/app/views.py @@ -2,6 +2,7 @@ from check_rights import * from flask import render_template, request, redirect, session, send_from_directory from app import app from database import * +from plot import * from user import User from product import Product from consumption import Consumption @@ -17,6 +18,7 @@ def static_proxy(path): @app.route('/index') def index(): consumed = get_consumed() + plot_total() return render_template("index.html", consumed=consumed, user=get_user_by_name(session.get('name'))) @@ -206,9 +208,10 @@ def consume(): username = session.get('name') add_consume(username, prod.id) message = "Du hast gerade ein %s konsumiert." % prod.name + plot_total(get_user_by_name(session.get('name'))) + plot_total() return render_template('consume.html', products=products, message=message, user=get_user_by_name(session.get('name'))) - @app.route('/billing') @requires_baron def billing(): diff --git a/app/views.pyc b/app/views.pyc index c5d2ccc..2fd544c 100644 Binary files a/app/views.pyc and b/app/views.pyc differ diff --git a/test/database.db b/test/database.db index f673745..babb98d 100644 Binary files a/test/database.db and b/test/database.db differ