diff --git a/data/interfaces/default/graphs.html b/data/interfaces/default/graphs.html index 7846a0df..b79ef59a 100644 --- a/data/interfaces/default/graphs.html +++ b/data/interfaces/default/graphs.html @@ -252,6 +252,7 @@ case "TV": media_type = 'episode'; break; case "Movies": media_type = 'movie'; break; case "Music": media_type = 'track'; break; + case "Live TV": media_type = 'live'; break; case "Direct Play": transcode_decision = 'direct play'; break; case "Direct Stream": transcode_decision = 'copy'; break; case "Transcode": transcode_decision = 'transcode'; break; diff --git a/data/interfaces/default/js/graphs/plays_by_day.js b/data/interfaces/default/js/graphs/plays_by_day.js index cb75d15b..da6de24d 100644 --- a/data/interfaces/default/js/graphs/plays_by_day.js +++ b/data/interfaces/default/js/graphs/plays_by_day.js @@ -40,7 +40,7 @@ var hc_plays_by_day_options = { } } }, - colors: ['#E5A00D', '#FFFFFF', '#F06464'], + colors: ['#E5A00D', '#FFFFFF', '#F06464', '#19A0D7'], xAxis: { type: 'datetime', labels: { diff --git a/data/interfaces/default/js/graphs/plays_by_dayofweek.js b/data/interfaces/default/js/graphs/plays_by_dayofweek.js index c24b8e01..d3cf4dfe 100644 --- a/data/interfaces/default/js/graphs/plays_by_dayofweek.js +++ b/data/interfaces/default/js/graphs/plays_by_dayofweek.js @@ -23,7 +23,7 @@ var hc_plays_by_dayofweek_options = { credits: { enabled: false }, - colors: ['#E5A00D', '#FFFFFF', '#F06464'], + colors: ['#E5A00D', '#FFFFFF', '#F06464', '#19A0D7'], xAxis: { categories: [{}], labels: { diff --git a/data/interfaces/default/js/graphs/plays_by_hourofday.js b/data/interfaces/default/js/graphs/plays_by_hourofday.js index 6d51bd81..a36d37c0 100644 --- a/data/interfaces/default/js/graphs/plays_by_hourofday.js +++ b/data/interfaces/default/js/graphs/plays_by_hourofday.js @@ -23,7 +23,7 @@ var hc_plays_by_hourofday_options = { credits: { enabled: false }, - colors: ['#E5A00D', '#FFFFFF', '#F06464'], + colors: ['#E5A00D', '#FFFFFF', '#F06464', '#19A0D7'], xAxis: { categories: [{}], labels: { diff --git a/data/interfaces/default/js/graphs/plays_by_month.js b/data/interfaces/default/js/graphs/plays_by_month.js index 71259fc1..9dc4d4da 100644 --- a/data/interfaces/default/js/graphs/plays_by_month.js +++ b/data/interfaces/default/js/graphs/plays_by_month.js @@ -23,7 +23,7 @@ var hc_plays_by_month_options = { credits: { enabled: false }, - colors: ['#E5A00D', '#FFFFFF', '#F06464'], + colors: ['#E5A00D', '#FFFFFF', '#F06464', '#19A0D7'], xAxis: { labels: { style: { diff --git a/data/interfaces/default/js/graphs/plays_by_platform.js b/data/interfaces/default/js/graphs/plays_by_platform.js index b81fba3c..a3e7f890 100644 --- a/data/interfaces/default/js/graphs/plays_by_platform.js +++ b/data/interfaces/default/js/graphs/plays_by_platform.js @@ -23,7 +23,7 @@ var hc_plays_by_platform_options = { credits: { enabled: false }, - colors: ['#E5A00D', '#FFFFFF', '#F06464'], + colors: ['#E5A00D', '#FFFFFF', '#F06464', '#19A0D7'], xAxis: { categories: [{}], labels: { diff --git a/data/interfaces/default/js/graphs/plays_by_user.js b/data/interfaces/default/js/graphs/plays_by_user.js index 1f506503..f49b837f 100644 --- a/data/interfaces/default/js/graphs/plays_by_user.js +++ b/data/interfaces/default/js/graphs/plays_by_user.js @@ -23,7 +23,7 @@ var hc_plays_by_user_options = { credits: { enabled: false }, - colors: ['#E5A00D', '#FFFFFF', '#F06464'], + colors: ['#E5A00D', '#FFFFFF', '#F06464', '#19A0D7'], xAxis: { categories: [{}], labels: { diff --git a/plexpy/graphs.py b/plexpy/graphs.py index 27500cfa..ee98dceb 100644 --- a/plexpy/graphs.py +++ b/plexpy/graphs.py @@ -47,10 +47,12 @@ class Graphs(object): try: if y_axis == 'plays': query = 'SELECT date(started, "unixepoch", "localtime") AS date_played, ' \ - 'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 THEN 1 ELSE 0 END) AS tv_count, ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 THEN 1 ELSE 0 END) AS movie_count, ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 THEN 1 ELSE 0 END) AS music_count, ' \ + 'SUM(live) AS live_count ' \ 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \ 'GROUP BY date(started, "unixepoch", "localtime"), %s) ' \ 'AS session_history ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \ @@ -60,13 +62,17 @@ class Graphs(object): result = monitor_db.select(query) else: query = 'SELECT date(started, "unixepoch", "localtime") AS date_played, ' \ - 'SUM(CASE WHEN media_type = "episode" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \ - ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count ' \ - 'FROM session_history ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count, ' \ + 'SUM(CASE WHEN live = 1 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS live_count ' \ + 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id) ' \ + 'AS session_history ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \ 'GROUP BY date_played ' \ 'ORDER BY started ASC' % (time_range, user_cond) @@ -85,6 +91,7 @@ class Graphs(object): series_1 = [] series_2 = [] series_3 = [] + series_4 = [] for date_item in sorted(date_list): date_string = date_item.strftime('%Y-%m-%d') @@ -92,20 +99,24 @@ class Graphs(object): series_1_value = 0 series_2_value = 0 series_3_value = 0 + series_4_value = 0 for item in result: if date_string == item['date_played']: series_1_value = item['tv_count'] series_2_value = item['movie_count'] series_3_value = item['music_count'] + series_4_value = item['live_count'] break else: series_1_value = 0 series_2_value = 0 series_3_value = 0 + series_4_value = 0 series_1.append(series_1_value) series_2.append(series_2_value) series_3.append(series_3_value) + series_4.append(series_4_value) series_1_output = {'name': 'TV', 'data': series_1} @@ -113,9 +124,11 @@ class Graphs(object): 'data': series_2} series_3_output = {'name': 'Music', 'data': series_3} + series_4_output = {'name': 'Live TV', + 'data': series_4} output = {'categories': categories, - 'series': [series_1_output, series_2_output, series_3_output]} + 'series': [series_1_output, series_2_output, series_3_output, series_4_output]} return output def get_total_plays_per_dayofweek(self, time_range='30', y_axis='plays', user_id=None, grouping=None): @@ -146,10 +159,12 @@ class Graphs(object): 'WHEN 4 THEN "Thursday" ' \ 'WHEN 5 THEN "Friday" ' \ 'ELSE "Saturday" END) AS dayofweek, ' \ - 'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 THEN 1 ELSE 0 END) AS tv_count, ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 THEN 1 ELSE 0 END) AS movie_count, ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 THEN 1 ELSE 0 END) AS music_count, ' \ + 'SUM(live) AS live_count ' \ 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \ 'GROUP BY strftime("%%w", datetime(started, "unixepoch", "localtime")), %s) ' \ 'AS session_history ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \ @@ -167,13 +182,17 @@ class Graphs(object): 'WHEN 4 THEN "Thursday" ' \ 'WHEN 5 THEN "Friday" ' \ 'ELSE "Saturday" END) AS dayofweek, ' \ - 'SUM(CASE WHEN media_type = "episode" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \ - ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count ' \ - 'FROM session_history ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count, ' \ + 'SUM(CASE WHEN live = 1 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS live_count ' \ + 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id) ' \ + 'AS session_history ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \ 'GROUP BY dayofweek ' \ 'ORDER BY daynumber' % (time_range, user_cond) @@ -194,26 +213,31 @@ class Graphs(object): series_1 = [] series_2 = [] series_3 = [] + series_4 = [] for day_item in days_list: categories.append(day_item) series_1_value = 0 series_2_value = 0 series_3_value = 0 + series_4_value = 0 for item in result: if day_item == item['dayofweek']: series_1_value = item['tv_count'] series_2_value = item['movie_count'] series_3_value = item['music_count'] + series_4_value = item['live_count'] break else: series_1_value = 0 series_2_value = 0 series_3_value = 0 + series_4_value = 0 series_1.append(series_1_value) series_2.append(series_2_value) series_3.append(series_3_value) + series_4.append(series_4_value) series_1_output = {'name': 'TV', 'data': series_1} @@ -221,9 +245,11 @@ class Graphs(object): 'data': series_2} series_3_output = {'name': 'Music', 'data': series_3} + series_4_output = {'name': 'Live TV', + 'data': series_4} output = {'categories': categories, - 'series': [series_1_output, series_2_output, series_3_output]} + 'series': [series_1_output, series_2_output, series_3_output, series_4_output]} return output def get_total_plays_per_hourofday(self, time_range='30', y_axis='plays', user_id=None, grouping=None): @@ -246,10 +272,12 @@ class Graphs(object): try: if y_axis == 'plays': query = 'SELECT strftime("%%H", datetime(started, "unixepoch", "localtime")) AS hourofday, ' \ - 'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 THEN 1 ELSE 0 END) AS tv_count, ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 THEN 1 ELSE 0 END) AS movie_count, ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 THEN 1 ELSE 0 END) AS music_count, ' \ + 'SUM(live) AS live_count ' \ 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \ 'GROUP BY strftime("%%H", datetime(started, "unixepoch", "localtime")) , %s) ' \ 'AS session_history ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \ @@ -259,13 +287,17 @@ class Graphs(object): result = monitor_db.select(query) else: query = 'SELECT strftime("%%H", datetime(started, "unixepoch", "localtime")) AS hourofday, ' \ - 'SUM(CASE WHEN media_type = "episode" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \ - ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count ' \ - 'FROM session_history ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count, ' \ + 'SUM(CASE WHEN live = 1 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS live_count ' \ + 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id) ' \ + 'AS session_history ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") %s' \ 'GROUP BY hourofday ' \ 'ORDER BY hourofday' % (time_range, user_cond) @@ -275,35 +307,40 @@ class Graphs(object): logger.warn(u"Tautulli Graphs :: Unable to execute database query for get_total_plays_per_hourofday: %s." % e) return None - hours_list = ['00','01','02','03','04','05', - '06','07','08','09','10','11', - '12','13','14','15','16','17', - '18','19','20','21','22','23'] + hours_list = ['00', '01', '02', '03', '04', '05', + '06', '07', '08', '09', '10', '11', + '12', '13', '14', '15', '16', '17', + '18', '19', '20', '21', '22', '23'] categories = [] series_1 = [] series_2 = [] series_3 = [] + series_4 = [] for hour_item in hours_list: categories.append(hour_item) series_1_value = 0 series_2_value = 0 series_3_value = 0 + series_4_value = 0 for item in result: if hour_item == item['hourofday']: series_1_value = item['tv_count'] series_2_value = item['movie_count'] series_3_value = item['music_count'] + series_4_value = item['live_count'] break else: series_1_value = 0 series_2_value = 0 series_3_value = 0 + series_4_value = 0 series_1.append(series_1_value) series_2.append(series_2_value) series_3.append(series_3_value) + series_4.append(series_4_value) series_1_output = {'name': 'TV', 'data': series_1} @@ -311,14 +348,14 @@ class Graphs(object): 'data': series_2} series_3_output = {'name': 'Music', 'data': series_3} + series_4_output = {'name': 'Live TV', + 'data': series_4} output = {'categories': categories, - 'series': [series_1_output, series_2_output, series_3_output]} + 'series': [series_1_output, series_2_output, series_3_output, series_4_output]} return output def get_total_plays_per_month(self, time_range='12', y_axis='plays', user_id=None, grouping=None): - import time as time - if not time_range.isdigit(): time_range = '12' @@ -338,10 +375,12 @@ class Graphs(object): try: if y_axis == 'plays': query = 'SELECT strftime("%%Y-%%m", datetime(started, "unixepoch", "localtime")) AS datestring, ' \ - 'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 THEN 1 ELSE 0 END) AS tv_count, ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 THEN 1 ELSE 0 END) AS movie_count, ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 THEN 1 ELSE 0 END) AS music_count, ' \ + 'SUM(live) AS live_count ' \ 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \ 'GROUP BY strftime("%%Y-%%m", datetime(started, "unixepoch", "localtime")), %s) ' \ 'AS session_history ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s months", "localtime") %s' \ @@ -351,13 +390,17 @@ class Graphs(object): result = monitor_db.select(query) else: query = 'SELECT strftime("%%Y-%%m", datetime(started, "unixepoch", "localtime")) AS datestring, ' \ - 'SUM(CASE WHEN media_type = "episode" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \ - ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count ' \ - 'FROM session_history ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count, ' \ + 'SUM(CASE WHEN live = 1 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS live_count ' \ + 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id) ' \ + 'AS session_history ' \ 'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s months", "localtime") %s' \ 'GROUP BY strftime("%%Y-%%m", datetime(started, "unixepoch", "localtime")) ' \ 'ORDER BY datestring DESC LIMIT %s' % (time_range, user_cond, time_range) @@ -383,6 +426,7 @@ class Graphs(object): series_1 = [] series_2 = [] series_3 = [] + series_4 = [] for dt in sorted(month_range): date_string = dt.strftime('%Y-%m') @@ -390,20 +434,24 @@ class Graphs(object): series_1_value = 0 series_2_value = 0 series_3_value = 0 + series_4_value = 0 for item in result: if date_string == item['datestring']: series_1_value = item['tv_count'] series_2_value = item['movie_count'] series_3_value = item['music_count'] + series_4_value = item['live_count'] break else: series_1_value = 0 series_2_value = 0 series_3_value = 0 + series_4_value = 0 series_1.append(series_1_value) series_2.append(series_2_value) series_3.append(series_3_value) + series_4.append(series_4_value) series_1_output = {'name': 'TV', 'data': series_1} @@ -411,9 +459,11 @@ class Graphs(object): 'data': series_2} series_3_output = {'name': 'Music', 'data': series_3} + series_4_output = {'name': 'Live TV', + 'data': series_4} output = {'categories': categories, - 'series': [series_1_output, series_2_output, series_3_output]} + 'series': [series_1_output, series_2_output, series_3_output, series_4_output]} return output def get_total_plays_by_top_10_platforms(self, time_range='30', y_axis='plays', user_id=None, grouping=None): @@ -436,11 +486,15 @@ class Graphs(object): try: if y_axis == 'plays': query = 'SELECT platform, ' \ - 'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count, ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 THEN 1 ELSE 0 END) AS tv_count, ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 THEN 1 ELSE 0 END) AS movie_count, ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 THEN 1 ELSE 0 END) AS music_count, ' \ + 'SUM(live) AS live_count, ' \ 'COUNT(id) AS total_count ' \ - 'FROM (SELECT * FROM session_history GROUP BY %s) AS session_history ' \ + 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \ + 'GROUP BY %s) ' \ + 'AS session_history ' \ 'WHERE (datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) %s' \ 'GROUP BY platform ' \ 'ORDER BY total_count DESC ' \ @@ -449,15 +503,19 @@ class Graphs(object): result = monitor_db.select(query) else: query = 'SELECT platform, ' \ - 'SUM(CASE WHEN media_type = "episode" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count, ' \ + 'SUM(CASE WHEN live = 1 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS live_count, ' \ 'SUM(CASE WHEN stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS total_duration ' \ - 'FROM session_history ' \ + 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id) ' \ + 'AS session_history ' \ 'WHERE (datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) %s' \ 'GROUP BY platform ' \ 'ORDER BY total_duration DESC ' \ @@ -472,12 +530,14 @@ class Graphs(object): series_1 = [] series_2 = [] series_3 = [] + series_4 = [] for item in result: categories.append(common.PLATFORM_NAME_OVERRIDES.get(item['platform'], item['platform'])) series_1.append(item['tv_count']) series_2.append(item['movie_count']) series_3.append(item['music_count']) + series_4.append(item['live_count']) series_1_output = {'name': 'TV', 'data': series_1} @@ -485,9 +545,11 @@ class Graphs(object): 'data': series_2} series_3_output = {'name': 'Music', 'data': series_3} + series_4_output = {'name': 'Live TV', + 'data': series_4} output = {'categories': categories, - 'series': [series_1_output, series_2_output, series_3_output]} + 'series': [series_1_output, series_2_output, series_3_output, series_4_output]} return output def get_total_plays_by_top_10_users(self, time_range='30', y_axis='plays', user_id=None, grouping=None): @@ -513,11 +575,15 @@ class Graphs(object): 'users.user_id, users.username, ' \ '(CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" ' \ ' THEN users.username ELSE users.friendly_name END) AS friendly_name,' \ - 'SUM(CASE WHEN media_type = "episode" THEN 1 ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" THEN 1 ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" THEN 1 ELSE 0 END) AS music_count, ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 THEN 1 ELSE 0 END) AS tv_count, ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 THEN 1 ELSE 0 END) AS movie_count, ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 THEN 1 ELSE 0 END) AS music_count, ' \ + 'SUM(live) AS live_count, ' \ 'COUNT(session_history.id) AS total_count ' \ - 'FROM (SELECT * FROM session_history GROUP BY %s) AS session_history ' \ + 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \ + 'GROUP BY %s) ' \ + 'AS session_history ' \ 'JOIN users ON session_history.user_id = users.user_id ' \ 'WHERE (datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) %s' \ 'GROUP BY session_history.user_id ' \ @@ -530,15 +596,19 @@ class Graphs(object): 'users.user_id, users.username, ' \ '(CASE WHEN users.friendly_name IS NULL OR TRIM(users.friendly_name) = "" ' \ ' THEN users.username ELSE users.friendly_name END) AS friendly_name,' \ - 'SUM(CASE WHEN media_type = "episode" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "episode" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS tv_count, ' \ - 'SUM(CASE WHEN media_type = "movie" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "movie" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS movie_count, ' \ - 'SUM(CASE WHEN media_type = "track" AND stopped > 0 THEN (stopped - started) ' \ + 'SUM(CASE WHEN media_type = "track" AND live = 0 AND stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS music_count, ' \ + 'SUM(CASE WHEN live = 1 AND stopped > 0 THEN (stopped - started) ' \ + ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS live_count, ' \ 'SUM(CASE WHEN stopped > 0 THEN (stopped - started) ' \ ' - (CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) ELSE 0 END) AS total_duration ' \ - 'FROM session_history ' \ + 'FROM (SELECT * FROM session_history ' \ + 'JOIN session_history_metadata ON session_history.id = session_history_metadata.id) ' \ + 'AS session_history ' \ 'JOIN users ON session_history.user_id = users.user_id ' \ 'WHERE (datetime(started, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime")) %s' \ 'GROUP BY session_history.user_id ' \ @@ -554,6 +624,7 @@ class Graphs(object): series_1 = [] series_2 = [] series_3 = [] + series_4 = [] session_user_id = session.get_session_user_id() @@ -565,6 +636,7 @@ class Graphs(object): series_1.append(item['tv_count']) series_2.append(item['movie_count']) series_3.append(item['music_count']) + series_4.append(item['live_count']) series_1_output = {'name': 'TV', 'data': series_1} @@ -572,9 +644,11 @@ class Graphs(object): 'data': series_2} series_3_output = {'name': 'Music', 'data': series_3} + series_4_output = {'name': 'Live TV', + 'data': series_4} output = {'categories': categories, - 'series': [series_1_output, series_2_output, series_3_output]} + 'series': [series_1_output, series_2_output, series_3_output, series_4_output]} return output def get_total_plays_per_stream_type(self, time_range='30', y_axis='plays', user_id=None, grouping=None):