mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 05:01:14 -07:00
Fix stats on live tv info pages
This commit is contained in:
parent
e3245bc126
commit
10e62ca42d
3 changed files with 54 additions and 12 deletions
|
@ -878,7 +878,7 @@ DOCUMENTATION :: END
|
||||||
transcode_decision: transcode_decision,
|
transcode_decision: transcode_decision,
|
||||||
user_id: "${history_user_id}",
|
user_id: "${history_user_id}",
|
||||||
% if data['live']:
|
% if data['live']:
|
||||||
guid: "${data['guid']}
|
guid: "${data['guid']}"
|
||||||
% elif data['media_type'] in ('show', 'artist'):
|
% elif data['media_type'] in ('show', 'artist'):
|
||||||
grandparent_rating_key: "${data['rating_key']}"
|
grandparent_rating_key: "${data['rating_key']}"
|
||||||
% elif data['media_type'] in ('season', 'album'):
|
% elif data['media_type'] in ('season', 'album'):
|
||||||
|
@ -947,8 +947,12 @@ DOCUMENTATION :: END
|
||||||
url: 'item_watch_time_stats',
|
url: 'item_watch_time_stats',
|
||||||
async: true,
|
async: true,
|
||||||
data: {
|
data: {
|
||||||
|
% if data['live']:
|
||||||
|
guid: "${data['guid']}"
|
||||||
|
% else:
|
||||||
rating_key: "${data['rating_key']}",
|
rating_key: "${data['rating_key']}",
|
||||||
media_type: "${data['media_type']}"
|
media_type: "${data['media_type']}"
|
||||||
|
% endif
|
||||||
},
|
},
|
||||||
complete: function(xhr, status) {
|
complete: function(xhr, status) {
|
||||||
$("#watch-time-stats").html(xhr.responseText);
|
$("#watch-time-stats").html(xhr.responseText);
|
||||||
|
@ -959,8 +963,12 @@ DOCUMENTATION :: END
|
||||||
url: 'item_user_stats',
|
url: 'item_user_stats',
|
||||||
async: true,
|
async: true,
|
||||||
data: {
|
data: {
|
||||||
|
% if data['live']:
|
||||||
|
guid: "${data['guid']}"
|
||||||
|
% else:
|
||||||
rating_key: "${data['rating_key']}",
|
rating_key: "${data['rating_key']}",
|
||||||
media_type: "${data['media_type']}"
|
media_type: "${data['media_type']}"
|
||||||
|
% endif
|
||||||
},
|
},
|
||||||
complete: function(xhr, status) {
|
complete: function(xhr, status) {
|
||||||
$("#user-stats").html(xhr.responseText);
|
$("#user-stats").html(xhr.responseText);
|
||||||
|
|
|
@ -1203,8 +1203,8 @@ class DataFactory(object):
|
||||||
|
|
||||||
return library_stats
|
return library_stats
|
||||||
|
|
||||||
def get_watch_time_stats(self, rating_key=None, media_type=None, grouping=None, query_days=None):
|
def get_watch_time_stats(self, rating_key=None, guid=None, media_type=None, grouping=None, query_days=None):
|
||||||
if rating_key is None:
|
if rating_key is None and guid is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if grouping is None:
|
if grouping is None:
|
||||||
|
@ -1253,6 +1253,16 @@ class DataFactory(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = monitor_db.select(query, args=[timestamp_query] + rating_keys * 3)
|
result = monitor_db.select(query, args=[timestamp_query] + rating_keys * 3)
|
||||||
|
elif guid:
|
||||||
|
query = "SELECT (SUM(stopped - started) - " \
|
||||||
|
"SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END)) AS total_time, " \
|
||||||
|
"COUNT(DISTINCT %s) AS total_plays, section_id " \
|
||||||
|
"FROM session_history " \
|
||||||
|
"JOIN session_history_metadata ON session_history_metadata.id = session_history.id " \
|
||||||
|
"WHERE stopped >= ? " \
|
||||||
|
"AND session_history_metadata.guid = ? " % group_by
|
||||||
|
|
||||||
|
result = monitor_db.select(query, args=[timestamp_query, guid])
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
else:
|
else:
|
||||||
|
@ -1269,6 +1279,15 @@ class DataFactory(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = monitor_db.select(query, args=rating_keys * 3)
|
result = monitor_db.select(query, args=rating_keys * 3)
|
||||||
|
elif guid:
|
||||||
|
query = "SELECT (SUM(stopped - started) - " \
|
||||||
|
"SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END)) AS total_time, " \
|
||||||
|
"COUNT(DISTINCT %s) AS total_plays, section_id " \
|
||||||
|
"FROM session_history " \
|
||||||
|
"JOIN session_history_metadata ON session_history_metadata.id = session_history.id " \
|
||||||
|
"WHERE session_history_metadata.guid = ? " % group_by
|
||||||
|
|
||||||
|
result = monitor_db.select(query, args=[guid])
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -1297,7 +1316,7 @@ class DataFactory(object):
|
||||||
|
|
||||||
return item_watch_time_stats
|
return item_watch_time_stats
|
||||||
|
|
||||||
def get_user_stats(self, rating_key=None, media_type=None, grouping=None):
|
def get_user_stats(self, rating_key=None, guid=None, media_type=None, grouping=None):
|
||||||
if grouping is None:
|
if grouping is None:
|
||||||
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
||||||
|
|
||||||
|
@ -1338,6 +1357,21 @@ class DataFactory(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
result = monitor_db.select(query, args=rating_keys * 3)
|
result = monitor_db.select(query, args=rating_keys * 3)
|
||||||
|
elif guid:
|
||||||
|
query = "SELECT (CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = '' " \
|
||||||
|
"THEN users.username ELSE users.friendly_name END) AS friendly_name, " \
|
||||||
|
"users.user_id, users.username, users.thumb, users.custom_avatar_url AS custom_thumb, " \
|
||||||
|
"COUNT(DISTINCT %s) AS total_plays, (SUM(stopped - started) - " \
|
||||||
|
"SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END)) AS total_time, " \
|
||||||
|
"section_id " \
|
||||||
|
"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_metadata.guid = ? " \
|
||||||
|
"GROUP BY users.user_id " \
|
||||||
|
"ORDER BY total_plays DESC, total_time DESC" % group_by
|
||||||
|
|
||||||
|
result = monitor_db.select(query, args=[guid])
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -4497,10 +4497,10 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@requireAuth()
|
@requireAuth()
|
||||||
def item_watch_time_stats(self, rating_key=None, media_type=None, **kwargs):
|
def item_watch_time_stats(self, rating_key=None, guid=None, media_type=None, **kwargs):
|
||||||
if rating_key:
|
if rating_key or guid:
|
||||||
item_data = datafactory.DataFactory()
|
item_data = datafactory.DataFactory()
|
||||||
result = item_data.get_watch_time_stats(rating_key=rating_key, media_type=media_type)
|
result = item_data.get_watch_time_stats(rating_key=rating_key, guid=guid, media_type=media_type)
|
||||||
else:
|
else:
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
@ -4512,10 +4512,10 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@requireAuth()
|
@requireAuth()
|
||||||
def item_user_stats(self, rating_key=None, media_type=None, **kwargs):
|
def item_user_stats(self, rating_key=None, guid=None, media_type=None, **kwargs):
|
||||||
if rating_key:
|
if rating_key or guid:
|
||||||
item_data = datafactory.DataFactory()
|
item_data = datafactory.DataFactory()
|
||||||
result = item_data.get_user_stats(rating_key=rating_key, media_type=media_type)
|
result = item_data.get_user_stats(rating_key=rating_key, guid=guid, media_type=media_type)
|
||||||
else:
|
else:
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue