mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Fix merge conflicts
This commit is contained in:
commit
82b567f15f
50 changed files with 9327 additions and 277 deletions
|
@ -60,6 +60,8 @@ class DataFactory(object):
|
|||
(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',
|
||||
'COUNT(*) AS group_count'
|
||||
'session_history_media_info.audio_decision',
|
||||
'session_history.user_id as user_id'
|
||||
]
|
||||
try:
|
||||
query = data_tables.ssp_query(table_name='session_history',
|
||||
|
@ -127,6 +129,8 @@ class DataFactory(object):
|
|||
"video_decision": item["video_decision"],
|
||||
"watched_status": watched_status,
|
||||
"group_count": item["group_count"]
|
||||
"audio_decision": item["audio_decision"],
|
||||
"user_id": item["user_id"]
|
||||
}
|
||||
|
||||
rows.append(row)
|
||||
|
@ -139,22 +143,14 @@ class DataFactory(object):
|
|||
|
||||
return dict
|
||||
|
||||
def get_home_stats(self, time_range='30', stat_type='0', stat_count='5'):
|
||||
def get_home_stats(self, time_range='30', stats_type=0, stats_count='5', stats_cards='', notify_watched_percent='85'):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
if not time_range.isdigit():
|
||||
time_range = '30'
|
||||
sort_type = 'total_plays' if stats_type == 0 else 'total_duration'
|
||||
|
||||
sort_type = 'total_plays' if stat_type == '0' else 'total_duration'
|
||||
|
||||
if not time_range.isdigit():
|
||||
stat_count = '5'
|
||||
|
||||
# This actually determines the output order in the home page
|
||||
stats_queries = ["top_tv", "popular_tv", "top_movies", "popular_movies", "top_users", "top_platforms", "last_watched"]
|
||||
home_stats = []
|
||||
|
||||
for stat in stats_queries:
|
||||
for stat in stats_cards:
|
||||
if 'top_tv' in stat:
|
||||
top_tv = []
|
||||
try:
|
||||
|
@ -174,7 +170,7 @@ class DataFactory(object):
|
|||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "episode" ' \
|
||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
|
@ -210,6 +206,10 @@ class DataFactory(object):
|
|||
'session_history_metadata.grandparent_rating_key, ' \
|
||||
'MAX(session_history.started) as last_watch, ' \
|
||||
'COUNT(session_history.id) as total_plays, ' \
|
||||
'SUM(case when session_history.stopped > 0 ' \
|
||||
'then (session_history.stopped - session_history.started) ' \
|
||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
||||
'else 0 end) as total_duration, ' \
|
||||
'session_history_metadata.grandparent_thumb ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
||||
|
@ -217,8 +217,8 @@ class DataFactory(object):
|
|||
'>= 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)
|
||||
'ORDER BY users_watched DESC, %s DESC ' \
|
||||
'LIMIT %s' % (time_range, sort_type, stats_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
|
@ -230,7 +230,7 @@ class DataFactory(object):
|
|||
'rating_key': item[3],
|
||||
'last_play': item[4],
|
||||
'total_plays': item[5],
|
||||
'grandparent_thumb': item[6],
|
||||
'grandparent_thumb': item[7],
|
||||
'thumb': '',
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
|
@ -262,7 +262,7 @@ class DataFactory(object):
|
|||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "movie" ' \
|
||||
'GROUP BY session_history_metadata.full_title ' \
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
|
@ -298,6 +298,10 @@ class DataFactory(object):
|
|||
'session_history_metadata.rating_key, ' \
|
||||
'MAX(session_history.started) as last_watch, ' \
|
||||
'COUNT(session_history.id) as total_plays, ' \
|
||||
'SUM(case when session_history.stopped > 0 ' \
|
||||
'then (session_history.stopped - session_history.started) ' \
|
||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
||||
'else 0 end) as total_duration, ' \
|
||||
'session_history_metadata.thumb ' \
|
||||
'FROM session_history_metadata ' \
|
||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
||||
|
@ -305,8 +309,8 @@ class DataFactory(object):
|
|||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'AND session_history_metadata.media_type = "movie" ' \
|
||||
'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, stats_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
|
@ -319,7 +323,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': '',
|
||||
|
@ -331,6 +335,98 @@ class DataFactory(object):
|
|||
home_stats.append({'stat_id': stat,
|
||||
'rows': popular_movies})
|
||||
|
||||
elif 'top_music' in stat:
|
||||
top_music = []
|
||||
try:
|
||||
query = 'SELECT session_history_metadata.id, ' \
|
||||
'session_history_metadata.grandparent_title, ' \
|
||||
'COUNT(session_history_metadata.grandparent_title) as total_plays, ' \
|
||||
'SUM(case when session_history.stopped > 0 ' \
|
||||
'then (session_history.stopped - session_history.started) ' \
|
||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
||||
'else 0 end) as total_duration, ' \
|
||||
'session_history_metadata.grandparent_rating_key, ' \
|
||||
'MAX(session_history.started) as last_watch,' \
|
||||
'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 = "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)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
return None
|
||||
|
||||
for item in result:
|
||||
row = {'title': item[1],
|
||||
'total_plays': item[2],
|
||||
'total_duration': item[3],
|
||||
'users_watched': '',
|
||||
'rating_key': item[4],
|
||||
'last_play': item[5],
|
||||
'grandparent_thumb': item[6],
|
||||
'thumb': '',
|
||||
'user': '',
|
||||
'friendly_name': '',
|
||||
'platform_type': '',
|
||||
'platform': '',
|
||||
'row_id': item[0]
|
||||
}
|
||||
top_music.append(row)
|
||||
|
||||
home_stats.append({'stat_id': stat,
|
||||
'stat_type': sort_type,
|
||||
'rows': top_music})
|
||||
|
||||
elif 'popular_music' in stat:
|
||||
popular_music = []
|
||||
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, ' \
|
||||
'SUM(case when session_history.stopped > 0 ' \
|
||||
'then (session_history.stopped - session_history.started) ' \
|
||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) ' \
|
||||
'else 0 end) as total_duration, ' \
|
||||
'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 = "track" ' \
|
||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
||||
'ORDER BY users_watched DESC, %s DESC ' \
|
||||
'LIMIT %s' % (time_range, sort_type, stats_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_music.append(row)
|
||||
|
||||
home_stats.append({'stat_id': stat,
|
||||
'rows': popular_music})
|
||||
|
||||
elif 'top_users' in stat:
|
||||
top_users = []
|
||||
try:
|
||||
|
@ -351,7 +447,7 @@ class DataFactory(object):
|
|||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||
'datetime("now", "-%s days", "localtime") '\
|
||||
'GROUP BY session_history.user_id ' \
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
|
@ -399,7 +495,7 @@ class DataFactory(object):
|
|||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||
'>= datetime("now", "-%s days", "localtime") ' \
|
||||
'GROUP BY session_history.platform ' \
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stat_count)
|
||||
'ORDER BY %s DESC LIMIT %s' % (time_range, sort_type, stats_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
|
@ -440,7 +536,11 @@ class DataFactory(object):
|
|||
'session_history_metadata.thumb, ' \
|
||||
'session_history_metadata.grandparent_thumb, ' \
|
||||
'MAX(session_history.started) as last_watch, ' \
|
||||
'session_history.player as platform ' \
|
||||
'session_history.player as platform, ' \
|
||||
'((CASE WHEN session_history.view_offset IS NULL THEN 0.1 ELSE \
|
||||
session_history.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 ' \
|
||||
'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 ' \
|
||||
|
@ -448,9 +548,10 @@ class DataFactory(object):
|
|||
'>= 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_metadata.full_title ' \
|
||||
'ORDER BY last_watch DESC ' \
|
||||
'LIMIT %s' % (time_range, stat_count)
|
||||
'LIMIT %s' % (time_range, notify_watched_percent, stats_count)
|
||||
result = monitor_db.select(query)
|
||||
except:
|
||||
logger.warn("Unable to execute database query.")
|
||||
|
@ -688,4 +789,4 @@ class DataFactory(object):
|
|||
|
||||
return 'Deleted all items for user_id %s.' % user_id
|
||||
else:
|
||||
return 'Unable to delete items. Input user_id not valid.'
|
||||
return 'Unable to delete items. Input user_id not valid.'
|
Loading…
Add table
Add a link
Reference in a new issue