mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-13 16:52:58 -07:00
Change months in Plays by Month graph
Add an option on the Graphs > Play Totals > Plays by Month page to change the amount of months the graph shows data for.
This commit is contained in:
parent
3742f33d08
commit
b9a22461c1
4 changed files with 60 additions and 18 deletions
|
@ -291,8 +291,11 @@ class Graphs(object):
|
|||
'series': [series_1_output, series_2_output, series_3_output]}
|
||||
return output
|
||||
|
||||
def get_total_plays_per_month(self, y_axis='plays', user_id=None):
|
||||
def get_total_plays_per_month(self, time_range='12', y_axis='plays', user_id=None):
|
||||
import time as time
|
||||
|
||||
if not time_range.isdigit():
|
||||
time_range = '12'
|
||||
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
|
@ -309,9 +312,9 @@ class Graphs(object):
|
|||
'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(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") %s' \
|
||||
'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 12' % (user_cond)
|
||||
'ORDER BY datestring DESC LIMIT %s' % (time_range, user_cond, time_range)
|
||||
|
||||
result = monitor_db.select(query)
|
||||
else:
|
||||
|
@ -323,18 +326,20 @@ class Graphs(object):
|
|||
'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 ' \
|
||||
'WHERE datetime(started, "unixepoch", "localtime") >= datetime("now", "-12 months", "localtime") %s' \
|
||||
'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 12' % (user_cond)
|
||||
'ORDER BY datestring DESC LIMIT %s' % (time_range, user_cond, time_range)
|
||||
|
||||
result = monitor_db.select(query)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn(u"PlexPy Graphs :: Unable to execute database query for get_total_plays_per_month: %s." % e)
|
||||
return None
|
||||
|
||||
# create our date range as some months may not have any data
|
||||
# but we still want to display them
|
||||
x = 12
|
||||
time_range = int(time_range)
|
||||
x = time_range
|
||||
|
||||
base = time.localtime()
|
||||
month_range = [time.localtime(
|
||||
time.mktime((base.tm_year, base.tm_mon - n, 1, 0, 0, 0, 0, 0, 0))) for n in range(x)]
|
||||
|
|
|
@ -1747,6 +1747,7 @@ class WebInterface(object):
|
|||
config = {
|
||||
"graph_type": plexpy.CONFIG.GRAPH_TYPE,
|
||||
"graph_days": plexpy.CONFIG.GRAPH_DAYS,
|
||||
"graph_months": 12,
|
||||
"graph_tab": plexpy.CONFIG.GRAPH_TAB,
|
||||
"music_logging_enable": plexpy.CONFIG.MUSIC_LOGGING_ENABLE
|
||||
}
|
||||
|
@ -1755,13 +1756,15 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
@requireAuth(member_of("admin"))
|
||||
def set_graph_config(self, graph_type=None, graph_days=None, graph_tab=None, **kwargs):
|
||||
def set_graph_config(self, graph_type=None, graph_days=None, graph_months=None, graph_tab=None, **kwargs):
|
||||
if graph_type:
|
||||
plexpy.CONFIG.__setattr__('GRAPH_TYPE', graph_type)
|
||||
plexpy.CONFIG.write()
|
||||
if graph_days:
|
||||
plexpy.CONFIG.__setattr__('GRAPH_DAYS', graph_days)
|
||||
plexpy.CONFIG.write()
|
||||
if graph_months:
|
||||
pass
|
||||
if graph_tab:
|
||||
plexpy.CONFIG.__setattr__('GRAPH_TAB', graph_tab)
|
||||
plexpy.CONFIG.write()
|
||||
|
@ -1908,7 +1911,7 @@ class WebInterface(object):
|
|||
@cherrypy.tools.json_out()
|
||||
@requireAuth()
|
||||
@addtoapi()
|
||||
def get_plays_per_month(self, y_axis='plays', user_id=None, **kwargs):
|
||||
def get_plays_per_month(self, time_range='12', y_axis='plays', user_id=None, **kwargs):
|
||||
""" Get graph data by month.
|
||||
|
||||
```
|
||||
|
@ -1916,7 +1919,7 @@ class WebInterface(object):
|
|||
None
|
||||
|
||||
Optional parameters:
|
||||
time_range (str): The number of days of data to return
|
||||
time_range (str): The number of months of data to return
|
||||
y_axis (str): "plays" or "duration"
|
||||
user_id (str): The user id to filter the data
|
||||
|
||||
|
@ -1933,7 +1936,7 @@ class WebInterface(object):
|
|||
```
|
||||
"""
|
||||
graph = graphs.Graphs()
|
||||
result = graph.get_total_plays_per_month(y_axis=y_axis, user_id=user_id)
|
||||
result = graph.get_total_plays_per_month(time_range=time_range, y_axis=y_axis, user_id=user_id)
|
||||
|
||||
if result:
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue