Commit ec0ecf1a authored by Julian Rother's avatar Julian Rother
Browse files

Implemented basic hls statistics

parent 477eea23
......@@ -126,12 +126,21 @@ CREATE TABLE IF NOT EXISTS `site_texts` (
`modified_by` text NOT NULL
);
CREATE TABLE IF NOT EXISTS `log` (
`id` INTEGER,
CREATE TABLE IF NOT EXISTS `streamlog` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`time` datetime NOT NULL,
`date` datetime NOT NULL,
`source` INTEGER,
`video` INTEGER
);
CREATE TABLE IF NOT EXISTS `hlslog` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`time` datetime NOT NULL,
`source` INTEGER,
`lecture` INTEGER,
`handle` varchar(32),
`format` varchar(16)
);
CREATE TABLE IF NOT EXISTS `logcache` (
`req` varchar(64),
`param` varchar(64),
......
......@@ -563,7 +563,7 @@ def auth(): # For use with nginx auth_request
return "OK", 200
if url.startswith('pub/hls/'):
handle = url[len('pub/hls/'):].split('_')[0].split('.')[0]
perms = query('''SELECT perm.*
perms = query('''SELECT lectures.id AS lecture, perm.*
FROM streams
JOIN lectures ON (streams.lecture_id = lectures.id)
JOIN courses ON (lectures.course_id = courses.id)
......@@ -592,6 +592,10 @@ def auth(): # For use with nginx auth_request
try:
if not url.startswith('pub/hls/'):
modify('INSERT INTO log (id, `time`, `date`, video, source) VALUES (?, ?, ?, ?, 1)', cookie, datetime.now(), datetime.combine(date.today(), time()), perms[0]['vid'])
elif url.endswith('.ts'):
fmt = url.split('_')[-1].split('-')[0]
seg = url.split('.')[0].split('-')[-1]
modify('INSERT INTO hlslog (id, `time`, segment, lecture, handle, format) VALUES (?, ?, ?, ?, ?, ?)', cookie, datetime.now(), seg, perms[0]['lecture'], handle, fmt)
except:
pass
r = make_response('OK', 200)
......
......@@ -17,6 +17,7 @@ statsqueries['categories_courses'] = "SELECT courses.subject AS labels, count(co
statsqueries['organizer_courses'] = "SELECT courses.organizer AS labels, count(courses.id) AS `values` FROM courses GROUP BY courses.organizer ORDER BY labels DESC LIMIT 100"
statsqueries['categories_lectures'] = "SELECT courses.subject AS labels, count(lectures.id) AS `values` FROM lectures JOIN courses ON (courses.id = lectures.course_id) WHERE lectures.visible GROUP BY courses.subject ORDER BY `values` DESC LIMIT 100"
statsqueries['lecture_views'] = "SELECT lectures.time AS x, count(DISTINCT log.id) AS y FROM log JOIN videos ON (videos.id = log.video) JOIN lectures ON (lectures.id = videos.lecture_id) WHERE (lectures.course_id = ?) GROUP BY lectures.id ORDER BY lectures.time"
statsqueries['live_views'] = "SELECT hlslog.segment AS x, COUNT(DISTINCT hlslog.id) AS y FROM hlslog WHERE hlslog.lecture = ? GROUP BY hlslog.segment ORDER BY hlslog.segment"
def plotly_date_handler(obj):
return obj.strftime("%Y-%m-%d %H:%M:%S")
......
......@@ -59,6 +59,7 @@
</table>
</div>
<div class="col-xs-12 plot-view" data-url="{{url_for('stats_viewsperday', req="lecture", param=lecture.id)}}"></div>
<div class="col-xs-12 plot-view" data-url="{{url_for('stats_generic', req="live_views", param=lecture.id)}}"></div>
{% endif %}
</div>
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment