[PATCH coffee-flask] Add support for another beverages (namely club mate)

This patch slightly changes structure of a `flavors` table. It adds another column called `ord`, which is used for ordering of coffee flavors / beverages on the graphs (to maintain the same color scheme). Scripts `app.py` and `coffee_db.py` are modified to work with this change. --- Drobná úprava skriptu, abychom zde mohli zaznamenávat i jiné nápoje -- v tomto případě jde o club mate. Tím pádem nebudeme potřebovat žádné další zařízení na počítání. (Záznam lze provést tlačítkem na spodní části obrazovky po přihlášení). app.py | 4 ++-- coffee_db.py | 3 ++- coffee_db.sql | 12 +++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index d66eff1..a172f5d 100644 --- a/app.py +++ b/app.py @@ -49,7 +49,7 @@ def user(): uid = session["uid"] return render_template('user.html', name=db.get_name(uid), - flavors=db.flavors(), + flavors=[_name for (_name, _ord) in db.flavors()], count=db.coffee_count(uid, 0), stamp=time.time() ) @@ -111,7 +111,7 @@ def coffee_graph_history(): fig = plt.figure(figsize=(4, 3)) ax = fig.add_subplot(111) - list_flavor = sorted(db.flavors()) + list_flavor = [_name for (_name, _ord) in sorted(db.flavors(), key=lambda x: x[1])] l = [{} for i in range(len(list_flavor))] for ll in l: for d in unix_days: diff --git a/coffee_db.py b/coffee_db.py index 7e28f92..8e65c43 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -56,7 +56,7 @@ def add_coffee(uid, flavor, time=None): def flavors(): conn, c = open_db() - res = [row for row, in c.execute("select distinct name from flavors")] + res = list(c.execute("select distinct name, ord from flavors")) close_db(conn) return res @@ -91,6 +91,7 @@ def coffee_flavors(uid=None, days=0, start=0): left join (select * from coffees """+query+""") c on f.name=c.flavor group by f.name + order by f.ord asc """, variables)) close_db(conn) diff --git a/coffee_db.sql b/coffee_db.sql index d9f7d8e..77a2f52 100644 --- a/coffee_db.sql +++ b/coffee_db.sql @@ -6,14 +6,16 @@ create table if not exists users ( ); create table if not exists flavors ( - name varchar(255) primary key not null + name varchar(255) primary key not null, + ord integer not null default 999 ); insert or ignore into flavors values - ("espresso"), - ("espresso lungo"), - ("cappuccino"), - ("latte macchiato") + ("espresso", 2), + ("espresso lungo", 3), + ("cappuccino", 1), + ("latte macchiato", 4), + ("club mate", 5) ; create table if not exists coffees ( -- 2.7.4

Akorát jsem zapomněl připsat, že je potřeba upravit stávající tabulku `flavors`: ``` alter table flavors add ord integer not null default 999; insert into flavors values ('club mate', 5); update flavors set ord=1 where name='cappuccino'; update flavors set ord=2 where name='espresso'; update flavors set ord=3 where name='espresso lungo'; update flavors set ord=4 where name='latte macchiato'; ``` J. Dne 06. 02. 19 v 20:42 Jaroslav Klapalek napsal(a):
This patch slightly changes structure of a `flavors` table. It adds another column called `ord`, which is used for ordering of coffee flavors / beverages on the graphs (to maintain the same color scheme).
Scripts `app.py` and `coffee_db.py` are modified to work with this change. --- Drobná úprava skriptu, abychom zde mohli zaznamenávat i jiné nápoje -- v tomto případě jde o club mate. Tím pádem nebudeme potřebovat žádné další zařízení na počítání. (Záznam lze provést tlačítkem na spodní části obrazovky po přihlášení). app.py | 4 ++-- coffee_db.py | 3 ++- coffee_db.sql | 12 +++++++----- 3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/app.py b/app.py index d66eff1..a172f5d 100644 --- a/app.py +++ b/app.py @@ -49,7 +49,7 @@ def user(): uid = session["uid"] return render_template('user.html', name=db.get_name(uid), - flavors=db.flavors(), + flavors=[_name for (_name, _ord) in db.flavors()], count=db.coffee_count(uid, 0), stamp=time.time() ) @@ -111,7 +111,7 @@ def coffee_graph_history(): fig = plt.figure(figsize=(4, 3)) ax = fig.add_subplot(111)
- list_flavor = sorted(db.flavors()) + list_flavor = [_name for (_name, _ord) in sorted(db.flavors(), key=lambda x: x[1])] l = [{} for i in range(len(list_flavor))] for ll in l: for d in unix_days: diff --git a/coffee_db.py b/coffee_db.py index 7e28f92..8e65c43 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -56,7 +56,7 @@ def add_coffee(uid, flavor, time=None):
def flavors(): conn, c = open_db() - res = [row for row, in c.execute("select distinct name from flavors")] + res = list(c.execute("select distinct name, ord from flavors")) close_db(conn) return res
@@ -91,6 +91,7 @@ def coffee_flavors(uid=None, days=0, start=0): left join (select * from coffees """+query+""") c on f.name=c.flavor group by f.name + order by f.ord asc """, variables))
close_db(conn) diff --git a/coffee_db.sql b/coffee_db.sql index d9f7d8e..77a2f52 100644 --- a/coffee_db.sql +++ b/coffee_db.sql @@ -6,14 +6,16 @@ create table if not exists users ( );
create table if not exists flavors ( - name varchar(255) primary key not null + name varchar(255) primary key not null, + ord integer not null default 999 );
insert or ignore into flavors values - ("espresso"), - ("espresso lungo"), - ("cappuccino"), - ("latte macchiato") + ("espresso", 2), + ("espresso lungo", 3), + ("cappuccino", 1), + ("latte macchiato", 4), + ("club mate", 5) ;
create table if not exists coffees (

Required to run on the server database before using this patch: ``` alter table flavors add ord integer not null default 999; update flavors set ord=1 where name='cappuccino'; update flavors set ord=2 where name='espresso'; update flavors set ord=3 where name='espresso lungo'; update flavors set ord=4 where name='latte macchiato'; ``` This patch slightly changes structure of a `flavors` table. It adds another column called `ord`, which is used for ordering of coffee flavors / beverages on the graphs (to maintain the same color scheme). Scripts `app.py` and `coffee_db.py` are modified to work with this change. --- Patch pro přidání dalších nápojů, teď obsahuje i malé Mate. app.py | 4 ++-- coffee_db.py | 3 ++- coffee_db.sql | 13 ++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index ef9075b..62f79b8 100644 --- a/app.py +++ b/app.py @@ -53,7 +53,7 @@ def user(): uid = session["uid"] return render_template('user.html', name=db.get_name(uid), - flavors=db.flavors(), + flavors=[_name for (_name, _ord) in db.flavors()], count=db.coffee_count(uid, 0), stamp=time.time() ) @@ -115,7 +115,7 @@ def coffee_graph_history(): fig = plt.figure(figsize=(4, 3)) ax = fig.add_subplot(111) - list_flavor = sorted(db.flavors()) + list_flavor = [_name for (_name, _ord) in sorted(db.flavors(), key=lambda x: x[1])] l = [{} for i in range(len(list_flavor))] for ll in l: for d in unix_days: diff --git a/coffee_db.py b/coffee_db.py index b7206fe..348113a 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -56,7 +56,7 @@ def add_coffee(uid, flavor, time=None): def flavors(): conn, c = open_db() - res = [row for row, in c.execute("select distinct name from flavors")] + res = list(c.execute("select distinct name, ord from flavors")) close_db(conn) return res @@ -91,6 +91,7 @@ def coffee_flavors(uid=None, days=0, start=0): left join (select * from coffees """+query+""") c on f.name=c.flavor group by f.name + order by f.ord asc """, variables)) close_db(conn) diff --git a/coffee_db.sql b/coffee_db.sql index 03a7e7c..acb42a2 100644 --- a/coffee_db.sql +++ b/coffee_db.sql @@ -6,14 +6,17 @@ create table if not exists users ( ); create table if not exists flavors ( - name varchar(255) primary key not null + name varchar(255) primary key not null, + ord integer not null default 999 ); insert or ignore into flavors values - ("espresso"), - ("espresso lungo"), - ("cappuccino"), - ("latte macchiato") + ("espresso", 2), + ("espresso lungo", 3), + ("cappuccino", 1), + ("latte macchiato", 4), + ("Club-Mate 0,5 l", 5), + ("Club-Mate 0,33 l", 6) ; create table if not exists coffees ( -- 2.7.4

Předpokládám, že bude ještě jeden patch, který mění HTML. 7. března 2019 14:47:03 SEČ, Jaroslav Klapalek <klapajar@fel.cvut.cz> napsal:
Required to run on the server database before using this patch: ``` alter table flavors add ord integer not null default 999; update flavors set ord=1 where name='cappuccino'; update flavors set ord=2 where name='espresso'; update flavors set ord=3 where name='espresso lungo'; update flavors set ord=4 where name='latte macchiato'; ```
This patch slightly changes structure of a `flavors` table. It adds another column called `ord`, which is used for ordering of coffee flavors / beverages on the graphs (to maintain the same color scheme).
Scripts `app.py` and `coffee_db.py` are modified to work with this change. --- Patch pro přidání dalších nápojů, teď obsahuje i malé Mate. app.py | 4 ++-- coffee_db.py | 3 ++- coffee_db.sql | 13 ++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/app.py b/app.py index ef9075b..62f79b8 100644 --- a/app.py +++ b/app.py @@ -53,7 +53,7 @@ def user(): uid = session["uid"] return render_template('user.html', name=db.get_name(uid), - flavors=db.flavors(), + flavors=[_name for (_name, _ord) in db.flavors()], count=db.coffee_count(uid, 0), stamp=time.time() ) @@ -115,7 +115,7 @@ def coffee_graph_history(): fig = plt.figure(figsize=(4, 3)) ax = fig.add_subplot(111)
- list_flavor = sorted(db.flavors()) + list_flavor = [_name for (_name, _ord) in sorted(db.flavors(), key=lambda x: x[1])] l = [{} for i in range(len(list_flavor))] for ll in l: for d in unix_days: diff --git a/coffee_db.py b/coffee_db.py index b7206fe..348113a 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -56,7 +56,7 @@ def add_coffee(uid, flavor, time=None):
def flavors(): conn, c = open_db() - res = [row for row, in c.execute("select distinct name from flavors")] + res = list(c.execute("select distinct name, ord from flavors")) close_db(conn) return res
@@ -91,6 +91,7 @@ def coffee_flavors(uid=None, days=0, start=0): left join (select * from coffees """+query+""") c on f.name=c.flavor group by f.name + order by f.ord asc """, variables))
close_db(conn) diff --git a/coffee_db.sql b/coffee_db.sql index 03a7e7c..acb42a2 100644 --- a/coffee_db.sql +++ b/coffee_db.sql @@ -6,14 +6,17 @@ create table if not exists users ( );
create table if not exists flavors ( - name varchar(255) primary key not null + name varchar(255) primary key not null, + ord integer not null default 999 );
insert or ignore into flavors values - ("espresso"), - ("espresso lungo"), - ("cappuccino"), - ("latte macchiato") + ("espresso", 2), + ("espresso lungo", 3), + ("cappuccino", 1), + ("latte macchiato", 4), + ("Club-Mate 0,5 l", 5), + ("Club-Mate 0,33 l", 6) ;
create table if not exists coffees ( -- 2.7.4
_______________________________________________ Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee
-- Odesláno aplikací K-9 Mail ze systému Android. Omluvte prosím moji stručnost.

Nene, tím, že je to generované z databáze, tak není asi potřeba do stránky vůbec zasahovat. J. Dne 07. 03. 19 v 14:56 Michal Sojka napsal(a):
Předpokládám, že bude ještě jeden patch, který mění HTML.
7. března 2019 14:47:03 SEČ, Jaroslav Klapalek <klapajar@fel.cvut.cz> napsal:
Required to run on the server database before using this patch: ``` alter table flavors add ord integer not null default 999; update flavors set ord=1 where name='cappuccino'; update flavors set ord=2 where name='espresso'; update flavors set ord=3 where name='espresso lungo'; update flavors set ord=4 where name='latte macchiato'; ```
This patch slightly changes structure of a `flavors` table. It adds another column called `ord`, which is used for ordering of coffee flavors / beverages on the graphs (to maintain the same color scheme).
Scripts `app.py` and `coffee_db.py` are modified to work with this change. ------------------------------------------------------------------------ Patch pro přidání dalších nápojů, teď obsahuje i malé Mate. app.py | 4 ++-- coffee_db.py | 3 ++- coffee_db.sql | 13 ++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/app.py b/app.py index ef9075b..62f79b8 100644 --- a/app.py +++ b/app.py @@ -53,7 +53,7 @@ def user(): uid = session["uid"] return render_template('user.html', name=db.get_name(uid), - flavors=db.flavors(), + flavors=[_name for (_name, _ord) in db.flavors()], count=db.coffee_count(uid, 0), stamp=time.time() ) @@ -115,7 +115,7 @@ def coffee_graph_history(): fig = plt.figure(figsize=(4, 3)) ax = fig.add_subplot(111)
- list_flavor = sorted(db.flavors()) + list_flavor = [_name for (_name, _ord) in sorted(db.flavors(), key=lambda x: x[1])] l = [{} for i in range(len(list_flavor))] for ll in l: for d in unix_days: diff --git a/coffee_db.py b/coffee_db.py index b7206fe..348113a 100644 --- a/coffee_db.py +++ b/coffee_db.py @@ -56,7 +56,7 @@ def add_coffee(uid, flavor, time=None):
def flavors(): conn, c = open_db() - res = [row for row, in c.execute("select distinct name from flavors")] + res = list(c.execute("select distinct name, ord from flavors")) close_db(conn) return res
@@ -91,6 +91,7 @@ def coffee_flavors(uid=None, days=0, start=0): left join (select * from coffees """+query+""") c on f.name=c.flavor group by f.name + order by f.ord asc """, variables))
close_db(conn) diff --git a/coffee_db.sql b/coffee_db.sql index 03a7e7c..acb42a2 100644 --- a/coffee_db.sql +++ b/coffee_db.sql @@ -6,14 +6,17 @@ create table if not exists users ( );
create table if not exists flavors ( - name varchar(255) primary key not null + name varchar(255) primary key not null, + ord integer not null default 999 );
insert or ignore into flavors values - ("espresso"), - ("espresso lungo"), - ("cappuccino"), - ("latte macchiato") + ("espresso", 2), + ("espresso lungo", 3), + ("cappuccino", 1), + ("latte macchiato", 4), + ("Club-Mate 0,5 l", 5), + ("Club-Mate 0,33 l", 6) ;
create table if not exists coffees (
-- Odesláno aplikací K-9 Mail ze systému Android. Omluvte prosím moji stručnost.

On Thu, Mar 07, 2019 at 02:56:31PM +0100, Michal Sojka wrote:
Předpokládám, že bude ještě jeden patch, který mění HTML.
To by nemělo být třeba.
7. března 2019 14:47:03 SEČ, Jaroslav Klapalek <klapajar@fel.cvut.cz> napsal:
+ ("Club-Mate 0,5 l", 5), + ("Club-Mate 0,33 l", 6)
Jsem pro desetinnou tečku. jiri
create table if not exists coffees ( -- 2.7.4
_______________________________________________ Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee
-- Odesláno aplikací K-9 Mail ze systému Android. Omluvte prosím moji stručnost.
_______________________________________________ Coffee mailing list Coffee@rtime.felk.cvut.cz https://rtime.felk.cvut.cz/mailman/listinfo/coffee
participants (4)
-
Jaroslav Klapalek
-
Jaroslav Klapálek
-
Jiri Vlasak
-
Michal Sojka