mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 15:56:07 -07:00
Clean up passing unnecessary configs to homepage
This commit is contained in:
parent
20056718db
commit
78f959d39a
3 changed files with 38 additions and 37 deletions
|
@ -84,15 +84,12 @@
|
||||||
currentActivity();
|
currentActivity();
|
||||||
setInterval(currentActivity, 15000);
|
setInterval(currentActivity, 15000);
|
||||||
|
|
||||||
function getHomeStats(days, stat_type, stat_count, notify_watched_percent) {
|
function getHomeStats(days) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'home_stats',
|
url: 'home_stats',
|
||||||
cache: false,
|
cache: false,
|
||||||
async: true,
|
async: true,
|
||||||
data: {time_range: days,
|
data: { },
|
||||||
stat_type: stat_type,
|
|
||||||
stat_count: stat_count,
|
|
||||||
notify_watched_percent: notify_watched_percent},
|
|
||||||
complete: function(xhr, status) {
|
complete: function(xhr, status) {
|
||||||
$("#home-stats").html(xhr.responseText);
|
$("#home-stats").html(xhr.responseText);
|
||||||
}
|
}
|
||||||
|
@ -170,10 +167,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
getHomeStats(${config['home_stats_length']},
|
getHomeStats();
|
||||||
${config['home_stats_type']},
|
|
||||||
${config['home_stats_count']},
|
|
||||||
${config['notify_watched_percent']});
|
|
||||||
getLibraryStatsHeader();
|
getLibraryStatsHeader();
|
||||||
getLibraryStats();
|
getLibraryStats();
|
||||||
|
|
||||||
|
|
|
@ -131,19 +131,12 @@ class DataFactory(object):
|
||||||
|
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
def get_home_stats(self, time_range='30', stat_type='0', stat_count='5', notify_watched_percent='85'):
|
def get_home_stats(self, time_range='30', stats_type='0', stats_count='5', stats_cards='', notify_watched_percent='85'):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
if not time_range.isdigit():
|
sort_type = 'total_plays' if stats_type == '0' else 'total_duration'
|
||||||
time_range = '30'
|
|
||||||
|
|
||||||
sort_type = 'total_plays' if stat_type == '0' else 'total_duration'
|
stats_queries = stats_cards.split(', ')
|
||||||
|
|
||||||
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 = []
|
home_stats = []
|
||||||
|
|
||||||
for stat in stats_queries:
|
for stat in stats_queries:
|
||||||
|
@ -166,7 +159,7 @@ class DataFactory(object):
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
'>= datetime("now", "-%s days", "localtime") ' \
|
||||||
'AND session_history_metadata.media_type = "episode" ' \
|
'AND session_history_metadata.media_type = "episode" ' \
|
||||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query.")
|
logger.warn("Unable to execute database query.")
|
||||||
|
@ -202,6 +195,10 @@ class DataFactory(object):
|
||||||
'session_history_metadata.grandparent_rating_key, ' \
|
'session_history_metadata.grandparent_rating_key, ' \
|
||||||
'MAX(session_history.started) as last_watch, ' \
|
'MAX(session_history.started) as last_watch, ' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
'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 ' \
|
'session_history_metadata.grandparent_thumb ' \
|
||||||
'FROM session_history_metadata ' \
|
'FROM session_history_metadata ' \
|
||||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
||||||
|
@ -209,8 +206,8 @@ class DataFactory(object):
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
'>= datetime("now", "-%s days", "localtime") ' \
|
||||||
'AND session_history_metadata.media_type = "episode" ' \
|
'AND session_history_metadata.media_type = "episode" ' \
|
||||||
'GROUP BY session_history_metadata.grandparent_title ' \
|
'GROUP BY session_history_metadata.grandparent_title ' \
|
||||||
'ORDER BY users_watched DESC, total_plays DESC ' \
|
'ORDER BY users_watched DESC, %s DESC ' \
|
||||||
'LIMIT %s' % (time_range, stat_count)
|
'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.")
|
logger.warn("Unable to execute database query.")
|
||||||
|
@ -222,7 +219,7 @@ class DataFactory(object):
|
||||||
'rating_key': item[3],
|
'rating_key': item[3],
|
||||||
'last_play': item[4],
|
'last_play': item[4],
|
||||||
'total_plays': item[5],
|
'total_plays': item[5],
|
||||||
'grandparent_thumb': item[6],
|
'grandparent_thumb': item[7],
|
||||||
'thumb': '',
|
'thumb': '',
|
||||||
'user': '',
|
'user': '',
|
||||||
'friendly_name': '',
|
'friendly_name': '',
|
||||||
|
@ -254,7 +251,7 @@ class DataFactory(object):
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
'>= datetime("now", "-%s days", "localtime") ' \
|
||||||
'AND session_history_metadata.media_type = "movie" ' \
|
'AND session_history_metadata.media_type = "movie" ' \
|
||||||
'GROUP BY session_history_metadata.full_title ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query.")
|
logger.warn("Unable to execute database query.")
|
||||||
|
@ -290,6 +287,10 @@ class DataFactory(object):
|
||||||
'session_history_metadata.rating_key, ' \
|
'session_history_metadata.rating_key, ' \
|
||||||
'MAX(session_history.started) as last_watch, ' \
|
'MAX(session_history.started) as last_watch, ' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
'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 ' \
|
'session_history_metadata.thumb ' \
|
||||||
'FROM session_history_metadata ' \
|
'FROM session_history_metadata ' \
|
||||||
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
'JOIN session_history ON session_history_metadata.id = session_history.id ' \
|
||||||
|
@ -297,8 +298,8 @@ class DataFactory(object):
|
||||||
'>= datetime("now", "-%s days", "localtime") ' \
|
'>= datetime("now", "-%s days", "localtime") ' \
|
||||||
'AND session_history_metadata.media_type = "movie" ' \
|
'AND session_history_metadata.media_type = "movie" ' \
|
||||||
'GROUP BY session_history_metadata.full_title ' \
|
'GROUP BY session_history_metadata.full_title ' \
|
||||||
'ORDER BY users_watched DESC, total_plays DESC ' \
|
'ORDER BY users_watched DESC, %s DESC ' \
|
||||||
'LIMIT %s' % (time_range, stat_count)
|
'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.")
|
logger.warn("Unable to execute database query.")
|
||||||
|
@ -311,7 +312,7 @@ class DataFactory(object):
|
||||||
'last_play': item[4],
|
'last_play': item[4],
|
||||||
'total_plays': item[5],
|
'total_plays': item[5],
|
||||||
'grandparent_thumb': '',
|
'grandparent_thumb': '',
|
||||||
'thumb': item[6],
|
'thumb': item[7],
|
||||||
'user': '',
|
'user': '',
|
||||||
'friendly_name': '',
|
'friendly_name': '',
|
||||||
'platform_type': '',
|
'platform_type': '',
|
||||||
|
@ -343,7 +344,7 @@ class DataFactory(object):
|
||||||
'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 session_history.user_id ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query.")
|
logger.warn("Unable to execute database query.")
|
||||||
|
@ -391,7 +392,7 @@ class DataFactory(object):
|
||||||
'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 session_history.platform ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query.")
|
logger.warn("Unable to execute database query.")
|
||||||
|
@ -447,7 +448,7 @@ class DataFactory(object):
|
||||||
'AND percent_complete >= %s ' \
|
'AND percent_complete >= %s ' \
|
||||||
'GROUP BY session_history_metadata.full_title ' \
|
'GROUP BY session_history_metadata.full_title ' \
|
||||||
'ORDER BY last_watch DESC ' \
|
'ORDER BY last_watch DESC ' \
|
||||||
'LIMIT %s' % (time_range, notify_watched_percent, stat_count)
|
'LIMIT %s' % (time_range, notify_watched_percent, stats_count)
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query.")
|
logger.warn("Unable to execute database query.")
|
||||||
|
|
|
@ -66,10 +66,8 @@ class WebInterface(object):
|
||||||
def home(self):
|
def home(self):
|
||||||
config = {
|
config = {
|
||||||
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
||||||
"home_stats_type": plexpy.CONFIG.HOME_STATS_TYPE,
|
"home_stats_cards": plexpy.CONFIG.HOME_STATS_CARDS,
|
||||||
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT,
|
"pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER
|
||||||
"pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER,
|
|
||||||
"notify_watched_percent": plexpy.CONFIG.NOTIFY_WATCHED_PERCENT
|
|
||||||
}
|
}
|
||||||
return serve_template(templatename="index.html", title="Home", config=config)
|
return serve_template(templatename="index.html", title="Home", config=config)
|
||||||
|
|
||||||
|
@ -122,11 +120,19 @@ class WebInterface(object):
|
||||||
return json.dumps(formats)
|
return json.dumps(formats)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def home_stats(self, time_range='30', stat_type='0', stat_count='5', notify_watched_percent='85', **kwargs):
|
def home_stats(self, **kwargs):
|
||||||
data_factory = datafactory.DataFactory()
|
data_factory = datafactory.DataFactory()
|
||||||
|
|
||||||
|
time_range = plexpy.CONFIG.HOME_STATS_LENGTH
|
||||||
|
stats_type = plexpy.CONFIG.HOME_STATS_TYPE
|
||||||
|
stats_count = plexpy.CONFIG.HOME_STATS_COUNT
|
||||||
|
stats_cards = plexpy.CONFIG.HOME_STATS_CARDS
|
||||||
|
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(time_range=time_range,
|
||||||
stat_type=stat_type,
|
stats_type=stats_type,
|
||||||
stat_count=stat_count,
|
stats_count=stats_count,
|
||||||
|
stats_cards=stats_cards,
|
||||||
notify_watched_percent=notify_watched_percent)
|
notify_watched_percent=notify_watched_percent)
|
||||||
|
|
||||||
return serve_template(templatename="home_stats.html", title="Stats", data=stats_data)
|
return serve_template(templatename="home_stats.html", title="Stats", data=stats_data)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue