mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 00:06:07 -07:00
Update to homepage statistics
* Added most popular movie to homepage * New setting to toggle statistics based on play duration instead of play count
This commit is contained in:
parent
58474d9565
commit
5c94b21bd1
6 changed files with 153 additions and 26 deletions
|
@ -21,10 +21,11 @@ grandparent_thumb Returns location of the item's thumbnail. Use with pms_i
|
||||||
rating_key Returns the unique identifier for the media item.
|
rating_key Returns the unique identifier for the media item.
|
||||||
title Returns the title for the associated stat.
|
title Returns the title for the associated stat.
|
||||||
|
|
||||||
== Only if 'stat_id' is 'top_tv' or 'top_user' or 'top_platform' ==
|
== Only if 'stat_id' is 'top_tv' or 'top_movies' or 'top_user' or 'top_platform' ==
|
||||||
total_plays Returns the count for the associated stat.
|
total_plays Returns the count for the associated stat.
|
||||||
|
total_duration Returns the total duration for the associated stat.
|
||||||
|
|
||||||
== Only of 'stat_id' is 'popular_tv' ==
|
== Only of 'stat_id' is 'popular_tv' or 'popular_movies' ==
|
||||||
users_watched Returns the count for the associated stat.
|
users_watched Returns the count for the associated stat.
|
||||||
|
|
||||||
== Only if 'stat_id' is 'top_user' ==
|
== Only if 'stat_id' is 'top_user' ==
|
||||||
|
@ -63,8 +64,13 @@ DOCUMENTATION :: END
|
||||||
</a></h5>
|
</a></h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-platforms-instance-playcount">
|
<div class="user-platforms-instance-playcount">
|
||||||
|
% if a['stat_type'] == 'total_plays':
|
||||||
<h3>${a['rows'][0]['total_plays']}</h3>
|
<h3>${a['rows'][0]['total_plays']}</h3>
|
||||||
<p> plays</p>
|
<p> plays</p>
|
||||||
|
% else:
|
||||||
|
<h3>${a['rows'][0]['total_duration']}</h3>
|
||||||
|
<p> mins</p>
|
||||||
|
% endif
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
|
@ -113,8 +119,38 @@ DOCUMENTATION :: END
|
||||||
</a></h5>
|
</a></h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-platforms-instance-playcount">
|
<div class="user-platforms-instance-playcount">
|
||||||
|
% if a['stat_type'] == 'total_plays':
|
||||||
<h3>${a['rows'][0]['total_plays']}</h3>
|
<h3>${a['rows'][0]['total_plays']}</h3>
|
||||||
<p> plays</p>
|
<p> plays</p>
|
||||||
|
% else:
|
||||||
|
<h3>${a['rows'][0]['total_duration']}</h3>
|
||||||
|
<p> mins</p>
|
||||||
|
% endif
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</div>
|
||||||
|
% elif a['stat_id'] == 'popular_movies' and a['rows']:
|
||||||
|
<div class="home-platforms-instance">
|
||||||
|
<li>
|
||||||
|
<span>
|
||||||
|
<a href="info?item_id=${a['rows'][0]['rating_key']}">
|
||||||
|
% if a['rows'][0]['thumb']:
|
||||||
|
<img class="home-platforms-instance-poster"
|
||||||
|
src="pms_image_proxy?img=${a['rows'][0]['thumb']}&width=162&height=240&fallback=poster">
|
||||||
|
% else:
|
||||||
|
<img class="home-platforms-instance-poster" src="interfaces/default/images/poster.png">
|
||||||
|
% endif
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
<div class="home-platforms-instance-name">
|
||||||
|
<h4>Most Popular Movie</h4>
|
||||||
|
<h5><a href="info?item_id=${a['rows'][0]['rating_key']}">
|
||||||
|
${a['rows'][0]['title']}
|
||||||
|
</a></h5>
|
||||||
|
</div>
|
||||||
|
<div class="user-platforms-instance-playcount">
|
||||||
|
<h3>${a['rows'][0]['users_watched']}</h3>
|
||||||
|
<p> users</p>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
|
@ -149,8 +185,13 @@ DOCUMENTATION :: END
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-platforms-instance-playcount">
|
<div class="user-platforms-instance-playcount">
|
||||||
|
% if a['stat_type'] == 'total_plays':
|
||||||
<h3>${a['rows'][0]['total_plays']}</h3>
|
<h3>${a['rows'][0]['total_plays']}</h3>
|
||||||
<p> plays</p>
|
<p> plays</p>
|
||||||
|
% else:
|
||||||
|
<h3>${a['rows'][0]['total_duration']}</h3>
|
||||||
|
<p> mins</p>
|
||||||
|
% endif
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
|
@ -165,8 +206,13 @@ DOCUMENTATION :: END
|
||||||
<h5>${a['rows'][0]['platform_type']}</h5>
|
<h5>${a['rows'][0]['platform_type']}</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-platforms-instance-playcount">
|
<div class="user-platforms-instance-playcount">
|
||||||
|
% if a['stat_type'] == 'total_plays':
|
||||||
<h3>${a['rows'][0]['total_plays']}</h3>
|
<h3>${a['rows'][0]['total_plays']}</h3>
|
||||||
<p> plays</p>
|
<p> plays</p>
|
||||||
|
% else:
|
||||||
|
<h3>${a['rows'][0]['total_duration']}</h3>
|
||||||
|
<p> mins</p>
|
||||||
|
% endif
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -45,12 +45,12 @@
|
||||||
<script src="interfaces/default/js/moment-with-locale.js"></script>
|
<script src="interfaces/default/js/moment-with-locale.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function getHomeStats(days) {
|
function getHomeStats(days, plays) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'home_stats',
|
url: 'home_stats',
|
||||||
cache: false,
|
cache: false,
|
||||||
async: true,
|
async: true,
|
||||||
data: {time_range: days},
|
data: {time_range: days, stat_type: plays},
|
||||||
complete: function(xhr, status) {
|
complete: function(xhr, status) {
|
||||||
$("#home-stats").html(xhr.responseText);
|
$("#home-stats").html(xhr.responseText);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
getHomeStats(${config['home_stats_length']});
|
getHomeStats(${config['home_stats_length']}, ${config['home_stats_type']});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -280,8 +280,12 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||||
<p class="help-block">If you have media indexing enabled on your server, use these on the activity pane.</p>
|
<p class="help-block">If you have media indexing enabled on your server, use these on the activity pane.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="padded-header">
|
||||||
|
<h3>Homepage Statistics</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="home_stats_length">Homepage Statistics Time Frame</label>
|
<label for="home_stats_length">Time Frame</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
<input type="text" class="form-control" data-parsley-type="integer" id="home_stats_length" name="home_stats_length" value="${config['home_stats_length']}" size="3" data-parsley-min="0" data-parsley-trigger="change" required>
|
<input type="text" class="form-control" data-parsley-type="integer" id="home_stats_length" name="home_stats_length" value="${config['home_stats_length']}" size="3" data-parsley-min="0" data-parsley-trigger="change" required>
|
||||||
|
@ -289,6 +293,12 @@ available_notification_agents = notifiers.available_notification_agents()
|
||||||
</div>
|
</div>
|
||||||
<p class="help-block">Specify the number of days for the statistics on the home page. Default is 30 days.</p>
|
<p class="help-block">Specify the number of days for the statistics on the home page. Default is 30 days.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="home_stats_type" name="home_stats_type" value="1" ${config['home_stats_type']}> Use play duration
|
||||||
|
</label>
|
||||||
|
<p class="help-block">Use play duration instead of play count to generate statistics.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="padded-header">
|
<div class="padded-header">
|
||||||
<h3>Plex Logs</h3>
|
<h3>Plex Logs</h3>
|
||||||
|
|
|
@ -83,6 +83,7 @@ _CONFIG_DEFINITIONS = {
|
||||||
'GROWL_ON_BUFFER': (int, 'Growl', 0),
|
'GROWL_ON_BUFFER': (int, 'Growl', 0),
|
||||||
'GROWL_ON_WATCHED': (int, 'Growl', 0),
|
'GROWL_ON_WATCHED': (int, 'Growl', 0),
|
||||||
'HOME_STATS_LENGTH': (int, 'General', 30),
|
'HOME_STATS_LENGTH': (int, 'General', 30),
|
||||||
|
'HOME_STATS_TYPE': (int, 'General', 0),
|
||||||
'HTTPS_CERT': (str, 'General', ''),
|
'HTTPS_CERT': (str, 'General', ''),
|
||||||
'HTTPS_KEY': (str, 'General', ''),
|
'HTTPS_KEY': (str, 'General', ''),
|
||||||
'HTTP_HOST': (str, 'General', '0.0.0.0'),
|
'HTTP_HOST': (str, 'General', '0.0.0.0'),
|
||||||
|
|
|
@ -110,14 +110,16 @@ class DataFactory(object):
|
||||||
|
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
def get_home_stats(self, time_range='30'):
|
def get_home_stats(self, time_range='30', stat_type='0'):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
if not time_range.isdigit():
|
if not time_range.isdigit():
|
||||||
time_range = '30'
|
time_range = '30'
|
||||||
|
|
||||||
|
sort_type = 'total_plays' if stat_type == '0' else 'total_duration'
|
||||||
|
|
||||||
# This actually determines the output order in the home page
|
# This actually determines the output order in the home page
|
||||||
stats_queries = ["top_tv", "popular_tv", "top_movies", "top_users", "top_platforms"]
|
stats_queries = ["top_tv", "popular_tv", "top_movies", "popular_movies", "top_users", "top_platforms"]
|
||||||
home_stats = []
|
home_stats = []
|
||||||
|
|
||||||
for stat in stats_queries:
|
for stat in stats_queries:
|
||||||
|
@ -127,6 +129,10 @@ class DataFactory(object):
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT session_history_metadata.id, ' \
|
||||||
'session_history_metadata.grandparent_title, ' \
|
'session_history_metadata.grandparent_title, ' \
|
||||||
'COUNT(session_history_metadata.grandparent_title) as total_plays, ' \
|
'COUNT(session_history_metadata.grandparent_title) as total_plays, ' \
|
||||||
|
'cast(round(SUM(round((julianday(datetime(session_history.stopped, "unixepoch", "localtime")) - ' \
|
||||||
|
'julianday(datetime(session_history.started, "unixepoch", "localtime"))) * 86400) - ' \
|
||||||
|
'(CASE WHEN session_history.paused_counter IS NULL THEN 0 ' \
|
||||||
|
'ELSE session_history.paused_counter END))/60) as integer) as total_duration,' \
|
||||||
'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,' \
|
||||||
'session_history_metadata.grandparent_thumb ' \
|
'session_history_metadata.grandparent_thumb ' \
|
||||||
|
@ -136,7 +142,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 total_plays DESC LIMIT 10' % time_range
|
'ORDER BY %s DESC LIMIT 10' % (time_range, sort_type)
|
||||||
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.")
|
||||||
|
@ -145,10 +151,11 @@ class DataFactory(object):
|
||||||
for item in result:
|
for item in result:
|
||||||
row = {'title': item[1],
|
row = {'title': item[1],
|
||||||
'total_plays': item[2],
|
'total_plays': item[2],
|
||||||
|
'total_duration': item[3],
|
||||||
'users_watched': '',
|
'users_watched': '',
|
||||||
'rating_key': item[3],
|
'rating_key': item[4],
|
||||||
'last_play': item[4],
|
'last_play': item[5],
|
||||||
'grandparent_thumb': item[5],
|
'grandparent_thumb': item[6],
|
||||||
'thumb': '',
|
'thumb': '',
|
||||||
'user': '',
|
'user': '',
|
||||||
'friendly_name': '',
|
'friendly_name': '',
|
||||||
|
@ -159,6 +166,7 @@ class DataFactory(object):
|
||||||
top_tv.append(row)
|
top_tv.append(row)
|
||||||
|
|
||||||
home_stats.append({'stat_id': stat,
|
home_stats.append({'stat_id': stat,
|
||||||
|
'stat_type': sort_type,
|
||||||
'rows': top_tv})
|
'rows': top_tv})
|
||||||
|
|
||||||
elif 'top_movies' in stat:
|
elif 'top_movies' in stat:
|
||||||
|
@ -167,6 +175,10 @@ class DataFactory(object):
|
||||||
query = 'SELECT session_history_metadata.id, ' \
|
query = 'SELECT session_history_metadata.id, ' \
|
||||||
'session_history_metadata.full_title, ' \
|
'session_history_metadata.full_title, ' \
|
||||||
'COUNT(session_history_metadata.full_title) as total_plays, ' \
|
'COUNT(session_history_metadata.full_title) as total_plays, ' \
|
||||||
|
'cast(round(SUM(round((julianday(datetime(session_history.stopped, "unixepoch", "localtime")) - ' \
|
||||||
|
'julianday(datetime(session_history.started, "unixepoch", "localtime"))) * 86400) - ' \
|
||||||
|
'(CASE WHEN session_history.paused_counter IS NULL THEN 0 ' \
|
||||||
|
'ELSE session_history.paused_counter END))/60) as integer) as total_duration,' \
|
||||||
'session_history_metadata.rating_key, ' \
|
'session_history_metadata.rating_key, ' \
|
||||||
'MAX(session_history.started) as last_watch,' \
|
'MAX(session_history.started) as last_watch,' \
|
||||||
'session_history_metadata.thumb ' \
|
'session_history_metadata.thumb ' \
|
||||||
|
@ -176,7 +188,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 total_plays DESC LIMIT 10' % time_range
|
'ORDER BY %s DESC LIMIT 10' % (time_range, sort_type)
|
||||||
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.")
|
||||||
|
@ -185,11 +197,12 @@ class DataFactory(object):
|
||||||
for item in result:
|
for item in result:
|
||||||
row = {'title': item[1],
|
row = {'title': item[1],
|
||||||
'total_plays': item[2],
|
'total_plays': item[2],
|
||||||
|
'total_duration': item[3],
|
||||||
'users_watched': '',
|
'users_watched': '',
|
||||||
'rating_key': item[3],
|
'rating_key': item[4],
|
||||||
'last_play': item[4],
|
'last_play': item[5],
|
||||||
'grandparent_thumb': '',
|
'grandparent_thumb': '',
|
||||||
'thumb': item[5],
|
'thumb': item[6],
|
||||||
'user': '',
|
'user': '',
|
||||||
'friendly_name': '',
|
'friendly_name': '',
|
||||||
'platform_type': '',
|
'platform_type': '',
|
||||||
|
@ -199,6 +212,7 @@ class DataFactory(object):
|
||||||
top_movies.append(row)
|
top_movies.append(row)
|
||||||
|
|
||||||
home_stats.append({'stat_id': stat,
|
home_stats.append({'stat_id': stat,
|
||||||
|
'stat_type': sort_type,
|
||||||
'rows': top_movies})
|
'rows': top_movies})
|
||||||
|
|
||||||
elif 'popular_tv' in stat:
|
elif 'popular_tv' in stat:
|
||||||
|
@ -243,6 +257,48 @@ class DataFactory(object):
|
||||||
home_stats.append({'stat_id': stat,
|
home_stats.append({'stat_id': stat,
|
||||||
'rows': popular_tv})
|
'rows': popular_tv})
|
||||||
|
|
||||||
|
elif 'popular_movies' in stat:
|
||||||
|
popular_movies = []
|
||||||
|
try:
|
||||||
|
query = 'SELECT session_history_metadata.id, ' \
|
||||||
|
'session_history_metadata.full_title, ' \
|
||||||
|
'COUNT(DISTINCT session_history.user_id) as users_watched, ' \
|
||||||
|
'session_history_metadata.rating_key, ' \
|
||||||
|
'MAX(session_history.started) as last_watch, ' \
|
||||||
|
'COUNT(session_history.id) as total_plays, ' \
|
||||||
|
'session_history_metadata.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 = "movie" ' \
|
||||||
|
'GROUP BY session_history_metadata.full_title ' \
|
||||||
|
'ORDER BY users_watched DESC, total_plays DESC ' \
|
||||||
|
'LIMIT 10' % time_range
|
||||||
|
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': '',
|
||||||
|
'thumb': item[6],
|
||||||
|
'user': '',
|
||||||
|
'friendly_name': '',
|
||||||
|
'platform_type': '',
|
||||||
|
'platform': '',
|
||||||
|
'row_id': item[0]
|
||||||
|
}
|
||||||
|
popular_movies.append(row)
|
||||||
|
|
||||||
|
home_stats.append({'stat_id': stat,
|
||||||
|
'rows': popular_movies})
|
||||||
|
|
||||||
elif 'top_users' in stat:
|
elif 'top_users' in stat:
|
||||||
top_users = []
|
top_users = []
|
||||||
try:
|
try:
|
||||||
|
@ -250,6 +306,10 @@ class DataFactory(object):
|
||||||
'(case when users.friendly_name is null then session_history.user else ' \
|
'(case when users.friendly_name is null then session_history.user else ' \
|
||||||
'users.friendly_name end) as friendly_name,' \
|
'users.friendly_name end) as friendly_name,' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
'COUNT(session_history.id) as total_plays, ' \
|
||||||
|
'cast(round(SUM(round((julianday(datetime(session_history.stopped, "unixepoch", "localtime")) - ' \
|
||||||
|
'julianday(datetime(session_history.started, "unixepoch", "localtime"))) * 86400) - ' \
|
||||||
|
'(CASE WHEN session_history.paused_counter IS NULL THEN 0 ' \
|
||||||
|
'ELSE session_history.paused_counter END))/60) as integer) as total_duration,' \
|
||||||
'MAX(session_history.started) as last_watch, ' \
|
'MAX(session_history.started) as last_watch, ' \
|
||||||
'users.custom_avatar_url as thumb, ' \
|
'users.custom_avatar_url as thumb, ' \
|
||||||
'users.user_id ' \
|
'users.user_id ' \
|
||||||
|
@ -259,23 +319,24 @@ 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 total_plays DESC LIMIT 10' % time_range
|
'ORDER BY %s DESC LIMIT 10' % (time_range, sort_type)
|
||||||
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.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for item in result:
|
for item in result:
|
||||||
if not item[4] or item[4] == '':
|
if not item[5] or item[5] == '':
|
||||||
user_thumb = common.DEFAULT_USER_THUMB
|
user_thumb = common.DEFAULT_USER_THUMB
|
||||||
else:
|
else:
|
||||||
user_thumb = item[4]
|
user_thumb = item[5]
|
||||||
|
|
||||||
row = {'user': item[0],
|
row = {'user': item[0],
|
||||||
'user_id': item[5],
|
'user_id': item[6],
|
||||||
'friendly_name': item[1],
|
'friendly_name': item[1],
|
||||||
'total_plays': item[2],
|
'total_plays': item[2],
|
||||||
'last_play': item[3],
|
'total_duration': item[3],
|
||||||
|
'last_play': item[4],
|
||||||
'thumb': user_thumb,
|
'thumb': user_thumb,
|
||||||
'grandparent_thumb': '',
|
'grandparent_thumb': '',
|
||||||
'users_watched': '',
|
'users_watched': '',
|
||||||
|
@ -288,6 +349,7 @@ class DataFactory(object):
|
||||||
top_users.append(row)
|
top_users.append(row)
|
||||||
|
|
||||||
home_stats.append({'stat_id': stat,
|
home_stats.append({'stat_id': stat,
|
||||||
|
'stat_type': sort_type,
|
||||||
'rows': top_users})
|
'rows': top_users})
|
||||||
|
|
||||||
elif 'top_platforms' in stat:
|
elif 'top_platforms' in stat:
|
||||||
|
@ -296,6 +358,10 @@ class DataFactory(object):
|
||||||
try:
|
try:
|
||||||
query = 'SELECT session_history.platform, ' \
|
query = 'SELECT session_history.platform, ' \
|
||||||
'COUNT(session_history.id) as total_plays, ' \
|
'COUNT(session_history.id) as total_plays, ' \
|
||||||
|
'cast(round(SUM(round((julianday(datetime(session_history.stopped, "unixepoch", "localtime")) - ' \
|
||||||
|
'julianday(datetime(session_history.started, "unixepoch", "localtime"))) * 86400) - ' \
|
||||||
|
'(CASE WHEN session_history.paused_counter IS NULL THEN 0 ' \
|
||||||
|
'ELSE session_history.paused_counter END))/60) as integer) as total_duration,' \
|
||||||
'MAX(session_history.started) as last_watch ' \
|
'MAX(session_history.started) as last_watch ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") ' \
|
||||||
|
@ -310,7 +376,8 @@ class DataFactory(object):
|
||||||
for item in result:
|
for item in result:
|
||||||
row = {'platform': item[0],
|
row = {'platform': item[0],
|
||||||
'total_plays': item[1],
|
'total_plays': item[1],
|
||||||
'last_play': item[2],
|
'total_duration': item[2],
|
||||||
|
'last_play': item[3],
|
||||||
'platform_type': item[0],
|
'platform_type': item[0],
|
||||||
'title': '',
|
'title': '',
|
||||||
'thumb': '',
|
'thumb': '',
|
||||||
|
@ -324,6 +391,7 @@ class DataFactory(object):
|
||||||
top_platform.append(row)
|
top_platform.append(row)
|
||||||
|
|
||||||
home_stats.append({'stat_id': stat,
|
home_stats.append({'stat_id': stat,
|
||||||
|
'stat_type': sort_type,
|
||||||
'rows': top_platform})
|
'rows': top_platform})
|
||||||
|
|
||||||
return home_stats
|
return home_stats
|
||||||
|
|
|
@ -65,7 +65,8 @@ class WebInterface(object):
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
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
|
||||||
}
|
}
|
||||||
return serve_template(templatename="index.html", title="Home", config=config)
|
return serve_template(templatename="index.html", title="Home", config=config)
|
||||||
|
|
||||||
|
@ -118,9 +119,9 @@ class WebInterface(object):
|
||||||
return json.dumps(formats)
|
return json.dumps(formats)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def home_stats(self, time_range='30', **kwargs):
|
def home_stats(self, time_range='30', stat_type='0', **kwargs):
|
||||||
data_factory = datafactory.DataFactory()
|
data_factory = datafactory.DataFactory()
|
||||||
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)
|
||||||
|
|
||||||
return serve_template(templatename="home_stats.html", title="Stats", data=stats_data)
|
return serve_template(templatename="home_stats.html", title="Stats", data=stats_data)
|
||||||
|
|
||||||
|
@ -451,6 +452,7 @@ class WebInterface(object):
|
||||||
"notify_on_watched_subject_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_SUBJECT_TEXT,
|
"notify_on_watched_subject_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_SUBJECT_TEXT,
|
||||||
"notify_on_watched_body_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT,
|
"notify_on_watched_body_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT,
|
||||||
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
"home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH,
|
||||||
|
"home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE),
|
||||||
"buffer_threshold": plexpy.CONFIG.BUFFER_THRESHOLD,
|
"buffer_threshold": plexpy.CONFIG.BUFFER_THRESHOLD,
|
||||||
"buffer_wait": plexpy.CONFIG.BUFFER_WAIT
|
"buffer_wait": plexpy.CONFIG.BUFFER_WAIT
|
||||||
}
|
}
|
||||||
|
@ -473,7 +475,7 @@ class WebInterface(object):
|
||||||
"tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start",
|
"tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start",
|
||||||
"tv_notify_on_stop", "movie_notify_on_stop", "music_notify_on_stop",
|
"tv_notify_on_stop", "movie_notify_on_stop", "music_notify_on_stop",
|
||||||
"tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause", "refresh_users_on_startup",
|
"tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause", "refresh_users_on_startup",
|
||||||
"ip_logging_enable", "video_logging_enable", "music_logging_enable", "pms_is_remote"
|
"ip_logging_enable", "video_logging_enable", "music_logging_enable", "pms_is_remote", "home_stats_type"
|
||||||
]
|
]
|
||||||
for checked_config in checked_configs:
|
for checked_config in checked_configs:
|
||||||
if checked_config not in kwargs:
|
if checked_config not in kwargs:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue