summaryrefslogtreecommitdiffstats
path: root/dash
diff options
context:
space:
mode:
authorLukas Metzger2020-07-23 15:07:49 +0200
committerLukas Metzger2020-07-23 15:07:49 +0200
commitab02fb626f4d300f61338040d3933c9cc6cddde9 (patch)
treeb991c31fef1998d7c905e4fd9eaa402a7f6b0738 /dash
parentAdd sample import script, fix readme (diff)
downloadbwlp-statistics-ab02fb626f4d300f61338040d3933c9cc6cddde9.tar.gz
bwlp-statistics-ab02fb626f4d300f61338040d3933c9cc6cddde9.tar.xz
bwlp-statistics-ab02fb626f4d300f61338040d3933c9cc6cddde9.zip
Use range from chart for total aggregation
Diffstat (limited to 'dash')
-rw-r--r--dash/pages/total.py52
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()