]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/blobdiff - coffee_db.py
When replaying offline queue, use the original event time rather than now()
[coffee/coffee-flask.git] / coffee_db.py
index 6207b29d3764c781e0cfdcfb63c448d2bbf1961a..0abb5a4fe68a0010ea5cb7d12ad97cc3062bf434 100644 (file)
@@ -48,7 +48,6 @@ def list_users():
 
 def add_coffee(uid, flavor, time=None):
     conn, c = open_db()
-    print(uid, flavor, time)
     if time is None:
         c.execute("insert into coffees (id, flavor) values (?,?)", (uid,flavor))
     else:
@@ -90,24 +89,25 @@ def coffee_flavors(uid=None):
     close_db(conn)
     return res
 
+
 def coffee_history(uid=None):
     conn, c = open_db()
 
     if uid is None:
         res = list(c.execute("""
-            select strftime('%d', ds.d),count(c.time) from
+            select strftime('%d', ds.d),count(c.flavor),c.flavor from
             (select num,date('now',-num || ' days') as d from days) ds
             left join coffees c
-            on d = date(c.time) group by d
+            on d = date(c.time) group by d, c.flavor
             """))
     else:
         res = list(c.execute(
             """
-            select strftime('%d', ds.d),count(c.time) from
+            select strftime('%d', ds.d),count(c.flavor),c.flavor from
             (select num,date('now',-num || ' days') as d from days) ds
             left join
-            (select time from coffees where id = ? ) c
-            on d = date(c.time) group by d
+            (select time,flavor from coffees where id = ?) c
+            on d = date(c.time) group by d, c.flavor
             """
             , (uid,)))