summaryrefslogtreecommitdiffstats
path: root/dash
diff options
context:
space:
mode:
Diffstat (limited to 'dash')
-rw-r--r--dash/pages/machines.py47
1 files changed, 47 insertions, 0 deletions
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<br><sub>Click Bar to view Details</sub>', typ='bar')
+
+#def make_graph_basesystem(days, date, satellites):
+# return make_graph(days, date, satellites, 'basesystem', 'BASE SYSTEMS<br><sub>Click Bar to view Details</sub>', 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()