<%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' == platform_type Returns the platform name for the associated stat. == Only if 'stat_id' is 'last_watched' == last_watch Returns the time the media item was last watched. DOCUMENTATION :: END <%! from plexpy import helpers # Human readable duration def hd(seconds): minutes = helpers.cast_to_float(seconds) / 60 if minutes > 60: hours = int(minutes / 60) minutes = int(minutes % 60) if minutes > 0: return "

### " + str(hours) + "

hrs

### " + str(minutes) + "

mins

" else: return "

### " + str(hours) + "

hrs

" else: return "

### " + str(int(minutes)) + "

mins

" %> % if data: % if data[0]['stat_id']:

% for top_stat in data: % if top_stat['stat_id'] == 'top_tv' and top_stat['rows']:

- #### Most Watched TV

  #### ${top_stat['rows'][0]['title']}

  % if top_stat['stat_type'] == 'total_plays':

  ### ${top_stat['rows'][0]['total_plays']}

  plays

  % else: ${top_stat['rows'][0]['total_duration'] | hd} % endif
  % if top_stat['rows'][0]['grandparent_thumb']:
  % else:
  % endif %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### ${top_stat['rows'][loop.index]['title']}

    % if top_stat['stat_type'] == 'total_plays':

    ### ${top_stat['rows'][loop.index]['total_plays']}

    plays

    % else: ${top_stat['rows'][loop.index]['total_duration'] | hd} % endif
    % if top_stat['rows'][loop.index]['grandparent_thumb']:
    % else:
    % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% elif top_stat['stat_id'] == 'popular_tv' and top_stat['rows']:

- #### Most Popular TV

  #### ${top_stat['rows'][0]['title']}

  ### ${top_stat['rows'][0]['users_watched']}

  users

  % if top_stat['rows'][0]['grandparent_thumb'] != '':
  % else:
  % endif %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### ${top_stat['rows'][loop.index]['title']}

    ### ${top_stat['rows'][loop.index]['users_watched']}

    users

    % if top_stat['rows'][loop.index]['grandparent_thumb']:
    % else:
    % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% elif top_stat['stat_id'] == 'top_movies' and top_stat['rows']:

- #### Most Watched Movie

  #### ${top_stat['rows'][0]['title']}

  % if top_stat['stat_type'] == 'total_plays':

  ### ${top_stat['rows'][0]['total_plays']}

  plays

  % else: ${top_stat['rows'][0]['total_duration'] | hd} % endif
  % if top_stat['rows'][0]['thumb']:
  % else:
  % endif %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### ${top_stat['rows'][loop.index]['title']}

    % if top_stat['stat_type'] == 'total_plays':

    ### ${top_stat['rows'][loop.index]['total_plays']}

    plays

    % else: ${top_stat['rows'][loop.index]['total_duration'] | hd} % endif
    % if top_stat['rows'][loop.index]['thumb']:
    % else:
    % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% elif top_stat['stat_id'] == 'popular_movies' and top_stat['rows']:

- #### Most Popular Movie

  #### ${top_stat['rows'][0]['title']}

  ### ${top_stat['rows'][0]['users_watched']}

  users

  % if top_stat['rows'][0]['thumb']:
  % else:
  % endif %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### ${top_stat['rows'][loop.index]['title']}

    ### ${top_stat['rows'][loop.index]['users_watched']}

    users

    % if top_stat['rows'][loop.index]['thumb']:
    % else:
    % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% elif top_stat['stat_id'] == 'top_music' and top_stat['rows']:

- #### Most Listened to Artist

  #### ${top_stat['rows'][0]['title']}

  % if top_stat['stat_type'] == 'total_plays':

  ### ${top_stat['rows'][0]['total_plays']}

  plays

  % else: ${top_stat['rows'][0]['total_duration'] | hd} % endif
  % if top_stat['rows'][0]['grandparent_thumb']:
  % else:
  % endif %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### ${top_stat['rows'][loop.index]['title']}

    % if top_stat['stat_type'] == 'total_plays':

    ### ${top_stat['rows'][loop.index]['total_plays']}

    plays

    % else: ${top_stat['rows'][loop.index]['total_duration'] | hd} % endif
    % if top_stat['rows'][loop.index]['grandparent_thumb']:
    % else:
    % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% elif top_stat['stat_id'] == 'popular_music' and top_stat['rows']:

- #### Most Popular Artist

  #### ${top_stat['rows'][0]['title']}

  ### ${top_stat['rows'][0]['users_watched']}

  users

  % if top_stat['rows'][0]['grandparent_thumb'] != '':
  % else:
  % endif %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### ${top_stat['rows'][loop.index]['title']}

    ### ${top_stat['rows'][loop.index]['users_watched']}

    users

    % if top_stat['rows'][loop.index]['grandparent_thumb']:
    % else:
    % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% elif top_stat['stat_id'] == 'top_users' and top_stat['rows']:

- #### Most Active User

  #### % if top_stat['rows'][0]['user_id']: % else: % endif ${top_stat['rows'][0]['friendly_name']}

  % if top_stat['stat_type'] == 'total_plays':

  ### ${top_stat['rows'][0]['total_plays']}

  plays

  % else: ${top_stat['rows'][0]['total_duration'] | hd} % endif
  % if top_stat['rows'][0]['user_id']: % else: % endif % if top_stat['rows'][0]['user_thumb'] != '':
  % else:
  % endif %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### % if top_stat['rows'][loop.index]['user_id']: % else: % endif ${top_stat['rows'][loop.index]['friendly_name']}

    % if top_stat['stat_type'] == 'total_plays':

    ### ${top_stat['rows'][loop.index]['total_plays']}

    plays

    % else: ${top_stat['rows'][loop.index]['total_duration'] | hd} % endif
    % if top_stat['rows'][loop.index]['user_id']: % else: % endif % if top_stat['rows'][loop.index]['user_thumb'] != '':
    % else:
    % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% elif top_stat['stat_id'] == 'top_platforms' and top_stat['rows']:

- #### Most Active Platform

  #### ${top_stat['rows'][0]['platform_type']}

  % if top_stat['stat_type'] == 'total_plays':

  ### ${top_stat['rows'][0]['total_plays']}

  plays

  % else: ${top_stat['rows'][0]['total_duration'] | hd} % endif
  %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### ${top_stat['rows'][loop.index]['platform_type']}

    % if top_stat['stat_type'] == 'total_plays':

    ### ${top_stat['rows'][loop.index]['total_plays']}

    plays

    % else: ${top_stat['rows'][loop.index]['total_duration'] | hd} % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% elif top_stat['stat_id'] == 'last_watched' and top_stat['rows']:

- #### Last Watched

  #### ${top_stat['rows'][0]['title']}

  ##### % if top_stat['rows'][0]['user_id']: % else: % endif ${top_stat['rows'][0]['friendly_name']}

  - ${top_stat['rows'][0]['platform_type']}

  % if top_stat['rows'][0]['thumb']:
  % else:
  % endif %if len(top_stat['rows']) > 1:
  % for row in top_stat['rows']: %if loop.index > 0:

  - ##### ${top_stat['rows'][loop.index]['title']}

    ##### % if top_stat['rows'][loop.index]['user_id']: % else: % endif ${top_stat['rows'][loop.index]['friendly_name']}

    - ${top_stat['rows'][loop.index]['platform_type']}

    % if top_stat['rows'][loop.index]['thumb']:
    % else:
    % endif

    #### ${loop.index + 1}

  % endif % endfor
  % endif
% endif % endfor

% else:
No stats for selected period.
% endif % else:
Unable to retrieve data from database. Please check your settings.
% endif