From 045df627ce6e16a75d543bc342fef31a9a86e50e Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 2 May 2022 16:57:53 +0200 Subject: machines.py: add basic base system graph --- dash/pages/machines.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/dash/pages/machines.py b/dash/pages/machines.py index f9d69da..a2db633 100644 --- a/dash/pages/machines.py +++ b/dash/pages/machines.py @@ -71,6 +71,9 @@ def layout(): dbc.Col(width=12, xl=7, children=[ dcc.Loading(dcc.Graph(id='machines-graph-systemmodel')), ]), + dbc.Col(width=12, xl=7, children=[ + dcc.Loading(dcc.Graph(id='machines-graph-basesystem')), + ]), dbc.Col(width=12, xl=4, id='machines-graph-systemmodel-locations-container', children=[ html.H3(id='machines-graph-systemmodel-locations-head', style=dict(fontWeight='normal', fontSize='25px', fontFamily='Open Sans', marginTop='20px')), dcc.Loading(dtbl.DataTable( @@ -179,6 +182,10 @@ def make_graph_ram(days, date, satellites): def make_graph_systemmodel(days, date, satellites): return make_graph(days, date, satellites, 'systemmodel', 'System Model
Click Bar to view Details', typ='bar') + +#def make_graph_basesystem(days, date, satellites): +# return make_graph(days, date, satellites, 'basesystem', 'BASE SYSTEMS
Click Bar to view Details', typ='bar') + @app.callback(Output('machines-graph-kvmstate', 'figure'), [Input('machines-days', 'value'), Input('machines-date', 'date'), @@ -279,6 +286,46 @@ def make_graph(days, date, satellites, prop, title, unit='', typ='pie'): ) return figure +@app.callback(Output('machines-graph-basesystem', 'figure'), + [Input('machines-days', 'value'), + Input('machines-date', 'date'), + Input('machines-satellites', 'value')]) +def make_graph_basesystem(days, date, satellites): + dbcon = db.getConnection() + cursor = dbcon.cursor() + + stmt = """ + SELECT b.system, SUM(b.count) AS count + FROM reports r + JOIN basesystem b ON r.id = b.report + WHERE r.date = (SELECT date FROM reports WHERE date >= %s ORDER BY date ASC LIMIT 1) + AND b.days = %s + """ + stmt_end = """ GROUP BY b.system""" + if len(satellites) > 0: + formatStrings = ','.join(['%s'] * len(satellites)) + cursor.execute(stmt + ' AND r.ip IN ({})'.format(formatStrings) + stmt_end, tuple([date, days] + satellites)) + else: + print(stmt) + cursor.execute(stmt + stmt_end, (date, days)) + + data = cursor.fetchall() + data = natsorted(data, key = lambda x: x['count']) + db.closeConnection(dbcon) + + figure = go.Figure() + figure.add_trace(go.Bar( + y=[item['system'] for item in data], + x=[item['count'] for item in data], + orientation='h' + )) + figure.update_layout( + title_text = "BASE SYSTEMS", + height = max(20 * len(data) + 200,300), + yaxis_automargin=True + ) + return figure + def get_newest_date(): dbcon = db.getConnection() cursor = dbcon.cursor() -- cgit v1.2.3-55-g7522