From a87ea6cf5865a74d56aa59754cb26c4833039e61 Mon Sep 17 00:00:00 2001 From: Bernhard Stampfer Date: Mon, 15 Feb 2016 20:14:37 +0100 Subject: [PATCH 1/2] First plot: beer over time - beer still hardcoded at index 1 --- app/plot.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ app/views.py | 5 +++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/plot.py 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/views.py b/app/views.py index 396890d..cd298bf 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'))) @@ -147,9 +149,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(): From 6a5096512e35f45487843dc65a1fbd1ec559f3db Mon Sep 17 00:00:00 2001 From: Bernhard Stampfer Date: Mon, 15 Feb 2016 20:28:00 +0100 Subject: [PATCH 2/2] ignore --- app/__init__.pyc | Bin 250 -> 247 bytes app/check_rights.pyc | Bin 1396 -> 1381 bytes app/consumption.pyc | Bin 626 -> 617 bytes app/database.pyc | Bin 5711 -> 5672 bytes app/gui.pyc | Bin 1681 -> 1663 bytes app/product.pyc | Bin 526 -> 517 bytes app/templates/base.html | 3 +-- app/templates/index.html | 6 ++++++ app/user.pyc | Bin 1495 -> 1483 bytes app/views.pyc | Bin 5292 -> 5345 bytes test/database.db | Bin 4096 -> 4096 bytes 11 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/__init__.pyc b/app/__init__.pyc index fd48e136bb575456bbc8c4fd22e42508b767f0ac..ad59d38708008ab6324e6ad1edd2b1ba48c7ff3d 100644 GIT binary patch delta 43 zcmeyx_??lR`7ZfGpr=;q;q!wqFU|?X-&&bbB)lW(-%FEPGN-WCHOD!&* o?7%8IIh!d2uY%3*nPl-AAu`#T#TKs-lixG(PTtB=fKQPL061+rZvX%Q delta 204 zcmaFL^@WR_`7b&f**O>)*)|I>YBNe}GcYjdXXNLm>ZfGpr=;q;q!wqF=2pJ|a*@(rK2*YX#s4)Qm!-qUn diff --git a/app/consumption.pyc b/app/consumption.pyc index 11a3bdd12e199efb95c0e2a543aca00632c36c59..ec3c67683ebf7591ddd2b1b201ffbe8483102b62 100644 GIT binary patch delta 107 zcmeyw@{)y}`7C#4Y)N P(FeC=45P&4cqU;0T?Qh} delta 116 zcmaFK@`;6=`7t#`5^$kv+<*gGZK!-w3zt~>7j>I@7F`WgATsro6I`6;RTE~&-YCHV#VNlC_&W105i zlizH_yq^)T0!~&oyf$oBXFrSI1Rl=w_!WHSvc<2!gU1)Yg0;Ll_!WHQGs3H2vbBI4 iBg^I{ffx9dedLqeJX=TvZ-`7jF7g*&kWRiM>H`2IQjBN- diff --git a/app/gui.pyc b/app/gui.pyc index 7ff6a8e23874c0355da49f13fac482f6f9b8b475..50cf307f942af206c9484b352332683e30cf7789 100644 GIT binary patch delta 191 zcmbQp`=5uM`7|u=3N(>AP`WgATsro6I`6;RTE~&-YCHV#VNlC_=OBpva g;Zrc#fu#wr{4JJxyz+&tNqFU7vxei9k782=0AE5uNdN!< diff --git a/app/product.pyc b/app/product.pyc index 11c6e6cfb414f4ca57d96cdd2624a00fb400819e..fd78f305bf8ba45c92fb10c53bd9e039a07c7799 100644 GIT binary patch delta 102 zcmeBUX=Pz&{>;lYWB0*{>>nkR85kJ!GxBp&^^;PI@-p?45{vTlQj3cx3o|C-mh5M= K$1VAiQ567??jdsk delta 111 zcmZo=>0@DM{>;l&H*3j6_K(tP3=9nV8Tq-X`YD {% 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:

  • graphical beer list
  • + + {% if user %} + {% set fils = "total%03d.png" % user.id %} + + {% endif %} +

Bierliste

diff --git a/app/user.pyc b/app/user.pyc index eefeaab0a2ced3d80a7c9508a8f5f06cdcffa1b4..cce4fd78c75dba1f3a355574e8cdff4b5a988880 100644 GIT binary patch delta 139 zcmcc4eVUt{`7aj0R diff --git a/app/views.pyc b/app/views.pyc index fd299c32d48373149e36ec3895316cce8b60d139..2fd544c4ab20e7a81c58953568849e6cb6f02fc9 100644 GIT binary patch delta 1836 zcma)6O>7%g5T41}-o)PZf8tG?IB5gOY1+7@{Iv~I0~Jzx;P7aRhJIQaQk(dR&k=bD;+$ACNd85U1YCfddB)6(>%B5JwO*&t7mtBjWXbo;Ne^&CK^^ ze0S}^TG{yBPJa96Hp1upv}~x` zqjduOG_*2M&j5NR>}Ell@E(GkhFicwJqKg`3@^uWQv0OFKJ1o{OcuyHKRJU!w9e^m zMUeRk@7c&&(AGJS#R+REvd)6EL8d`wpfN?B=#l5#gr^gEmd2h9)NbZLm*QwGZ60Z9 z^9sm$xW&uyx4sY^vA`M*P@V`-j;xE?N@XlfSQjH}CEB|@w#J#0rQu(=iq0Xrm)f;X z%d72py>_#<AjI7AxIE_ zF@xst-B=xQPW=%7dMi&lQD9ggs7|poPe9oL^s5A*A=odX`Y}<$dG$x)HkQ>*)7hVg z&rJtUs(a>V)I}5}#=w!Q97;UK621Qu?%@J0@^86qx8ZH~1FsjH9)367!o(b@g`>_T zzZ`Ha)hw@dX^SkG3}uETh6+Q5fhiDc3`ZE&3BqXtS4w@p(3$SZUZ1pi{7-%j*m!i zROE5C>PjchA{{jwz{OtQ6DN4Z9rKdw2cCG6Byo~;DT01iy5WdqVSu`ywvXzZSIBmN zTT@nM6|bn{nV-+>VNWOg+yPH{HG3FutGBZ2I8>izH}HM+efHGjG#`{>n1Ee_=jflA zM>6n)wW$V66>>M8;y58Q)}pzjrqPsFZBmF+3{1Hu#O*bL(NvVxSGn3iv!_|+NfNpS z&b-Qe2|iYAGMpjM2XuR#(bXM*oQGSQ)4SSf2mO}!A&CL^!Yq$%0`q9mlff+7IFCv7 zcE0o49y-bSAoua#kULG^Z?+qsa7d;BVlP)K>O$fC%%~pv`%$WJwo)XMI7AR~yY{^6 z{btV#w*5|{*%qtnw?gT{6YR3VpgZ(gmQFKlF}y(VFDY8u|G(u@ae3hx+K|L5Rh^_K S%TLUSTUa*L2gM~LZQk6^$IoBR=vH*i0pU*w7`~vpU){kaXbOh{dUv$)uqW^tY%wz&RqkWk8PQ`lou&=y;wX2b{=+U z+5439ev5JP&<2IR4aWWGgo@%A#lC34j~?=CCwtKlsWY)VJT$}39L94oH=VjL?W$u7 z^P+ICdrs3_Uq4}5&8B&?Dz@DD<}EKl2k2Q|bz`mBa<*^9<$BVDYK(AQd+)~ zu|$G!>d3z)IOEsiL*6}`!KUB;XF=q8{{law>C#gR0X@pXEX@-5)|tT!`7rG)9?*&s z2isA8m&t3tV!BK7LU6TIlv|k<`7E;>&Y*)&Nj;kr(`b5h^IGCYyV?@&+Pc+p8vIL2 zIYOYW*-5e%36=@YBfO`ftPee@@?LgwYyoRxtb~)rXgX#D$3h8K2+JqgVj!7d{{x?p BU6%j= diff --git a/test/database.db b/test/database.db index c4318304e4290d080440d521c36146a996ddbb46..babb98d733b196badcc3a6e2e9996a1feca28935 100644 GIT binary patch delta 416 zcmZorXi%6S&1f=F#+lWGLH8Nc#*_uj0&Gmn7?_VSw=ml>3o>10TDDn{WfGIVE*lqv zxTv_QJO>A7R(^4EMoDUMi5G~GSe%mP03!4fOAIPNjN-(U%~#pkujCglTnvZkl`!CO@_S_8*A&OWY`!u899xajSLLUbPbGj4NVmcEv$@9tV~R# zq;bg^8A(Y&u04?SVv1FhF4g~_$00YJYgabVT5dzh-5eUNqv(*MK W1p^WR)sqJdC9@#}sR6Uq4J!gS*b%${