mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 21:51:14 -07:00
Add music to graphs
* Separate out TV, movies, and music on bar graphs * Separate out direct play, direct stream, and transcode on bar graphs
This commit is contained in:
parent
fb872596d6
commit
7b9210a5fc
10 changed files with 465 additions and 197 deletions
|
@ -48,7 +48,7 @@
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h4><i class="fa fa-history"></i> Daily <span class="yaxis-text">Play count</span> <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-history"></i> Daily <span class="yaxis-text">Play count</span> <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The total play count or duration of movies and tv played per day. Click a graph point to open up a list of items played for that specific date.
|
The total play count or duration of tv, movies, and music played per day. Click a graph point to open up a list of items played for that specific date.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_day">
|
<div class="watch-chart" id="chart_div_plays_by_day">
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4><i class="fa fa-calendar"></i> <span class="yaxis-text">Play count</span> by day of week <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-calendar"></i> <span class="yaxis-text">Play count</span> by day of week <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv played per day of the week.
|
The combined total of tv, movies, and music played per day of the week.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_dayofweek" style="float: left;">
|
<div class="watch-chart" id="chart_div_plays_by_dayofweek" style="float: left;">
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4><i class="fa fa-clock-o"></i> <span class="yaxis-text">Play count</span> by hour of day <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-clock-o"></i> <span class="yaxis-text">Play count</span> by hour of day <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv played per hour of the day.
|
The combined total of tv, movies, and music played per hour of the day.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_hourofday">
|
<div class="watch-chart" id="chart_div_plays_by_hourofday">
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4><i class="fa fa-television"></i> <span class="yaxis-text">Play count</span> by top 10 platforms <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-television"></i> <span class="yaxis-text">Play count</span> by top 10 platforms <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv played by top 10 most active platforms.
|
The combined total of tv, movies, and music played by top 10 most active platforms.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_platform" style="float: left;">
|
<div class="watch-chart" id="chart_div_plays_by_platform" style="float: left;">
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4><i class="fa fa-user"></i> <span class="yaxis-text">Play count</span> by top 10 users <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-user"></i> <span class="yaxis-text">Play count</span> by top 10 users <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv played by top 10 most active users.
|
The combined total of tv, movies, and music played by top 10 most active users.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_user">
|
<div class="watch-chart" id="chart_div_plays_by_user">
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h4><i class="fa fa-video-camera"></i> Daily Stream type breakdown <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-video-camera"></i> Daily Stream type breakdown <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The total play count or duration of movies and tv by the transcode decision. Click a graph point to open up a list of items played for that specific date.
|
The total play count or duration of tv, movies, and music by the transcode decision. Click a graph point to open up a list of items played for that specific date.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_stream_type">
|
<div class="watch-chart" id="chart_div_plays_by_stream_type">
|
||||||
|
@ -135,7 +135,7 @@
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4><i class="fa fa-expand"></i> <span class="yaxis-text">Play count</span> by source resolution <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-expand"></i> <span class="yaxis-text">Play count</span> by source resolution <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv by their original resolution (pre-transcoding).
|
The combined total of tv and movies by their original resolution (pre-transcoding).
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_source_resolution" style="float: left;">
|
<div class="watch-chart" id="chart_div_plays_by_source_resolution" style="float: left;">
|
||||||
|
@ -148,7 +148,7 @@
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4><i class="fa fa-expand"></i> <span class="yaxis-text">Play count</span> by stream resolution <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-expand"></i> <span class="yaxis-text">Play count</span> by stream resolution <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv by their streamed resolution (post-transcoding).
|
The combined total of tv and movies by their streamed resolution (post-transcoding).
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_stream_resolution">
|
<div class="watch-chart" id="chart_div_plays_by_stream_resolution">
|
||||||
|
@ -163,7 +163,7 @@
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4><i class="fa fa-television"></i> <span class="yaxis-text">Play count</span> by platform and stream type <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-television"></i> <span class="yaxis-text">Play count</span> by platform and stream type <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv by platform and stream type.
|
The combined total of tv, movies, and music by platform and stream type.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_platform_by_stream_type" style="float: left;">
|
<div class="watch-chart" id="chart_div_plays_by_platform_by_stream_type" style="float: left;">
|
||||||
|
@ -176,7 +176,7 @@
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4><i class="fa fa-user"></i> <span class="yaxis-text">Play count</span> by user and stream type <small>Last <span class="days">30</span> days</small></h4>
|
<h4><i class="fa fa-user"></i> <span class="yaxis-text">Play count</span> by user and stream type <small>Last <span class="days">30</span> days</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv by user and stream type.
|
The combined total of tv, movies, and music by user and stream type.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_user_by_stream_type" style="float: left;">
|
<div class="watch-chart" id="chart_div_plays_by_user_by_stream_type" style="float: left;">
|
||||||
|
@ -194,7 +194,7 @@
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h4><i class="fa fa-calendar"></i> Plays by Month <small>Last 12 months</small></h4>
|
<h4><i class="fa fa-calendar"></i> Plays by Month <small>Last 12 months</small></h4>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
The combined total of movies and tv by month.
|
The combined total of tv, movies, and music by month.
|
||||||
</p>
|
</p>
|
||||||
<div class="graphs-instance">
|
<div class="graphs-instance">
|
||||||
<div class="watch-chart" id="chart_div_plays_by_month">
|
<div class="watch-chart" id="chart_div_plays_by_month">
|
||||||
|
|
|
@ -35,7 +35,7 @@ var hc_plays_by_day_options = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
colors: ['#F9AA03', '#FFFFFF'],
|
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
labels: {
|
labels: {
|
||||||
|
|
|
@ -29,7 +29,7 @@ var hc_plays_by_dayofweek_options = {
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
colors: ['#F9AA03', '#FFFFFF'],
|
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
categories: [{}],
|
categories: [{}],
|
||||||
labels: {
|
labels: {
|
||||||
|
@ -46,6 +46,24 @@ var hc_plays_by_dayofweek_options = {
|
||||||
style: {
|
style: {
|
||||||
color: '#aaa'
|
color: '#aaa'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
stackLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
column: {
|
||||||
|
stacking: 'normal',
|
||||||
|
borderWidth: '0',
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#000'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
|
|
|
@ -29,7 +29,7 @@ var hc_plays_by_hourofday_options = {
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
colors: ['#F9AA03', '#FFFFFF'],
|
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
categories: [{}],
|
categories: [{}],
|
||||||
labels: {
|
labels: {
|
||||||
|
@ -46,6 +46,24 @@ var hc_plays_by_hourofday_options = {
|
||||||
style: {
|
style: {
|
||||||
color: '#aaa'
|
color: '#aaa'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
stackLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
column: {
|
||||||
|
stacking: 'normal',
|
||||||
|
borderWidth: '0',
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#000'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
|
|
|
@ -23,7 +23,7 @@ var hc_plays_by_month_options = {
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
colors: ['#F9AA03', '#FFFFFF'],
|
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
labels: {
|
labels: {
|
||||||
style: {
|
style: {
|
||||||
|
|
|
@ -29,7 +29,7 @@ var hc_plays_by_platform_options = {
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
colors: ['#F9AA03', '#FFFFFF'],
|
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
categories: [{}],
|
categories: [{}],
|
||||||
labels: {
|
labels: {
|
||||||
|
@ -46,6 +46,24 @@ var hc_plays_by_platform_options = {
|
||||||
style: {
|
style: {
|
||||||
color: '#aaa'
|
color: '#aaa'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
stackLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
column: {
|
||||||
|
stacking: 'normal',
|
||||||
|
borderWidth: '0',
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#000'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
|
|
|
@ -29,7 +29,7 @@ var hc_plays_by_source_resolution_options = {
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
colors: ['#F9AA03', '#FFFFFF'],
|
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
categories: [{}],
|
categories: [{}],
|
||||||
labels: {
|
labels: {
|
||||||
|
@ -46,6 +46,24 @@ var hc_plays_by_source_resolution_options = {
|
||||||
style: {
|
style: {
|
||||||
color: '#aaa'
|
color: '#aaa'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
stackLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
column: {
|
||||||
|
stacking: 'normal',
|
||||||
|
borderWidth: '0',
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#000'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
|
|
|
@ -29,7 +29,7 @@ var hc_plays_by_stream_resolution_options = {
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
colors: ['#F9AA03', '#FFFFFF'],
|
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
categories: [{}],
|
categories: [{}],
|
||||||
labels: {
|
labels: {
|
||||||
|
@ -46,6 +46,24 @@ var hc_plays_by_stream_resolution_options = {
|
||||||
style: {
|
style: {
|
||||||
color: '#aaa'
|
color: '#aaa'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
stackLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
column: {
|
||||||
|
stacking: 'normal',
|
||||||
|
borderWidth: '0',
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#000'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
|
|
|
@ -29,7 +29,7 @@ var hc_plays_by_user_options = {
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
colors: ['#F9AA03', '#FFFFFF'],
|
colors: ['#F9AA03', '#FFFFFF', '#FF4747'],
|
||||||
xAxis: {
|
xAxis: {
|
||||||
categories: [{}],
|
categories: [{}],
|
||||||
labels: {
|
labels: {
|
||||||
|
@ -46,6 +46,24 @@ var hc_plays_by_user_options = {
|
||||||
style: {
|
style: {
|
||||||
color: '#aaa'
|
color: '#aaa'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
stackLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
column: {
|
||||||
|
stacking: 'normal',
|
||||||
|
borderWidth: '0',
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false,
|
||||||
|
style: {
|
||||||
|
color: '#000'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
|
|
516
plexpy/graphs.py
516
plexpy/graphs.py
|
@ -33,7 +33,8 @@ class Graphs(object):
|
||||||
if y_axis == 'plays':
|
if y_axis == 'plays':
|
||||||
query = 'SELECT date(started, "unixepoch", "localtime") as date_played, ' \
|
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 = "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 = "movie" then 1 else 0 end) as movie_count, ' \
|
||||||
|
'SUM(case when media_type = "track" then 1 else 0 end) as music_count ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'GROUP BY date_played ' \
|
'GROUP BY date_played ' \
|
||||||
|
@ -45,7 +46,9 @@ class Graphs(object):
|
||||||
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
|
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \
|
||||||
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
|
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \
|
||||||
|
'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_duration ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
'WHERE datetime(stopped, "unixepoch", "localtime") >= datetime("now", "-%s days", "localtime") ' \
|
||||||
'GROUP BY date_played ' \
|
'GROUP BY date_played ' \
|
||||||
|
@ -64,31 +67,38 @@ class Graphs(object):
|
||||||
categories = []
|
categories = []
|
||||||
series_1 = []
|
series_1 = []
|
||||||
series_2 = []
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
for date_item in sorted(date_list):
|
for date_item in sorted(date_list):
|
||||||
date_string = date_item.strftime('%Y-%m-%d')
|
date_string = date_item.strftime('%Y-%m-%d')
|
||||||
categories.append(date_string)
|
categories.append(date_string)
|
||||||
series_1_value = 0
|
series_1_value = 0
|
||||||
series_2_value = 0
|
series_2_value = 0
|
||||||
|
series_3_value = 0
|
||||||
for item in result:
|
for item in result:
|
||||||
if date_string == item[0]:
|
if date_string == item[0]:
|
||||||
series_1_value = item[1]
|
series_1_value = item[1]
|
||||||
series_2_value = item[2]
|
series_2_value = item[2]
|
||||||
|
series_3_value = item[3]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
series_1_value = 0
|
series_1_value = 0
|
||||||
series_2_value = 0
|
series_2_value = 0
|
||||||
|
series_3_value = 0
|
||||||
|
|
||||||
series_1.append(series_1_value)
|
series_1.append(series_1_value)
|
||||||
series_2.append(series_2_value)
|
series_2.append(series_2_value)
|
||||||
|
series_3.append(series_3_value)
|
||||||
|
|
||||||
series_1_output = {'name': 'TV',
|
series_1_output = {'name': 'TV',
|
||||||
'data': series_1}
|
'data': series_1}
|
||||||
series_2_output = {'name': 'Movies',
|
series_2_output = {'name': 'Movies',
|
||||||
'data': series_2}
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Music',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output, series_2_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_total_plays_per_dayofweek(self, time_range='30', y_axis='plays'):
|
def get_total_plays_per_dayofweek(self, time_range='30', y_axis='plays'):
|
||||||
|
@ -107,16 +117,16 @@ class Graphs(object):
|
||||||
'when 4 then "Thursday" ' \
|
'when 4 then "Thursday" ' \
|
||||||
'when 5 then "Friday" ' \
|
'when 5 then "Friday" ' \
|
||||||
'else "Saturday" end as dayofweek, ' \
|
'else "Saturday" end as dayofweek, ' \
|
||||||
'COUNT(id) as total_plays ' \
|
'SUM(case when media_type = "episode" then 1 else 0 end) as tv_count, ' \
|
||||||
'from session_history ' \
|
'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 ' \
|
||||||
|
'FROM session_history ' \
|
||||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime") ' \
|
||||||
'(media_type = "episode" OR media_type = "movie") ' \
|
|
||||||
'GROUP BY dayofweek ' \
|
'GROUP BY dayofweek ' \
|
||||||
'ORDER BY daynumber'
|
'ORDER BY daynumber'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total plays'
|
|
||||||
else:
|
else:
|
||||||
query = 'SELECT strftime("%w", datetime(started, "unixepoch", "localtime")) as daynumber, ' \
|
query = 'SELECT strftime("%w", datetime(started, "unixepoch", "localtime")) as daynumber, ' \
|
||||||
'case cast (strftime("%w", datetime(started, "unixepoch", "localtime")) as integer) ' \
|
'case cast (strftime("%w", datetime(started, "unixepoch", "localtime")) as integer) ' \
|
||||||
|
@ -127,41 +137,57 @@ class Graphs(object):
|
||||||
'when 4 then "Thursday" ' \
|
'when 4 then "Thursday" ' \
|
||||||
'when 5 then "Friday" ' \
|
'when 5 then "Friday" ' \
|
||||||
'else "Saturday" end as dayofweek, ' \
|
'else "Saturday" end as dayofweek, ' \
|
||||||
'SUM(case when stopped > 0 then (stopped - started) ' \
|
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as duration ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \
|
||||||
'from session_history ' \
|
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \
|
||||||
|
'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_duration ' \
|
||||||
|
'FROM session_history ' \
|
||||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime") ' \
|
||||||
'(media_type = "episode" OR media_type = "movie") ' \
|
|
||||||
'GROUP BY dayofweek ' \
|
'GROUP BY dayofweek ' \
|
||||||
'ORDER BY daynumber'
|
'ORDER BY daynumber'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total duration'
|
|
||||||
|
|
||||||
days_list = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
|
days_list = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
|
||||||
'Thursday', 'Friday', 'Saturday']
|
'Thursday', 'Friday', 'Saturday']
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
series_1 = []
|
series_1 = []
|
||||||
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
for day_item in days_list:
|
for day_item in days_list:
|
||||||
categories.append(day_item)
|
categories.append(day_item)
|
||||||
series_1_value = 0
|
series_1_value = 0
|
||||||
|
series_2_value = 0
|
||||||
|
series_3_value = 0
|
||||||
for item in result:
|
for item in result:
|
||||||
if day_item == item[1]:
|
if day_item == item[1]:
|
||||||
series_1_value = item[2]
|
series_1_value = item[2]
|
||||||
|
series_2_value = item[3]
|
||||||
|
series_3_value = item[4]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
series_1_value = 0
|
series_1_value = 0
|
||||||
|
series_2_value = 0
|
||||||
|
series_3_value = 0
|
||||||
|
|
||||||
series_1.append(series_1_value)
|
series_1.append(series_1_value)
|
||||||
|
series_2.append(series_2_value)
|
||||||
|
series_3.append(series_3_value)
|
||||||
|
|
||||||
series_1_output = {'name': y_axis_label,
|
series_1_output = {'name': 'TV',
|
||||||
'data': series_1}
|
'data': series_1}
|
||||||
|
series_2_output = {'name': 'Movies',
|
||||||
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Music',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_total_plays_per_hourofday(self, time_range='30', y_axis='plays'):
|
def get_total_plays_per_hourofday(self, time_range='30', y_axis='plays'):
|
||||||
|
@ -172,29 +198,31 @@ class Graphs(object):
|
||||||
|
|
||||||
if y_axis == 'plays':
|
if y_axis == 'plays':
|
||||||
query = 'select strftime("%H", datetime(started, "unixepoch", "localtime")) as hourofday, ' \
|
query = 'select strftime("%H", datetime(started, "unixepoch", "localtime")) as hourofday, ' \
|
||||||
'COUNT(id) ' \
|
'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 ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime") ' \
|
||||||
'(media_type = "episode" OR media_type = "movie") ' \
|
|
||||||
'GROUP BY hourofday ' \
|
'GROUP BY hourofday ' \
|
||||||
'ORDER BY hourofday'
|
'ORDER BY hourofday'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total plays'
|
|
||||||
else:
|
else:
|
||||||
query = 'select strftime("%H", datetime(started, "unixepoch", "localtime")) as hourofday, ' \
|
query = 'select strftime("%H", datetime(started, "unixepoch", "localtime")) as hourofday, ' \
|
||||||
'SUM(case when stopped > 0 then (stopped - started) ' \
|
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as duration ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \
|
||||||
|
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \
|
||||||
|
'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_duration ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
'WHERE datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime") ' \
|
||||||
'(media_type = "episode" OR media_type = "movie") ' \
|
|
||||||
'GROUP BY hourofday ' \
|
'GROUP BY hourofday ' \
|
||||||
'ORDER BY hourofday'
|
'ORDER BY hourofday'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total duration'
|
|
||||||
|
|
||||||
hours_list = ['00','01','02','03','04','05',
|
hours_list = ['00','01','02','03','04','05',
|
||||||
'06','07','08','09','10','11',
|
'06','07','08','09','10','11',
|
||||||
|
@ -203,24 +231,38 @@ class Graphs(object):
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
series_1 = []
|
series_1 = []
|
||||||
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
for hour_item in hours_list:
|
for hour_item in hours_list:
|
||||||
categories.append(hour_item)
|
categories.append(hour_item)
|
||||||
series_1_value = 0
|
series_1_value = 0
|
||||||
|
series_2_value = 0
|
||||||
|
series_3_value = 0
|
||||||
for item in result:
|
for item in result:
|
||||||
if hour_item == item[0]:
|
if hour_item == item[0]:
|
||||||
series_1_value = item[1]
|
series_1_value = item[1]
|
||||||
|
series_2_value = item[2]
|
||||||
|
series_3_value = item[3]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
series_1_value = 0
|
series_1_value = 0
|
||||||
|
series_2_value = 0
|
||||||
|
series_3_value = 0
|
||||||
|
|
||||||
series_1.append(series_1_value)
|
series_1.append(series_1_value)
|
||||||
|
series_2.append(series_2_value)
|
||||||
|
series_3.append(series_3_value)
|
||||||
|
|
||||||
series_1_output = {'name': y_axis_label,
|
series_1_output = {'name': 'TV',
|
||||||
'data': series_1}
|
'data': series_1}
|
||||||
|
series_2_output = {'name': 'Movies',
|
||||||
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Music',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_total_plays_per_month(self, y_axis='plays'):
|
def get_total_plays_per_month(self, y_axis='plays'):
|
||||||
|
@ -230,7 +272,8 @@ class Graphs(object):
|
||||||
if y_axis == 'plays':
|
if y_axis == 'plays':
|
||||||
query = 'SELECT strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) as datestring, ' \
|
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 = "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 = "movie" then 1 else 0 end) as movie_count, ' \
|
||||||
|
'SUM(case when media_type = "track" then 1 else 0 end) as music_count ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
|
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
|
||||||
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
|
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
|
||||||
|
@ -242,7 +285,9 @@ class Graphs(object):
|
||||||
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
|
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \
|
||||||
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
|
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \
|
||||||
|
'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_duration ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
|
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") ' \
|
||||||
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
|
'GROUP BY strftime("%Y-%m", datetime(started, "unixepoch", "localtime")) ' \
|
||||||
|
@ -260,6 +305,7 @@ class Graphs(object):
|
||||||
categories = []
|
categories = []
|
||||||
series_1 = []
|
series_1 = []
|
||||||
series_2 = []
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
for month_item in sorted(month_range):
|
for month_item in sorted(month_range):
|
||||||
dt = datetime.datetime(*month_item[:6])
|
dt = datetime.datetime(*month_item[:6])
|
||||||
|
@ -268,25 +314,31 @@ class Graphs(object):
|
||||||
categories.append(dt.strftime('%b %Y'))
|
categories.append(dt.strftime('%b %Y'))
|
||||||
series_1_value = 0
|
series_1_value = 0
|
||||||
series_2_value = 0
|
series_2_value = 0
|
||||||
|
series_3_value = 0
|
||||||
for item in result:
|
for item in result:
|
||||||
if date_string == item[0]:
|
if date_string == item[0]:
|
||||||
series_1_value = item[1]
|
series_1_value = item[1]
|
||||||
series_2_value = item[2]
|
series_2_value = item[2]
|
||||||
|
series_3_value = item[3]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
series_1_value = 0
|
series_1_value = 0
|
||||||
series_2_value = 0
|
series_2_value = 0
|
||||||
|
series_3_value = 0
|
||||||
|
|
||||||
series_1.append(series_1_value)
|
series_1.append(series_1_value)
|
||||||
series_2.append(series_2_value)
|
series_2.append(series_2_value)
|
||||||
|
series_3.append(series_3_value)
|
||||||
|
|
||||||
series_1_output = {'name': 'TV',
|
series_1_output = {'name': 'TV',
|
||||||
'data': series_1}
|
'data': series_1}
|
||||||
series_2_output = {'name': 'Movies',
|
series_2_output = {'name': 'Movies',
|
||||||
'data': series_2}
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Music',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output, series_2_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_total_plays_by_top_10_platforms(self, time_range='30', y_axis='plays'):
|
def get_total_plays_by_top_10_platforms(self, time_range='30', y_axis='plays'):
|
||||||
|
@ -297,44 +349,57 @@ class Graphs(object):
|
||||||
|
|
||||||
if y_axis == 'plays':
|
if y_axis == 'plays':
|
||||||
query = 'SELECT platform, ' \
|
query = 'SELECT platform, ' \
|
||||||
'count(id) as platform_count ' \
|
'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, ' \
|
||||||
|
'COUNT(id) as total_count ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE (datetime(stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime")) ' \
|
||||||
'(media_type = "episode" OR media_type = "movie") ' \
|
|
||||||
'GROUP BY platform ' \
|
'GROUP BY platform ' \
|
||||||
'ORDER BY platform_count DESC ' \
|
'ORDER BY total_count DESC ' \
|
||||||
'LIMIT 10'
|
'LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total plays'
|
|
||||||
else:
|
else:
|
||||||
query = 'SELECT platform, ' \
|
query = 'SELECT platform, ' \
|
||||||
|
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \
|
||||||
|
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \
|
||||||
|
'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_duration, ' \
|
||||||
'SUM(case when stopped > 0 then (stopped - started) ' \
|
'SUM(case when stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as duration ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'WHERE (datetime(stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime")) ' \
|
||||||
'(media_type = "episode" OR media_type = "movie") ' \
|
|
||||||
'GROUP BY platform ' \
|
'GROUP BY platform ' \
|
||||||
'ORDER BY duration DESC ' \
|
'ORDER BY total_duration DESC ' \
|
||||||
'LIMIT 10'
|
'LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total duration'
|
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
series_1 = []
|
series_1 = []
|
||||||
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
for item in result:
|
for item in result:
|
||||||
categories.append(item[0])
|
categories.append(item[0])
|
||||||
series_1.append(item[1])
|
series_1.append(item[1])
|
||||||
|
series_2.append(item[2])
|
||||||
|
series_3.append(item[3])
|
||||||
|
|
||||||
series_1_output = {'name': y_axis_label,
|
series_1_output = {'name': 'TV',
|
||||||
'data': series_1}
|
'data': series_1}
|
||||||
|
series_2_output = {'name': 'Movies',
|
||||||
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Music',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_total_plays_by_top_10_users(self, time_range='30', y_axis='plays'):
|
def get_total_plays_by_top_10_users(self, time_range='30', y_axis='plays'):
|
||||||
|
@ -347,48 +412,61 @@ class Graphs(object):
|
||||||
query = 'SELECT ' \
|
query = 'SELECT ' \
|
||||||
'(case when users.friendly_name is null then session_history.user else ' \
|
'(case when users.friendly_name is null then session_history.user else ' \
|
||||||
'users.friendly_name end) as friendly_name,' \
|
'users.friendly_name end) as friendly_name,' \
|
||||||
'count(session_history.id) as user_count ' \
|
'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, ' \
|
||||||
|
'COUNT(session_history.id) as total_count ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN users on session_history.user_id = users.user_id ' \
|
'JOIN users on session_history.user_id = users.user_id ' \
|
||||||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime")) ' \
|
||||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
|
||||||
'GROUP BY session_history.user_id ' \
|
'GROUP BY session_history.user_id ' \
|
||||||
'ORDER BY user_count DESC ' \
|
'ORDER BY total_count DESC ' \
|
||||||
'LIMIT 10'
|
'LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total plays'
|
|
||||||
else:
|
else:
|
||||||
query = 'SELECT ' \
|
query = 'SELECT ' \
|
||||||
'(case when users.friendly_name is null then session_history.user else ' \
|
'(case when users.friendly_name is null then session_history.user else ' \
|
||||||
'users.friendly_name end) as friendly_name,' \
|
'users.friendly_name end) as friendly_name,' \
|
||||||
|
'SUM(case when media_type = "episode" and stopped > 0 then (stopped - started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tv_duration, ' \
|
||||||
|
'SUM(case when media_type = "movie" and stopped > 0 then (stopped - started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as movie_duration, ' \
|
||||||
|
'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_duration, ' \
|
||||||
'SUM(case when stopped > 0 then (stopped - started) ' \
|
'SUM(case when stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as duration ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN users on session_history.user_id = users.user_id ' \
|
'JOIN users on session_history.user_id = users.user_id ' \
|
||||||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime")) ' \
|
||||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
|
||||||
'GROUP BY session_history.user_id ' \
|
'GROUP BY session_history.user_id ' \
|
||||||
'ORDER BY duration DESC ' \
|
'ORDER BY total_duration DESC ' \
|
||||||
'LIMIT 10'
|
'LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total duration'
|
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
series_1 = []
|
series_1 = []
|
||||||
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
for item in result:
|
for item in result:
|
||||||
categories.append(item[0])
|
categories.append(item[0])
|
||||||
series_1.append(item[1])
|
series_1.append(item[1])
|
||||||
|
series_2.append(item[2])
|
||||||
|
series_3.append(item[3])
|
||||||
|
|
||||||
series_1_output = {'name': y_axis_label,
|
series_1_output = {'name': 'TV',
|
||||||
'data': series_1}
|
'data': series_1}
|
||||||
|
series_2_output = {'name': 'Movies',
|
||||||
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Music',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_total_plays_per_stream_type(self, time_range='30', y_axis='plays'):
|
def get_total_plays_per_stream_type(self, time_range='30', y_axis='plays'):
|
||||||
|
@ -400,34 +478,43 @@ class Graphs(object):
|
||||||
try:
|
try:
|
||||||
if y_axis == 'plays':
|
if y_axis == 'plays':
|
||||||
query = 'SELECT date(session_history.started, "unixepoch", "localtime") as date_played, ' \
|
query = 'SELECT date(session_history.started, "unixepoch", "localtime") as date_played, ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "direct play" then 1 else 0 end) as dp_count, ' \
|
'SUM(case when session_history_media_info.video_decision = "direct play" ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "copy" then 1 else 0 end) as ds_count, ' \
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play") ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "transcode" then 1 else 0 end) as tc_count ' \
|
'then 1 else 0 end) as dp_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy") ' \
|
||||||
|
'then 1 else 0 end) as ds_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode") ' \
|
||||||
|
'then 1 else 0 end) as tc_count ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
||||||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-%s days", "localtime")) AND ' \
|
'datetime("now", "-%s days", "localtime")) AND ' \
|
||||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") ' \
|
||||||
'GROUP BY date_played ' \
|
'GROUP BY date_played ' \
|
||||||
'ORDER BY started ASC' % time_range
|
'ORDER BY started ASC' % time_range
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
else:
|
else:
|
||||||
query = 'SELECT date(session_history.started, "unixepoch", "localtime") as date_played, ' \
|
query = 'SELECT date(session_history.started, "unixepoch", "localtime") as date_played, ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "direct play" AND ' \
|
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
|
||||||
'session_history.stopped > 0 then (stopped - started) ' \
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "copy" AND ' \
|
'SUM(case when (session_history_media_info.video_decision = "copy" ' \
|
||||||
'session_history.stopped > 0 then (stopped - started) ' \
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "transcode" ' \
|
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
|
||||||
'AND session_history.stopped > 0 then (stopped - started) ' \
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
||||||
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'WHERE datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-%s days", "localtime") AND ' \
|
'datetime("now", "-%s days", "localtime") AND ' \
|
||||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") ' \
|
||||||
'GROUP BY date_played ' \
|
'GROUP BY date_played ' \
|
||||||
'ORDER BY started ASC' % time_range
|
'ORDER BY started ASC' % time_range
|
||||||
|
|
||||||
|
@ -476,7 +563,6 @@ class Graphs(object):
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output, series_2_output, series_3_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_total_plays_by_source_resolution(self, time_range='30', y_axis='plays'):
|
def get_total_plays_by_source_resolution(self, time_range='30', y_axis='plays'):
|
||||||
|
@ -486,50 +572,74 @@ class Graphs(object):
|
||||||
time_range = '30'
|
time_range = '30'
|
||||||
|
|
||||||
if y_axis == 'plays':
|
if y_axis == 'plays':
|
||||||
query = 'SELECT ' \
|
query = 'SELECT session_history_media_info.video_resolution AS resolution, ' \
|
||||||
'count(session_history.id) as play_count, ' \
|
'SUM(case when session_history_media_info.video_decision = "direct play" ' \
|
||||||
'session_history_media_info.video_resolution AS resolution ' \
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play") ' \
|
||||||
|
'then 1 else 0 end) as dp_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy") ' \
|
||||||
|
'then 1 else 0 end) as ds_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode") ' \
|
||||||
|
'then 1 else 0 end) as tc_count, ' \
|
||||||
|
'COUNT(session_history.id) as total_count ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN session_history_media_info on session_history.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info on session_history.id = session_history_media_info.id ' \
|
||||||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||||
'GROUP BY resolution ' \
|
'GROUP BY resolution ' \
|
||||||
'ORDER BY play_count DESC ' \
|
'ORDER BY total_count DESC ' \
|
||||||
'LIMIT 10'
|
'LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total plays'
|
|
||||||
else:
|
else:
|
||||||
query = 'SELECT ' \
|
query = 'SELECT session_history_media_info.video_resolution AS resolution,' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration, ' \
|
||||||
'SUM(case when stopped > 0 then (stopped - started) ' \
|
'SUM(case when stopped > 0 then (stopped - started) ' \
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as duration, ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
|
||||||
'session_history_media_info.video_resolution AS resolution ' \
|
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN session_history_media_info on session_history.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info on session_history.id = session_history_media_info.id ' \
|
||||||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||||
'GROUP BY resolution ' \
|
'GROUP BY resolution ' \
|
||||||
'ORDER BY duration DESC ' \
|
'ORDER BY total_duration DESC ' \
|
||||||
'LIMIT 10'
|
'LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total duration'
|
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
series_1 = []
|
series_1 = []
|
||||||
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
for item in result:
|
for item in result:
|
||||||
categories.append(item[1])
|
categories.append(item[0])
|
||||||
series_1.append(item[0])
|
series_1.append(item[1])
|
||||||
|
series_2.append(item[2])
|
||||||
|
series_3.append(item[3])
|
||||||
|
|
||||||
series_1_output = {'name': y_axis_label,
|
series_1_output = {'name': 'Direct Play',
|
||||||
'data': series_1}
|
'data': series_1}
|
||||||
|
series_2_output = {'name': 'Direct Stream',
|
||||||
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Transcode',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_total_plays_by_stream_resolution(self, time_range='30', y_axis='plays'):
|
def get_total_plays_by_stream_resolution(self, time_range='30', y_axis='plays'):
|
||||||
|
@ -540,7 +650,6 @@ class Graphs(object):
|
||||||
|
|
||||||
if y_axis == 'plays':
|
if y_axis == 'plays':
|
||||||
query = 'SELECT ' \
|
query = 'SELECT ' \
|
||||||
'count(session_history.id) as play_count, ' \
|
|
||||||
'(case when session_history_media_info.video_decision = "transcode" then ' \
|
'(case when session_history_media_info.video_decision = "transcode" then ' \
|
||||||
'(case ' \
|
'(case ' \
|
||||||
'when session_history_media_info.transcode_height <= 360 then "sd" ' \
|
'when session_history_media_info.transcode_height <= 360 then "sd" ' \
|
||||||
|
@ -550,22 +659,29 @@ class Graphs(object):
|
||||||
'when session_history_media_info.transcode_height <= 1080 then "1080" ' \
|
'when session_history_media_info.transcode_height <= 1080 then "1080" ' \
|
||||||
'when session_history_media_info.transcode_height <= 1440 then "QHD" ' \
|
'when session_history_media_info.transcode_height <= 1440 then "QHD" ' \
|
||||||
'when session_history_media_info.transcode_height <= 2160 then "4K" ' \
|
'when session_history_media_info.transcode_height <= 2160 then "4K" ' \
|
||||||
'else "unknown" end) else session_history_media_info.video_resolution end) as resolution ' \
|
'else "unknown" end) else session_history_media_info.video_resolution end) as resolution, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "direct play" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play") ' \
|
||||||
|
'then 1 else 0 end) as dp_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy") ' \
|
||||||
|
'then 1 else 0 end) as ds_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode") ' \
|
||||||
|
'then 1 else 0 end) as tc_count, ' \
|
||||||
|
'COUNT(session_history.id) as total_count ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN session_history_media_info on session_history.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info on session_history.id = session_history_media_info.id ' \
|
||||||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||||
'GROUP BY resolution ' \
|
'GROUP BY resolution ' \
|
||||||
'ORDER BY play_count DESC ' \
|
'ORDER BY total_count DESC ' \
|
||||||
'LIMIT 10'
|
'LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total plays'
|
|
||||||
else:
|
else:
|
||||||
query = 'SELECT ' \
|
query = 'SELECT ' \
|
||||||
'SUM(case when stopped > 0 then (stopped - started) ' \
|
|
||||||
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as duration, ' \
|
|
||||||
'(case when session_history_media_info.video_decision = "transcode" then ' \
|
'(case when session_history_media_info.video_decision = "transcode" then ' \
|
||||||
'(case ' \
|
'(case ' \
|
||||||
'when session_history_media_info.transcode_height <= 360 then "sd" ' \
|
'when session_history_media_info.transcode_height <= 360 then "sd" ' \
|
||||||
|
@ -575,31 +691,130 @@ class Graphs(object):
|
||||||
'when session_history_media_info.transcode_height <= 1080 then "1080" ' \
|
'when session_history_media_info.transcode_height <= 1080 then "1080" ' \
|
||||||
'when session_history_media_info.transcode_height <= 1440 then "QHD" ' \
|
'when session_history_media_info.transcode_height <= 1440 then "QHD" ' \
|
||||||
'when session_history_media_info.transcode_height <= 2160 then "4K" ' \
|
'when session_history_media_info.transcode_height <= 2160 then "4K" ' \
|
||||||
'else "unknown" end) else session_history_media_info.video_resolution end) as resolution ' \
|
'else "unknown" end) else session_history_media_info.video_resolution end) as resolution, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration, ' \
|
||||||
|
'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 session_history ' \
|
||||||
'JOIN session_history_media_info on session_history.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info on session_history.id = session_history_media_info.id ' \
|
||||||
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
'WHERE (datetime(session_history.stopped, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
'datetime("now", "-' + time_range + ' days", "localtime")) AND ' \
|
||||||
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie") ' \
|
||||||
'GROUP BY resolution ' \
|
'GROUP BY resolution ' \
|
||||||
'ORDER BY duration DESC ' \
|
'ORDER BY total_duration DESC ' \
|
||||||
'LIMIT 10'
|
'LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
y_axis_label = 'Total duration'
|
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
series_1 = []
|
series_1 = []
|
||||||
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
for item in result:
|
for item in result:
|
||||||
categories.append(item[1])
|
categories.append(item[0])
|
||||||
series_1.append(item[0])
|
series_1.append(item[1])
|
||||||
|
series_2.append(item[2])
|
||||||
|
series_3.append(item[3])
|
||||||
|
|
||||||
series_1_output = {'name': y_axis_label,
|
series_1_output = {'name': 'Direct Play',
|
||||||
'data': series_1}
|
'data': series_1}
|
||||||
|
series_2_output = {'name': 'Direct Stream',
|
||||||
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Transcode',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
output = {'categories': categories,
|
output = {'categories': categories,
|
||||||
'series': [series_1_output]}
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
|
return output
|
||||||
|
|
||||||
|
def get_stream_type_by_top_10_platforms(self, time_range='30', y_axis='plays'):
|
||||||
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
if not time_range.isdigit():
|
||||||
|
time_range = '30'
|
||||||
|
|
||||||
|
if y_axis == 'plays':
|
||||||
|
query = 'SELECT ' \
|
||||||
|
'session_history.platform as platform, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "direct play" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play") ' \
|
||||||
|
'then 1 else 0 end) as dp_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy") ' \
|
||||||
|
'then 1 else 0 end) as ds_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode") ' \
|
||||||
|
'then 1 else 0 end) as tc_count, ' \
|
||||||
|
'COUNT(session_history.id) as total_count ' \
|
||||||
|
'FROM session_history ' \
|
||||||
|
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
||||||
|
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
|
||||||
|
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
||||||
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") ' \
|
||||||
|
'GROUP BY platform ' \
|
||||||
|
'ORDER BY total_count DESC LIMIT 10'
|
||||||
|
|
||||||
|
result = monitor_db.select(query)
|
||||||
|
else:
|
||||||
|
query = 'SELECT ' \
|
||||||
|
'session_history.platform as platform, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration, ' \
|
||||||
|
'SUM(case when session_history.stopped > 0 ' \
|
||||||
|
'then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
|
||||||
|
'FROM session_history ' \
|
||||||
|
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
||||||
|
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
|
||||||
|
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
||||||
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") ' \
|
||||||
|
'GROUP BY platform ' \
|
||||||
|
'ORDER BY total_duration DESC LIMIT 10'
|
||||||
|
|
||||||
|
result = monitor_db.select(query)
|
||||||
|
|
||||||
|
categories = []
|
||||||
|
series_1 = []
|
||||||
|
series_2 = []
|
||||||
|
series_3 = []
|
||||||
|
|
||||||
|
for item in result:
|
||||||
|
categories.append(item[0])
|
||||||
|
series_1.append(item[1])
|
||||||
|
series_2.append(item[2])
|
||||||
|
series_3.append(item[3])
|
||||||
|
|
||||||
|
series_1_output = {'name': 'Direct Play',
|
||||||
|
'data': series_1}
|
||||||
|
series_2_output = {'name': 'Direct Stream',
|
||||||
|
'data': series_2}
|
||||||
|
series_3_output = {'name': 'Transcode',
|
||||||
|
'data': series_3}
|
||||||
|
|
||||||
|
output = {'categories': categories,
|
||||||
|
'series': [series_1_output, series_2_output, series_3_output]}
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
@ -612,15 +827,22 @@ class Graphs(object):
|
||||||
if y_axis == 'plays':
|
if y_axis == 'plays':
|
||||||
query = 'SELECT ' \
|
query = 'SELECT ' \
|
||||||
'CASE WHEN users.friendly_name is null then users.username else users.friendly_name end as username, ' \
|
'CASE WHEN users.friendly_name is null then users.username else users.friendly_name end as username, ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "direct play" then 1 else 0 end) as dp_count, ' \
|
'SUM(case when session_history_media_info.video_decision = "direct play" ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "copy" then 1 else 0 end) as ds_count, ' \
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play") ' \
|
||||||
'SUM(case when session_history_media_info.video_decision = "transcode" then 1 else 0 end) as tr_count, ' \
|
'then 1 else 0 end) as dp_count, ' \
|
||||||
'SUM(case when session_history.media_type != "track" then 1 else 0 end) as total_count ' \
|
'SUM(case when session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy") ' \
|
||||||
|
'then 1 else 0 end) as ds_count, ' \
|
||||||
|
'SUM(case when session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode") ' \
|
||||||
|
'then 1 else 0 end) as tc_count, ' \
|
||||||
|
'COUNT(session_history.id) as total_count ' \
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN users ON session_history.user_id = users.user_id ' \
|
'JOIN users ON session_history.user_id = users.user_id ' \
|
||||||
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
||||||
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
|
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime") ' \
|
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
||||||
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") ' \
|
||||||
'GROUP BY username ' \
|
'GROUP BY username ' \
|
||||||
'ORDER BY total_count DESC LIMIT 10'
|
'ORDER BY total_count DESC LIMIT 10'
|
||||||
|
|
||||||
|
@ -628,91 +850,29 @@ class Graphs(object):
|
||||||
else:
|
else:
|
||||||
query = 'SELECT ' \
|
query = 'SELECT ' \
|
||||||
'CASE WHEN users.friendly_name is null then users.username else users.friendly_name end as username, ' \
|
'CASE WHEN users.friendly_name is null then users.username else users.friendly_name end as username, ' \
|
||||||
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "direct play" ' \
|
'SUM(case when (session_history_media_info.video_decision = "direct play" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "direct play")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as dp_duration, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "copy" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "copy")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as ds_duration, ' \
|
||||||
|
'SUM(case when (session_history_media_info.video_decision = "transcode" ' \
|
||||||
|
'or (session_history_media_info.video_decision = "" and session_history_media_info.audio_decision = "transcode")) ' \
|
||||||
|
'and session_history.stopped > 0 then (session_history.stopped - session_history.started) ' \
|
||||||
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as tc_duration, ' \
|
||||||
|
'SUM(case when session_history.stopped > 0 ' \
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
'then (session_history.stopped - session_history.started) ' \
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) else 0 end) as dp_count, ' \
|
' - (case when paused_counter is NULL then 0 else paused_counter end) else 0 end) as total_duration ' \
|
||||||
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "copy" ' \
|
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) else 0 end) as ds_count, ' \
|
|
||||||
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "transcode" ' \
|
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) else 0 end) as tr_count, ' \
|
|
||||||
'SUM(case when session_history.stopped > 0 AND session_history.media_type != "track" ' \
|
|
||||||
'then (session_history.stopped - session_history.started) else 0 end) as total_count ' \
|
|
||||||
'FROM session_history ' \
|
'FROM session_history ' \
|
||||||
'JOIN users ON session_history.user_id = users.user_id ' \
|
'JOIN users ON session_history.user_id = users.user_id ' \
|
||||||
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
||||||
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
|
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime") ' \
|
'datetime("now", "-' + time_range + ' days", "localtime") AND ' \
|
||||||
|
'(session_history.media_type = "episode" OR session_history.media_type = "movie" OR session_history.media_type = "track") ' \
|
||||||
'GROUP BY username ' \
|
'GROUP BY username ' \
|
||||||
'ORDER BY total_count DESC LIMIT 10'
|
'ORDER BY total_duration DESC LIMIT 10'
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
|
||||||
|
|
||||||
categories = []
|
|
||||||
series_1 = []
|
|
||||||
series_2 = []
|
|
||||||
series_3 = []
|
|
||||||
|
|
||||||
for item in result:
|
|
||||||
categories.append(item[0])
|
|
||||||
series_1.append(item[1])
|
|
||||||
series_2.append(item[2])
|
|
||||||
series_3.append(item[3])
|
|
||||||
|
|
||||||
series_1_output = {'name': 'Direct Play',
|
|
||||||
'data': series_1}
|
|
||||||
series_2_output = {'name': 'Direct Stream',
|
|
||||||
'data': series_2}
|
|
||||||
series_3_output = {'name': 'Transcode',
|
|
||||||
'data': series_3}
|
|
||||||
|
|
||||||
output = {'categories': categories,
|
|
||||||
'series': [series_1_output, series_2_output, series_3_output]}
|
|
||||||
|
|
||||||
return output
|
|
||||||
|
|
||||||
def get_stream_type_by_top_10_platforms(self, time_range='30', y_axis='plays'):
|
|
||||||
monitor_db = database.MonitorDatabase()
|
|
||||||
|
|
||||||
if not time_range.isdigit():
|
|
||||||
time_range = '30'
|
|
||||||
|
|
||||||
if y_axis == 'plays':
|
|
||||||
query = 'SELECT ' \
|
|
||||||
'session_history.platform as platform, ' \
|
|
||||||
'SUM(case when session_history_media_info.video_decision = "direct play" then 1 else 0 end) as dp_count, ' \
|
|
||||||
'SUM(case when session_history_media_info.video_decision = "copy" then 1 else 0 end) as ds_count, ' \
|
|
||||||
'SUM(case when session_history_media_info.video_decision = "transcode" then 1 else 0 end) as tr_count, ' \
|
|
||||||
'SUM(case when session_history.media_type != "track" then 1 else 0 end) as total_count ' \
|
|
||||||
'FROM session_history ' \
|
|
||||||
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
|
||||||
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
|
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime") ' \
|
|
||||||
'GROUP BY platform ' \
|
|
||||||
'ORDER BY total_count DESC LIMIT 10'
|
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
|
||||||
else:
|
|
||||||
query = 'SELECT ' \
|
|
||||||
'session_history.platform as platform, ' \
|
|
||||||
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "direct play" ' \
|
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) else 0 end) as dp_count, ' \
|
|
||||||
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "copy" ' \
|
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) else 0 end) as ds_count, ' \
|
|
||||||
'SUM(case when session_history.stopped > 0 AND session_history_media_info.video_decision = "transcode" ' \
|
|
||||||
'then (session_history.stopped - session_history.started) ' \
|
|
||||||
' - (case when session_history.paused_counter is NULL then 0 else session_history.paused_counter end) else 0 end) as tr_count, ' \
|
|
||||||
'SUM(case when session_history.stopped > 0 AND session_history.media_type != "track" ' \
|
|
||||||
'then (session_history.stopped - session_history.started) else 0 end) as total_count ' \
|
|
||||||
'FROM session_history ' \
|
|
||||||
'JOIN session_history_media_info ON session_history.id = session_history_media_info.id ' \
|
|
||||||
'WHERE datetime(session_history.started, "unixepoch", "localtime") >= ' \
|
|
||||||
'datetime("now", "-' + time_range + ' days", "localtime") ' \
|
|
||||||
'GROUP BY platform ' \
|
|
||||||
'ORDER BY total_count DESC LIMIT 10'
|
|
||||||
|
|
||||||
result = monitor_db.select(query)
|
result = monitor_db.select(query)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue