|
@@ -60,7 +60,7 @@ sns.set_theme(style='darkgrid', palette='pastel')
|
|
|
|
|
|
def get_product_rollup_statement(filters, having=None):
|
|
|
where = [ get_where_include_exclude(
|
|
|
- k[0], "name", include, exclude
|
|
|
+ k[0], "name", list(include), list(exclude)
|
|
|
) for k, (include, exclude) in filters.items() ]
|
|
|
return SQL('\n').join([
|
|
|
SQL("""
|
|
@@ -121,12 +121,12 @@ def get_form(action, method, filter_data, data):
|
|
|
k for k in keys
|
|
|
]]
|
|
|
return template(
|
|
|
- 'app/rest/form',
|
|
|
+ 'app/rest/templates/form',
|
|
|
action=action,
|
|
|
method=method,
|
|
|
header=[
|
|
|
template(
|
|
|
- 'app/rest/filter-heading',
|
|
|
+ 'app/rest/templates/filter-heading',
|
|
|
fname=k,
|
|
|
first=(idx == 0),
|
|
|
) for idx, k in enumerate(keys)
|
|
@@ -200,7 +200,7 @@ def trend():
|
|
|
if request.query_string != normalized:
|
|
|
return redirect(f'{path}?{normalized}')
|
|
|
|
|
|
- loading = template("app/rest/loading", progress=[])
|
|
|
+ loading = template("app/rest/templates/loading", progress=[])
|
|
|
if request.query_string in CACHE:
|
|
|
if LOCK.acquire(block=False):
|
|
|
try:
|
|
@@ -239,37 +239,37 @@ def trend_internal(path, query):
|
|
|
raise abort(400, f"Unsupported unit {unit}")
|
|
|
|
|
|
progress.append({ "name": "Loading data", "status": ""})
|
|
|
- yield template("app/rest/loading", progress=progress)
|
|
|
+ yield template("app/rest/templates/loading", progress=progress)
|
|
|
data = get_data(query_manager, **fields)
|
|
|
|
|
|
progress[-1]["status"] = "done"
|
|
|
- yield template("app/rest/loading", progress=progress)
|
|
|
+ yield template("app/rest/templates/loading", progress=progress)
|
|
|
|
|
|
if data.empty:
|
|
|
raise abort(404, f"No data for {fields}")
|
|
|
|
|
|
progress.append({ "name": "Loading chart", "status": ""})
|
|
|
- yield template("app/rest/loading", progress=progress)
|
|
|
+ yield template("app/rest/templates/loading", progress=progress)
|
|
|
pivot = data.pivot_table(index=['ts_raw',], columns=['product',], values=['$/unit'], aggfunc='mean')
|
|
|
pivot.columns = pivot.columns.droplevel()
|
|
|
plt.figure(facecolor='black', figsize=[16, 9])
|
|
|
line(pivot, xlabel='Time', ylabel=f'$ / {unit}')
|
|
|
|
|
|
progress[-1]["status"] = "done"
|
|
|
- yield template("app/rest/loading", progress=progress)
|
|
|
+ yield template("app/rest/templates/loading", progress=progress)
|
|
|
|
|
|
progress.append({ "name": "Rendering chart", "status": ""})
|
|
|
- yield template("app/rest/loading", progress=progress)
|
|
|
+ yield template("app/rest/templates/loading", progress=progress)
|
|
|
|
|
|
f = StringIO()
|
|
|
plt.savefig(f, format='svg')
|
|
|
form = get_form(path, 'get', get_filter(request.query, allow=PARAMS), data)
|
|
|
|
|
|
progress[-1]["status"] = "done"
|
|
|
- yield template("app/rest/loading", progress=progress)
|
|
|
+ yield template("app/rest/templates/loading", progress=progress)
|
|
|
|
|
|
- final = template("app/rest/trend", form=form, svg=f.getvalue())
|
|
|
- resp = lambda: template("app/rest/trend", form=form, svg=f.getvalue())
|
|
|
+ final = template("app/rest/templates/trend", form=form, svg=f.getvalue())
|
|
|
+ resp = lambda: template("app/rest/templates/trend", form=form, svg=f.getvalue())
|
|
|
|
|
|
except HTTPError as e:
|
|
|
resp = lambda exception=e: exception
|
|
@@ -284,7 +284,7 @@ def table():
|
|
|
title = request.query['title'] if 'title' in request.query.keys() else None
|
|
|
foot = request.query['foot'] == 'True' and "last()" if 'foot' in request.query.keys() else "-1"
|
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
|
- return template("app/rest/query-to-xml-xslt", title=title, foot=foot)
|
|
|
+ return template("app/rest/templates/query-to-xml-xslt", title=title, foot=foot)
|
|
|
|
|
|
@route('/grocery/groups')
|
|
|
def groups():
|
|
@@ -336,7 +336,7 @@ FROM (
|
|
|
conn.commit()
|
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
|
return template(
|
|
|
- "app/rest/query-to-xml",
|
|
|
+ "app/rest/templates/query-to-xml",
|
|
|
title="Categories",
|
|
|
foot=True,
|
|
|
xml=xml
|
|
@@ -365,7 +365,7 @@ FROM (
|
|
|
conn.commit()
|
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
|
return template(
|
|
|
- "app/rest/query-to-xml",
|
|
|
+ "app/rest/templates/query-to-xml",
|
|
|
title="Products",
|
|
|
foot=True,
|
|
|
xml=xml
|
|
@@ -390,7 +390,7 @@ SELECT query_to_xml_and_xmlschema({inner}, false, false, ''::text)
|
|
|
conn.commit()
|
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
|
return template(
|
|
|
- "app/rest/query-to-xml",
|
|
|
+ "app/rest/templates/query-to-xml",
|
|
|
title="Tags",
|
|
|
foot="false",
|
|
|
xml=xml
|