mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-14 01:02:59 -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:
|
Optional parameters:
|
||||||
grouping (int): 0 or 1
|
grouping (int): 0 or 1
|
||||||
time_range (str): The time range to calculate statistics, '30'
|
time_range (int): The time range to calculate statistics, 30
|
||||||
stats_type (str): plays or duration
|
stats_type (str): 'plays' or 'duration'
|
||||||
stats_count (str): The number of top items to list, '5'
|
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:
|
Returns:
|
||||||
json:
|
json:
|
||||||
|
|
|
@ -296,9 +296,12 @@ class DataFactory(object):
|
||||||
|
|
||||||
return dict
|
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()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
if stat_id:
|
||||||
|
stats_cards = [stat_id]
|
||||||
if grouping is None:
|
if grouping is None:
|
||||||
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
grouping = plexpy.CONFIG.GROUP_HISTORY_TABLES
|
||||||
if stats_cards is None:
|
if stats_cards is None:
|
||||||
|
@ -331,7 +334,7 @@ class DataFactory(object):
|
||||||
' GROUP BY %s) AS t ' \
|
' GROUP BY %s) AS t ' \
|
||||||
'GROUP BY t.full_title, t.year ' \
|
'GROUP BY t.full_title, t.year ' \
|
||||||
'ORDER BY %s DESC, started DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_movies: %s." % 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 %s) AS t ' \
|
||||||
'GROUP BY t.full_title, t.year ' \
|
'GROUP BY t.full_title, t.year ' \
|
||||||
'ORDER BY users_watched DESC, %s DESC, started DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: popular_movies: %s." % 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 %s) AS t ' \
|
||||||
'GROUP BY t.grandparent_title ' \
|
'GROUP BY t.grandparent_title ' \
|
||||||
'ORDER BY %s DESC, started DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_tv: %s." % 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 %s) AS t ' \
|
||||||
'GROUP BY t.grandparent_title ' \
|
'GROUP BY t.grandparent_title ' \
|
||||||
'ORDER BY users_watched DESC, %s DESC, started DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: popular_tv: %s." % 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 %s) AS t ' \
|
||||||
'GROUP BY t.original_title, t.grandparent_title ' \
|
'GROUP BY t.original_title, t.grandparent_title ' \
|
||||||
'ORDER BY %s DESC, started DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_music: %s." % 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 %s) AS t ' \
|
||||||
'GROUP BY t.original_title, t.grandparent_title ' \
|
'GROUP BY t.original_title, t.grandparent_title ' \
|
||||||
'ORDER BY users_watched DESC, %s DESC, started DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: popular_music: %s." % 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 %s) AS t ' \
|
||||||
'GROUP BY t.user_id ' \
|
'GROUP BY t.user_id ' \
|
||||||
'ORDER BY %s DESC, started DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_users: %s." % 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 %s) AS t ' \
|
||||||
'GROUP BY t.platform ' \
|
'GROUP BY t.platform ' \
|
||||||
'ORDER BY %s DESC, started DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_platforms: %s." % 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 ' \
|
' OR t.media_type == "episode" AND percent_complete >= %s ' \
|
||||||
'GROUP BY t.id ' \
|
'GROUP BY t.id ' \
|
||||||
'ORDER BY last_watch DESC ' \
|
'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)
|
result = monitor_db.select(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: last_watched: %s." % 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',
|
'stat_title': 'Most Concurrent Streams',
|
||||||
'rows': most_concurrent})
|
'rows': most_concurrent})
|
||||||
|
|
||||||
|
if stat_id and home_stats:
|
||||||
|
return home_stats[0]
|
||||||
return home_stats
|
return home_stats
|
||||||
|
|
||||||
def get_library_stats(self, library_cards=[]):
|
def get_library_stats(self, library_cards=[]):
|
||||||
|
|
|
@ -5911,7 +5911,8 @@ class WebInterface(object):
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
@addtoapi()
|
@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.
|
""" Get the homepage watch statistics.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -5920,9 +5921,13 @@ class WebInterface(object):
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
grouping (int): 0 or 1
|
grouping (int): 0 or 1
|
||||||
time_range (str): The time range to calculate statistics, '30'
|
time_range (int): The time range to calculate statistics, 30
|
||||||
stats_type (str): plays or duration
|
stats_type (str): 'plays' or 'duration'
|
||||||
stats_count (str): The number of top items to list, '5'
|
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:
|
Returns:
|
||||||
json:
|
json:
|
||||||
|
@ -5999,7 +6004,9 @@ class WebInterface(object):
|
||||||
result = data_factory.get_home_stats(grouping=grouping,
|
result = data_factory.get_home_stats(grouping=grouping,
|
||||||
time_range=time_range,
|
time_range=time_range,
|
||||||
stats_type=stats_type,
|
stats_type=stats_type,
|
||||||
stats_count=stats_count)
|
stats_start=stats_start,
|
||||||
|
stats_count=stats_count,
|
||||||
|
stat_id=stat_id)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue