mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-29 19:18:33 -07:00
Add a "Most Popular TV" in home stats (unique users who watched the same show)
This commit is contained in:
parent
a4a44ec34f
commit
3d56afd89d
2 changed files with 149 additions and 72 deletions
|
@ -1,79 +1,112 @@
|
||||||
% if stats != None:
|
% if stats != None:
|
||||||
% if stats[0]['rows']:
|
% if stats[0]['rows']:
|
||||||
<div class="user-platforms">
|
<div class="user-platforms">
|
||||||
<ul>
|
<ul>
|
||||||
% for a in stats:
|
% for a in stats:
|
||||||
% if a['stat_id'] == 'top_tv':
|
% if a['stat_id'] == 'top_tv':
|
||||||
<div class="home-platforms-instance">
|
<div class="home-platforms-instance">
|
||||||
<li>
|
<li>
|
||||||
<span>
|
<span>
|
||||||
<a href="info?rating_key=${a['rows'][0]['rating_key']}">
|
<a href="info?rating_key=${a['rows'][0]['rating_key']}">
|
||||||
% if a['rows'][0]['grandparent_thumb'] != '':
|
% if a['rows'][0]['grandparent_thumb'] != '':
|
||||||
<img class="home-platforms-instance-poster" src="pms_image_proxy?img=${a['rows'][0]['grandparent_thumb']}&width=153&height=225">
|
<img class="home-platforms-instance-poster"
|
||||||
% else:
|
src="pms_image_proxy?img=${a['rows'][0]['grandparent_thumb']}&width=153&height=225">
|
||||||
<img class="home-platforms-instance-poster" src="interfaces/default/images/poster.png">
|
% else:
|
||||||
% endif
|
<img class="home-platforms-instance-poster" src="interfaces/default/images/poster.png">
|
||||||
</a>
|
% endif
|
||||||
</span>
|
</a>
|
||||||
<div class="home-platforms-instance-name">
|
</span>
|
||||||
<h4>Most Watched TV</h4>
|
<div class="home-platforms-instance-name">
|
||||||
<a href="info?rating_key=${a['rows'][0]['rating_key']}">
|
<h4>Most Watched TV</h4>
|
||||||
<h5>${a['rows'][0]['orig_title']}</h5>
|
<a href="info?rating_key=${a['rows'][0]['rating_key']}">
|
||||||
</a>
|
<h5>${a['rows'][0]['orig_title']}</h5>
|
||||||
</div>
|
</a>
|
||||||
<div class="user-platforms-instance-playcount">
|
|
||||||
<h3>${a['rows'][0]['total_plays']}</h3><p> plays</p>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</div>
|
</div>
|
||||||
% elif a['stat_id'] == 'top_users':
|
<div class="user-platforms-instance-playcount">
|
||||||
<div class="home-platforms-instance">
|
<h3>${a['rows'][0]['total_plays']}</h3>
|
||||||
<li>
|
<p> plays</p>
|
||||||
<span>
|
|
||||||
<a href="user?user=${a['rows'][0]['user']}">
|
|
||||||
% if a['rows'][0]['thumb'] != '':
|
|
||||||
<img class="home-platforms-instance-oval" src="${a['rows'][0]['thumb']}" class="poster-face">
|
|
||||||
% else:
|
|
||||||
<img class="home-platforms-instance-oval" src="interfaces/default/images/gravatar-default.png">
|
|
||||||
% endif
|
|
||||||
</a>
|
|
||||||
</span>
|
|
||||||
<div class="home-platforms-instance-name">
|
|
||||||
<h4>Most Active User</h4>
|
|
||||||
<a href="user?user=${a['rows'][0]['user']}">
|
|
||||||
<h5>${a['rows'][0]['user']}</h5>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="user-platforms-instance-playcount">
|
|
||||||
<h3>${a['rows'][0]['total_plays']}</h3><p> plays</p>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</div>
|
</div>
|
||||||
% elif a['stat_id'] == 'top_platforms':
|
</li>
|
||||||
<div class="home-platforms-instance">
|
</div>
|
||||||
<li>
|
% elif a['stat_id'] == 'popular_tv':
|
||||||
<div id="platform-stat">
|
<div class="home-platforms-instance">
|
||||||
<img class="home-platforms-instance-box" src="interfaces/default/images/platforms/default.png">
|
<li>
|
||||||
</div>
|
<span>
|
||||||
<div class="home-platforms-instance-name">
|
<a href="info?rating_key=${a['rows'][0]['rating_key']}">
|
||||||
<h4>Most Active Platform</h4>
|
% if a['rows'][0]['grandparent_thumb'] != '':
|
||||||
<h5>${a['rows'][0]['platform_type']}</h5>
|
<img class="home-platforms-instance-poster"
|
||||||
</div>
|
src="pms_image_proxy?img=${a['rows'][0]['grandparent_thumb']}&width=153&height=225">
|
||||||
<div class="user-platforms-instance-playcount">
|
% else:
|
||||||
<h3>${a['rows'][0]['total_plays']}</h3><p> plays</p>
|
<img class="home-platforms-instance-poster" src="interfaces/default/images/poster.png">
|
||||||
</div>
|
% endif
|
||||||
</li>
|
</a>
|
||||||
|
</span>
|
||||||
|
<div class="home-platforms-instance-name">
|
||||||
|
<h4>Most Popular TV</h4>
|
||||||
|
<a href="info?rating_key=${a['rows'][0]['rating_key']}">
|
||||||
|
<h5>${a['rows'][0]['orig_title']}</h5>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<div class="user-platforms-instance-playcount">
|
||||||
$("#platform-stat").html("<img class='home-platforms-instance-box' src='" + getPlatformImagePath('${a['rows'][0]['platform_type']}') + "'>");
|
<h3>${a['rows'][0]['users_watched']}</h3>
|
||||||
</script>
|
<p> users</p>
|
||||||
% endif
|
</div>
|
||||||
|
</li>
|
||||||
|
</div>
|
||||||
|
% elif a['stat_id'] == 'top_users':
|
||||||
|
<div class="home-platforms-instance">
|
||||||
|
<li>
|
||||||
|
<span>
|
||||||
|
<a href="user?user=${a['rows'][0]['user']}">
|
||||||
|
% if a['rows'][0]['thumb'] != '':
|
||||||
|
<img class="home-platforms-instance-oval" src="${a['rows'][0]['thumb']}"
|
||||||
|
class="poster-face">
|
||||||
|
% else:
|
||||||
|
<img class="home-platforms-instance-oval"
|
||||||
|
src="interfaces/default/images/gravatar-default.png">
|
||||||
|
% endif
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
<div class="home-platforms-instance-name">
|
||||||
|
<h4>Most Active User</h4>
|
||||||
|
<a href="user?user=${a['rows'][0]['user']}">
|
||||||
|
<h5>${a['rows'][0]['user']}</h5>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="user-platforms-instance-playcount">
|
||||||
|
<h3>${a['rows'][0]['total_plays']}</h3>
|
||||||
|
|
||||||
|
<p> plays</p>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</div>
|
||||||
|
% elif a['stat_id'] == 'top_platforms':
|
||||||
|
<div class="home-platforms-instance">
|
||||||
|
<li>
|
||||||
|
<div id="platform-stat">
|
||||||
|
<img class="home-platforms-instance-box" src="interfaces/default/images/platforms/default.png">
|
||||||
|
</div>
|
||||||
|
<div class="home-platforms-instance-name">
|
||||||
|
<h4>Most Active Platform</h4>
|
||||||
|
<h5>${a['rows'][0]['platform_type']}</h5>
|
||||||
|
</div>
|
||||||
|
<div class="user-platforms-instance-playcount">
|
||||||
|
<h3>${a['rows'][0]['total_plays']}</h3>
|
||||||
|
<p> plays</p>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$("#platform-stat").html("<img class='home-platforms-instance-box' src='" + getPlatformImagePath('${a['rows'][0]['platform_type']}') + "'>");
|
||||||
|
</script>
|
||||||
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
% else:
|
|
||||||
<div class="muted">No stats for selected period.</div><br>
|
|
||||||
% endif
|
|
||||||
% else:
|
% else:
|
||||||
<div class="muted">There was an error loading your PlexWatch data. Please check your <a href="config">settings</a>.</div><br>
|
<div class="muted">No stats for selected period.</div><br>
|
||||||
|
% endif
|
||||||
|
% else:
|
||||||
|
<div class="muted">There was an error loading your PlexWatch data. Please check your <a href="config">settings</a>.
|
||||||
|
</div><br>
|
||||||
% endif
|
% endif
|
|
@ -576,7 +576,7 @@ class PlexWatch(object):
|
||||||
if not time_range.isdigit():
|
if not time_range.isdigit():
|
||||||
time_range = '30'
|
time_range = '30'
|
||||||
|
|
||||||
stats_queries = ["top_tv", "top_users", "top_platforms"]
|
stats_queries = ["top_tv", "popular_tv", "top_users", "top_platforms"]
|
||||||
home_stats = []
|
home_stats = []
|
||||||
|
|
||||||
for stat in stats_queries:
|
for stat in stats_queries:
|
||||||
|
@ -622,6 +622,50 @@ class PlexWatch(object):
|
||||||
home_stats.append({'stat_id': stat,
|
home_stats.append({'stat_id': stat,
|
||||||
'rows': top_tv})
|
'rows': top_tv})
|
||||||
|
|
||||||
|
elif 'popular_tv' in stat:
|
||||||
|
popular_tv = []
|
||||||
|
try:
|
||||||
|
query = 'SELECT orig_title, COUNT(DISTINCT user) as users_watched, grandparentRatingKey, ' \
|
||||||
|
'MAX(time) as last_watch, xml, COUNT(id) as total_plays ' \
|
||||||
|
'FROM %s ' \
|
||||||
|
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||||
|
'AND episode != "" ' \
|
||||||
|
'GROUP BY orig_title ' \
|
||||||
|
'ORDER BY users_watched DESC, total_plays DESC LIMIT 10' % (self.get_user_table_name(), time_range)
|
||||||
|
result = myDB.select(query)
|
||||||
|
except:
|
||||||
|
logger.warn("Unable to open PlexWatch database.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
for item in result:
|
||||||
|
xml_data = helpers.latinToAscii(item[4])
|
||||||
|
|
||||||
|
try:
|
||||||
|
xml_parse = minidom.parseString(xml_data)
|
||||||
|
except:
|
||||||
|
logger.warn("Error parsing XML for Plexwatch database.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
xml_head = xml_parse.getElementsByTagName('opt')
|
||||||
|
if not xml_head:
|
||||||
|
logger.warn("Error parsing XML for Plexwatch database.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
for a in xml_head:
|
||||||
|
grandparent_thumb = self.get_xml_attr(a, 'grandparentThumb')
|
||||||
|
|
||||||
|
row = {'orig_title': item[0],
|
||||||
|
'users_watched': item[1],
|
||||||
|
'rating_key': item[2],
|
||||||
|
'last_play': item[3],
|
||||||
|
'total_plays': item[5],
|
||||||
|
'grandparent_thumb': grandparent_thumb
|
||||||
|
}
|
||||||
|
popular_tv.append(row)
|
||||||
|
|
||||||
|
home_stats.append({'stat_id': stat,
|
||||||
|
'rows': popular_tv})
|
||||||
|
|
||||||
elif 'top_users' in stat:
|
elif 'top_users' in stat:
|
||||||
top_users = []
|
top_users = []
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue