|
@@ -22,9 +22,11 @@ from bottle import (
|
|
|
static_file,
|
|
|
TEMPLATE_PATH,
|
|
|
)
|
|
|
+from matplotlib.axes import Axes
|
|
|
TEMPLATE_PATH.append("app/rest/templates")
|
|
|
from psycopg import connect
|
|
|
from psycopg.sql import SQL, Literal
|
|
|
+from pandas import DataFrame
|
|
|
import matplotlib.pyplot as plt
|
|
|
import seaborn as sns
|
|
|
from multiprocessing import Lock
|
|
@@ -39,14 +41,6 @@ from ..data.util import(
|
|
|
import matplotlib
|
|
|
matplotlib.use('agg')
|
|
|
|
|
|
-def line(pivot, ylabel=None, xlabel=None):
|
|
|
- ax = sns.lineplot(data=pivot, markers=True)
|
|
|
- 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' }
|
|
|
CACHE = dict()
|
|
@@ -269,10 +263,33 @@ def trend_internal(path, query):
|
|
|
|
|
|
progress.append({ "name": "Loading chart", "status": ""})
|
|
|
yield template("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}')
|
|
|
+
|
|
|
+ sns.set(style="darkgrid", palette='pastel', context="talk")
|
|
|
+ plt.style.use("dark_background")
|
|
|
+ plt.rcParams.update({"grid.linewidth":0.1, "grid.alpha":0.5})
|
|
|
+ plt.figure(figsize=[16, 9], layout="tight")
|
|
|
+ xlabel='Time'
|
|
|
+ ylabel=f'$ / {unit}'
|
|
|
+ if pivot.columns.size > 50:
|
|
|
+ ax = sns.scatterplot(data=pivot, markers=True)
|
|
|
+ else:
|
|
|
+ ax = sns.lineplot(data=pivot, markers=True)
|
|
|
+ legend = plt.figlegend(
|
|
|
+ loc='upper center', ncol=6,
|
|
|
+ title_fontsize="14", fontsize="12", labelcolor='#a0a0a0',
|
|
|
+ framealpha=0.5
|
|
|
+ )
|
|
|
+ legend.set_title(title="Products")
|
|
|
+ ax.legend().set_visible(False)
|
|
|
+
|
|
|
+ ax.set_xlabel(xlabel, color='#a0a0a0', fontsize="14")
|
|
|
+ ax.set_ylabel(ylabel, color='#a0a0a0', fontsize="14")
|
|
|
+ ax.axes.tick_params(colors='#a0a0a0', labelsize="12", which='both')
|
|
|
+ for _, spine in ax.spines.items():
|
|
|
+ spine.set_color('#a0a0a0')
|
|
|
|
|
|
progress[-1]["status"] = "done"
|
|
|
yield template("loading", progress=progress)
|
|
@@ -287,7 +304,6 @@ def trend_internal(path, query):
|
|
|
progress[-1]["status"] = "done"
|
|
|
yield template("loading", progress=progress)
|
|
|
|
|
|
- final = template("trend", form=form, svg=f.getvalue())
|
|
|
resp = lambda: template("trend", form=form, svg=f.getvalue())
|
|
|
|
|
|
except HTTPError as e:
|