diff options
-rw-r--r-- | dash/pages/total.py | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/dash/pages/total.py b/dash/pages/total.py index 91bcc87..9678d6e 100644 --- a/dash/pages/total.py +++ b/dash/pages/total.py @@ -257,22 +257,25 @@ def make_graph_users(days, rangeStart, rangeEnd, satellites): ) return figure -@app.callback([Output('total-sum-times', 'children'), - Output('total-sum-sessions', 'children')], +@app.callback(Output('total-sum-times', 'children'), [Input('total-range', 'start_date'), Input('total-range', 'end_date'), + Input('total-graph-times', 'relayoutData'), Input('total-satellites', 'value')]) -def make_sums(rangeStart, rangeEnd, satellites): +def make_sum_times(rangeStart, rangeEnd, layoutData, satellites): dbcon = db.getConnection() cursor = dbcon.cursor() + if layoutData != None and layoutData.get('xaxis.range[0]'): + rangeStart = layoutData['xaxis.range[0]'].split()[0] + rangeEnd = layoutData['xaxis.range[1]'].split()[0] + + 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 + SUM(t.totalOffTime) AS totalOffTime FROM reports r JOIN total t ON r.id = t.report WHERE t.days = 7 AND r.date >= %s AND r.date <= %s @@ -297,12 +300,47 @@ def make_sums(rangeStart, rangeEnd, satellites): except: strTimes = "No Data available!" + return strTimes + +@app.callback(Output('total-sum-sessions', 'children'), + [Input('total-range', 'start_date'), + Input('total-range', 'end_date'), + Input('total-graph-sessions', 'relayoutData'), + Input('total-satellites', 'value')]) +def make_sum_sessions(rangeStart, rangeEnd, layoutData, satellites): + dbcon = db.getConnection() + cursor = dbcon.cursor() + + if layoutData != None and layoutData.get('xaxis.range[0]'): + rangeStart = layoutData['xaxis.range[0]'].split()[0] + rangeEnd = layoutData['xaxis.range[1]'].split()[0] + + + stmt = """ + SELECT + 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([rangeStart, rangeEnd] + satellites)) + else: + cursor.execute(stmt, (rangeStart, rangeEnd)) + + data = cursor.fetchall()[0] + + db.closeConnection(dbcon) + try: strSessions = 'Total Short Sessions: {} Total Long Sessions: {}'.format(data['shortSessions'], data['longSessions']) except: strSessions = "No Data available!" - return strTimes, strSessions + return strSessions def get_satellites(): dbcon = db.getConnection() |