mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-20 13:23:24 -07:00
Added missing user filtering to a pair of graphs and renamed a few things
This commit is contained in:
parent
dacb4ea7d6
commit
ffa1331802
4 changed files with 39 additions and 35 deletions
|
@ -319,8 +319,8 @@
|
|||
// 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']}";
|
||||
var selected_user_id = undefined;
|
||||
|
||||
$('.days').html(current_range);
|
||||
|
||||
|
@ -352,7 +352,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_by_date",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
var dateArray = [];
|
||||
|
@ -379,7 +379,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_by_dayofweek",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_dayofweek_options.xAxis.categories = data.categories;
|
||||
|
@ -392,7 +392,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_by_hourofday",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_hourofday_options.xAxis.categories = data.categories;
|
||||
|
@ -405,7 +405,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_by_top_10_platforms",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_platform_options.xAxis.categories = data.categories;
|
||||
|
@ -418,7 +418,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_by_top_10_users",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_user_options.xAxis.categories = data.categories;
|
||||
|
@ -437,7 +437,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_by_stream_type",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
var dateArray = [];
|
||||
|
@ -463,7 +463,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_by_source_resolution",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_source_resolution_options.xAxis.categories = data.categories;
|
||||
|
@ -475,7 +475,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_by_stream_resolution",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_stream_resolution_options.xAxis.categories = data.categories;
|
||||
|
@ -487,7 +487,7 @@
|
|||
$.ajax({
|
||||
url: "get_stream_type_by_top_10_platforms",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_platform_by_stream_type_options.xAxis.categories = data.categories;
|
||||
|
@ -499,7 +499,7 @@
|
|||
$.ajax({
|
||||
url: "get_stream_type_by_top_10_users",
|
||||
type: 'get',
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: current_user },
|
||||
data: { time_range: time_range, y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_user_by_stream_type_options.xAxis.categories = data.categories;
|
||||
|
@ -517,7 +517,7 @@
|
|||
$.ajax({
|
||||
url: "get_plays_per_month",
|
||||
type: 'get',
|
||||
data: { y_axis: yaxis, user_id: current_user },
|
||||
data: { y_axis: yaxis, user_id: selected_user_id },
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
hc_plays_by_month_options.yAxis.min = 0;
|
||||
|
@ -589,7 +589,7 @@
|
|||
|
||||
// User changed
|
||||
$('#graph-user').on('change', function() {
|
||||
current_user = $(this).val() || undefined;
|
||||
selected_user_id = $(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); }
|
||||
|
|
|
@ -424,12 +424,14 @@ class Graphs(object):
|
|||
'series': [series_1_output, series_2_output, series_3_output]}
|
||||
return output
|
||||
|
||||
def get_total_plays_by_top_10_users(self, time_range='30', y_axis='plays'):
|
||||
def get_total_plays_by_top_10_users(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 users.user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
|
||||
|
||||
try:
|
||||
if y_axis == 'plays':
|
||||
query = 'SELECT ' \
|
||||
|
@ -440,10 +442,10 @@ class Graphs(object):
|
|||
'COUNT(session_history.id) AS total_count ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users ON session_history.user_id = users.user_id ' \
|
||||
'WHERE (datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) ' \
|
||||
'WHERE (datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) %s' \
|
||||
'GROUP BY session_history.user_id ' \
|
||||
'ORDER BY total_count DESC ' \
|
||||
'LIMIT 10' % time_range
|
||||
'LIMIT 10' % (time_range, user_cond)
|
||||
|
||||
result = monitor_db.select(query)
|
||||
else:
|
||||
|
@ -459,10 +461,10 @@ class Graphs(object):
|
|||
' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS total_duration ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users ON session_history.user_id = users.user_id ' \
|
||||
'WHERE (datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) ' \
|
||||
'WHERE (datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) %s' \
|
||||
'GROUP BY session_history.user_id ' \
|
||||
'ORDER BY total_duration DESC ' \
|
||||
'LIMIT 10' % time_range
|
||||
'LIMIT 10' % (time_range, user_cond)
|
||||
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
|
@ -836,12 +838,14 @@ class Graphs(object):
|
|||
|
||||
return output
|
||||
|
||||
def get_stream_type_by_top_10_users(self, time_range='30', y_axis='plays'):
|
||||
def get_stream_type_by_top_10_users(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 users.user_id = %s ' % user_id) if user_id and user_id.isdigit() else ''
|
||||
|
||||
try:
|
||||
if y_axis == 'plays':
|
||||
query = 'SELECT ' \
|
||||
|
@ -858,9 +862,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 username ' \
|
||||
'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:
|
||||
|
@ -883,9 +887,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 username ' \
|
||||
'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:
|
||||
|
|
|
@ -21,7 +21,7 @@ class Users(object):
|
|||
def __init__(self):
|
||||
pass
|
||||
|
||||
def get_names(self, kwargs=None):
|
||||
def get_user_names(self, kwargs=None):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
try:
|
||||
|
|
|
@ -867,7 +867,7 @@ class WebInterface(object):
|
|||
def get_user_names(self, **kwargs):
|
||||
|
||||
user_data = users.Users()
|
||||
user_names = user_data.get_names(kwargs=kwargs)
|
||||
user_names = user_data.get_user_names(kwargs=kwargs)
|
||||
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(user_names)
|
||||
|
@ -939,10 +939,10 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_top_10_users(self, time_range='30', y_axis='plays', **kwargs):
|
||||
def get_plays_by_top_10_users(self, time_range='30', y_axis='plays', user_id=None, **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
result = graph.get_total_plays_by_top_10_users(time_range=time_range, y_axis=y_axis)
|
||||
result = graph.get_total_plays_by_top_10_users(time_range=time_range, y_axis=y_axis, user_id=user_id)
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
|
@ -952,10 +952,10 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_stream_type(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
|
||||
def get_plays_by_stream_type(self, time_range='30', y_axis='plays', user_id=None, **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
result = graph.get_total_plays_per_stream_type(time_range=time_range, user_id=user_id, y_axis=y_axis)
|
||||
result = graph.get_total_plays_per_stream_type(time_range=time_range, y_axis=y_axis, user_id=user_id)
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
|
@ -965,10 +965,10 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_source_resolution(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
|
||||
def get_plays_by_source_resolution(self, time_range='30', y_axis='plays', user_id=None, **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
result = graph.get_total_plays_by_source_resolution(time_range=time_range, user_id=user_id, y_axis=y_axis)
|
||||
result = graph.get_total_plays_by_source_resolution(time_range=time_range, y_axis=y_axis, user_id=user_id)
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
|
@ -978,10 +978,10 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_stream_resolution(self, time_range='30', user_id=None, y_axis='plays', **kwargs):
|
||||
def get_plays_by_stream_resolution(self, time_range='30', y_axis='plays', user_id=None, **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
result = graph.get_total_plays_by_stream_resolution(time_range=time_range, user_id=user_id, y_axis=y_axis)
|
||||
result = graph.get_total_plays_by_stream_resolution(time_range=time_range, y_axis=y_axis, user_id=user_id)
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
|
@ -991,10 +991,10 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_stream_type_by_top_10_users(self, time_range='30', y_axis='plays', **kwargs):
|
||||
def get_stream_type_by_top_10_users(self, time_range='30', y_axis='plays', user_id=None, **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
result = graph.get_stream_type_by_top_10_users(time_range=time_range, y_axis=y_axis)
|
||||
result = graph.get_stream_type_by_top_10_users(time_range=time_range, y_axis=y_axis, user_id=user_id)
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue