summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Metzger2020-05-29 19:21:07 +0200
committerLukas Metzger2020-05-29 19:21:07 +0200
commit9160bbd982a981de642b9be4c50bd2ea7b61cf15 (patch)
tree24184caf01437ecc55f3bfa41de70fdfb6fd3688
parentAdded website title (diff)
downloadbwlp-statistics-9160bbd982a981de642b9be4c50bd2ea7b61cf15.tar.gz
bwlp-statistics-9160bbd982a981de642b9be4c50bd2ea7b61cf15.tar.xz
bwlp-statistics-9160bbd982a981de642b9be4c50bd2ea7b61cf15.zip
Added overview of location for cpumodel and systemmodel
-rw-r--r--pages/machines.py58
1 files changed, 56 insertions, 2 deletions
diff --git a/pages/machines.py b/pages/machines.py
index 5ec8956..ab0b413 100644
--- a/pages/machines.py
+++ b/pages/machines.py
@@ -58,10 +58,12 @@ def layout():
dcc.Loading(dcc.Graph(id='machines-graph-kvmstate'))
]),
dbc.Col(width=12, xl=6, children=[
- dcc.Loading(dcc.Graph(id='machines-graph-cpumodel'))
+ dcc.Loading(dcc.Graph(id='machines-graph-cpumodel')),
+ dcc.Loading(dcc.Graph(id='machines-graph-cpumodel-locations')),
]),
dbc.Col(width=12, xl=6, children=[
- dcc.Loading(dcc.Graph(id='machines-graph-systemmodel'))
+ dcc.Loading(dcc.Graph(id='machines-graph-systemmodel')),
+ dcc.Loading(dcc.Graph(id='machines-graph-systemmodel-locations')),
])
])
])
@@ -138,6 +140,58 @@ def make_graph_systemmodel(days, date, satellites):
def make_graph_kvmstate(days, date, satellites):
return make_graph(days, date, satellites, 'kvmstate', 'KVM State')
+@app.callback([Output('machines-graph-cpumodel-locations', 'style'),
+ Output('machines-graph-cpumodel-locations', 'figure')],
+ [Input('machines-days', 'value'),
+ Input('machines-date', 'date'),
+ Input('machines-graph-cpumodel', 'clickData')])
+def make_graph_cpumodel_locations(days, date, clickData):
+ return make_graph_locations(days, date, clickData, 'cpumodel')
+
+@app.callback([Output('machines-graph-systemmodel-locations', 'style'),
+ Output('machines-graph-systemmodel-locations', 'figure')],
+ [Input('machines-days', 'value'),
+ Input('machines-date', 'date'),
+ Input('machines-graph-systemmodel', 'clickData')])
+def make_graph_systemmodel_locations(days, date, clickData):
+ return make_graph_locations(days, date, clickData, 'systemmodel')
+
+def make_graph_locations(days, date, clickData, prop):
+ if clickData == None:
+ return dict(display='none'), dict()
+
+ dbcon = db.getConnection()
+ cursor = dbcon.cursor()
+
+ stmt = """
+ SELECT r.ip, m.count
+ FROM reports r
+ JOIN machine m ON r.id = m.report
+ WHERE r.date = (SELECT date FROM reports WHERE date >= %s ORDER BY date ASC LIMIT 1)
+ AND m.days = %s
+ AND m.property = %s
+ AND m.value = %s
+ ORDER BY m.count DESC
+ """
+ item = clickData['points'][0]['y']
+
+ cursor.execute(stmt, (date, days, prop, item))
+
+ data = cursor.fetchall()
+
+ db.closeConnection(dbcon)
+
+ figure = go.Figure()
+ figure.add_trace(go.Bar(
+ x=[item['ip'] for item in data],
+ y=[item['count'] for item in data]
+ ))
+ figure.update_layout(
+ height = 400
+ )
+
+ return dict(display='block'), figure
+
def make_graph(days, date, satellites, prop, title, unit='', typ='pie'):
dbcon = db.getConnection()