summaryrefslogtreecommitdiffstats
path: root/dash/pages/locations.py
diff options
context:
space:
mode:
authorLukas Metzger2020-07-02 13:18:33 +0200
committerLukas Metzger2020-07-02 13:18:33 +0200
commit17609e1523369c5b29cfc34e2bf8a82fc5b6bd23 (patch)
treeff58aa48e0691acde15176616734dd4374ed7324 /dash/pages/locations.py
parentAdded additional prettytime (diff)
downloadbwlp-statistics-17609e1523369c5b29cfc34e2bf8a82fc5b6bd23.tar.gz
bwlp-statistics-17609e1523369c5b29cfc34e2bf8a82fc5b6bd23.tar.xz
bwlp-statistics-17609e1523369c5b29cfc34e2bf8a82fc5b6bd23.zip
Added names for sattelites
Diffstat (limited to 'dash/pages/locations.py')
-rw-r--r--dash/pages/locations.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/dash/pages/locations.py b/dash/pages/locations.py
index 74e86b2..f62baf6 100644
--- a/dash/pages/locations.py
+++ b/dash/pages/locations.py
@@ -44,7 +44,7 @@ def layout():
dbc.Col(width=12, lg=6, children=[
dcc.Dropdown(
id='locations-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,
@@ -82,10 +82,10 @@ def make_content_all(days, date):
db.closeConnection(dbcon)
- satellites = natsorted(get_satellites())
+ satellites = natsorted(get_satellites(), key = lambda x: x[0])
figures = []
- for sat in satellites:
+ for sat, name in satellites:
figure = go.Figure()
figure.add_trace(go.Pie(
labels=[item['locationname'][0:9] for item in data if item['ip'] == sat],
@@ -98,7 +98,7 @@ def make_content_all(days, date):
))
numElements = len([item['ip'] for item in data if item['ip'] == sat])
figure.update_layout(
- title_text = '<sub>Sessiontime per Location (Total: {})</sub><br>{}'.format(numElements, sat),
+ title_text = '<sub>Sessiontime per Location (Total: {})</sub><br>{}'.format(numElements, name),
showlegend=False
)
if len([item for item in data if item['ip'] == sat and item['totalSessionTime'] > 0]) > 0:
@@ -213,17 +213,6 @@ def make_content_sat_sessions(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()
@@ -246,3 +235,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