Fix home stats Last Watched to use watched percent specified in settings

This commit is contained in:
Jonathan Wong 2015-09-16 01:13:08 -07:00
parent 048b31c87a
commit 7170dbd800
3 changed files with 23 additions and 8 deletions

View file

@ -82,12 +82,15 @@
currentActivity(); currentActivity();
setInterval(currentActivity, 15000); setInterval(currentActivity, 15000);
function getHomeStats(days, stat_type, stat_count) { function getHomeStats(days, stat_type, stat_count, notify_watched_percent) {
$.ajax({ $.ajax({
url: 'home_stats', url: 'home_stats',
cache: false, cache: false,
async: true, async: true,
data: {time_range: days, stat_type: stat_type, stat_count: stat_count}, data: {time_range: days,
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);
} }
@ -165,7 +168,10 @@
} }
}); });
getHomeStats(${config['home_stats_length']}, ${config['home_stats_type']}, ${config['home_stats_count']}); getHomeStats(${config['home_stats_length']},
${config['home_stats_type']},
${config['home_stats_count']},
${config['notify_watched_percent']});
getLibraryStatsHeader(); getLibraryStatsHeader();
getLibraryStats(); getLibraryStats();

View file

@ -131,7 +131,7 @@ class DataFactory(object):
return dict return dict
def get_home_stats(self, time_range='30', stat_type='0', stat_count='5'): def get_home_stats(self, time_range='30', stat_type='0', stat_count='5', notify_watched_percent='85'):
monitor_db = database.MonitorDatabase() monitor_db = database.MonitorDatabase()
if not time_range.isdigit(): if not time_range.isdigit():
@ -432,7 +432,11 @@ class DataFactory(object):
'session_history_metadata.thumb, ' \ 'session_history_metadata.thumb, ' \
'session_history_metadata.grandparent_thumb, ' \ 'session_history_metadata.grandparent_thumb, ' \
'MAX(session_history.started) as last_watch, ' \ '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 ' \ '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 ' \
'LEFT OUTER JOIN users ON session_history.user_id = users.user_id ' \ 'LEFT OUTER JOIN users ON session_history.user_id = users.user_id ' \
@ -440,9 +444,10 @@ 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" ' \
'OR session_history_metadata.media_type = "episode") ' \ 'OR session_history_metadata.media_type = "episode") ' \
'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, stat_count) 'LIMIT %s' % (time_range, notify_watched_percent, stat_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.")

View file

@ -69,6 +69,7 @@ class WebInterface(object):
"home_stats_type": plexpy.CONFIG.HOME_STATS_TYPE, "home_stats_type": plexpy.CONFIG.HOME_STATS_TYPE,
"home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT, "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)
@ -121,9 +122,12 @@ 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', **kwargs): def home_stats(self, time_range='30', stat_type='0', stat_count='5', notify_watched_percent='85', **kwargs):
data_factory = datafactory.DataFactory() data_factory = datafactory.DataFactory()
stats_data = data_factory.get_home_stats(time_range=time_range, stat_type=stat_type, stat_count=stat_count) stats_data = data_factory.get_home_stats(time_range=time_range,
stat_type=stat_type,
stat_count=stat_count,
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)