Update library and user watch time query to match homepage

This commit is contained in:
JonnyWong16 2021-06-05 08:54:13 -07:00
parent 895d67fad3
commit 092d858b12
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 8 additions and 4 deletions

View file

@ -902,6 +902,8 @@ class Libraries(object):
else:
query_days = [1, 7, 30, 0]
timestamp = helpers.timestamp()
monitor_db = database.MonitorDatabase()
library_watch_time_stats = []
@ -909,7 +911,7 @@ class Libraries(object):
group_by = 'session_history.reference_id' if grouping else 'session_history.id'
for days in query_days:
timestamp = int((datetime.now(tz=plexpy.SYS_TIMEZONE) - timedelta(days=days)).timestamp())
timestamp_query = timestamp - days * 24 * 60 * 60
try:
if days > 0:
@ -920,7 +922,7 @@ class Libraries(object):
'FROM session_history ' \
'JOIN session_history_metadata ON session_history_metadata.id = session_history.id ' \
'WHERE stopped >= %s ' \
'AND section_id = ?' % (group_by, timestamp)
'AND section_id = ?' % (group_by, timestamp_query)
result = monitor_db.select(query, args=[section_id])
else:
result = []

View file

@ -494,6 +494,8 @@ class Users(object):
else:
query_days = [1, 7, 30, 0]
timestamp = helpers.timestamp()
monitor_db = database.MonitorDatabase()
user_watch_time_stats = []
@ -501,7 +503,7 @@ class Users(object):
group_by = 'reference_id' if grouping else 'id'
for days in query_days:
timestamp = int((datetime.now(tz=plexpy.SYS_TIMEZONE) - timedelta(days=days)).timestamp())
timestamp_query = timestamp - days * 24 * 60 * 60
try:
if days > 0:
@ -511,7 +513,7 @@ class Users(object):
'COUNT(DISTINCT %s) AS total_plays ' \
'FROM session_history ' \
'WHERE stopped >= %s ' \
'AND user_id = ? ' % (group_by, timestamp)
'AND user_id = ? ' % (group_by, timestamp_query)
result = monitor_db.select(query, args=[user_id])
else:
result = []