<%doc> USAGE DOCUMENTATION :: PLEASE LEAVE THIS AT THE TOP OF THIS FILE For Mako templating syntax documentation please visit: http://docs.makotemplates.org/en/latest/ Filename: home_stats.html Version: 0.1 Variable names: data [array] data[array_index] :: Usable parameters data['stat_id'] Returns the name of the stat. Either 'top_tv', 'top_movies', 'popular_tv', 'popular_movies', 'top_user' or 'top_platform' data['stat_type'] Returns the type of the stat. Either 'total_plays' or 'total_duration' data['rows'] Returns an array containing stat data data[array_index]['rows'] :: Usable parameters row_id Return the db row id for a metadata item if one exists == Only if 'stat_id' is 'top_tv' or 'popular_tv' or 'top_movies' or 'popular_movies' or 'top_music' or 'popular_music' or 'last_watched' == thumb Return the thumb for the media item. == Only if 'stat_id' is 'top_tv' or 'popular_tv' or 'top_music' or 'popular_music' == grandparent_thumb Returns location of the item's thumbnail. Use with pms_image_proxy. rating_key Returns the unique identifier for the media item. title Returns the title for the associated stat. == Only if 'stat_id' is 'top_tv' or 'top_movies' or 'top_music' or 'top_user' or 'top_platform' == 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' or 'popular_movies' or 'popular_music' == users_watched Returns the count for the associated stat. == Only if 'stat_id' is 'top_user' or 'last_watched' == user_thumb Returns url of the user's gravatar. Returns '' if none exists. user Returns the username for the associated stat. user_id Returns the user id for the associated stat. friendly_name Returns the friendly name of the user for the associated stat. == Only if 'stat_id' is 'top_platform' or 'last_watched' == player Returns the player name for the associated stat. == Only if 'stat_id' is 'last_watched' == last_watch Returns the time the media item was last watched. == Only if 'stat_id' is 'most_concurrent' == count Returns the count of the most concurrent streams. started Returns the start time of the most concurrent streams. stopped Returns the stop time of the most concurrent streams. DOCUMENTATION :: END <%! from plexpy import helpers # Human readable duration def hd(seconds): m, s = divmod(helpers.cast_to_int(seconds), 60) h, m = divmod(m, 60) return str(h).zfill(1) + ':' + str(m).zfill(2) %> % if data and any(top_stat['rows'] for top_stat in data): % for top_stat in data: % if top_stat['rows']: <% stat_id = top_stat['stat_id'] row0 = top_stat['rows'][0] %>
% if stat_id in ('top_movies', 'popular_movies', 'top_tv', 'popular_tv', 'top_music', 'popular_music', 'last_watched'): % if row0['art']:
% else:
% endif % elif stat_id == 'top_platforms':
% else:
% endif % if stat_id in ('top_movies', 'popular_movies', 'top_tv', 'popular_tv', 'top_music', 'popular_music', 'last_watched'):
% if stat_id in ('top_music', 'popular_music'):
% endif <% type = 'cover' if stat_id in ('top_music', 'popular_music') else 'poster' %> % if row0['thumb']:
% else:
% endif
% elif stat_id == 'top_users':
% elif stat_id == 'top_platforms':
% elif stat_id == 'most_concurrent':
% endif

#### ${top_stat['stat_title']}

% if stat_id.startswith('top') and top_stat.get('stat_type') == 'total_plays': plays % elif stat_id.startswith('top') and top_stat.get('stat_type') == 'total_duration': hh:mm % elif stat_id.startswith('popular'): users % elif stat_id == 'last_watched': ${row0['friendly_name']} % elif stat_id == 'most_concurrent': streams % endif

% for row in top_stat['rows']:
- ${loop.index + 1}
  % if stat_id in ('top_movies', 'popular_movies', 'top_tv', 'popular_tv', 'top_music', 'popular_music', 'last_watched'): % if top_stat['rows'][loop.index]['rating_key']: ${row['title']} % else: ${row['title']} % endif % elif stat_id == 'top_users': % if top_stat['rows'][loop.index]['user_id']: ${row['friendly_name']} % else: ${row['friendly_name']} % endif % elif stat_id == 'top_platforms': ${row['platform']} % elif stat_id == 'most_concurrent': ${row['title']} % endif
  % if stat_id.startswith('top') and top_stat.get('stat_type') == 'total_plays': ${row['total_plays']} % elif stat_id.startswith('top') and top_stat.get('stat_type') == 'total_duration': ${row['total_duration'] | hd} % elif stat_id.startswith('popular'): ${row['users_watched']} % elif stat_id == 'most_concurrent': ${row['count']} % endif
% endfor

% endif % endfor
% else:
No stats to show for the selected period.
% endif