diff options
author | Lukas Metzger | 2020-07-02 13:18:33 +0200 |
---|---|---|
committer | Lukas Metzger | 2020-07-02 13:18:33 +0200 |
commit | 17609e1523369c5b29cfc34e2bf8a82fc5b6bd23 (patch) | |
tree | ff58aa48e0691acde15176616734dd4374ed7324 /dash/pages/total.py | |
parent | Added additional prettytime (diff) | |
download | bwlp-statistics-17609e1523369c5b29cfc34e2bf8a82fc5b6bd23.tar.gz bwlp-statistics-17609e1523369c5b29cfc34e2bf8a82fc5b6bd23.tar.xz bwlp-statistics-17609e1523369c5b29cfc34e2bf8a82fc5b6bd23.zip |
Added names for sattelites
Diffstat (limited to 'dash/pages/total.py')
-rw-r--r-- | dash/pages/total.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/dash/pages/total.py b/dash/pages/total.py index 461c03a..91bcc87 100644 --- a/dash/pages/total.py +++ b/dash/pages/total.py @@ -41,7 +41,7 @@ def layout(): dbc.Col(width=12, lg=6, children=[ dcc.Dropdown( id='total-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', @@ -135,9 +135,14 @@ def make_graph_session_length(days, rangeStart, rangeEnd, satellites): cursor = dbcon.cursor() stmt = """ - SELECT r.date, r.ip, t.medianSessionLength + SELECT + r.date, + r.ip, + COALESCE(nm.name, r.ip) AS name, + t.medianSessionLength FROM reports r JOIN total t ON r.id = t.report + LEFT OUTER JOIN names nm ON r.ip = nm.ip WHERE t.days = %s AND r.date >= %s AND r.date <= %s """ @@ -152,12 +157,12 @@ def make_graph_session_length(days, rangeStart, rangeEnd, satellites): db.closeConnection(dbcon) figure = go.Figure() - for sat in set([item['ip'] for item in data]): + for sat, n in set([(item['ip'], item['name']) for item in data]): figure.add_trace(go.Scatter( x=[item['date'] for item in data if item['ip'] == sat], y=[int(item['medianSessionLength'] / 60) for item in data if item['ip'] == sat], mode='lines+markers', - name=sat + name=n )) figure.update_layout( yaxis_ticksuffix=' min', @@ -303,9 +308,13 @@ def get_satellites(): dbcon = db.getConnection() cursor = dbcon.cursor() - cursor.execute("""SELECT DISTINCT ip FROM reports""") + 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'] for item in cursor.fetchall()] + data = [(item['ip'], item['name']) for item in cursor.fetchall()] db.closeConnection(dbcon) return data |