diff --git a/data/interfaces/default/home_stats.html b/data/interfaces/default/home_stats.html index e3773f3f..e6efb512 100644 --- a/data/interfaces/default/home_stats.html +++ b/data/interfaces/default/home_stats.html @@ -44,6 +44,11 @@ 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 @@ -782,6 +787,30 @@ DOCUMENTATION :: END % endif + % elif top_stat['stat_id'] == 'most_concurrent' and top_stat['rows']: +
+
  • +
    +
    +

    Most Concurrent Streams

    +
    +
    +

    + + + +

    +

    ${top_stat['rows'][0]['count']}

    +

    streams

    +
    +
    +
    +
    +
    +
  • +
    % endif % endfor diff --git a/data/interfaces/default/images/home-stat_most-concurrent.png b/data/interfaces/default/images/home-stat_most-concurrent.png new file mode 100644 index 00000000..085dc93e Binary files /dev/null and b/data/interfaces/default/images/home-stat_most-concurrent.png differ diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 384290f9..ee3643ff 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -111,6 +111,7 @@ available_notification_agents = sorted(notifiers.available_notification_agents() + diff --git a/plexpy/config.py b/plexpy/config.py index 491f2081..664a69ec 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -98,7 +98,8 @@ _CONFIG_DEFINITIONS = { 'HOME_STATS_LENGTH': (int, 'General', 30), 'HOME_STATS_TYPE': (int, 'General', 0), 'HOME_STATS_COUNT': (int, 'General', 5), - 'HOME_STATS_CARDS': (str, 'General', 'watch_statistics, top_tv, popular_tv, top_movies, popular_movies, top_music, popular_music, top_users, top_platforms, last_watched'), + 'HOME_STATS_CARDS': (str, 'General', 'watch_statistics, top_tv, popular_tv, top_movies, popular_movies, ' \ + 'top_music, popular_music, last_watched, top_users, top_platforms, most_concurrent'), 'HTTPS_CERT': (str, 'General', ''), 'HTTPS_KEY': (str, 'General', ''), 'HTTP_HOST': (str, 'General', '0.0.0.0'), diff --git a/plexpy/datafactory.py b/plexpy/datafactory.py index 8d797fae..d1b656e5 100644 --- a/plexpy/datafactory.py +++ b/plexpy/datafactory.py @@ -589,6 +589,38 @@ class DataFactory(object): home_stats.append({'stat_id': stat, 'rows': last_watched}) + elif stat == 'most_concurrent': + try: + query = 'SELECT started, stopped ' \ + 'FROM session_history ' + result = monitor_db.select(query) + except: + logger.warn("Unable to execute database query for get_home_stats: most_concurrent.") + return None + + times = {} + for item in result: + times.update({str(item['stopped']) + 'A': -1, str(item['started']) + 'B': 1}) + + count = 0 + last_start = 0 + most_concurrent = {'count': count} + + for key in sorted(times): + if times[key] == 1: + count += times[key] + if count >= most_concurrent['count']: + last_start = key + else: + if count >= most_concurrent['count']: + most_concurrent = {'count': count, + 'started': last_start[:-1], + 'stopped': key[:-1]} + count += times[key] + + home_stats.append({'stat_id': stat, + 'rows': [most_concurrent]}) + return home_stats def get_stream_details(self, row_id=None):