|
@@ -39,8 +39,11 @@ matplotlib.use('agg')
|
|
|
|
|
|
def line(pivot, ylabel=None, xlabel=None):
|
|
|
ax = sns.lineplot(data=pivot, markers=True)
|
|
|
- ax.set_xlabel(xlabel)
|
|
|
- ax.set_ylabel(ylabel)
|
|
|
+ ax.set_xlabel(xlabel, color='#cccccc')
|
|
|
+ ax.set_ylabel(ylabel, color='#cccccc')
|
|
|
+ ax.axes.tick_params(colors='#cccccc', which='both')
|
|
|
+ for _, spine in ax.spines.items():
|
|
|
+ spine.set_color('#cccccc')
|
|
|
|
|
|
ALL_UNITS = {'g', 'kg', 'mL', 'L', 'Pieces', 'Bunches', 'Bags'}
|
|
|
PARAMS = { 'group', 'category', 'product', 'unit', 'tag' }
|
|
@@ -53,7 +56,7 @@ password = f"password={os.getenv('PASSWORD','')}"
|
|
|
if not password.split('=',1)[1]:
|
|
|
password = ''
|
|
|
conn = connect(f"{host} {db} {user} {password}")
|
|
|
-sns.set_theme()
|
|
|
+sns.set_theme(style='darkgrid', palette='pastel')
|
|
|
|
|
|
def get_product_rollup_statement(filters, having=None):
|
|
|
where = [ get_where_include_exclude(
|
|
@@ -128,53 +131,56 @@ def get_form(action, method, filter_data, data):
|
|
|
first=(idx == 0),
|
|
|
) for idx, k in enumerate(keys)
|
|
|
],
|
|
|
- _include=[ template(
|
|
|
- 'app/rest/filter-item',
|
|
|
- label="+",
|
|
|
- hint="Include",
|
|
|
- id=f"{k}-include",
|
|
|
- fname=k,
|
|
|
- options=sorted(map(lambda x: {
|
|
|
+ **{
|
|
|
+ k: {
|
|
|
+ "name": k,
|
|
|
+ "_include": {
|
|
|
+ "options": sorted(map(lambda x: {
|
|
|
+ "selected": x[0],
|
|
|
+ "value": x[1],
|
|
|
+ }, chain(
|
|
|
+ map(lambda x: (True, x), filter_data[k][0]),
|
|
|
+ map(lambda x: (False, x), set([
|
|
|
+ x[k] for _, x in group.iterrows()
|
|
|
+ ]) - filter_data[k][0])
|
|
|
+ )), key=lambda x: x["display"] if "display" in x else x["value"])
|
|
|
+ },
|
|
|
+ "_exclude": {
|
|
|
+ "options": sorted(map(lambda x: {
|
|
|
+ "selected": x[0],
|
|
|
+ "value": f"!{x[1]}",
|
|
|
+ "display": x[1]
|
|
|
+ }, chain(
|
|
|
+ map(lambda x: (True, x), filter_data[k][1]),
|
|
|
+ map(lambda x: (False, x), set([
|
|
|
+ x[k] for _, x in group.iterrows()
|
|
|
+ ]) - filter_data[k][1])
|
|
|
+ )), key=lambda x: x["display"] if "display" in x else x["value"])
|
|
|
+ }
|
|
|
+ } for k in keys
|
|
|
+ },
|
|
|
+ tags={
|
|
|
+ "name": "tags",
|
|
|
+ "_include": {
|
|
|
+ "options": sorted(map(lambda x: {
|
|
|
"selected": x[0],
|
|
|
"value": x[1],
|
|
|
- }, chain(
|
|
|
- map(lambda x: (True, x), filter_data[k][0]),
|
|
|
- map(lambda x: (False, x), set([
|
|
|
- x[k] for _, x in group.iterrows()
|
|
|
- ]) - filter_data[k][0])
|
|
|
- )), key=lambda x: x["display"] if "display" in x else x["value"]), # include
|
|
|
- ) for k in keys ],
|
|
|
- _exclude=[ template(
|
|
|
- 'app/rest/filter-item',
|
|
|
- label="-",
|
|
|
- hint="Exclude",
|
|
|
- id=f"{k}-exclude",
|
|
|
- fname=k,
|
|
|
- options=sorted(map(lambda x: {
|
|
|
- "selected": x[0],
|
|
|
- "value": f"!{x[1]}",
|
|
|
- "display": x[1]
|
|
|
- }, chain(
|
|
|
- map(lambda x: (True, x), filter_data[k][1]),
|
|
|
- map(lambda x: (False, x), set([
|
|
|
- x[k] for _, x in group.iterrows()
|
|
|
- ]) - filter_data[k][1])
|
|
|
- )), key=lambda x: x["display"] if "display" in x else x["value"]), # exclude
|
|
|
- ) for k in keys ],
|
|
|
- tags=sorted(map(lambda x: {
|
|
|
- "selected": x[0],
|
|
|
- "value": x[1],
|
|
|
- },chain(
|
|
|
- map(lambda x: (True, x), filter_data['tag'][0]),
|
|
|
- map(lambda x: (False, x), set(chain(*data[in_chart]['tags'])) - filter_data['tag'][0])
|
|
|
- )), key=lambda x: x["display"] if "display" in x else x["value"]), # include,
|
|
|
- units=sorted(map(lambda x: {
|
|
|
+ },chain(
|
|
|
+ map(lambda x: (True, x), filter_data['tag'][0]),
|
|
|
+ map(lambda x: (False, x), set(chain(*data[in_chart]['tags'])) - filter_data['tag'][0])
|
|
|
+ )), key=lambda x: x["display"] if "display" in x else x["value"])
|
|
|
+ }
|
|
|
+ },
|
|
|
+ units={
|
|
|
+ "name": "units",
|
|
|
+ "options": sorted(map(lambda x: {
|
|
|
"selected": x[0],
|
|
|
"value": x[1],
|
|
|
},chain(
|
|
|
map(lambda x: (True, x), filter_data['unit'][0]),
|
|
|
map(lambda x: (False, x), ALL_UNITS - filter_data['unit'][0])
|
|
|
- )), key=lambda x: x["display"] if "display" in x else x["value"]), # include
|
|
|
+ )), key=lambda x: x["display"] if "display" in x else x["value"])
|
|
|
+ }
|
|
|
)
|
|
|
|
|
|
@route('/grocery/static/<filename:path>')
|
|
@@ -246,7 +252,7 @@ def trend_internal(path, query):
|
|
|
yield template("app/rest/loading", progress=progress)
|
|
|
pivot = data.pivot_table(index=['ts_raw',], columns=['product',], values=['$/unit'], aggfunc='mean')
|
|
|
pivot.columns = pivot.columns.droplevel()
|
|
|
- plt.figure(figsize=[16, 9])
|
|
|
+ plt.figure(facecolor='black', figsize=[16, 9])
|
|
|
line(pivot, xlabel='Time', ylabel=f'$ / {unit}')
|
|
|
|
|
|
progress[-1]["status"] = "done"
|