New graphs for user and platform by stream type.

Add totals to tooltips when more than one series on graph.
This commit is contained in:
Tim 2015-08-10 15:47:08 +02:00
parent 39160df79b
commit a8e591f7f7
6 changed files with 386 additions and 10 deletions

View file

@ -156,6 +156,34 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-6">
<h4><i class="fa fa-television"></i> <span class="yaxis-text">Play count</span> by platform and stream type <small>Last <span class="days">30</span> days</small></h4>
<p class="help-block">
The combined total of movies and tv by platform and stream type.
</p>
<div class="graphs-instance">
<div class="watch-chart" id="chart_div_plays_by_platform_by_stream_type" style="float: left;">
<div class="graphs-load"><i class="fa fa-refresh fa-spin"></i> Loading chart...
</div>
<br>
</div>
</div>
</div>
<div class="col-md-6">
<h4><i class="fa fa-user"></i> <span class="yaxis-text">Play count</span> by user and stream type <small>Last <span class="days">30</span> days</small></h4>
<p class="help-block">
The combined total of movies and tv by user and stream type.
</p>
<div class="graphs-instance">
<div class="watch-chart" id="chart_div_plays_by_user_by_stream_type" style="float: left;">
<div class="graphs-load"><i class="fa fa-refresh fa-spin"></i> Loading chart...
</div>
<br>
</div>
</div>
</div>
</div>
</div> </div>
<div role="tabpanel" class="tab-pane" id="tabs-3"> <div role="tabpanel" class="tab-pane" id="tabs-3">
@ -226,6 +254,8 @@
<script src="interfaces/default/js/graphs/plays_by_stream_type.js"></script> <script src="interfaces/default/js/graphs/plays_by_stream_type.js"></script>
<script src="interfaces/default/js/graphs/plays_by_source_resolution.js"></script> <script src="interfaces/default/js/graphs/plays_by_source_resolution.js"></script>
<script src="interfaces/default/js/graphs/plays_by_stream_resolution.js"></script> <script src="interfaces/default/js/graphs/plays_by_stream_resolution.js"></script>
<script src="interfaces/default/js/graphs/plays_by_platform_by_stream_type.js"></script>
<script src="interfaces/default/js/graphs/plays_by_user_by_stream_type.js"></script>
<script src="interfaces/default/js/graphs/plays_by_month.js"></script> <script src="interfaces/default/js/graphs/plays_by_month.js"></script>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
@ -346,6 +376,30 @@
var hc_plays_by_stream_resolution = new Highcharts.Chart(hc_plays_by_stream_resolution_options); var hc_plays_by_stream_resolution = new Highcharts.Chart(hc_plays_by_stream_resolution_options);
} }
}); });
$.ajax({
url: "get_stream_type_by_top_10_platforms",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
dataType: "json",
success: function(data) {
hc_plays_by_platform_by_stream_type_options.xAxis.categories = data.categories;
hc_plays_by_platform_by_stream_type_options.series = data.series;
var hc_plays_by_platform_by_stream_type = new Highcharts.Chart(hc_plays_by_platform_by_stream_type_options);
}
});
$.ajax({
url: "get_stream_type_by_top_10_users",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
dataType: "json",
success: function(data) {
hc_plays_by_user_by_stream_type_options.xAxis.categories = data.categories;
hc_plays_by_user_by_stream_type_options.series = data.series;
var hc_plays_by_user_by_stream_type = new Highcharts.Chart(hc_plays_by_user_by_stream_type_options);
}
});
} }
function loadGraphsTab3(yaxis) { function loadGraphsTab3(yaxis) {
@ -423,10 +477,18 @@
} else { } else {
var s = '<b>'+ this.x +'</b>'; var s = '<b>'+ this.x +'</b>';
} }
if (this.points.length > 1) {
$.each(this.points, function(i, point) { var total = 0;
s += '<br/>'+point.series.name+': '+point.y; $.each(this.points, function(i, point) {
}); s += '<br/>'+point.series.name+': '+point.y;
total += point.y;
});
s += '<br><b>Total: '+total+'</b>';
} else {
$.each(this.points, function(i, point) {
s += '<br/>'+point.series.name+': '+point.y;
});
}
return s; return s;
} }
stack_labels_format = function() { stack_labels_format = function() {
@ -442,10 +504,18 @@
} else { } else {
var s = '<b>'+ this.x +'</b>'; var s = '<b>'+ this.x +'</b>';
} }
if (this.points.length > 1) {
$.each(this.points, function(i, point) { var total = 0;
s += '<br/>'+point.series.name+': '+moment.duration(point.y, 'seconds').format('D [days] H [hrs] m [mins]'); $.each(this.points, function(i, point) {
}); s += '<br/>'+point.series.name+': '+moment.duration(point.y, 'seconds').format('D [days] H [hrs] m [mins]');
total += point.y;
});
s += '<br/><b>Total: '+moment.duration(total, 'seconds').format('D [days] H [hrs] m [mins]')+'</b>';
} else {
$.each(this.points, function(i, point) {
s += '<br/>'+point.series.name+': '+moment.duration(point.y, 'seconds').format('D [days] H [hrs] m [mins]');
});
}
return s; return s;
} }
stack_labels_format = function() { stack_labels_format = function() {
@ -463,6 +533,8 @@
hc_plays_by_stream_type_options.yAxis.labels.formatter = yaxis_format; hc_plays_by_stream_type_options.yAxis.labels.formatter = yaxis_format;
hc_plays_by_source_resolution_options.yAxis.labels.formatter = yaxis_format; hc_plays_by_source_resolution_options.yAxis.labels.formatter = yaxis_format;
hc_plays_by_stream_resolution_options.yAxis.labels.formatter = yaxis_format; hc_plays_by_stream_resolution_options.yAxis.labels.formatter = yaxis_format;
hc_plays_by_platform_by_stream_type_options.yAxis.labels.formatter = yaxis_format;
hc_plays_by_user_by_stream_type_options.yAxis.labels.formatter = yaxis_format;
hc_plays_by_month_options.yAxis.labels.formatter = yaxis_format; hc_plays_by_month_options.yAxis.labels.formatter = yaxis_format;
hc_plays_by_day_options.tooltip.formatter = tooltip_format; hc_plays_by_day_options.tooltip.formatter = tooltip_format;
@ -473,6 +545,10 @@
hc_plays_by_stream_type_options.tooltip.formatter = tooltip_format; hc_plays_by_stream_type_options.tooltip.formatter = tooltip_format;
hc_plays_by_source_resolution_options.tooltip.formatter = tooltip_format; hc_plays_by_source_resolution_options.tooltip.formatter = tooltip_format;
hc_plays_by_stream_resolution_options.tooltip.formatter = tooltip_format; hc_plays_by_stream_resolution_options.tooltip.formatter = tooltip_format;
hc_plays_by_platform_by_stream_type_options.tooltip.formatter = tooltip_format;
hc_plays_by_platform_by_stream_type_options.yAxis.stackLabels.formatter = stack_labels_format;
hc_plays_by_user_by_stream_type_options.tooltip.formatter = tooltip_format;
hc_plays_by_user_by_stream_type_options.yAxis.stackLabels.formatter = stack_labels_format;
hc_plays_by_month_options.tooltip.formatter = tooltip_format; hc_plays_by_month_options.tooltip.formatter = tooltip_format;
hc_plays_by_month_options.yAxis.stackLabels.formatter = stack_labels_format; hc_plays_by_month_options.yAxis.stackLabels.formatter = stack_labels_format;
} }

View file

@ -46,7 +46,7 @@ var hc_plays_by_month_options = {
} }
}, },
stackLabels: { stackLabels: {
enabled: true, enabled: false,
style: { style: {
color: '#fff' color: '#fff'
} }

View file

@ -0,0 +1,73 @@
var hc_plays_by_platform_by_stream_type_options = {
chart: {
type: 'column',
backgroundColor: 'rgba(0,0,0,0)',
renderTo: 'chart_div_plays_by_platform_by_stream_type'
},
title: {
text: ''
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
legend: {
enabled: true,
itemStyle: {
font: '9pt "Open Sans", sans-serif',
color: '#A0A0A0'
},
itemHoverStyle: {
color: '#FFF'
},
itemHiddenStyle: {
color: '#444'
}
},
credits: {
enabled: false
},
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
xAxis: {
categories: [{}],
labels: {
style: {
color: '#aaa'
}
}
},
yAxis: {
title: {
text: null
},
labels: {
style: {
color: '#aaa'
}
},
stackLabels: {
enabled: false,
style: {
color: '#fff'
}
}
},
plotOptions: {
column: {
stacking: 'normal',
borderWidth: '0',
dataLabels: {
enabled: false,
style: {
color: '#000'
}
}
}
},
tooltip: {
shared: true
},
series: [{}]
};

View file

@ -0,0 +1,73 @@
var hc_plays_by_user_by_stream_type_options = {
chart: {
type: 'column',
backgroundColor: 'rgba(0,0,0,0)',
renderTo: 'chart_div_plays_by_user_by_stream_type'
},
title: {
text: ''
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
legend: {
enabled: true,
itemStyle: {
font: '9pt "Open Sans", sans-serif',
color: '#A0A0A0'
},
itemHoverStyle: {
color: '#FFF'
},
itemHiddenStyle: {
color: '#444'
}
},
credits: {
enabled: false
},
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
xAxis: {
categories: [{}],
labels: {
style: {
color: '#aaa'
}
}
},
yAxis: {
title: {
text: null
},
labels: {
style: {
color: '#aaa'
}
},
stackLabels: {
enabled: false,
style: {
color: '#fff'
}
}
},
plotOptions: {
column: {
stacking: 'normal',
borderWidth: '0',
dataLabels: {
enabled: false,
style: {
color: '#000'
}
}
}
},
tooltip: {
shared: true
},
series: [{}]
};

View file

@ -589,3 +589,133 @@ class Graphs(object):
'series': [series_1_output]} 'series': [series_1_output]}
return output return output
def get_stream_type_by_top_10_users(self, time_range='30', y_axis='plays'):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
if y_axis == 'plays':
query = 'SELECT ' \
'CASE WHEN users.friendly_name != null then users.friendly_name else users.username end as username, ' \
'SUM(case when session_history_media_info.video_decision = "direct play" then 1 else 0 end) as dp_count, ' \
'SUM(case when session_history_media_info.video_decision = "copy" then 1 else 0 end) as ds_count, ' \
'SUM(case when session_history_media_info.video_decision = "transcode" then 1 else 0 end) as tr_count, ' \
'SUM(case when session_history.media_type != "track" then 1 else 0 end) as total_count ' \
'FROM session_history ' \
'JOIN users ON session_history.user_id = users.user_id ' \
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
'datetime("now", "-' + time_range + ' days", "localtime") ' \
'GROUP BY username ' \
'ORDER BY total_count DESC LIMIT 10'
result = monitor_db.select(query)
else:
query = 'SELECT ' \
'CASE WHEN users.friendly_name != null then users.friendly_name else users.username end as username, ' \
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "direct play" ' \
'then (session_history.stopped - session_history.started) else 0 end) as dp_count, ' \
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "copy" ' \
'then (session_history.stopped - session_history.started) else 0 end) as ds_count, ' \
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "transcode" ' \
'then (session_history.stopped - session_history.started) else 0 end) as tr_count, ' \
'SUM(case when session_history.stopped > 0 AND session_history.media_type != "track" ' \
'then (session_history.stopped - session_history.started) else 0 end) as total_count ' \
'FROM session_history ' \
'JOIN users ON session_history.user_id = users.user_id ' \
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
'datetime("now", "-' + time_range + ' days", "localtime") ' \
'GROUP BY username ' \
'ORDER BY total_count DESC LIMIT 10'
result = monitor_db.select(query)
categories = []
series_1 = []
series_2 = []
series_3 = []
for item in result:
categories.append(item[0])
series_1.append(item[1])
series_2.append(item[2])
series_3.append(item[3])
series_1_output = {'name': 'Direct Play',
'data': series_1}
series_2_output = {'name': 'Direct Stream',
'data': series_2}
series_3_output = {'name': 'Transcode',
'data': series_3}
output = {'categories': categories,
'series': [series_1_output, series_2_output, series_3_output]}
return output
def get_stream_type_by_top_10_platforms(self, time_range='30', y_axis='plays'):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
if y_axis == 'plays':
query = 'SELECT ' \
'session_history.platform as platform, ' \
'SUM(case when session_history_media_info.video_decision = "direct play" then 1 else 0 end) as dp_count, ' \
'SUM(case when session_history_media_info.video_decision = "copy" then 1 else 0 end) as ds_count, ' \
'SUM(case when session_history_media_info.video_decision = "transcode" then 1 else 0 end) as tr_count, ' \
'SUM(case when session_history.media_type != "track" then 1 else 0 end) as total_count ' \
'FROM session_history ' \
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
'datetime("now", "-' + time_range + ' days", "localtime") ' \
'GROUP BY platform ' \
'ORDER BY total_count DESC LIMIT 10'
result = monitor_db.select(query)
else:
query = 'SELECT ' \
'session_history.platform as platform, ' \
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "direct play" ' \
'then (session_history.stopped - session_history.started) else 0 end) as dp_count, ' \
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "copy" ' \
'then (session_history.stopped - session_history.started) else 0 end) as ds_count, ' \
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "transcode" ' \
'then (session_history.stopped - session_history.started) else 0 end) as tr_count, ' \
'SUM(case when session_history.stopped > 0 AND session_history.media_type != "track" ' \
'then (session_history.stopped - session_history.started) else 0 end) as total_count ' \
'FROM session_history ' \
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
'datetime("now", "-' + time_range + ' days", "localtime") ' \
'GROUP BY platform ' \
'ORDER BY total_count DESC LIMIT 10'
result = monitor_db.select(query)
categories = []
series_1 = []
series_2 = []
series_3 = []
for item in result:
categories.append(item[0])
series_1.append(item[1])
series_2.append(item[2])
series_3.append(item[3])
series_1_output = {'name': 'Direct Play',
'data': series_1}
series_2_output = {'name': 'Direct Stream',
'data': series_2}
series_3_output = {'name': 'Transcode',
'data': series_3}
output = {'categories': categories,
'series': [series_1_output, series_2_output, series_3_output]}
return output

View file

@ -938,6 +938,30 @@ class WebInterface(object):
else: else:
logger.warn('Unable to retrieve data.') logger.warn('Unable to retrieve data.')
@cherrypy.expose
def get_stream_type_by_top_10_users(self, time_range='30', y_axis='plays', **kwargs):
graph = graphs.Graphs()
result = graph.get_stream_type_by_top_10_users(time_range=time_range, y_axis=y_axis)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps(result)
else:
logger.warn('Unable to retrieve data.')
@cherrypy.expose
def get_stream_type_by_top_10_platforms(self, time_range='30', y_axis='plays', **kwargs):
graph = graphs.Graphs()
result = graph.get_stream_type_by_top_10_platforms(time_range=time_range, y_axis=y_axis)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps(result)
else:
logger.warn('Unable to retrieve data.')
@cherrypy.expose @cherrypy.expose
def get_friends_list(self, **kwargs): def get_friends_list(self, **kwargs):