Added ability to view per-user graphs

This commit is contained in:
Otger 2016-04-09 23:54:31 +02:00
parent 8ca6255ff3
commit d62f7b2a5f
5 changed files with 167 additions and 81 deletions

View file

@ -113,6 +113,8 @@ img {
}
.btn {
outline:0px !important;
}
.btn:not(select) {
-webkit-appearance:none;
}
.btn-dark {

View file

@ -12,6 +12,14 @@
<span><i class="fa fa-bar-chart"></i> Graphs</span>
</div>
<div class="button-bar hidden-xs">
<div class="btn-group" id="user-selection">
<label>
<select name="graph-user" id="graph-user" class="btn" style="color: inherit;">
<option value="">All Users</option>
<option disabled>&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;</option>
</select>
</label>
</div>
<div class="btn-group" data-toggle="buttons" id="yaxis-selection">
% if config['graph_type'] == 'duration':
<label class="btn btn-dark">
@ -281,6 +289,10 @@
complete: function(xhr, status) {
$('#history-modal').modal('show');
$("#history-modal").html(xhr.responseText);
var opt = $('#graph-user :selected');
if (opt.prev().length) {
$('#history_table_modal_filter input[type=search]').val(opt.text()).trigger("input");
}
}
});
}
@ -307,10 +319,29 @@
// Initial values for graph from config
var yaxis = "${config['graph_type']}";
var current_range = ${config['graph_days']};
var current_user = undefined;
var current_tab = "${'#' + config['graph_tab']}";
$('.days').html(current_range);
// Load user ids and names (for the selector)
$.ajax({
url: 'get_user_names',
type: 'get',
dataType: "json",
success: function (data) {
var select = $('#graph-user');
data.sort(function(a, b) {
return a.friendly_name.localeCompare(b.friendly_name);
});
data.forEach(function(item) {
select.append('<option value="' + item.user_id + '">' +
item.friendly_name + '</option>');
});
}
});
var music_visible = (${config['music_logging_enable']} == 1 ? true : false);
function loadGraphsTab1(time_range, yaxis) {
@ -321,7 +352,7 @@
$.ajax({
url: "get_plays_by_date",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
var dateArray = [];
@ -348,7 +379,7 @@
$.ajax({
url: "get_plays_by_dayofweek",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
hc_plays_by_dayofweek_options.xAxis.categories = data.categories;
@ -361,7 +392,7 @@
$.ajax({
url: "get_plays_by_hourofday",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
hc_plays_by_hourofday_options.xAxis.categories = data.categories;
@ -374,7 +405,7 @@
$.ajax({
url: "get_plays_by_top_10_platforms",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
hc_plays_by_platform_options.xAxis.categories = data.categories;
@ -406,7 +437,7 @@
$.ajax({
url: "get_plays_by_stream_type",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
var dateArray = [];
@ -432,7 +463,7 @@
$.ajax({
url: "get_plays_by_source_resolution",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
hc_plays_by_source_resolution_options.xAxis.categories = data.categories;
@ -444,7 +475,7 @@
$.ajax({
url: "get_plays_by_stream_resolution",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
hc_plays_by_stream_resolution_options.xAxis.categories = data.categories;
@ -456,7 +487,7 @@
$.ajax({
url: "get_stream_type_by_top_10_platforms",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
hc_plays_by_platform_by_stream_type_options.xAxis.categories = data.categories;
@ -468,7 +499,7 @@
$.ajax({
url: "get_stream_type_by_top_10_users",
type: 'get',
data: { time_range: time_range, y_axis: yaxis },
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
hc_plays_by_user_by_stream_type_options.xAxis.categories = data.categories;
@ -486,7 +517,7 @@
$.ajax({
url: "get_plays_per_month",
type: 'get',
data: { y_axis: yaxis },
data: { y_axis: yaxis, user_id: current_user },
dataType: "json",
success: function(data) {
hc_plays_by_month_options.yAxis.min = 0;
@ -556,6 +587,14 @@
});
});
// User changed
$('#graph-user').on('change', function() {
current_user = $(this).val() || undefined;
if (current_tab == '#tabs-1') { loadGraphsTab1(current_range, yaxis); }
if (current_tab == '#tabs-2') { loadGraphsTab2(current_range, yaxis); }
if (current_tab == '#tabs-3') { loadGraphsTab3(yaxis); }
});
// Y-axis changed
$('#yaxis-selection').on('change', function() {
yaxis = $('input[name=yaxis-options]:checked', '#yaxis-selection').val();
@ -598,7 +637,7 @@
$('.yaxis-text').html('Play count');
} else {
yaxis_format = function() { return moment.duration(this.value, 'seconds').format("m [mins]"); };
yaxis_format = function() { return moment.duration(this.value, 'seconds').format("H [h] m [m]"); };
tooltip_format = function() {
if (moment(this.x, 'X').isValid() && (this.x > 946684800)) {
var s = '<b>'+ moment(this.x).format("ddd MMM D") +'</b>';

View file

@ -24,12 +24,14 @@ class Graphs(object):
def __init__(self):
pass
def get_total_plays_per_day(self, time_range='30', y_axis='plays'):
def get_total_plays_per_day(self, time_range='30', y_axis='plays', user_id=None):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT date(started, "unixepoch", "localtime") AS date_played, ' \
@ -37,9 +39,9 @@ class Graphs(object):
'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \
'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \
'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \
'GROUP BY date_played ' \
'ORDER BY started ASC' % time_range
'ORDER BY started ASC' % (time_range, user_cond)
result = monitor_db.select(query)
else:
@ -51,9 +53,9 @@ class Graphs(object):
'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \
' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count ' \
'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \
'GROUP BY date_played ' \
'ORDER BY started ASC' % time_range
'ORDER BY started ASC' % (time_range, user_cond)
result = monitor_db.select(query)
except Exception as e:
@ -102,12 +104,14 @@ class Graphs(object):
'series': [series_1_output, series_2_output, series_3_output]}
return output
def get_total_plays_per_dayofweek(self, time_range='30', y_axis='plays'):
def get_total_plays_per_dayofweek(self, time_range='30', y_axis='plays', user_id=None):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT strftime("%%w", datetime(started, "unixepoch", "localtime")) AS daynumber, ' \
@ -123,9 +127,9 @@ class Graphs(object):
'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \
'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \
'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \
'GROUP BY dayofweek ' \
'ORDER BY daynumber' % time_range
'ORDER BY daynumber' % (time_range, user_cond)
result = monitor_db.select(query)
else:
@ -145,9 +149,9 @@ class Graphs(object):
'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \
' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count ' \
'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \
'GROUP BY dayofweek ' \
'ORDER BY daynumber' % time_range
'ORDER BY daynumber' % (time_range, user_cond)
result = monitor_db.select(query)
except Exception as e:
@ -193,12 +197,14 @@ class Graphs(object):
'series': [series_1_output, series_2_output, series_3_output]}
return output
def get_total_plays_per_hourofday(self, time_range='30', y_axis='plays'):
def get_total_plays_per_hourofday(self, time_range='30', y_axis='plays', user_id=None):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT strftime("%%H", datetime(started, "unixepoch", "localtime")) AS hourofday, ' \
@ -206,9 +212,9 @@ class Graphs(object):
'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \
'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \
'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \
'GROUP BY hourofday ' \
'ORDER BY hourofday' % time_range
'ORDER BY hourofday' % (time_range, user_cond)
result = monitor_db.select(query)
else:
@ -220,9 +226,9 @@ class Graphs(object):
'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \
' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count ' \
'FROM session_history ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \
'GROUP BY hourofday ' \
'ORDER BY hourofday' % time_range
'ORDER BY hourofday' % (time_range, user_cond)
result = monitor_db.select(query)
except Exception as e:
@ -270,25 +276,27 @@ class Graphs(object):
'series': [series_1_output, series_2_output, series_3_output]}
return output
def get_total_plays_per_month(self, y_axis='plays'):
def get_total_plays_per_month(self, y_axis='plays', user_id=None):
import time as time
monitor_db = database.MonitorDatabase()
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) AS datestring, ' \
query = 'SELECT strftime("%%Y-%%m", datetime(started, "unixepoch", "localtime")) AS datestring, ' \
'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \
'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \
'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \
'FROM session_history ' \
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
'ORDER BY datestring DESC LIMIT 12'
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") %s' \
'GROUP BY strftime("%%Y-%%m", datetime(started, "unixepoch", "localtime")) ' \
'ORDER BY datestring DESC LIMIT 12' % (user_cond)
result = monitor_db.select(query)
else:
query = 'SELECT strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) AS datestring, ' \
query = 'SELECT strftime("%%Y-%%m", datetime(started, "unixepoch", "localtime")) AS datestring, ' \
'SUM(CASE WHEN media_type = "episode" AND stopped > 0 THEN (stopped - started) ' \
' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS tv_count, ' \
'SUM(CASE WHEN media_type = "movie" AND stopped > 0 THEN (stopped - started) ' \
@ -296,9 +304,9 @@ class Graphs(object):
'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \
' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count ' \
'FROM session_history ' \
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
'ORDER BY datestring DESC LIMIT 12'
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") %s' \
'GROUP BY strftime("%%Y-%%m", datetime(started, "unixepoch", "localtime")) ' \
'ORDER BY datestring DESC LIMIT 12' % (user_cond)
result = monitor_db.select(query)
except Exception as e:
@ -351,12 +359,14 @@ class Graphs(object):
'series': [series_1_output, series_2_output, series_3_output]}
return output
def get_total_plays_by_top_10_platforms(self, time_range='30', y_axis='plays'):
def get_total_plays_by_top_10_platforms(self, time_range='30', y_axis='plays', user_id=None):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT platform, ' \
@ -365,10 +375,10 @@ class Graphs(object):
'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count, ' \
'COUNT(id) AS total_count ' \
'FROM session_history ' \
'WHERE (datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) ' \
'WHERE (datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) %s' \
'GROUP BY platform ' \
'ORDER BY total_count DESC ' \
'LIMIT 10' % time_range
'LIMIT 10' % (time_range, user_cond)
result = monitor_db.select(query)
else:
@ -382,10 +392,10 @@ class Graphs(object):
'SUM(CASE WHEN stopped > 0 THEN (stopped - started) ' \
' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS total_duration ' \
'FROM session_history ' \
'WHERE (datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) ' \
'WHERE (datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) %s' \
'GROUP BY platform ' \
'ORDER BY total_duration DESC ' \
'LIMIT 10' % time_range
'LIMIT 10' % (time_range, user_cond)
result = monitor_db.select(query)
except Exception as e:
@ -481,12 +491,14 @@ class Graphs(object):
'series': [series_1_output, series_2_output, series_3_output]}
return output
def get_total_plays_per_stream_type(self, time_range='30', y_axis='plays'):
def get_total_plays_per_stream_type(self, time_range='30', y_axis='plays', user_id=None):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT date(session_history.started, "unixepoch", "localtime") AS date_played, ' \
@ -501,9 +513,9 @@ class Graphs(object):
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
'datetime("now", "-%s days", "localtime")) AND ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR ' \
'session_history.media_type = "track") ' \
'session_history.media_type = "track") %s' \
'GROUP BY date_played ' \
'ORDER BY started ASC' % time_range
'ORDER BY started ASC' % (time_range, user_cond)
result = monitor_db.select(query)
else:
@ -522,9 +534,9 @@ class Graphs(object):
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
'datetime("now", "-%s days", "localtime") AND ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR ' \
'session_history.media_type = "track") ' \
'session_history.media_type = "track") %s' \
'GROUP BY date_played ' \
'ORDER BY started ASC' % time_range
'ORDER BY started ASC' % (time_range, user_cond)
result = monitor_db.select(query)
except Exception as e:
@ -573,12 +585,14 @@ class Graphs(object):
'series': [series_1_output, series_2_output, series_3_output]}
return output
def get_total_plays_by_source_resolution(self, time_range='30', y_axis='plays'):
def get_total_plays_by_source_resolution(self, time_range='30', y_axis='plays', user_id=None):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT session_history_media_info.video_resolution AS resolution, ' \
@ -593,10 +607,10 @@ class Graphs(object):
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
'datetime("now", "-%s days", "localtime")) AND ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie") %s' \
'GROUP BY resolution ' \
'ORDER BY total_count DESC ' \
'LIMIT 10' % time_range
'LIMIT 10' % (time_range, user_cond)
result = monitor_db.select(query)
else:
@ -616,10 +630,10 @@ class Graphs(object):
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
'datetime("now", "-%s days", "localtime")) AND ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie") %s' \
'GROUP BY resolution ' \
'ORDER BY total_duration DESC ' \
'LIMIT 10' % time_range
'LIMIT 10' % (time_range, user_cond)
result = monitor_db.select(query)
except Exception as e:
@ -648,12 +662,14 @@ class Graphs(object):
'series': [series_1_output, series_2_output, series_3_output]}
return output
def get_total_plays_by_stream_resolution(self, time_range='30', y_axis='plays'):
def get_total_plays_by_stream_resolution(self, time_range='30', y_axis='plays', user_id=None):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT ' \
@ -678,10 +694,10 @@ class Graphs(object):
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
'datetime("now", "-%s days", "localtime")) AND ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie") %s' \
'GROUP BY resolution ' \
'ORDER BY total_count DESC ' \
'LIMIT 10' % time_range
'LIMIT 10' % (time_range, user_cond)
result = monitor_db.select(query)
else:
@ -711,10 +727,10 @@ class Graphs(object):
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
'datetime("now", "-%s days", "localtime")) AND ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie") %s' \
'GROUP BY resolution ' \
'ORDER BY total_duration DESC ' \
'LIMIT 10' % time_range
'LIMIT 10' % (time_range, user_cond)
result = monitor_db.select(query)
except Exception as e:
@ -743,12 +759,14 @@ class Graphs(object):
'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'):
def get_stream_type_by_top_10_platforms(self, time_range='30', y_axis='plays', user_id=None):
monitor_db = database.MonitorDatabase()
if not time_range.isdigit():
time_range = '30'
user_cond = ('AND user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
try:
if y_axis == 'plays':
query = 'SELECT session_history.platform AS platform, ' \
@ -763,9 +781,9 @@ class Graphs(object):
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
'datetime("now", "-%s days", "localtime") AND ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") %s' \
'GROUP BY platform ' \
'ORDER BY total_count DESC LIMIT 10' % time_range
'ORDER BY total_count DESC LIMIT 10' % (time_range, user_cond)
result = monitor_db.select(query)
else:
@ -786,9 +804,9 @@ class Graphs(object):
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
'datetime("now", "-%s days", "localtime") AND ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") ' \
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") %s' \
'GROUP BY platform ' \
'ORDER BY total_duration DESC LIMIT 10' % time_range
'ORDER BY total_duration DESC LIMIT 10' % (time_range, user_cond)
result = monitor_db.select(query)
except Exception as e:

View file

@ -21,6 +21,23 @@ class Users(object):
def __init__(self):
pass
def get_names(self, kwargs=None):
monitor_db = database.MonitorDatabase()
try:
query = 'SELECT user_id, ' \
'(CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" \
THEN users.username ELSE users.friendly_name END) AS friendly_name ' \
'FROM users ' \
'WHERE deleted_user = 0'
result = monitor_db.select(query)
except Exception as e:
logger.warn(u"PlexPy Graphs :: Unable to execute database query for get_user_names: %s." % e)
return None
return result
def get_datatables_list(self, kwargs=None):
data_tables = datatables.DataTables()

View file

@ -864,10 +864,20 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_plays_by_date(self, time_range='30', y_axis='plays', **kwargs):
def get_user_names(self, **kwargs):
user_data = users.Users()
user_names = user_data.get_names(kwargs=kwargs)
cherrypy.response.headers['Content-type'] = 'application/json'
return json.dumps(user_names)
@cherrypy.expose
@addtoapi()
def get_plays_by_date(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
graph = graphs.Graphs()
result = graph.get_total_plays_per_day(time_range=time_range, y_axis=y_axis)
result = graph.get_total_plays_per_day(time_range=time_range, user_id=user_id, y_axis=y_axis)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
@ -877,10 +887,10 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_plays_by_dayofweek(self, time_range='30', y_axis='plays', **kwargs):
def get_plays_by_dayofweek(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
graph = graphs.Graphs()
result = graph.get_total_plays_per_dayofweek(time_range=time_range, y_axis=y_axis)
result = graph.get_total_plays_per_dayofweek(time_range=time_range, user_id=user_id, y_axis=y_axis)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
@ -890,10 +900,10 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_plays_by_hourofday(self, time_range='30', y_axis='plays', **kwargs):
def get_plays_by_hourofday(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
graph = graphs.Graphs()
result = graph.get_total_plays_per_hourofday(time_range=time_range, y_axis=y_axis)
result = graph.get_total_plays_per_hourofday(time_range=time_range, user_id=user_id, y_axis=y_axis)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
@ -903,10 +913,10 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_plays_per_month(self, y_axis='plays', **kwargs):
def get_plays_per_month(self, y_axis='plays', user_id=None, **kwargs):
graph = graphs.Graphs()
result = graph.get_total_plays_per_month(y_axis=y_axis)
result = graph.get_total_plays_per_month(y_axis=y_axis, user_id=user_id)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
@ -916,10 +926,10 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_plays_by_top_10_platforms(self, time_range='30', y_axis='plays', **kwargs):
def get_plays_by_top_10_platforms(self, time_range='30', y_axis='plays', user_id=None, **kwargs):
graph = graphs.Graphs()
result = graph.get_total_plays_by_top_10_platforms(time_range=time_range, y_axis=y_axis)
result = graph.get_total_plays_by_top_10_platforms(time_range=time_range, y_axis=y_axis, user_id=user_id)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
@ -942,10 +952,10 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_plays_by_stream_type(self, time_range='30', y_axis='plays', **kwargs):
def get_plays_by_stream_type(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
graph = graphs.Graphs()
result = graph.get_total_plays_per_stream_type(time_range=time_range, y_axis=y_axis)
result = graph.get_total_plays_per_stream_type(time_range=time_range, user_id=user_id, y_axis=y_axis)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
@ -955,10 +965,10 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_plays_by_source_resolution(self, time_range='30', y_axis='plays', **kwargs):
def get_plays_by_source_resolution(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
graph = graphs.Graphs()
result = graph.get_total_plays_by_source_resolution(time_range=time_range, y_axis=y_axis)
result = graph.get_total_plays_by_source_resolution(time_range=time_range, user_id=user_id, y_axis=y_axis)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
@ -968,10 +978,10 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_plays_by_stream_resolution(self, time_range='30', y_axis='plays', **kwargs):
def get_plays_by_stream_resolution(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
graph = graphs.Graphs()
result = graph.get_total_plays_by_stream_resolution(time_range=time_range, y_axis=y_axis)
result = graph.get_total_plays_by_stream_resolution(time_range=time_range, user_id=user_id, y_axis=y_axis)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'
@ -994,10 +1004,10 @@ class WebInterface(object):
@cherrypy.expose
@addtoapi()
def get_stream_type_by_top_10_platforms(self, time_range='30', y_axis='plays', **kwargs):
def get_stream_type_by_top_10_platforms(self, time_range='30', y_axis='plays', user_id=None, **kwargs):
graph = graphs.Graphs()
result = graph.get_stream_type_by_top_10_platforms(time_range=time_range, y_axis=y_axis)
result = graph.get_stream_type_by_top_10_platforms(time_range=time_range, y_axis=y_axis, user_id=user_id)
if result:
cherrypy.response.headers['Content-type'] = 'application/json'