mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 22:23:36 -07:00
watch_time_stats for collection
This commit is contained in:
parent
a85dd7d27e
commit
dc16df9192
3 changed files with 28 additions and 12 deletions
|
@ -931,7 +931,10 @@ DOCUMENTATION :: END
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'item_watch_time_stats',
|
url: 'item_watch_time_stats',
|
||||||
async: true,
|
async: true,
|
||||||
data: { rating_key: "${data['rating_key']}" },
|
data: {
|
||||||
|
rating_key: "${data['rating_key']}",
|
||||||
|
media_type: "${data['media_type']}"
|
||||||
|
},
|
||||||
complete: function(xhr, status) {
|
complete: function(xhr, status) {
|
||||||
$("#watch-time-stats").html(xhr.responseText);
|
$("#watch-time-stats").html(xhr.responseText);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1134,7 +1134,7 @@ class DataFactory(object):
|
||||||
|
|
||||||
return library_stats
|
return library_stats
|
||||||
|
|
||||||
def get_watch_time_stats(self, rating_key=None, grouping=None, query_days=None):
|
def get_watch_time_stats(self, rating_key=None, media_type=None, grouping=None, query_days=None):
|
||||||
if rating_key is None:
|
if rating_key is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -1156,6 +1156,18 @@ class DataFactory(object):
|
||||||
|
|
||||||
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
|
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) + ')'
|
||||||
|
|
||||||
for days in query_days:
|
for days in query_days:
|
||||||
timestamp_query = timestamp - days * 24 * 60 * 60
|
timestamp_query = timestamp - days * 24 * 60 * 60
|
||||||
|
|
||||||
|
@ -1168,10 +1180,11 @@ class DataFactory(object):
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
'WHERE stopped >= %s ' \
|
'WHERE stopped >= %s ' \
|
||||||
'AND (session_history.grandparent_rating_key = ? ' \
|
'AND (session_history.grandparent_rating_key IN %s ' \
|
||||||
'OR session_history.parent_rating_key = ? ' \
|
'OR session_history.parent_rating_key IN %s ' \
|
||||||
'OR session_history.rating_key = ?)' % (group_by, timestamp_query)
|
'OR session_history.rating_key IN %s)' % (group_by, timestamp_query,
|
||||||
result = monitor_db.select(query, args=[rating_key, rating_key, rating_key])
|
rating_keys, rating_keys, rating_keys)
|
||||||
|
result = monitor_db.select(query)
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
else:
|
else:
|
||||||
|
@ -1181,10 +1194,10 @@ class DataFactory(object):
|
||||||
'COUNT(DISTINCT %s) AS total_plays, section_id ' \
|
'COUNT(DISTINCT %s) AS total_plays, section_id ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
'WHERE (session_history.grandparent_rating_key = ? ' \
|
'WHERE (session_history.grandparent_rating_key IN %s ' \
|
||||||
'OR session_history.parent_rating_key = ? ' \
|
'OR session_history.parent_rating_key IN %s ' \
|
||||||
'OR session_history.rating_key = ?)' % group_by
|
'OR session_history.rating_key IN %s)' % (group_by, rating_keys, rating_keys, rating_keys)
|
||||||
result = monitor_db.select(query, args=[rating_key, rating_key, rating_key])
|
result = monitor_db.select(query)
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -4431,10 +4431,10 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@requireAuth()
|
@requireAuth()
|
||||||
def item_watch_time_stats(self, rating_key=None, **kwargs):
|
def item_watch_time_stats(self, rating_key=None, media_type=None, **kwargs):
|
||||||
if rating_key:
|
if rating_key:
|
||||||
item_data = datafactory.DataFactory()
|
item_data = datafactory.DataFactory()
|
||||||
result = item_data.get_watch_time_stats(rating_key=rating_key)
|
result = item_data.get_watch_time_stats(rating_key=rating_key, media_type=media_type)
|
||||||
else:
|
else:
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue