From ae3bb5c1d32dd0cb72d0d4d90cb272ed27983594 Mon Sep 17 00:00:00 2001 From: Rich Gibson Date: Wed, 9 Mar 2016 19:02:02 -0800 Subject: [PATCH 1/3] trending now has options to show drinks for a date range, and to show a date, drink count, and volume, by date. Days are partially using an offset - ie. a day is from 10am or noon until the next day. --- ui/bartendro/view/trending.py | 77 +++++++++++++++++++++++++++++++++-- ui/content/templates/trending | 20 ++++++++- 2 files changed, 92 insertions(+), 5 deletions(-) diff --git a/ui/bartendro/view/trending.py b/ui/bartendro/view/trending.py index 807f007d..7fb61997 100644 --- a/ui/bartendro/view/trending.py +++ b/ui/bartendro/view/trending.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import time +import time, datetime from bartendro import app, db from sqlalchemy import desc from flask import Flask, request, render_template @@ -10,6 +10,7 @@ from bartendro.model.booze_group import BoozeGroup from bartendro.form.booze import BoozeForm +BARTENDRO_DAY_START_TIME = 10 * 60 * 60 DEFAULT_TIME = 12 display_info = { 12 : 'Drinks poured in the last 12 hours.', @@ -20,7 +21,51 @@ @app.route('/trending') def trending_drinks(): - return trending_drinks_detail(DEFAULT_TIME) + return trending_drinks_detail(DEFAULT_TIME,'') + +# figure out begindate and enddate +# begindate exists, but no enddate = assume it is one day +# enddate exists but no beginndate = assume begindate=first day +# need some text for this. +# begin and enddate need to be in timestamp format. + +@app.route('/trending/date/') +def trending_drinks_date(): + """ this assumes ?begindate=yyyy-mm-dd&enddate=yyyy-mm-dd + or ?begindate=yyyy-mm-dd (with no enddate) + """ + + title = "Drinks by date" + + begindate = request.args.get("begindate", "") + if (len(begindate) > 0) : + begin_ts = time.mktime(datetime.datetime.strptime(begindate, "%Y-%m-%d").timetuple()) + begin_ts = begin_ts + BARTENDRO_DAY_START_TIME + #begindate = datetime.datetime.fromtimestamp(begin_ts).strftime('%Y-%m-%d %H:%M:%S') + + begindate = datetime.datetime.fromtimestamp(begin_ts).strftime('%c') + else: + begin_ts = 0 + begindate = 'The beginning of time' + + enddate = request.args.get("enddate", "") + if (len(enddate) == 0): + end_ts = begin_ts + (24 * 60 * 60) - 1 + #end_ts = end_ts + BARTENDRO_DAY_START_TIME - 1 + enddate = datetime.datetime.fromtimestamp(end_ts).strftime('%c') + else: + end_ts = time.mktime(datetime.datetime.strptime(enddate, "%Y-%m-%d").timetuple()) + end_ts = end_ts + 24*60*60+BARTENDRO_DAY_START_TIME - 1 + #begin_ts = time.mktime(datetime.datetime.strptime(enddate, "%YYYY-m/-%d").timetuple()) + enddate = datetime.datetime.fromtimestamp(end_ts).strftime('%c') + + try: + txt = "Drinks poured from %s to %s

begin_ts: %i end_ts: %i" % (begindate, enddate,begin_ts, end_ts) + except IndexError: + txt = "Drinks poured by date" + + hours = 0 + return trending_drinks_detail(begin_ts, end_ts, txt, hours) @app.route('/trending/') def trending_drinks_detail(hours): @@ -44,10 +89,19 @@ def trending_drinks_detail(hours): else: begindate = 0 else: - begindate = 0 + begindate = 0 enddate = 0 txt = "" + return trending_drinks_detail(begindate, enddate, txt, hours) + + +def trending_drinks_detail(begindate, enddate, txt='', hours=''): + + title = "Trending drinks" + + #import pdb + #pdb.set_trace() total_number = db.session.query("number")\ .from_statement("""SELECT count(*) as number FROM drink_log @@ -75,9 +129,24 @@ def trending_drinks_detail(hours): ORDER BY count(drink_log.drink_id) desc;""")\ .params(begin=begindate, end=enddate).all() - return render_template("trending", top_drinks = top_drinks, options=app.options, + drinks_by_date = db.session.query("date", "number", "volume")\ + .from_statement("""SELECT date(time-43200,'unixepoch') as date, + count(drink_log.drink_id) AS number, + sum(drink_log.size) AS volume + FROM drink_log, drink_name, drink + WHERE drink_log.drink_id = drink_name.id + AND drink_name.id = drink.id + GROUP BY date + ORDER BY date desc;""")\ + .params().all() + + return render_template("trending", top_drinks = top_drinks, + drinks_by_date = drinks_by_date, + options=app.options, title="Trending drinks", txt=txt, total_number=total_number[0], total_volume=total_volume[0], hours=hours) + + diff --git a/ui/content/templates/trending b/ui/content/templates/trending index 2e56e21e..c0fb667f 100644 --- a/ui/content/templates/trending +++ b/ui/content/templates/trending @@ -2,7 +2,8 @@ {% set active = "trending" %} {% block body %}

- {% if top_drinks %} + + {% if 1%}

{{ title }}

@@ -38,6 +39,7 @@ {% endif %}
+ {% for id, name, number, volume in top_drinks %} @@ -50,12 +52,28 @@ {% endif %} {% endfor %}
drinknumbervolume
+

Drinks by Date

+ (A day starts at BARTENDRO_DAY_START_TIME, and lasts until BARTENDRO_DAY_START_TIME the next day) + + + {% for date, number, volume in drinks_by_date %} + +
datenumbervolume
{{ date }}{{ number }} + + {% if options.metric %} + {{ "%.2f" | format((volume / 1000)|float) }} liters + {% else %} + {{ "%.2f" | format((volume / 1000) / 3.81|float) }} gallons + {% endif %} + {% endfor %} +
{% else %}

No drinks have been poured in the last {{ hours }} hours! Go and be a trend setter!

Main menu
{% endif %} +
{% endblock %} From 70750b3748c495ea7af73696557375071c4fa334 Mon Sep 17 00:00:00 2001 From: Rich Gibson Date: Thu, 10 Mar 2016 01:28:28 -0800 Subject: [PATCH 2/3] Trending drinks improvement for a first pass at issue 105. Shows the drinks by date on the trending page, along with the ability to see the drinks for each day. Implements 'bartendro standard time' to start at 10 am. This handles most of the cases when an event runs across midnight. If you enter Jan 1st as a begin date it will show you drinks from 10 am Jan 1st - 10 am Jan 2nd. --- ui/bartendro/view/trending.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ui/bartendro/view/trending.py b/ui/bartendro/view/trending.py index 7fb61997..890271e8 100644 --- a/ui/bartendro/view/trending.py +++ b/ui/bartendro/view/trending.py @@ -41,8 +41,6 @@ def trending_drinks_date(): if (len(begindate) > 0) : begin_ts = time.mktime(datetime.datetime.strptime(begindate, "%Y-%m-%d").timetuple()) begin_ts = begin_ts + BARTENDRO_DAY_START_TIME - #begindate = datetime.datetime.fromtimestamp(begin_ts).strftime('%Y-%m-%d %H:%M:%S') - begindate = datetime.datetime.fromtimestamp(begin_ts).strftime('%c') else: begin_ts = 0 @@ -56,11 +54,10 @@ def trending_drinks_date(): else: end_ts = time.mktime(datetime.datetime.strptime(enddate, "%Y-%m-%d").timetuple()) end_ts = end_ts + 24*60*60+BARTENDRO_DAY_START_TIME - 1 - #begin_ts = time.mktime(datetime.datetime.strptime(enddate, "%YYYY-m/-%d").timetuple()) enddate = datetime.datetime.fromtimestamp(end_ts).strftime('%c') try: - txt = "Drinks poured from %s to %s

begin_ts: %i end_ts: %i" % (begindate, enddate,begin_ts, end_ts) + txt = "Drinks poured from %s to %s " % (begindate, enddate) except IndexError: txt = "Drinks poured by date" @@ -130,7 +127,7 @@ def trending_drinks_detail(begindate, enddate, txt='', hours=''): .params(begin=begindate, end=enddate).all() drinks_by_date = db.session.query("date", "number", "volume")\ - .from_statement("""SELECT date(time-43200,'unixepoch') as date, + .from_statement("""SELECT date(time- :BARTENDRO_DAY_START_TIME,'unixepoch') as date, count(drink_log.drink_id) AS number, sum(drink_log.size) AS volume FROM drink_log, drink_name, drink @@ -138,7 +135,7 @@ def trending_drinks_detail(begindate, enddate, txt='', hours=''): AND drink_name.id = drink.id GROUP BY date ORDER BY date desc;""")\ - .params().all() + .params(BARTENDRO_DAY_START_TIME=BARTENDRO_DAY_START_TIME).all() return render_template("trending", top_drinks = top_drinks, drinks_by_date = drinks_by_date, From fa727e01198515b133d9fbb367bd752c6c7e13a0 Mon Sep 17 00:00:00 2001 From: Rich Gibson Date: Thu, 10 Mar 2016 01:34:34 -0800 Subject: [PATCH 3/3] Added the drink size underneath the list of ingredients. This is a duplicate of the obvious drink size on the right side, but it seemed reasonable to me. ymmv. --- ui/content/templates/drink/index | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/content/templates/drink/index b/ui/content/templates/drink/index index 11cec482..d03724d1 100644 --- a/ui/content/templates/drink/index +++ b/ui/content/templates/drink/index @@ -18,6 +18,9 @@ {% endfor %} + +

{{ options.drink_size }}
+