Add homepage stats toggles

This commit is contained in:
JonnyWong16 2017-07-22 18:13:53 -07:00
parent 25455e8194
commit 1f55b5457e
8 changed files with 235 additions and 111 deletions

View file

@ -203,6 +203,7 @@ _CONFIG_DEFINITIONS = {
'HOME_STATS_COUNT': (int, 'General', 5),
'HOME_STATS_CARDS': (list, 'General', ['top_movies', 'popular_movies', 'top_tv', 'popular_tv', 'top_music', \
'popular_music', 'last_watched', 'top_users', 'top_platforms', 'most_concurrent']),
'HOME_STATS_RECENTLY_ADDED_COUNT': (int, 'General', 50),
'HTTPS_CREATE_CERT': (int, 'General', 1),
'HTTPS_CERT': (str, 'General', ''),
'HTTPS_CERT_CHAIN': (str, 'General', ''),

View file

@ -255,21 +255,26 @@ class DataFactory(object):
return dict
def get_home_stats(self, grouping=0, time_range=0, stats_type=0, stats_count=0, stats_cards=[]):
def get_home_stats(self, grouping=None, time_range=None, stats_type=None, stats_count=None, stats_cards=None):
monitor_db = database.MonitorDatabase()
grouping = grouping or plexpy.CONFIG.GROUP_HISTORY_TABLES
time_range = time_range or plexpy.CONFIG.HOME_STATS_LENGTH
stats_type = stats_type or plexpy.CONFIG.HOME_STATS_TYPE
stats_count = stats_count or plexpy.CONFIG.HOME_STATS_COUNT
stats_cards = stats_cards or plexpy.CONFIG.HOME_STATS_CARDS
if grouping is None:
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
if time_range is None:
time_range = plexpy.CONFIG.HOME_STATS_LENGTH
if stats_type is None:
stats_type = plexpy.CONFIG.HOME_STATS_TYPE
if stats_count is None:
stats_count = plexpy.CONFIG.HOME_STATS_COUNT
if stats_cards is None:
stats_cards = plexpy.CONFIG.HOME_STATS_CARDS
movie_watched_percent = plexpy.CONFIG.MOVIE_WATCHED_PERCENT
tv_watched_percent = plexpy.CONFIG.TV_WATCHED_PERCENT
music_watched_percent = plexpy.CONFIG.MUSIC_WATCHED_PERCENT
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_duration' if helpers.cast_to_int(stats_type) == 1 else 'total_plays'
home_stats = []

View file

@ -173,6 +173,9 @@ class WebInterface(object):
config = {
"home_sections": plexpy.CONFIG.HOME_SECTIONS,
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
"home_stats_type": plexpy.CONFIG.HOME_STATS_TYPE,
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT,
"home_stats_recently_added_count": plexpy.CONFIG.HOME_STATS_RECENTLY_ADDED_COUNT,
"pms_name": plexpy.CONFIG.PMS_NAME,
"pms_use_bif": plexpy.CONFIG.PMS_USE_BIF,
"update_show_changelog": plexpy.CONFIG.UPDATE_SHOW_CHANGELOG
@ -308,12 +311,32 @@ class WebInterface(object):
@cherrypy.expose
@requireAuth()
def home_stats(self, **kwargs):
def home_stats(self, time_range=30, stats_type=0, stats_count=5, **kwargs):
data_factory = datafactory.DataFactory()
stats_data = data_factory.get_home_stats()
stats_data = data_factory.get_home_stats(time_range=time_range,
stats_type=stats_type,
stats_count=stats_count)
return serve_template(templatename="home_stats.html", title="Stats", data=stats_data)
@cherrypy.expose
@requireAuth(member_of("admin"))
def set_home_stats_config(self, time_range=None, stats_type=None, stats_count=None, recently_added_count=None, **kwargs):
if time_range:
plexpy.CONFIG.__setattr__('HOME_STATS_LENGTH', time_range)
plexpy.CONFIG.write()
if stats_type:
plexpy.CONFIG.__setattr__('HOME_STATS_TYPE', stats_type)
plexpy.CONFIG.write()
if stats_count:
plexpy.CONFIG.__setattr__('HOME_STATS_COUNT', stats_count)
plexpy.CONFIG.write()
if recently_added_count:
plexpy.CONFIG.__setattr__('HOME_STATS_RECENTLY_ADDED_COUNT', recently_added_count)
plexpy.CONFIG.write()
return "Updated home stats config values."
@cherrypy.expose
@requireAuth()
def library_stats(self, **kwargs):
@ -2589,9 +2612,6 @@ class WebInterface(object):
"notify_concurrent_by_ip": checked(plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP),
"notify_concurrent_threshold": plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD,
"home_sections": json.dumps(plexpy.CONFIG.HOME_SECTIONS),
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
"home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE),
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT,
"home_stats_cards": json.dumps(plexpy.CONFIG.HOME_STATS_CARDS),
"home_library_cards": json.dumps(plexpy.CONFIG.HOME_LIBRARY_CARDS),
"buffer_threshold": plexpy.CONFIG.BUFFER_THRESHOLD,