]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/blobdiff - coffee_db.py
Add `type` for flavors and build current consumption dynamically
[coffee/coffee-flask.git] / coffee_db.py
index f0ad4078bfe3c34223721ce539266bc06b624318..c7dbdcca22574f60ce134e2a450a88eea438f691 100644 (file)
@@ -183,6 +183,8 @@ def drink_count(uid=None, start=None, stop=None):
     if stop is not None:
         clauses.append("date(time, 'localtime') <= date('now', 'localtime', '-%d days')" % int(stop))
 
-    return dict(c.execute("select case when flavor like 'Club%' then 'Club-Mate' else 'Coffee' end as drink, count(*) "
-                          "from coffees co left join identifiers ids on co.id = ids.id where "
-                          + " and ".join(clauses) + " group by drink", args))
+    return list(c.execute("select fl.type, count(*) from coffees co "
+                          "left join flavors fl on co.flavor = fl.name "
+                          "left join identifiers ids on co.id = ids.id where "
+                          + " and ".join(clauses) + " group by fl.type "
+                          "order by fl.ord asc", args))