Commit ba420007 authored by Andreas Valder's avatar Andreas Valder
Browse files

made statistics filterable per semester

parent 06123aa5
......@@ -289,9 +289,11 @@ var moderator = {
bsum += b.y[i]
return bsum-asum;
});
for (var i = 0; i < traces.length; i++)
if (i > 20)
for (var i = 0; i < traces.length; i++) {
if (i > 30) {
traces[i].visible = "legendonly";
}
}
$(this.divobj).html("");
Plotly.newPlot(this.divobj.id, traces, layout, { "modeBarButtonsToRemove": ['sendDataToCloud','hoverCompareCartesian'], "displaylogo": false});
}
......
......@@ -2,13 +2,23 @@ from server import *
import json
from jobs import date_json_handler
from hashlib import md5
from datetime import datetime
@app.route('/internal/stats')
@app.route('/internal/stats/<semester>')
@register_navbar('Statistiken', icon='stats')
@mod_required
def stats(semester=None):
return render_template('stats.html',semester=semester)
def stats():
semester = query('SELECT DISTINCT semester from courses WHERE semester != ""');
for s in semester:
year = int(s['semester'][0:4])
if s['semester'].endswith('ss'):
s['from'] = datetime(year,4,1)
s['to'] = datetime(year,10,1)
if s['semester'].endswith('ws'):
s['from'] = datetime(year,10,1)
s['to'] = datetime(year+1,4,1)
return render_template('stats.html',semester=semester,filter=request.args.get('filter'))
statsqueries = {}
statsqueries['formats_views'] = "SELECT formats.description AS labels, count(DISTINCT log.id) AS `values` FROM log JOIN videos ON (videos.id = log.video) JOIN formats ON (formats.id = videos.video_format) GROUP BY formats.id"
......@@ -115,6 +125,12 @@ def stats_viewsperday(req, param=""):
data[row['date']][row['trace']] = row['y']
end = date.today()
res = [{'name': trace, 'x': [], 'y': []} for trace in traces]
filter = request.args.get('filter')
if filter:
filter = filter.split('-')
start = date.fromtimestamp(int(filter[0]))
end = date.fromtimestamp(int(filter[1]))
while start and start <= end:
for trace in res:
trace['x'].append(start)
......
......@@ -3,7 +3,7 @@
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Statistiken</h1>
<h1 class="panel-title">Gesamt</h1>
</div>
<div class="panel-body">
<div class="row col-xs-12">
......@@ -11,13 +11,31 @@
<div class="col-xs-12 col-md-6 plot-view" data-url="{{url_for('stats_generic', req="lectures_count")}}"></div>
<div class="col-xs-12 col-md-6 plot-view" data-type="pie" data-url="{{url_for('stats_generic', req="categories_courses")}}"></div>
<div class="col-xs-12 col-md-6 plot-view" data-type="pie" data-url="{{url_for('stats_generic', req="categories_lectures")}}"></div>
<!--<div class="col-xs-12 col-md-6 plot-view" data-type="pie" data-url="{{url_for('stats_generic', req="organizer_courses")}}"></div>-->
<!--<div class="col-xs-12 col-md-6 plot-view" data-type="pie" data-url="{{url_for('stats_generic', req="formats_views")}}"></div>-->
<div class="col-xs-12 plot-view" data-url="{{url_for('stats_viewsperday', req="global")}}"></div>
<div class="col-xs-12 plot-view" data-url="{{url_for('stats_viewsperday', req="courses")}}"></div>
<div class="col-xs-12 col-md-6 plot-view" data-type="pie" data-url="{{url_for('stats_generic', req="organizer_courses")}}"></div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<span class="panel-title"><a name="semesterstats"></a>Semester <select id="semesterselect" name="semester"><option value="">alle</option></select></span>
</div>
<div class="panel-body" >
<div class="row col-xs-12">
<div class="col-xs-12 plot-view" data-url="{{url_for('stats_viewsperday', req="global", filter=filter)}}"></div>
<div class="col-xs-12 plot-view" data-url="{{url_for('stats_viewsperday', req="courses", filter=filter)}}"></div>
</div>
</div>
</div>
</div>
<script>
$( document ).ready(function () {
{% for s in semester if s.semester != '' %}
$("#semesterselect").append('<option value="{{ s.from.timestamp()|int }}-{{ s.to.timestamp()|int }}">{{ s.semester }}</option>');
{% endfor %}
$("#semesterselect").val("{{ filter }}")
$("#semesterselect").on("change", function () {
window.location.href="{{ url_for('stats') }}?filter="+$("#semesterselect").val()+"#semesterstats";
});
});
</script>
{% endblock %}
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