From 48a74145c39b739bbd06fb779fca46c70bcf4006 Mon Sep 17 00:00:00 2001 From: Chuck SmileyRekiere Date: Wed, 4 Aug 2021 08:05:58 -0600 Subject: [PATCH] kpi_csv_sq.py : code fixes , runs Signed-off-by: Chuck SmileyRekiere --- py-scripts/sandbox/kpi_csv_sq.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/py-scripts/sandbox/kpi_csv_sq.py b/py-scripts/sandbox/kpi_csv_sq.py index 589c4312..66d11726 100755 --- a/py-scripts/sandbox/kpi_csv_sq.py +++ b/py-scripts/sandbox/kpi_csv_sq.py @@ -33,7 +33,7 @@ class csv_sqlite_dash(): self.conn = None self.df = pd.DataFrame() self.plot_figure = [] - children_div = [] + self.children_div = [] # information on sqlite database # https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_sql.html @@ -58,7 +58,7 @@ class csv_sqlite_dash(): self.conn.close() # duplicates the store since the the png are put back into the directory where the kpi are gathered - def generate_png(self): + def generate_graph_png(self): print("generating png files") if not self.kpi_list: self.store() @@ -69,7 +69,7 @@ class csv_sqlite_dash(): #https://datacarpentry.org/python-ecology-lesson/09-working-with-sql/index.html self.conn = sqlite3.connect(self.database) # df3 is just a name - df3 = pd.read_sql_query("SELECT * from dp_table" ,self.conn) + df3 = pd.read_sql_query("SELECT * from {}".format(self.table) ,self.conn) #print(df3.head()) self.conn.close() @@ -118,6 +118,11 @@ class csv_sqlite_dash(): # access from server # https://stackoverflow.com/questions/61678129/how-to-access-a-plotly-dash-app-server-via-lan def show(self): + if not self.children_div: + self.generate_graph_png() + if not self.children_div: + print("no graph data from kpi.csv found, check input paths, will continue") + app = dash.Dash(__name__, external_stylesheets=external_stylesheets) app.layout = html.Div([ @@ -152,6 +157,7 @@ Usage: kpi_csv_sq.py --path --database --database