mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-14 09:12:58 -07:00
Add stat_id and stats_start options to get_home_stats API
This commit is contained in:
parent
d97b87d9cc
commit
da7c66f414
3 changed files with 35 additions and 18 deletions
10
API.md
10
API.md
|
@ -930,9 +930,13 @@ Required parameters:
|
|||
|
||||
Optional parameters:
|
||||
grouping (int): 0 or 1
|
||||
time_range (str): The time range to calculate statistics, '30'
|
||||
stats_type (str): plays or duration
|
||||
stats_count (str): The number of top items to list, '5'
|
||||
time_range (int): The time range to calculate statistics, 30
|
||||
stats_type (str): 'plays' or 'duration'
|
||||
stats_start (int) The row number of the stat item to start at, 0
|
||||
stats_count (int): The number of stat items to return, 5
|
||||
stat_id (str): A single stat to return, 'top_movies', 'popular_movies',
|
||||
'top_tv', 'popular_tv', 'top_music', 'popular_music',
|
||||
'top_users', 'top_platforms', 'last_watched', 'most_concurrent'
|
||||
|
||||
Returns:
|
||||
json:
|
||||
|
|
|
@ -296,9 +296,12 @@ class DataFactory(object):
|
|||
|
||||
return dict
|
||||
|
||||
def get_home_stats(self, grouping=None, time_range=30, stats_type='plays', stats_count=10, stats_cards=None):
|
||||
def get_home_stats(self, grouping=None, time_range=30, stats_type='plays',
|
||||
stats_start=0, stats_count=10, stat_id='', stats_cards=None):
|
||||
monitor_db = database.MonitorDatabase()
|
||||
|
||||
if stat_id:
|
||||
stats_cards = [stat_id]
|
||||
if grouping is None:
|
||||
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
||||
if stats_cards is None:
|
||||
|
@ -331,7 +334,7 @@ class DataFactory(object):
|
|||
' GROUP BY %s) AS t ' \
|
||||
'GROUP BY t.full_title, t.year ' \
|
||||
'ORDER BY %s DESC, started DESC ' \
|
||||
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||
'LIMIT %s OFFSET %s ' % (time_range, group_by, sort_type, stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_movies: %s." % e)
|
||||
|
@ -383,7 +386,7 @@ class DataFactory(object):
|
|||
' GROUP BY %s) AS t ' \
|
||||
'GROUP BY t.full_title, t.year ' \
|
||||
'ORDER BY users_watched DESC, %s DESC, started DESC ' \
|
||||
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||
'LIMIT %s OFFSET %s ' % (time_range, group_by, sort_type, stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: popular_movies: %s." % e)
|
||||
|
@ -432,7 +435,7 @@ class DataFactory(object):
|
|||
' GROUP BY %s) AS t ' \
|
||||
'GROUP BY t.grandparent_title ' \
|
||||
'ORDER BY %s DESC, started DESC ' \
|
||||
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||
'LIMIT %s OFFSET %s ' % (time_range, group_by, sort_type, stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_tv: %s." % e)
|
||||
|
@ -484,7 +487,7 @@ class DataFactory(object):
|
|||
' GROUP BY %s) AS t ' \
|
||||
'GROUP BY t.grandparent_title ' \
|
||||
'ORDER BY users_watched DESC, %s DESC, started DESC ' \
|
||||
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||
'LIMIT %s OFFSET %s ' % (time_range, group_by, sort_type, stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: popular_tv: %s." % e)
|
||||
|
@ -534,7 +537,7 @@ class DataFactory(object):
|
|||
' GROUP BY %s) AS t ' \
|
||||
'GROUP BY t.original_title, t.grandparent_title ' \
|
||||
'ORDER BY %s DESC, started DESC ' \
|
||||
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||
'LIMIT %s OFFSET %s ' % (time_range, group_by, sort_type, stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_music: %s." % e)
|
||||
|
@ -587,7 +590,7 @@ class DataFactory(object):
|
|||
' GROUP BY %s) AS t ' \
|
||||
'GROUP BY t.original_title, t.grandparent_title ' \
|
||||
'ORDER BY users_watched DESC, %s DESC, started DESC ' \
|
||||
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||
'LIMIT %s OFFSET %s ' % (time_range, group_by, sort_type, stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: popular_music: %s." % e)
|
||||
|
@ -637,7 +640,7 @@ class DataFactory(object):
|
|||
' GROUP BY %s) AS t ' \
|
||||
'GROUP BY t.user_id ' \
|
||||
'ORDER BY %s DESC, started DESC ' \
|
||||
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||
'LIMIT %s OFFSET %s ' % (time_range, group_by, sort_type, stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_users: %s." % e)
|
||||
|
@ -689,7 +692,7 @@ class DataFactory(object):
|
|||
' GROUP BY %s) AS t ' \
|
||||
'GROUP BY t.platform ' \
|
||||
'ORDER BY %s DESC, started DESC ' \
|
||||
'LIMIT %s ' % (time_range, group_by, sort_type, stats_count)
|
||||
'LIMIT %s OFFSET %s ' % (time_range, group_by, sort_type, stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_platforms: %s." % e)
|
||||
|
@ -746,7 +749,8 @@ class DataFactory(object):
|
|||
' OR t.media_type == "episode" AND percent_complete >= %s ' \
|
||||
'GROUP BY t.id ' \
|
||||
'ORDER BY last_watch DESC ' \
|
||||
'LIMIT %s' % (time_range, group_by, movie_watched_percent, tv_watched_percent, stats_count)
|
||||
'LIMIT %s OFFSET %s' % (time_range, group_by, movie_watched_percent, tv_watched_percent,
|
||||
stats_count, stats_start)
|
||||
result = monitor_db.select(query)
|
||||
except Exception as e:
|
||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: last_watched: %s." % e)
|
||||
|
@ -864,6 +868,8 @@ class DataFactory(object):
|
|||
'stat_title': 'Most Concurrent Streams',
|
||||
'rows': most_concurrent})
|
||||
|
||||
if stat_id and home_stats:
|
||||
return home_stats[0]
|
||||
return home_stats
|
||||
|
||||
def get_library_stats(self, library_cards=[]):
|
||||
|
|
|
@ -5911,7 +5911,8 @@ class WebInterface(object):
|
|||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def get_home_stats(self, time_range=30, stats_type='plays', stats_count=10, grouping=None, **kwargs):
|
||||
def get_home_stats(self, grouping=None, time_range=30, stats_type='plays',
|
||||
stats_start=0, stats_count=10, stat_id='', **kwargs):
|
||||
""" Get the homepage watch statistics.
|
||||
|
||||
```
|
||||
|
@ -5920,9 +5921,13 @@ class WebInterface(object):
|
|||
|
||||
Optional parameters:
|
||||
grouping (int): 0 or 1
|
||||
time_range (str): The time range to calculate statistics, '30'
|
||||
stats_type (str): plays or duration
|
||||
stats_count (str): The number of top items to list, '5'
|
||||
time_range (int): The time range to calculate statistics, 30
|
||||
stats_type (str): 'plays' or 'duration'
|
||||
stats_start (int) The row number of the stat item to start at, 0
|
||||
stats_count (int): The number of stat items to return, 5
|
||||
stat_id (str): A single stat to return, 'top_movies', 'popular_movies',
|
||||
'top_tv', 'popular_tv', 'top_music', 'popular_music',
|
||||
'top_users', 'top_platforms', 'last_watched', 'most_concurrent'
|
||||
|
||||
Returns:
|
||||
json:
|
||||
|
@ -5999,7 +6004,9 @@ class WebInterface(object):
|
|||
result = data_factory.get_home_stats(grouping=grouping,
|
||||
time_range=time_range,
|
||||
stats_type=stats_type,
|
||||
stats_count=stats_count)
|
||||
stats_start=stats_start,
|
||||
stats_count=stats_count,
|
||||
stat_id=stat_id)
|
||||
|
||||
if result:
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue