if hist == []:
days = tuple()
counts = tuple()
+ flavors = tuple()
else:
- days, counts = zip(*hist)
+ days, counts, flavors = zip(*hist)
fig = plt.figure(figsize=(4,3))
ax = fig.add_subplot(111)
+
+ list_flavor=sorted(db.flavors())
+ l=[{} for i in range(len(list_flavor))]
+ for ll in l:
+ for d in days:
+ ll[d] = 0
+
+ for(d, c, f) in zip(days, counts, flavors):
+ if f is None:
+ continue
+ what_f = 0
+ for i in range(len(list_flavor)):
+ if f == list_flavor[i]:
+ what_f = i;
+ break
+ l[what_f][d] += c
+
+ z=list(0 for i in range(len(l[0])))
+ for flavor in range(len(list_flavor)):
+ sortedlist = [(k, l[flavor][k]) for k in sorted(l[flavor])]
+ x=[i[0] for i in sortedlist]
+ y=[i[1] for i in sortedlist]
+ ax.bar(range(len(x)),y,bottom=z)
+ z=[sum(i) for i in zip(y, z)]
+
+ days=set(days)
xdays = [i.strftime("%a") for i in [
date.today() - timedelta(j - 1) for j in
range(len(days), 0, -1)]]
xdays[-2] = "YDA"
ax.set_xticks(range(len(days)))
ax.set_xticklabels(xdays)
- ax.bar(range(len(days)), counts)
ax.set_title("Your week")
fig.savefig(b, format="svg", bbox_inches="tight")
b.seek(0)
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,)))