mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 14:13:40 -07:00
user_stats for collection
This commit is contained in:
parent
3c996f01a9
commit
a85dd7d27e
3 changed files with 26 additions and 11 deletions
|
@ -542,7 +542,7 @@ DOCUMENTATION :: END
|
|||
</div>
|
||||
</div>
|
||||
% endif
|
||||
% if data['media_type'] in ('movie', 'show', 'season', 'episode', 'artist', 'album', 'track'):
|
||||
% if data['media_type'] in ('movie', 'show', 'season', 'episode', 'artist', 'album', 'track', 'collection'):
|
||||
<div class="col-md-12">
|
||||
<div class="table-card-header">
|
||||
<div class="header-bar">
|
||||
|
@ -925,7 +925,7 @@ DOCUMENTATION :: END
|
|||
});
|
||||
</script>
|
||||
% endif
|
||||
% if data['media_type'] in ('movie', 'show', 'season', 'episode', 'artist', 'album', 'track'):
|
||||
% if data['media_type'] in ('movie', 'show', 'season', 'episode', 'artist', 'album', 'track', 'collection'):
|
||||
<script>
|
||||
// Populate watch time stats
|
||||
$.ajax({
|
||||
|
@ -940,7 +940,10 @@ DOCUMENTATION :: END
|
|||
$.ajax({
|
||||
url: 'item_user_stats',
|
||||
async: true,
|
||||
data: { rating_key: "${data['rating_key']}" },
|
||||
data: {
|
||||
rating_key: "${data['rating_key']}",
|
||||
media_type: "${data['media_type']}"
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
$("#user-stats").html(xhr.responseText);
|
||||
}
|
||||
|
|
|
@ -1213,7 +1213,7 @@ class DataFactory(object):
|
|||
|
||||
return item_watch_time_stats
|
||||
|
||||
def get_user_stats(self, rating_key=None, grouping=None):
|
||||
def get_user_stats(self, rating_key=None, media_type=None, grouping=None):
|
||||
if grouping is None:
|
||||
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
||||
|
||||
|
@ -1225,6 +1225,18 @@ class DataFactory(object):
|
|||
|
||||
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
|
||||
|
||||
_rating_keys = []
|
||||
if media_type == 'collection':
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_item_children(rating_key=rating_key)
|
||||
|
||||
for child in result['children_list']:
|
||||
_rating_keys.append(child['rating_key'])
|
||||
else:
|
||||
_rating_keys.append(rating_key)
|
||||
|
||||
rating_keys = '(' + ','.join(_rating_keys) + ')'
|
||||
|
||||
try:
|
||||
if str(rating_key).isdigit():
|
||||
query = 'SELECT (CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" ' \
|
||||
|
@ -1236,12 +1248,12 @@ class DataFactory(object):
|
|||
'FROM session_history ' \
|
||||
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||
'JOIN users ON users.user_id = session_history.user_id ' \
|
||||
'WHERE (session_history.grandparent_rating_key = ? ' \
|
||||
'OR session_history.parent_rating_key = ? ' \
|
||||
'OR session_history.rating_key = ?) ' \
|
||||
'WHERE (session_history.grandparent_rating_key IN %s ' \
|
||||
'OR session_history.parent_rating_key IN %s ' \
|
||||
'OR session_history.rating_key IN %s) ' \
|
||||
'GROUP BY users.user_id ' \
|
||||
'ORDER BY total_plays DESC, total_time DESC' % group_by
|
||||
result = monitor_db.select(query, args=[rating_key, rating_key, rating_key])
|
||||
'ORDER BY total_plays DESC, total_time DESC' % (group_by, rating_keys, rating_keys, rating_keys)
|
||||
result = monitor_db.select(query)
|
||||
else:
|
||||
result = []
|
||||
except Exception as e:
|
||||
|
|
|
@ -4446,10 +4446,10 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
@requireAuth()
|
||||
def item_user_stats(self, rating_key=None, **kwargs):
|
||||
def item_user_stats(self, rating_key=None, media_type=None, **kwargs):
|
||||
if rating_key:
|
||||
item_data = datafactory.DataFactory()
|
||||
result = item_data.get_user_stats(rating_key=rating_key)
|
||||
result = item_data.get_user_stats(rating_key=rating_key, media_type=media_type)
|
||||
else:
|
||||
result = None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue