diff options
Diffstat (limited to 'dash/pages/vms.py')
-rw-r--r-- | dash/pages/vms.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/dash/pages/vms.py b/dash/pages/vms.py index fae6fb9..953ff3b 100644 --- a/dash/pages/vms.py +++ b/dash/pages/vms.py @@ -43,7 +43,7 @@ def layout(): dbc.Col(width=12, lg=6, children=[ dcc.Dropdown( id='vms-satellite', - options=[{'label': s, 'value': s} for s in get_satellites()], + options=[{'label': name, 'value': ip} for ip, name in get_satellites()], value=None, placeholder='All Satellites', persistence=True, @@ -69,8 +69,9 @@ def make_content_all(days, date): cursor = dbcon.cursor() stmt = """ - SELECT r.ip, COUNT(DISTINCT v.vm) as count + SELECT COUNT(DISTINCT v.vm) as count, COALESCE(nm.name, r.ip) AS name FROM reports r + LEFT OUTER JOIN names nm ON r.ip = nm.ip JOIN perVM v ON r.id = v.report WHERE r.date = (SELECT date FROM reports WHERE date >= %s ORDER BY date ASC LIMIT 1) AND v.days = %s @@ -85,7 +86,7 @@ def make_content_all(days, date): figure = go.Figure() figure.add_trace(go.Bar( - x=[item['ip'] for item in data], + x=[item['name'] for item in data], y=[item['count'] for item in data] )) figure.update_layout( @@ -123,17 +124,6 @@ def make_content_sat(days, date, satellite): return figure -def get_satellites(): - dbcon = db.getConnection() - cursor = dbcon.cursor() - - cursor.execute("""SELECT DISTINCT ip FROM reports""") - - data = [item['ip'] for item in cursor.fetchall()] - - db.closeConnection(dbcon) - return data - def get_newest_date(): dbcon = db.getConnection() cursor = dbcon.cursor() @@ -156,3 +146,17 @@ def get_oldest_date(): db.closeConnection(dbcon) return data[0]['date'] +def get_satellites(): + dbcon = db.getConnection() + cursor = dbcon.cursor() + + cursor.execute(""" + SELECT DISTINCT r.ip, COALESCE(nm.name, r.ip) AS name FROM reports r + LEFT OUTER JOIN names nm ON r.ip = nm.ip + ORDER BY name ASC + """) + + data = [(item['ip'], item['name']) for item in cursor.fetchall()] + + db.closeConnection(dbcon) + return data |