diff options
author | Lukas Metzger | 2020-06-11 14:46:16 +0200 |
---|---|---|
committer | Lukas Metzger | 2020-06-11 14:46:16 +0200 |
commit | fb657d7462b0e67bc14c1358fd603bf7110857c3 (patch) | |
tree | 94a5919caba6632b534dee358be8f2d4a224b4c6 /dash/pages | |
parent | Only show location if data is available (diff) | |
download | bwlp-statistics-fb657d7462b0e67bc14c1358fd603bf7110857c3.tar.gz bwlp-statistics-fb657d7462b0e67bc14c1358fd603bf7110857c3.tar.xz bwlp-statistics-fb657d7462b0e67bc14c1358fd603bf7110857c3.zip |
Added total aggregation
Diffstat (limited to 'dash/pages')
-rw-r--r-- | dash/pages/total.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/dash/pages/total.py b/dash/pages/total.py index eb7a63c..130c7f2 100644 --- a/dash/pages/total.py +++ b/dash/pages/total.py @@ -53,12 +53,18 @@ def layout(): dcc.Loading(dcc.Graph(id='total-graph-times')) ])]), dbc.Row([dbc.Col([ + dcc.Loading(html.Pre(id='total-sum-times')) + ])]), + dbc.Row([dbc.Col([ dcc.Loading(dcc.Graph(id='total-graph-session-length')) ])]), dbc.Row([dbc.Col([ dcc.Loading(dcc.Graph(id='total-graph-sessions')) ])]), dbc.Row([dbc.Col([ + dcc.Loading(html.Pre(id='total-sum-sessions')) + ])]), + dbc.Row([dbc.Col([ dcc.Loading(dcc.Graph(id='total-graph-users')) ])]) ]) @@ -242,6 +248,46 @@ def make_graph_users(days, rangeStart, rangeEnd, satellites): ) return figure +@app.callback([Output('total-sum-times', 'children'), + Output('total-sum-sessions', 'children')], + [Input('total-range', 'start_date'), + Input('total-range', 'end_date'), + Input('total-satellites', 'value')]) +def make_sums(rangeStart, rangeEnd, satellites): + dbcon = db.getConnection() + cursor = dbcon.cursor() + + stmt = """ + SELECT + SUM(t.totalTime) AS totalTime, + SUM(t.totalSessionTime) AS totalSessionTime, + SUM(t.totalOffTime) AS totalOffTime, + SUM(t.shortSessions) AS shortSessions, + SUM(t.longSessions) AS longSessions + FROM reports r + JOIN total t ON r.id = t.report + WHERE t.days = 7 AND r.date >= %s AND r.date <= %s + """ + + if len(satellites) > 0: + formatStrings = ','.join(['%s'] * len(satellites)) + cursor.execute(stmt + ' AND r.ip IN ({})'.format(formatStrings), tuple([days, rangeStart, rangeEnd] + satellites)) + else: + cursor.execute(stmt, (rangeStart, rangeEnd)) + + data = cursor.fetchall()[0] + + db.closeConnection(dbcon) + + strTimes = 'Total Time: {}h Total Session Time: {}h Total Off Time: {}h'.format( + int(data['totalTime'] / 3600), + int(data['totalSessionTime'] / 3600), + int(data['totalOffTime'] / 3600) + ) + strSessions = 'Total Short Sessions: {} Total Long Sessions: {}'.format(data['shortSessions'], data['longSessions']) + + return strTimes, strSessions + def get_satellites(): dbcon = db.getConnection() cursor = dbcon.cursor() |