return render_template('user.html',
name=db.get_name(uid),
flavors=[_name for (_name, _ord) in db.flavors()],
- count=counts.get("Coffee", 0),
- count_mate=counts.get("Club-Mate", 0),
+ counts=counts,
identifiers=db.list_user_identifiers(uid),
iid=session["iid"],
stamp=time.time()
def coffee_count():
start = request.args.get("start")
stop = request.args.get("stop")
- return str(db.drink_count(session.get("uid"), start, stop).get("Coffee", 0))
+ return str(dict(db.drink_count(session.get("uid"), start, stop)).get("coffee", 0))
@app.route('/js')
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))
create table if not exists flavors (
name varchar(255) primary key not null,
- ord integer not null default 999
+ ord integer not null default 999,
+ type varchar(24) not null default ""
);
insert or ignore into flavors values
- ("espresso", 2),
- ("espresso lungo", 3),
- ("cappuccino", 1),
- ("latte macchiato", 4),
- ("Club-Mate 0,5 l", 5),
- ("Club-Mate 0,33 l", 6),
- ("tea", 7)
+ ("espresso", 2, "coffee"),
+ ("espresso lungo", 3, "coffee"),
+ ("cappuccino", 1, "coffee"),
+ ("latte macchiato", 4, "coffee"),
+ ("Club-Mate 0,5 l", 5, "Club-Mate"),
+ ("Club-Mate 0,33 l", 6, "Club-Mate"),
+ ("tea", 7, "tea")
;
create table if not exists coffees (
<p id="nextStep"></p>
- {% if count or count_mate%}
- <p>You've had {{ count }} coffee{% if count != 1 %}s{% endif %} and {{ count_mate }} Club-Mate today.</p>
+ {% if counts|length > 0 %}
+ <p>You've had
+ {% for c in counts %}
+ {%- if counts|length > 1 -%}
+ {%- if loop.last -%}
+ {%- if counts|length > 2 -%}
+ ,
+ {% endif %}
+ and
+ {%- elif not loop.first -%}
+ ,
+ {% endif %}
+ {% endif %}
+ {{ c[1] }}
+ {% if c[0] == "" %}
+ other beverage
+ {%- else -%}
+ {{ c[0] }}
+ {%- endif -%}
+ {%- if c[1] != 1 -%}s{%- endif -%}
+ {% endfor %}
+ today.</p>
{% endif %}
<img src="{{ url_for('coffee_graph_history', _external=True, stamp=stamp) }}">