Add most concurrent streams home statistic

This commit is contained in:
Jonathan Wong 2015-12-12 14:28:59 -08:00
commit 9cf6793b24
5 changed files with 64 additions and 1 deletions

View file

@ -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'),

View file

@ -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):