Commit 602fc3de authored by Andreas Valder's avatar Andreas Valder

automaticly reload statistics for videos every 60s

parent 7047b2bf
......@@ -294,46 +294,58 @@ var moderator = {
resize: function() {
$(".plot-view").each(function () {Plotly.Plots.resize(this)});
},
createsingleplot: function(htmlobj, id) {
if (!htmlobj.id && id)
htmlobj.id = "plot-"+id;
$(htmlobj).html('<div class="plot-loader"></div>');
$.ajax({
divobj: htmlobj,
autorefresh: htmlobj.dataset.reload,
method: "GET",
url: htmlobj.dataset.url,
dataType: "json",
error: function (jqXHR, textStatus, errorThrow) {
$(this.divobj).html('<div class="plot-error">'+errorThrow+'</div>');
},
success: function (traces) {
var layout = {margin: {l: 30, r: 30, t: 10, b: 70, pad: 0}};
for (var i = 0; i < traces.length; i ++) {
traces[i].type = this.divobj.dataset.type;
}
if (this.divobj.dataset.type == "pie")
layout.showlegend = false;
traces.sort(function (a, b) {
asum = 0;
bsum = 0;
for (var i = 0; i < a.y.length; i++)
asum += a.y[i]
for (var i = 0; i < b.y.length; i++)
bsum += b.y[i]
return bsum-asum;
});
for (var i = 0; i < traces.length; i++) {
if (i > 15) {
traces[i].visible = "legendonly";
}
}
$(this.divobj).html("");
Plotly.newPlot(this.divobj.id, traces, layout, { "modeBarButtonsToRemove": ['sendDataToCloud','hoverCompareCartesian'], "displaylogo": false});
},
complete: function() {
if (this.autorefresh) {
setTimeout(
function(obj){
moderator.plots.createsingleplot(obj);
}, this.autorefresh, this.divobj);
}
}
});
},
createplots: function (selector) {
var l = $(selector);
for (var i = 0; i < l.length; i ++) {
if (!l[i].id)
l[i].id = "plot-"+i;
$(l[i]).html('<div class="plot-loader"></div>');
$.ajax({
divobj: l[i],
method: "GET",
url: l[i].dataset.url,
dataType: "json",
error: function (jqXHR, textStatus, errorThrow) {
$(this.divobj).html('<div class="plot-error">'+errorThrow+'</div>');
},
success: function (traces) {
var layout = {margin: {l: 30, r: 30, t: 10, b: 70, pad: 0}};
for (var i = 0; i < traces.length; i ++) {
traces[i].type = this.divobj.dataset.type;
}
if (this.divobj.dataset.type == "pie")
layout.showlegend = false;
traces.sort(function (a, b) {
asum = 0;
bsum = 0;
for (var i = 0; i < a.y.length; i++)
asum += a.y[i]
for (var i = 0; i < b.y.length; i++)
bsum += b.y[i]
return bsum-asum;
});
for (var i = 0; i < traces.length; i++) {
if (i > 15) {
traces[i].visible = "legendonly";
}
}
$(this.divobj).html("");
Plotly.newPlot(this.divobj.id, traces, layout, { "modeBarButtonsToRemove": ['sendDataToCloud','hoverCompareCartesian'], "displaylogo": false});
}
});
};
moderator.plots.createsingleplot(l[i], i);
}
},
},
init: function () {
......
......@@ -86,7 +86,7 @@
</div>
<div class="col-md-6 col-xs-12">
<p class="text-center">Zuschauer im Livestream</p>
<div class="plot-view" data-url="{{url_for('stats_generic', req="live_views", param=lecture.id)}}"></div>
<div class="plot-view" data-url="{{url_for('stats_generic', req="live_views", param=lecture.id)}}" data-reload="60000"></div>
</div>
</div>
</div>
......
Markdown is supported
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