diff options
Diffstat (limited to 'dash/pages/machines.py')
-rw-r--r-- | dash/pages/machines.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/dash/pages/machines.py b/dash/pages/machines.py index b6cb6f8..f9d69da 100644 --- a/dash/pages/machines.py +++ b/dash/pages/machines.py @@ -43,7 +43,7 @@ def layout(): dbc.Col(width=12, lg=6, children=[ dcc.Dropdown( id='machines-satellites', - options=[{'label': s, 'value': s} for s in get_satellites()], + options=[{'label': name, 'value': ip} for ip, name in get_satellites()], multi=True, value=[], placeholder='All Satellites', @@ -279,17 +279,6 @@ def make_graph(days, date, satellites, prop, title, unit='', typ='pie'): ) 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() @@ -312,3 +301,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 |