mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 00:06:07 -07:00
Group watch statistics history
This commit is contained in:
parent
0620ebebcf
commit
447c50fd03
4 changed files with 150 additions and 173 deletions
|
@ -487,7 +487,8 @@ textarea.form-control:focus {
|
||||||
.users-poster-face {
|
.users-poster-face {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
float: left;
|
float: left;
|
||||||
background-size: contain;
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
width: 40px;
|
width: 40px;
|
||||||
-webkit-border-radius: 50%;
|
-webkit-border-radius: 50%;
|
||||||
|
@ -1537,7 +1538,8 @@ a:hover .item-children-poster {
|
||||||
float: left;
|
float: left;
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
background-size: contain;
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
height: 80px;
|
height: 80px;
|
||||||
width: 80px;
|
width: 80px;
|
||||||
-webkit-border-radius: 50%;
|
-webkit-border-radius: 50%;
|
||||||
|
|
|
@ -86,9 +86,9 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="group_history_tables" name="group_history_tables" value="1" ${config['group_history_tables']}> Group Table History
|
<input type="checkbox" id="group_history_tables" name="group_history_tables" value="1" ${config['group_history_tables']}> Group Table and Watch Statistics History
|
||||||
</label>
|
</label>
|
||||||
<p class="help-block">Group successive play history by the same user as a single entry in tables.</p>
|
<p class="help-block">Group successive play history by the same user as a single entry in the tables and watch statistics.</p>
|
||||||
</div>
|
</div>
|
||||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -41,7 +41,8 @@ class DataFactory(object):
|
||||||
'SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) AS paused_counter',
|
'SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) AS paused_counter',
|
||||||
'session_history.user_id',
|
'session_history.user_id',
|
||||||
'session_history.user',
|
'session_history.user',
|
||||||
'(CASE WHEN users.friendly_name IS NULL THEN users.username ELSE users.friendly_name END) as friendly_name',
|
'(CASE WHEN users.friendly_name IS NULL THEN users.username ELSE users.friendly_name END) \
|
||||||
|
AS friendly_name',
|
||||||
'platform',
|
'platform',
|
||||||
'player',
|
'player',
|
||||||
'ip_address',
|
'ip_address',
|
||||||
|
@ -58,7 +59,8 @@ class DataFactory(object):
|
||||||
'session_history_metadata.parent_thumb',
|
'session_history_metadata.parent_thumb',
|
||||||
'session_history_metadata.grandparent_thumb',
|
'session_history_metadata.grandparent_thumb',
|
||||||
'((CASE WHEN view_offset IS NULL THEN 0.1 ELSE view_offset * 1.0 END) / \
|
'((CASE WHEN view_offset IS NULL THEN 0.1 ELSE view_offset * 1.0 END) / \
|
||||||
(CASE WHEN session_history_metadata.duration IS NULL THEN 1.0 ELSE session_history_metadata.duration * 1.0 END) * 100) AS percent_complete',
|
(CASE WHEN session_history_metadata.duration IS NULL THEN 1.0 \
|
||||||
|
ELSE session_history_metadata.duration * 1.0 END) * 100) AS percent_complete',
|
||||||
'session_history_media_info.video_decision',
|
'session_history_media_info.video_decision',
|
||||||
'session_history_media_info.audio_decision',
|
'session_history_media_info.audio_decision',
|
||||||
'COUNT(*) AS group_count',
|
'COUNT(*) AS group_count',
|
||||||
|
@ -156,9 +158,10 @@ class DataFactory(object):
|
||||||
|
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
def get_home_stats(self, time_range='30', stats_type=0, stats_count='5', stats_cards='', notify_watched_percent='85'):
|
def get_home_stats(self, grouping=0, time_range='30', stats_type=0, stats_count='5', stats_cards='', notify_watched_percent='85'):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
|
||||||
sort_type = 'total_plays' if stats_type == 0 else 'total_duration'
|
sort_type = 'total_plays' if stats_type == 0 else 'total_duration'
|
||||||
|
|
||||||
home_stats = []
|
home_stats = []
|
||||||
|
@ -167,23 +170,20 @@ class DataFactory(object):
|
||||||
if stat == 'top_tv':
|
if stat == 'top_tv':
|
||||||
top_tv = []
|
top_tv = []
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT t.id, t.grandparent_title, t.grandparent_rating_key, t.grandparent_thumb, ' \
|
||||||
'session_history_metadata.grandparent_title, ' \
|
'MAX(t.started) AS last_watch, COUNT(t.id) AS total_plays, ' \
|
||||||
'COUNT(session_history_metadata.grandparent_title) as total_plays, ' \
|
'SUM(CASE WHEN t.stopped > 0 THEN (t.stopped - t.started) ' \
|
||||||
'SUM(case when session_history.stopped > 0 ' \
|
' - (CASE WHEN t.paused_counter IS NULL THEN 0 ELSE t.paused_counter END) ELSE 0 END) ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
' AS total_duration ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'else 0 end) as total_duration, ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
'session_history_metadata.grandparent_rating_key, ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'MAX(session_history.started) as last_watch,' \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'session_history_metadata.grandparent_thumb ' \
|
' AND session_history.media_type = "episode" ' \
|
||||||
'FROM session_history_metadata ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'JOIN session_history on session_history_metadata.id = session_history.id ' \
|
'GROUP BY t.grandparent_title ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
'ORDER BY %s DESC ' \
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||||
'AND session_history_metadata.media_type = "episode" ' \
|
|
||||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
|
||||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: top_tv.")
|
logger.warn("Unable to execute database query for get_home_stats: top_tv.")
|
||||||
|
@ -213,25 +213,21 @@ class DataFactory(object):
|
||||||
elif stat == 'popular_tv':
|
elif stat == 'popular_tv':
|
||||||
popular_tv = []
|
popular_tv = []
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT t.id, t.grandparent_title, t.grandparent_rating_key, t.grandparent_thumb, ' \
|
||||||
'session_history_metadata.grandparent_title, ' \
|
'COUNT(DISTINCT t.user_id) AS users_watched, ' \
|
||||||
'COUNT(DISTINCT session_history.user_id) as users_watched, ' \
|
'MAX(t.started) AS last_watch, COUNT(t.id) as total_plays, ' \
|
||||||
'session_history_metadata.grandparent_rating_key, ' \
|
'SUM(CASE WHEN t.stopped > 0 THEN (t.stopped - t.started) ' \
|
||||||
'MAX(session_history.started) as last_watch, ' \
|
' - (CASE WHEN t.paused_counter IS NULL THEN 0 ELSE t.paused_counter END) ELSE 0 END) ' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
' AS total_duration ' \
|
||||||
'SUM(case when session_history.stopped > 0 ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'else 0 end) as total_duration, ' \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'session_history_metadata.grandparent_thumb ' \
|
' AND session_history.media_type = "episode" ' \
|
||||||
'FROM session_history_metadata ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
'GROUP BY t.grandparent_title ' \
|
||||||
'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, %s DESC ' \
|
'ORDER BY users_watched DESC, %s DESC ' \
|
||||||
'LIMIT %s' % (time_range, sort_type, stats_count)
|
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: popular_tv.")
|
logger.warn("Unable to execute database query for get_home_stats: popular_tv.")
|
||||||
|
@ -259,23 +255,20 @@ class DataFactory(object):
|
||||||
elif stat == 'top_movies':
|
elif stat == 'top_movies':
|
||||||
top_movies = []
|
top_movies = []
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT t.id, t.full_title, t.rating_key, t.thumb, ' \
|
||||||
'session_history_metadata.full_title, ' \
|
'MAX(t.started) AS last_watch, COUNT(t.id) AS total_plays, ' \
|
||||||
'COUNT(session_history_metadata.full_title) as total_plays, ' \
|
'SUM(CASE WHEN t.stopped > 0 THEN (t.stopped - t.started) ' \
|
||||||
'SUM(case when session_history.stopped > 0 ' \
|
' - (CASE WHEN t.paused_counter IS NULL THEN 0 ELSE t.paused_counter END) ELSE 0 END) ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
' AS total_duration ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'else 0 end) as total_duration, ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
'session_history_metadata.rating_key, ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'MAX(session_history.started) as last_watch,' \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'session_history_metadata.thumb ' \
|
' AND session_history.media_type = "movie" ' \
|
||||||
'FROM session_history_metadata ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'JOIN session_history on session_history_metadata.id = session_history.id ' \
|
'GROUP BY t.full_title ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
'ORDER BY %s DESC ' \
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||||
'AND session_history_metadata.media_type = "movie" ' \
|
|
||||||
'GROUP BY session_history_metadata.full_title ' \
|
|
||||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: top_movies.")
|
logger.warn("Unable to execute database query for get_home_stats: top_movies.")
|
||||||
|
@ -297,7 +290,6 @@ class DataFactory(object):
|
||||||
'row_id': item['id']
|
'row_id': item['id']
|
||||||
}
|
}
|
||||||
top_movies.append(row)
|
top_movies.append(row)
|
||||||
|
|
||||||
home_stats.append({'stat_id': stat,
|
home_stats.append({'stat_id': stat,
|
||||||
'stat_type': sort_type,
|
'stat_type': sort_type,
|
||||||
'rows': top_movies})
|
'rows': top_movies})
|
||||||
|
@ -305,25 +297,21 @@ class DataFactory(object):
|
||||||
elif stat == 'popular_movies':
|
elif stat == 'popular_movies':
|
||||||
popular_movies = []
|
popular_movies = []
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT t.id, t.full_title, t.rating_key, t.thumb, ' \
|
||||||
'session_history_metadata.full_title, ' \
|
'COUNT(DISTINCT t.user_id) AS users_watched, ' \
|
||||||
'COUNT(DISTINCT session_history.user_id) as users_watched, ' \
|
'MAX(t.started) AS last_watch, COUNT(t.id) as total_plays, ' \
|
||||||
'session_history_metadata.rating_key, ' \
|
'SUM(CASE WHEN t.stopped > 0 THEN (t.stopped - t.started) ' \
|
||||||
'MAX(session_history.started) as last_watch, ' \
|
' - (CASE WHEN t.paused_counter IS NULL THEN 0 ELSE t.paused_counter END) ELSE 0 END) ' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
' AS total_duration ' \
|
||||||
'SUM(case when session_history.stopped > 0 ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'else 0 end) as total_duration, ' \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'session_history_metadata.thumb ' \
|
' AND session_history.media_type = "movie" ' \
|
||||||
'FROM session_history_metadata ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
'GROUP BY t.full_title ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
|
||||||
'AND session_history_metadata.media_type = "movie" ' \
|
|
||||||
'GROUP BY session_history_metadata.full_title ' \
|
|
||||||
'ORDER BY users_watched DESC, %s DESC ' \
|
'ORDER BY users_watched DESC, %s DESC ' \
|
||||||
'LIMIT %s' % (time_range, sort_type, stats_count)
|
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: popular_movies.")
|
logger.warn("Unable to execute database query for get_home_stats: popular_movies.")
|
||||||
|
@ -351,23 +339,20 @@ class DataFactory(object):
|
||||||
elif stat == 'top_music':
|
elif stat == 'top_music':
|
||||||
top_music = []
|
top_music = []
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT t.id, t.grandparent_title, t.grandparent_rating_key, t.grandparent_thumb, ' \
|
||||||
'session_history_metadata.grandparent_title, ' \
|
'MAX(t.started) AS last_watch, COUNT(t.id) AS total_plays, ' \
|
||||||
'COUNT(session_history_metadata.grandparent_title) as total_plays, ' \
|
'SUM(CASE WHEN t.stopped > 0 THEN (t.stopped - t.started) ' \
|
||||||
'SUM(case when session_history.stopped > 0 ' \
|
' - (CASE WHEN t.paused_counter IS NULL THEN 0 ELSE t.paused_counter END) ELSE 0 END) ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
' AS total_duration ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'else 0 end) as total_duration, ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
'session_history_metadata.grandparent_rating_key, ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'MAX(session_history.started) as last_watch,' \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'session_history_metadata.grandparent_thumb ' \
|
' AND session_history.media_type = "track" ' \
|
||||||
'FROM session_history_metadata ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'JOIN session_history on session_history_metadata.id = session_history.id ' \
|
'GROUP BY t.grandparent_title ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
'ORDER BY %s DESC ' \
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||||
'AND session_history_metadata.media_type = "track" ' \
|
|
||||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
|
||||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: top_music.")
|
logger.warn("Unable to execute database query for get_home_stats: top_music.")
|
||||||
|
@ -397,25 +382,21 @@ class DataFactory(object):
|
||||||
elif stat == 'popular_music':
|
elif stat == 'popular_music':
|
||||||
popular_music = []
|
popular_music = []
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT t.id, t.grandparent_title, t.grandparent_rating_key, t.grandparent_thumb, ' \
|
||||||
'session_history_metadata.grandparent_title, ' \
|
'COUNT(DISTINCT t.user_id) AS users_watched, ' \
|
||||||
'COUNT(DISTINCT session_history.user_id) as users_watched, ' \
|
'MAX(t.started) AS last_watch, COUNT(t.id) as total_plays, ' \
|
||||||
'session_history_metadata.grandparent_rating_key, ' \
|
'SUM(CASE WHEN t.stopped > 0 THEN (t.stopped - t.started) ' \
|
||||||
'MAX(session_history.started) as last_watch, ' \
|
' - (CASE WHEN t.paused_counter IS NULL THEN 0 ELSE t.paused_counter END) ELSE 0 END) ' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
' AS total_duration ' \
|
||||||
'SUM(case when session_history.stopped > 0 ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'else 0 end) as total_duration, ' \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'session_history_metadata.grandparent_thumb ' \
|
' AND session_history.media_type = "track" ' \
|
||||||
'FROM session_history_metadata ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
'GROUP BY t.grandparent_title ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
|
||||||
'AND session_history_metadata.media_type = "track" ' \
|
|
||||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
|
||||||
'ORDER BY users_watched DESC, %s DESC ' \
|
'ORDER BY users_watched DESC, %s DESC ' \
|
||||||
'LIMIT %s' % (time_range, sort_type, stats_count)
|
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: popular_music.")
|
logger.warn("Unable to execute database query for get_home_stats: popular_music.")
|
||||||
|
@ -443,24 +424,22 @@ class DataFactory(object):
|
||||||
elif stat == 'top_users':
|
elif stat == 'top_users':
|
||||||
top_users = []
|
top_users = []
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history.user, ' \
|
query = 'SELECT t.user, t.user_id, t.custom_avatar_url as thumb, ' \
|
||||||
'(case when users.friendly_name is null then users.username else ' \
|
'(CASE WHEN t.friendly_name IS NULL THEN t.username ELSE t.friendly_name END) ' \
|
||||||
'users.friendly_name end) as friendly_name,' \
|
' AS friendly_name, ' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
'MAX(t.started) AS last_watch, COUNT(t.id) AS total_plays, ' \
|
||||||
'SUM(case when session_history.stopped > 0 ' \
|
'SUM(CASE WHEN t.stopped > 0 THEN (t.stopped - t.started) ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
' - (CASE WHEN t.paused_counter IS NULL THEN 0 ELSE t.paused_counter END) ELSE 0 END) ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
' AS total_duration ' \
|
||||||
'else 0 end) as total_duration, ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'MAX(session_history.started) as last_watch, ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
'users.custom_avatar_url as thumb, ' \
|
' LEFT OUTER JOIN users ON session_history.user_id = users.user_id ' \
|
||||||
'users.user_id ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'FROM session_history ' \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'LEFT OUTER JOIN users ON session_history.user_id = users.user_id ' \
|
'GROUP BY t.user_id ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'ORDER BY %s DESC ' \
|
||||||
'datetime("now", "-%s days", "localtime") '\
|
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||||
'GROUP BY session_history.user_id ' \
|
|
||||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: top_users.")
|
logger.warn("Unable to execute database query for get_home_stats: top_users.")
|
||||||
|
@ -497,18 +476,19 @@ class DataFactory(object):
|
||||||
top_platform = []
|
top_platform = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history.platform, ' \
|
query = 'SELECT t.platform, ' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
'MAX(t.started) AS last_watch, COUNT(t.id) AS total_plays, ' \
|
||||||
'SUM(case when session_history.stopped > 0 ' \
|
'SUM(CASE WHEN t.stopped > 0 THEN (t.stopped - t.started) ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
' - (CASE WHEN t.paused_counter IS NULL THEN 0 ELSE t.paused_counter END) ELSE 0 END) ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
' AS total_duration ' \
|
||||||
'else 0 end) as total_duration, ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'MAX(session_history.started) as last_watch ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
'FROM session_history ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'GROUP BY session_history.platform ' \
|
'GROUP BY t.platform ' \
|
||||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
'ORDER BY %s DESC ' \
|
||||||
|
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: top_platforms.")
|
logger.warn("Unable to execute database query for get_home_stats: top_platforms.")
|
||||||
|
@ -541,33 +521,26 @@ class DataFactory(object):
|
||||||
elif stat == 'last_watched':
|
elif stat == 'last_watched':
|
||||||
last_watched = []
|
last_watched = []
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT t.id, t.full_title, t.rating_key, t.thumb, t.grandparent_thumb, ' \
|
||||||
'session_history.user, ' \
|
't.user, t.user_id, t.custom_avatar_url as user_thumb, t.player, ' \
|
||||||
'(case when users.friendly_name is null then users.username else ' \
|
'(CASE WHEN t.friendly_name IS NULL THEN t.username ELSE t.friendly_name END) ' \
|
||||||
'users.friendly_name end) as friendly_name,' \
|
' AS friendly_name, ' \
|
||||||
'users.user_id, ' \
|
'MAX(t.started) AS last_watch, ' \
|
||||||
'users.custom_avatar_url as user_thumb, ' \
|
'((CASE WHEN t.view_offset IS NULL THEN 0.1 ELSE t.view_offset * 1.0 END) / ' \
|
||||||
'session_history_metadata.full_title, ' \
|
' (CASE WHEN t.duration IS NULL THEN 1.0 ELSE t.duration * 1.0 END) * 100) ' \
|
||||||
'session_history_metadata.rating_key, ' \
|
' AS percent_complete ' \
|
||||||
'session_history_metadata.thumb, ' \
|
'FROM (SELECT * FROM session_history ' \
|
||||||
'session_history_metadata.grandparent_thumb, ' \
|
' JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
|
||||||
'MAX(session_history.started) as last_watch, ' \
|
' LEFT OUTER JOIN users ON session_history.user_id = users.user_id ' \
|
||||||
'session_history.player, ' \
|
' WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
'((CASE WHEN session_history.view_offset IS NULL THEN 0.1 ELSE \
|
' >= datetime("now", "-%s days", "localtime") ' \
|
||||||
session_history.view_offset * 1.0 END) / \
|
' AND (session_history.media_type = "movie" ' \
|
||||||
(CASE WHEN session_history_metadata.duration IS NULL THEN 1.0 ELSE \
|
' OR session_history_metadata.media_type = "episode") ' \
|
||||||
session_history_metadata.duration * 1.0 END) * 100) as percent_complete ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'FROM session_history_metadata ' \
|
'WHERE percent_complete >= %s ' \
|
||||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
'GROUP BY t.id ' \
|
||||||
'LEFT OUTER 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 percent_complete >= %s ' \
|
|
||||||
'GROUP BY session_history.id ' \
|
|
||||||
'ORDER BY last_watch DESC ' \
|
'ORDER BY last_watch DESC ' \
|
||||||
'LIMIT %s' % (time_range, notify_watched_percent, stats_count)
|
'LIMIT %s' % (time_range, group_by, notify_watched_percent, stats_count)
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query for get_home_stats: last_watched.")
|
logger.warn("Unable to execute database query for get_home_stats: last_watched.")
|
||||||
|
|
|
@ -128,13 +128,15 @@ class WebInterface(object):
|
||||||
def home_stats(self, **kwargs):
|
def home_stats(self, **kwargs):
|
||||||
data_factory = datafactory.DataFactory()
|
data_factory = datafactory.DataFactory()
|
||||||
|
|
||||||
|
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
||||||
time_range = plexpy.CONFIG.HOME_STATS_LENGTH
|
time_range = plexpy.CONFIG.HOME_STATS_LENGTH
|
||||||
stats_type = plexpy.CONFIG.HOME_STATS_TYPE
|
stats_type = plexpy.CONFIG.HOME_STATS_TYPE
|
||||||
stats_count = plexpy.CONFIG.HOME_STATS_COUNT
|
stats_count = plexpy.CONFIG.HOME_STATS_COUNT
|
||||||
stats_cards = plexpy.CONFIG.HOME_STATS_CARDS.split(', ')
|
stats_cards = plexpy.CONFIG.HOME_STATS_CARDS.split(', ')
|
||||||
notify_watched_percent = plexpy.CONFIG.NOTIFY_WATCHED_PERCENT
|
notify_watched_percent = plexpy.CONFIG.NOTIFY_WATCHED_PERCENT
|
||||||
|
|
||||||
stats_data = data_factory.get_home_stats(time_range=time_range,
|
stats_data = data_factory.get_home_stats(grouping=grouping,
|
||||||
|
time_range=time_range,
|
||||||
stats_type=stats_type,
|
stats_type=stats_type,
|
||||||
stats_count=stats_count,
|
stats_count=stats_count,
|
||||||
stats_cards=stats_cards,
|
stats_cards=stats_cards,
|
||||||
|
@ -613,7 +615,7 @@ class WebInterface(object):
|
||||||
custom_where.append(['session_history.grandparent_rating_key', rating_key])
|
custom_where.append(['session_history.grandparent_rating_key', rating_key])
|
||||||
if 'start_date' in kwargs:
|
if 'start_date' in kwargs:
|
||||||
start_date = kwargs.get('start_date', "")
|
start_date = kwargs.get('start_date', "")
|
||||||
custom_where.append(['strftime("%Y-%m-%d", datetime(date, "unixepoch", "localtime"))', start_date])
|
custom_where.append(['strftime("%Y-%m-%d", datetime(started, "unixepoch", "localtime"))', start_date])
|
||||||
if 'reference_id' in kwargs:
|
if 'reference_id' in kwargs:
|
||||||
reference_id = kwargs.get('reference_id', "")
|
reference_id = kwargs.get('reference_id', "")
|
||||||
custom_where.append(['session_history.reference_id', reference_id])
|
custom_where.append(['session_history.reference_id', reference_id])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue