Add total time result to user player stats

This commit is contained in:
JonnyWong16 2022-01-03 12:55:42 -08:00
parent cd59e1d4c4
commit 925a16e66d
No known key found for this signature in database
GPG key ID: 7A649674469E6574
2 changed files with 12 additions and 7 deletions

View file

@ -564,11 +564,13 @@ class Users(object):
try:
if str(user_id).isdigit():
query = 'SELECT player, COUNT(DISTINCT %s) as player_count, platform ' \
query = 'SELECT player, COUNT(DISTINCT %s) as total_plays, (SUM(stopped - started) - ' \
'SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END)) AS total_time, ' \
'platform ' \
'FROM session_history ' \
'WHERE user_id = ? ' \
'GROUP BY player ' \
'ORDER BY player_count DESC' % group_by
'ORDER BY total_plays DESC, total_time DESC' % group_by
result = monitor_db.select(query, args=[user_id])
else:
result = []
@ -584,7 +586,8 @@ class Users(object):
row = {'player_name': item['player'],
'platform': platform,
'platform_name': platform_name,
'total_plays': item['player_count'],
'total_plays': item['total_plays'],
'total_time': item['total_time'],
'result_id': result_id
}
player_stats.append(row)

View file

@ -1069,14 +1069,14 @@ class WebInterface(object):
json:
[{"friendly_name": "Jon Snow",
"total_plays": 170,
"total_time": 349618
"total_time": 349618,
"user_id": 133788,
"user_thumb": "https://plex.tv/users/k10w42309cynaopq/avatar",
"username": "LordCommanderSnow"
},
{"friendly_name": "DanyKhaleesi69",
"total_plays": 42,
"total_time": 50185
"total_time": 50185,
"user_id": 8008135,
"user_thumb": "https://plex.tv/users/568gwwoib5t98a3a/avatar",
"username: "DanyKhaleesi69"
@ -1744,12 +1744,14 @@ class WebInterface(object):
[{"platform_type": "Chrome",
"player_name": "Plex Web (Chrome)",
"result_id": 1,
"total_plays": 170
"total_plays": 170,
"total_time": 349618
},
{"platform_type": "Chromecast",
"player_name": "Chromecast",
"result_id": 2,
"total_plays": 42
"total_plays": 42,
"total_time": 50185
},
{...},
{...}