mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-21 22:03:18 -07:00
Merge bdf8f4e6a9
into c608c7c9fc
This commit is contained in:
commit
a9d111d591
7 changed files with 202 additions and 106 deletions
|
@ -24,9 +24,8 @@ users_list_table_options = {
|
|||
"createdCell": function (td, cellData, rowData, row, col) {
|
||||
$(td).html('<div class="edit-user-toggles"><button class="btn btn-xs btn-warning" data-id="' + rowData['user_id'] + '" data-toggle="button"><i class="fa fa-eraser fa-fw"></i> Purge</button>   ' +
|
||||
'<input type="checkbox" id="do_notify-' + rowData['user_id'] + '" name="do_notify" value="1" ' + rowData['do_notify'] + '><label class="edit-tooltip" for="do_notify-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle Notifications"><i class="fa fa-bell fa-lg fa-fw"></i></label> ' +
|
||||
'<input type="checkbox" id="keep_history-' + rowData['user_id'] + '" name="keep_history" value="1" ' + rowData['keep_history'] + '><label class="edit-tooltip" for="keep_history-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle History"><i class="fa fa-history fa-lg fa-fw"></i></label> ');
|
||||
// Show/hide user currently doesn't work
|
||||
//'<input type="checkbox" id="show_hide-' + rowData['user_id'] + '" name="show_hide" value="1" checked><label class="edit-tooltip" for="show_hide-' + rowData['user_id'] + '" data-toggle="tooltip" title="Show/Hide User"><i class="fa fa-eye fa-lg fa-fw"></i></label>');
|
||||
'<input type="checkbox" id="keep_history-' + rowData['user_id'] + '" name="keep_history" value="1" ' + rowData['keep_history'] + '><label class="edit-tooltip" for="keep_history-' + rowData['user_id'] + '" data-toggle="tooltip" title="Toggle History"><i class="fa fa-history fa-lg fa-fw"></i></label> ' +
|
||||
'<input type="checkbox" id="show_user-' + rowData['user_id'] + '" name="show_user" value="1" ' + rowData['show_user'] + '><label class="edit-tooltip" for="show_user-' + rowData['user_id'] + '" data-toggle="tooltip" title="Show/Hide User"><i class="fa fa-eye fa-lg fa-fw"></i></label>');
|
||||
},
|
||||
"width": "7%",
|
||||
"className": "edit-control no-wrap hidden",
|
||||
|
@ -184,6 +183,13 @@ users_list_table_options = {
|
|||
$('.edit-control').each(function () {
|
||||
$(this).removeClass('hidden');
|
||||
});
|
||||
$('.edit-control > .edit-user-toggles').each(function () {
|
||||
$(this).children('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger');
|
||||
});
|
||||
$('.edit-user-control > .edit-user-name').each(function () {
|
||||
$(this).children('a').addClass('hidden');
|
||||
$(this).children('input').removeClass('hidden');
|
||||
});
|
||||
}
|
||||
},
|
||||
"preDrawCallback": function(settings) {
|
||||
|
@ -246,12 +252,16 @@ $('#users_list_table').on('change', 'td.edit-control > .edit-user-toggles > inpu
|
|||
|
||||
var do_notify = 0;
|
||||
var keep_history = 0;
|
||||
var show_user = 0;
|
||||
if ($('#do_notify-' + rowData['user_id']).is(':checked')) {
|
||||
do_notify = 1;
|
||||
}
|
||||
if ($('#keep_history-' + rowData['user_id']).is(':checked')) {
|
||||
keep_history = 1;
|
||||
}
|
||||
if ($('#show_user-' + rowData['user_id']).is(':checked')) {
|
||||
show_user = 1;
|
||||
}
|
||||
|
||||
friendly_name = tr.find('td.edit-user-control > .edit-user-name > input').val();
|
||||
|
||||
|
@ -262,6 +272,7 @@ $('#users_list_table').on('change', 'td.edit-control > .edit-user-toggles > inpu
|
|||
friendly_name: friendly_name,
|
||||
do_notify: do_notify,
|
||||
keep_history: keep_history,
|
||||
show_user: show_user,
|
||||
thumb: rowData['user_thumb']
|
||||
},
|
||||
cache: false,
|
||||
|
|
|
@ -72,11 +72,15 @@
|
|||
<script src="interfaces/default/js/tables/users.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
filtered_users = true;
|
||||
users_list_table_options.ajax = {
|
||||
"url": "get_user_list",
|
||||
type: "post",
|
||||
data: function ( d ) {
|
||||
return { 'json_data': JSON.stringify( d ) };
|
||||
return {
|
||||
'filtered_users': filtered_users,
|
||||
'json_data': JSON.stringify(d)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +93,8 @@
|
|||
$('#users-to-delete').html('');
|
||||
|
||||
if ($(this).hasClass('active')) {
|
||||
filtered_users = true;
|
||||
users_list_table.ajax.reload();
|
||||
if (users_to_purge.length > 0) {
|
||||
$('.edit-control').each(function () {
|
||||
$(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger');
|
||||
|
@ -129,14 +135,8 @@
|
|||
|
||||
} else {
|
||||
users_to_purge = [];
|
||||
$('.edit-control').each(function () {
|
||||
$(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger');
|
||||
$(this).removeClass('hidden');
|
||||
});
|
||||
$('.edit-user-control > .edit-user-name').each(function () {
|
||||
$(this).children('a').addClass('hidden');
|
||||
$(this).children('input').removeClass('hidden');
|
||||
});
|
||||
filtered_users = false;
|
||||
users_list_table.ajax.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -388,7 +388,15 @@ def dbcheck():
|
|||
'user_id INTEGER DEFAULT NULL UNIQUE, username TEXT NOT NULL UNIQUE, '
|
||||
'friendly_name TEXT, thumb TEXT, email TEXT, is_home_user INTEGER DEFAULT NULL, '
|
||||
'is_allow_sync INTEGER DEFAULT NULL, is_restricted INTEGER DEFAULT NULL, do_notify INTEGER DEFAULT 1, '
|
||||
'keep_history INTEGER DEFAULT 1, custom_avatar_url TEXT)'
|
||||
'keep_history INTEGER DEFAULT 1, custom_avatar_url TEXT, show_user INTEGER DEFAULT 1)'
|
||||
)
|
||||
|
||||
# notify_log table :: This is a table which logs notifications sent
|
||||
c_db.execute(
|
||||
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||
'session_key INTEGER, rating_key INTEGER, user_id INTEGER, user TEXT, '
|
||||
'agent_id INTEGER, agent_name TEXT, on_play INTEGER, on_stop INTEGER, on_watched INTEGER, '
|
||||
'on_pause INTEGER, on_resume INTEGER, on_buffer INTEGER)'
|
||||
)
|
||||
|
||||
# Upgrade sessions table from earlier versions
|
||||
|
@ -517,6 +525,18 @@ def dbcheck():
|
|||
'ALTER TABLE sessions ADD COLUMN transcode_height INTEGER'
|
||||
)
|
||||
|
||||
# Upgrade sessions table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT buffer_count from sessions')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table sessions.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE sessions ADD COLUMN buffer_count INTEGER DEFAULT 0'
|
||||
)
|
||||
c_db.execute(
|
||||
'ALTER TABLE sessions ADD COLUMN buffer_last_triggered INTEGER'
|
||||
)
|
||||
|
||||
# Upgrade session_history_metadata table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT full_title from session_history_metadata')
|
||||
|
@ -535,14 +555,6 @@ def dbcheck():
|
|||
'ALTER TABLE session_history_metadata ADD COLUMN tagline TEXT'
|
||||
)
|
||||
|
||||
# notify_log table :: This is a table which logs notifications sent
|
||||
c_db.execute(
|
||||
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||
'session_key INTEGER, rating_key INTEGER, user_id INTEGER, user TEXT, '
|
||||
'agent_id INTEGER, agent_name TEXT, on_play INTEGER, on_stop INTEGER, on_watched INTEGER, '
|
||||
'on_pause INTEGER, on_resume INTEGER, on_buffer INTEGER)'
|
||||
)
|
||||
|
||||
# Upgrade users table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT do_notify from users')
|
||||
|
@ -561,6 +573,24 @@ def dbcheck():
|
|||
'ALTER TABLE users ADD COLUMN keep_history INTEGER DEFAULT 1'
|
||||
)
|
||||
|
||||
# Upgrade users table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT custom_avatar_url from users')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table users.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE users ADD COLUMN custom_avatar_url TEXT'
|
||||
)
|
||||
|
||||
# Upgrade users table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT show_user from users')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table users.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE users ADD COLUMN show_user INTEGER DEFAULT 1'
|
||||
)
|
||||
|
||||
# Upgrade notify_log table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT on_pause from notify_log')
|
||||
|
@ -576,27 +606,6 @@ def dbcheck():
|
|||
'ALTER TABLE notify_log ADD COLUMN on_buffer INTEGER'
|
||||
)
|
||||
|
||||
# Upgrade sessions table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT buffer_count from sessions')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table sessions.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE sessions ADD COLUMN buffer_count INTEGER DEFAULT 0'
|
||||
)
|
||||
c_db.execute(
|
||||
'ALTER TABLE sessions ADD COLUMN buffer_last_triggered INTEGER'
|
||||
)
|
||||
|
||||
# Upgrade users table from earlier versions
|
||||
try:
|
||||
c_db.execute('SELECT custom_avatar_url from users')
|
||||
except sqlite3.OperationalError:
|
||||
logger.debug(u"Altering database. Updating database table users.")
|
||||
c_db.execute(
|
||||
'ALTER TABLE users ADD COLUMN custom_avatar_url TEXT'
|
||||
)
|
||||
|
||||
# Add "Local" user to database as default unauthenticated user.
|
||||
result = c_db.execute('SELECT id FROM users WHERE username = "Local"')
|
||||
if not result.fetchone():
|
||||
|
|
|
@ -60,7 +60,8 @@ class DataFactory(object):
|
|||
'session_history.user',
|
||||
'session_history_metadata.media_type',
|
||||
'session_history_media_info.video_decision',
|
||||
'session_history.user_id as user_id'
|
||||
'session_history.user_id as user_id',
|
||||
'users.show_user as show_user'
|
||||
]
|
||||
try:
|
||||
query = data_tables.ssp_query(table_name='session_history',
|
||||
|
@ -161,10 +162,12 @@ class DataFactory(object):
|
|||
'MAX(session_history.started) as last_watch,' \
|
||||
'session_history_metadata.grandparent_thumb ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'JOIN session_history on session_history_metadata.id = session_history.id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "episode" ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
result = monitor_db.select(query)
|
||||
|
@ -193,6 +196,54 @@ class DataFactory(object):
|
|||
'stat_type': sort_type,
|
||||
'rows': top_tv})
|
||||
|
||||
elif 'popular_tv' in stat:
|
||||
popular_tv = []
|
||||
try:
|
||||
query = 'SELECT session_history_metadata.id, ' \
|
||||
'session_history_metadata.grandparent_title, ' \
|
||||
'COUNT(DISTINCT session_history.user_id) as users_watched, ' \
|
||||
'session_history_metadata.grandparent_rating_key, ' \
|
||||
'MAX(session_history.started) as last_watch, ' \
|
||||
'COUNT(session_history.id) as total_plays, ' \
|
||||
'cast(round(SUM(round((julianday(datetime(session_history.stopped, "unixepoch", "localtime")) - ' \
|
||||
'julianday(datetime(session_history.started, "unixepoch", "localtime"))) * 86400) - ' \
|
||||
'(CASE WHEN session_history.paused_counter IS NULL THEN 0 ' \
|
||||
'ELSE session_history.paused_counter END))/60) as integer) as total_duration,' \
|
||||
'session_history_metadata.grandparent_thumb ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "episode" ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
||||
'ORDER BY users_watched DESC, %s DESC ' \
|
||||
'LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return None
|
||||
|
||||
for item in result:
|
||||
row = {'title': item[1],
|
||||
'users_watched': item[2],
|
||||
'rating_key': item[3],
|
||||
'last_play': item[4],
|
||||
'total_plays': item[5],
|
||||
'grandparent_thumb': item[7],
|
||||
'thumb': '',
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
'platform_type': '',
|
||||
'platform': '',
|
||||
'row_id': item[0]
|
||||
}
|
||||
popular_tv.append(row)
|
||||
|
||||
home_stats.append({'stat_id': stat,
|
||||
'rows': popular_tv})
|
||||
|
||||
elif 'top_movies' in stat:
|
||||
top_movies = []
|
||||
try:
|
||||
|
@ -207,10 +258,12 @@ class DataFactory(object):
|
|||
'MAX(session_history.started) as last_watch,' \
|
||||
'session_history_metadata.thumb ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'JOIN session_history on session_history_metadata.id = session_history.id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "movie" ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history_metadata.full_title ' \
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
result = monitor_db.select(query)
|
||||
|
@ -239,48 +292,6 @@ class DataFactory(object):
|
|||
'stat_type': sort_type,
|
||||
'rows': top_movies})
|
||||
|
||||
elif 'popular_tv' in stat:
|
||||
popular_tv = []
|
||||
try:
|
||||
query = 'SELECT session_history_metadata.id, ' \
|
||||
'session_history_metadata.grandparent_title, ' \
|
||||
'COUNT(DISTINCT session_history.user_id) as users_watched, ' \
|
||||
'session_history_metadata.grandparent_rating_key, ' \
|
||||
'MAX(session_history.started) as last_watch, ' \
|
||||
'COUNT(session_history.id) as total_plays, ' \
|
||||
'session_history_metadata.grandparent_thumb ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "episode" ' \
|
||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
||||
'ORDER BY users_watched DESC, total_plays DESC ' \
|
||||
'LIMIT %s' % (time_range, stat_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return None
|
||||
|
||||
for item in result:
|
||||
row = {'title': item[1],
|
||||
'users_watched': item[2],
|
||||
'rating_key': item[3],
|
||||
'last_play': item[4],
|
||||
'total_plays': item[5],
|
||||
'grandparent_thumb': item[6],
|
||||
'thumb': '',
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
'platform_type': '',
|
||||
'platform': '',
|
||||
'row_id': item[0]
|
||||
}
|
||||
popular_tv.append(row)
|
||||
|
||||
home_stats.append({'stat_id': stat,
|
||||
'rows': popular_tv})
|
||||
|
||||
elif 'popular_movies' in stat:
|
||||
popular_movies = []
|
||||
try:
|
||||
|
@ -290,15 +301,21 @@ class DataFactory(object):
|
|||
'session_history_metadata.rating_key, ' \
|
||||
'MAX(session_history.started) as last_watch, ' \
|
||||
'COUNT(session_history.id) as total_plays, ' \
|
||||
'cast(round(SUM(round((julianday(datetime(session_history.stopped, "unixepoch", "localtime")) - ' \
|
||||
'julianday(datetime(session_history.started, "unixepoch", "localtime"))) * 86400) - ' \
|
||||
'(CASE WHEN session_history.paused_counter IS NULL THEN 0 ' \
|
||||
'ELSE session_history.paused_counter END))/60) as integer) as total_duration,' \
|
||||
'session_history_metadata.thumb ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "movie" ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history_metadata.full_title ' \
|
||||
'ORDER BY users_watched DESC, total_plays DESC ' \
|
||||
'LIMIT %s' % (time_range, stat_count)
|
||||
'ORDER BY users_watched DESC, %s DESC ' \
|
||||
'LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
|
@ -311,7 +328,7 @@ class DataFactory(object):
|
|||
'last_play': item[4],
|
||||
'total_plays': item[5],
|
||||
'grandparent_thumb': '',
|
||||
'thumb': item[6],
|
||||
'thumb': item[7],
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
'platform_type': '',
|
||||
|
@ -339,9 +356,10 @@ class DataFactory(object):
|
|||
'users.user_id ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \
|
||||
'LEFT OUTER JOIN users ON session_history.user_id = users.user_id ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-%s days", "localtime") '\
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history.user_id ' \
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
result = monitor_db.select(query)
|
||||
|
@ -388,8 +406,10 @@ class DataFactory(object):
|
|||
'ELSE session_history.paused_counter END))/60) as integer) as total_duration,' \
|
||||
'MAX(session_history.started) as last_watch ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history.platform ' \
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
result = monitor_db.select(query)
|
||||
|
@ -435,11 +455,12 @@ class DataFactory(object):
|
|||
'session_history.player as platform ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
||||
'LEFT OUTER JOIN users ON session_history.user_id = users.user_id ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND (session_history_metadata.media_type = "movie" ' \
|
||||
'OR session_history_metadata.media_type = "episode") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history_metadata.full_title ' \
|
||||
'ORDER BY last_watch DESC ' \
|
||||
'LIMIT %s' % (time_range, stat_count)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# This file is part of PlexPy.
|
||||
# This file is part of PlexPy.
|
||||
#
|
||||
# PlexPy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -35,7 +35,9 @@ class Graphs(object):
|
|||
'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 ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY date_played ' \
|
||||
'ORDER BY started ASC' % time_range
|
||||
|
||||
|
@ -45,7 +47,9 @@ class Graphs(object):
|
|||
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) else 0 end) as tv_duration, ' \
|
||||
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) else 0 end) as movie_duration ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY date_played ' \
|
||||
'ORDER BY started ASC' % time_range
|
||||
|
||||
|
@ -105,11 +109,13 @@ class Graphs(object):
|
|||
'when 4 then "Thursday" ' \
|
||||
'when 5 then "Friday" ' \
|
||||
'else "Saturday" end as dayofweek, ' \
|
||||
'COUNT(id) as total_plays ' \
|
||||
'COUNT(session_history.id) as total_plays ' \
|
||||
'from session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
||||
'(media_type = "episode" OR media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY dayofweek ' \
|
||||
'ORDER BY daynumber'
|
||||
|
||||
|
@ -127,9 +133,11 @@ class Graphs(object):
|
|||
'else "Saturday" end as dayofweek, ' \
|
||||
'SUM(case when media_type != "track" and stopped > 0 then (stopped - started) else 0 end) as duration ' \
|
||||
'from session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
||||
'(media_type = "episode" OR media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY dayofweek ' \
|
||||
'ORDER BY daynumber'
|
||||
|
||||
|
@ -169,11 +177,13 @@ class Graphs(object):
|
|||
|
||||
if y_axis == 'plays':
|
||||
query = 'select strftime("%H", datetime(started, "unixepoch", "localtime")) as hourofday, ' \
|
||||
'COUNT(id) ' \
|
||||
'COUNT(session_history.id) ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
||||
'(media_type = "episode" OR media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY hourofday ' \
|
||||
'ORDER BY hourofday'
|
||||
|
||||
|
@ -183,9 +193,11 @@ class Graphs(object):
|
|||
query = 'select strftime("%H", datetime(started, "unixepoch", "localtime")) as hourofday, ' \
|
||||
'SUM(case when media_type != "track" and stopped > 0 then (stopped - started) else 0 end) as duration ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
||||
'(media_type = "episode" OR media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY hourofday ' \
|
||||
'ORDER BY hourofday'
|
||||
|
||||
|
@ -228,7 +240,9 @@ class Graphs(object):
|
|||
'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 ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
|
||||
'ORDER BY datestring DESC LIMIT 12'
|
||||
|
||||
|
@ -238,7 +252,9 @@ class Graphs(object):
|
|||
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) else 0 end) as tv_duration, ' \
|
||||
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) else 0 end) as movie_duration ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
|
||||
'ORDER BY datestring DESC LIMIT 12'
|
||||
|
||||
|
@ -291,11 +307,13 @@ class Graphs(object):
|
|||
|
||||
if y_axis == 'plays':
|
||||
query = 'SELECT platform, ' \
|
||||
'count(id) as platform_count ' \
|
||||
'count(session_history.id) as platform_count ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE (datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||
'(media_type = "episode" OR media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY platform ' \
|
||||
'ORDER BY platform_count DESC ' \
|
||||
'LIMIT 10'
|
||||
|
@ -306,9 +324,11 @@ class Graphs(object):
|
|||
query = 'SELECT platform, ' \
|
||||
'SUM(case when stopped > 0 then (stopped - started) else 0 end) as duration ' \
|
||||
'FROM session_history ' \
|
||||
'JOIN users on session_history.user_id = users.user_id ' \
|
||||
'WHERE (datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||
'(media_type = "episode" OR media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY platform ' \
|
||||
'ORDER BY duration DESC ' \
|
||||
'LIMIT 10'
|
||||
|
@ -346,6 +366,7 @@ class Graphs(object):
|
|||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history.user_id ' \
|
||||
'ORDER BY user_count DESC ' \
|
||||
'LIMIT 10'
|
||||
|
@ -362,6 +383,7 @@ class Graphs(object):
|
|||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY session_history.user_id ' \
|
||||
'ORDER BY duration DESC ' \
|
||||
'LIMIT 10'
|
||||
|
@ -396,10 +418,12 @@ class Graphs(object):
|
|||
'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 tc_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.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-%s days", "localtime")) AND ' \
|
||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY date_played ' \
|
||||
'ORDER BY started ASC' % time_range
|
||||
|
||||
|
@ -413,10 +437,12 @@ class Graphs(object):
|
|||
'SUM(case when session_history_media_info.video_decision = "transcode" ' \
|
||||
'AND session_history.stopped > 0 then (stopped - started) else 0 end) as tc_duration ' \
|
||||
'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.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-%s days", "localtime") AND ' \
|
||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY date_played ' \
|
||||
'ORDER BY started ASC' % time_range
|
||||
|
||||
|
@ -479,10 +505,12 @@ class Graphs(object):
|
|||
'count(session_history.id) as play_count, ' \
|
||||
'session_history_media_info.video_resolution AS resolution ' \
|
||||
'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.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY resolution ' \
|
||||
'ORDER BY play_count DESC ' \
|
||||
'LIMIT 10'
|
||||
|
@ -494,10 +522,12 @@ class Graphs(object):
|
|||
'SUM(case when stopped > 0 then (stopped - started) else 0 end) as duration, ' \
|
||||
'session_history_media_info.video_resolution AS resolution ' \
|
||||
'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.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY resolution ' \
|
||||
'ORDER BY duration DESC ' \
|
||||
'LIMIT 10'
|
||||
|
@ -540,10 +570,12 @@ class Graphs(object):
|
|||
'when session_history_media_info.transcode_height <= 2160 then "4K" ' \
|
||||
'else "unknown" end) else session_history_media_info.video_resolution end) as resolution ' \
|
||||
'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.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY resolution ' \
|
||||
'ORDER BY play_count DESC ' \
|
||||
'LIMIT 10'
|
||||
|
@ -564,10 +596,12 @@ class Graphs(object):
|
|||
'when session_history_media_info.transcode_height <= 2160 then "4K" ' \
|
||||
'else "unknown" end) else session_history_media_info.video_resolution end) as resolution ' \
|
||||
'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.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY resolution ' \
|
||||
'ORDER BY duration DESC ' \
|
||||
'LIMIT 10'
|
||||
|
@ -608,6 +642,7 @@ 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", "-' + time_range + ' days", "localtime") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY username ' \
|
||||
'ORDER BY total_count DESC LIMIT 10'
|
||||
|
||||
|
@ -628,6 +663,7 @@ 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", "-' + time_range + ' days", "localtime") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY username ' \
|
||||
'ORDER BY total_count DESC LIMIT 10'
|
||||
|
||||
|
@ -670,9 +706,11 @@ class Graphs(object):
|
|||
'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") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY platform ' \
|
||||
'ORDER BY total_count DESC LIMIT 10'
|
||||
|
||||
|
@ -689,9 +727,11 @@ class Graphs(object):
|
|||
'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") ' \
|
||||
'AND users.show_user = 1 ' \
|
||||
'GROUP BY platform ' \
|
||||
'ORDER BY total_count DESC LIMIT 10'
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class Users(object):
|
|||
def __init__(self):
|
||||
pass
|
||||
|
||||
def get_user_list(self, kwargs=None):
|
||||
def get_user_list(self, kwargs=None, custom_where=None):
|
||||
data_tables = datatables.DataTables()
|
||||
|
||||
columns = ['session_history.id',
|
||||
|
@ -42,12 +42,13 @@ class Users(object):
|
|||
'session_history_media_info.video_decision',
|
||||
'users.username as user',
|
||||
'users.do_notify as do_notify',
|
||||
'users.keep_history as keep_history'
|
||||
'users.keep_history as keep_history',
|
||||
'users.show_user as show_user'
|
||||
]
|
||||
try:
|
||||
query = data_tables.ssp_query(table_name='users',
|
||||
columns=columns,
|
||||
custom_where=[],
|
||||
custom_where=custom_where,
|
||||
group_by=['users.user_id'],
|
||||
join_types=['LEFT OUTER JOIN',
|
||||
'LEFT OUTER JOIN',
|
||||
|
@ -98,7 +99,8 @@ class Users(object):
|
|||
"user": item["user"],
|
||||
"user_id": item['user_id'],
|
||||
"do_notify": helpers.checked(item['do_notify']),
|
||||
"keep_history": helpers.checked(item['keep_history'])
|
||||
"keep_history": helpers.checked(item['keep_history']),
|
||||
"show_user": helpers.checked(item['show_user'])
|
||||
}
|
||||
|
||||
rows.append(row)
|
||||
|
@ -193,7 +195,7 @@ class Users(object):
|
|||
return dict
|
||||
|
||||
# TODO: The getter and setter for this needs to become a config getter/setter for more than just friendlyname
|
||||
def set_user_friendly_name(self, user=None, user_id=None, friendly_name=None, do_notify=0, keep_history=1):
|
||||
def set_user_friendly_name(self, user=None, user_id=None, friendly_name=None, do_notify=0, keep_history=1, show_user=1):
|
||||
if user_id:
|
||||
if friendly_name.strip() == '':
|
||||
friendly_name = None
|
||||
|
@ -203,7 +205,8 @@ class Users(object):
|
|||
control_value_dict = {"user_id": user_id}
|
||||
new_value_dict = {"friendly_name": friendly_name,
|
||||
"do_notify": do_notify,
|
||||
"keep_history": keep_history}
|
||||
"keep_history": keep_history,
|
||||
"show_user": show_user}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
|
@ -217,7 +220,8 @@ class Users(object):
|
|||
control_value_dict = {"username": user}
|
||||
new_value_dict = {"friendly_name": friendly_name,
|
||||
"do_notify": do_notify,
|
||||
"keep_history": keep_history}
|
||||
"keep_history": keep_history,
|
||||
"show_user": show_user}
|
||||
try:
|
||||
monitor_db.upsert('users', new_value_dict, control_value_dict)
|
||||
except Exception, e:
|
||||
|
|
|
@ -194,6 +194,10 @@ class WebInterface(object):
|
|||
keep_history = kwargs.get('keep_history')
|
||||
else:
|
||||
keep_history = 0
|
||||
if 'show_user' in kwargs:
|
||||
show_user = kwargs.get('show_user')
|
||||
else:
|
||||
show_user = 0
|
||||
if 'thumb' in kwargs:
|
||||
custom_avatar = kwargs['thumb']
|
||||
else:
|
||||
|
@ -205,7 +209,8 @@ class WebInterface(object):
|
|||
user_data.set_user_friendly_name(user_id=user_id,
|
||||
friendly_name=friendly_name,
|
||||
do_notify=do_notify,
|
||||
keep_history=keep_history)
|
||||
keep_history=keep_history,
|
||||
show_user=show_user)
|
||||
user_data.set_user_profile_url(user_id=user_id,
|
||||
profile_url=custom_avatar)
|
||||
|
||||
|
@ -219,7 +224,8 @@ class WebInterface(object):
|
|||
user_data.set_user_friendly_name(user=user,
|
||||
friendly_name=friendly_name,
|
||||
do_notify=do_notify,
|
||||
keep_history=keep_history)
|
||||
keep_history=keep_history,
|
||||
show_user=show_user)
|
||||
user_data.set_user_profile_url(user=user,
|
||||
profile_url=custom_avatar)
|
||||
|
||||
|
@ -249,10 +255,14 @@ class WebInterface(object):
|
|||
return serve_template(templatename="ip_address_modal.html", title="IP Address Details", data=ip_address)
|
||||
|
||||
@cherrypy.expose
|
||||
def get_user_list(self, **kwargs):
|
||||
|
||||
def get_user_list(self, filtered_users=None, **kwargs):
|
||||
|
||||
custom_where=[]
|
||||
if filtered_users == 'true':
|
||||
custom_where = [['show_user', 1]]
|
||||
|
||||
user_data = users.Users()
|
||||
user_list = user_data.get_user_list(kwargs=kwargs)
|
||||
user_list = user_data.get_user_list(kwargs=kwargs, custom_where=custom_where)
|
||||
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(user_list)
|
||||
|
@ -586,6 +596,7 @@ class WebInterface(object):
|
|||
if 'start_date' in kwargs:
|
||||
start_date = kwargs.get('start_date', "")
|
||||
custom_where = [['strftime("%Y-%m-%d", datetime(date, "unixepoch", "localtime"))', start_date]]
|
||||
custom_where.append(['show_user', 1])
|
||||
|
||||
data_factory = datafactory.DataFactory()
|
||||
history = data_factory.get_history(kwargs=kwargs, custom_where=custom_where)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue