mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 21:51:14 -07:00
Add duration to history table footer
This commit is contained in:
parent
b51d442673
commit
f9f65eae53
4 changed files with 50 additions and 13 deletions
|
@ -18,7 +18,7 @@ history_table_options = {
|
||||||
"lengthMenu":"Show _MENU_ entries per page",
|
"lengthMenu":"Show _MENU_ entries per page",
|
||||||
"info":"Showing _START_ to _END_ of _TOTAL_ history items",
|
"info":"Showing _START_ to _END_ of _TOTAL_ history items",
|
||||||
"infoEmpty":"Showing 0 to 0 of 0 entries",
|
"infoEmpty":"Showing 0 to 0 of 0 entries",
|
||||||
"infoFiltered":"(filtered from _MAX_ total entries)",
|
"infoFiltered":"<span class='hidden-md hidden-sm hidden-xs'>(filtered from _MAX_ total entries)</span>",
|
||||||
"emptyTable": "No data in table"
|
"emptyTable": "No data in table"
|
||||||
},
|
},
|
||||||
"pagingType": "bootstrap",
|
"pagingType": "bootstrap",
|
||||||
|
@ -265,6 +265,9 @@ history_table_options = {
|
||||||
createChildTable(this, rowData)
|
createChildTable(this, rowData)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#history_table_info").append('<span class="hidden-md hidden-sm hidden-xs"> with a duration of ' + settings.json.filter_duration +
|
||||||
|
' (filtered from ' + settings.json.total_duration + ' total)</span>');
|
||||||
},
|
},
|
||||||
"preDrawCallback": function(settings) {
|
"preDrawCallback": function(settings) {
|
||||||
var msg = "<i class='fa fa-refresh fa-spin'></i> Fetching rows...";
|
var msg = "<i class='fa fa-refresh fa-spin'></i> Fetching rows...";
|
||||||
|
|
|
@ -45,7 +45,7 @@ class DataFactory(object):
|
||||||
'platform',
|
'platform',
|
||||||
'player',
|
'player',
|
||||||
'ip_address',
|
'ip_address',
|
||||||
'session_history_metadata.media_type',
|
'session_history.media_type',
|
||||||
'session_history_metadata.rating_key',
|
'session_history_metadata.rating_key',
|
||||||
'session_history_metadata.parent_rating_key',
|
'session_history_metadata.parent_rating_key',
|
||||||
'session_history_metadata.grandparent_rating_key',
|
'session_history_metadata.grandparent_rating_key',
|
||||||
|
@ -80,7 +80,7 @@ class DataFactory(object):
|
||||||
['session_history.id', 'session_history_media_info.id']],
|
['session_history.id', 'session_history_media_info.id']],
|
||||||
kwargs=kwargs)
|
kwargs=kwargs)
|
||||||
except:
|
except:
|
||||||
logger.warn("Unable to execute database query.")
|
logger.warn("Unable to execute database query for get_history.")
|
||||||
return {'recordsFiltered': 0,
|
return {'recordsFiltered': 0,
|
||||||
'recordsTotal': 0,
|
'recordsTotal': 0,
|
||||||
'draw': 0,
|
'draw': 0,
|
||||||
|
@ -89,8 +89,13 @@ class DataFactory(object):
|
||||||
|
|
||||||
history = query['result']
|
history = query['result']
|
||||||
|
|
||||||
|
filter_duration = 0
|
||||||
|
total_duration = self.get_total_duration(custom_where=custom_where)
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for item in history:
|
for item in history:
|
||||||
|
filter_duration += int(item['duration'])
|
||||||
|
|
||||||
if item["media_type"] == 'episode' and item["parent_thumb"]:
|
if item["media_type"] == 'episode' and item["parent_thumb"]:
|
||||||
thumb = item["parent_thumb"]
|
thumb = item["parent_thumb"]
|
||||||
elif item["media_type"] == 'episode':
|
elif item["media_type"] == 'episode':
|
||||||
|
@ -144,7 +149,9 @@ class DataFactory(object):
|
||||||
dict = {'recordsFiltered': query['filteredCount'],
|
dict = {'recordsFiltered': query['filteredCount'],
|
||||||
'recordsTotal': query['totalCount'],
|
'recordsTotal': query['totalCount'],
|
||||||
'data': rows,
|
'data': rows,
|
||||||
'draw': query['draw']
|
'draw': query['draw'],
|
||||||
|
'filter_duration': helpers.human_duration(filter_duration, sig='dhm'),
|
||||||
|
'total_duration': helpers.human_duration(total_duration, sig='dhm')
|
||||||
}
|
}
|
||||||
|
|
||||||
return dict
|
return dict
|
||||||
|
@ -1083,3 +1090,26 @@ class DataFactory(object):
|
||||||
ip_address = item['ip_address']
|
ip_address = item['ip_address']
|
||||||
|
|
||||||
return ip_address
|
return ip_address
|
||||||
|
|
||||||
|
def get_total_duration(self, custom_where=None):
|
||||||
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
# Split up custom wheres
|
||||||
|
if custom_where:
|
||||||
|
where = 'WHERE ' + ' AND '.join([w[0] + ' = "' + w[1] + '"' for w in custom_where])
|
||||||
|
else:
|
||||||
|
where = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
query = 'SELECT SUM(CASE WHEN stopped > 0 THEN (stopped - started) ELSE 0 END) - ' \
|
||||||
|
'SUM(CASE WHEN paused_counter IS NULL THEN 0 ELSE paused_counter END) AS total_duration ' \
|
||||||
|
'FROM session_history %s ' % where
|
||||||
|
result = monitor_db.select(query)
|
||||||
|
except:
|
||||||
|
logger.warn("Unable to execute database query for get_total_duration.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
for item in result:
|
||||||
|
total_duration = item['total_duration']
|
||||||
|
|
||||||
|
return total_duration
|
|
@ -146,7 +146,7 @@ def now():
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
return now.strftime("%Y-%m-%d %H:%M:%S")
|
return now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
def human_duration(s):
|
def human_duration(s, sig='dhms'):
|
||||||
|
|
||||||
hd = ''
|
hd = ''
|
||||||
|
|
||||||
|
@ -157,20 +157,24 @@ def human_duration(s):
|
||||||
s = int(((s % 84600) % 3600) % 60)
|
s = int(((s % 84600) % 3600) % 60)
|
||||||
|
|
||||||
hd_list = []
|
hd_list = []
|
||||||
if d > 0:
|
if sig >= 'd' and d > 0:
|
||||||
|
d = d + 1 if sig == 'd' and h >= 12 else d
|
||||||
hd_list.append(str(d) + ' days')
|
hd_list.append(str(d) + ' days')
|
||||||
if h > 0:
|
|
||||||
|
if sig >= 'dh' and h > 0:
|
||||||
|
h = h + 1 if sig == 'dh' and m >= 30 else h
|
||||||
hd_list.append(str(h) + ' hrs')
|
hd_list.append(str(h) + ' hrs')
|
||||||
if m > 0:
|
|
||||||
|
if sig >= 'dhm' and m > 0:
|
||||||
|
m = m + 1 if sig == 'dhm' and s >= 30 else m
|
||||||
hd_list.append(str(m) + ' mins')
|
hd_list.append(str(m) + ' mins')
|
||||||
if s > 0:
|
|
||||||
|
if sig >= 'dhms' and s > 0:
|
||||||
hd_list.append(str(s) + ' secs')
|
hd_list.append(str(s) + ' secs')
|
||||||
|
|
||||||
hd = ' '.join(hd_list)
|
hd = ' '.join(hd_list)
|
||||||
|
|
||||||
return hd
|
return hd
|
||||||
else:
|
|
||||||
return hd
|
|
||||||
|
|
||||||
def get_age(date):
|
def get_age(date):
|
||||||
|
|
||||||
|
|
|
@ -617,7 +617,7 @@ class WebInterface(object):
|
||||||
if 'media_type' in kwargs:
|
if 'media_type' in kwargs:
|
||||||
media_type = kwargs.get('media_type', "")
|
media_type = kwargs.get('media_type', "")
|
||||||
if media_type != 'all':
|
if media_type != 'all':
|
||||||
custom_where.append(['session_history_metadata.media_type', media_type])
|
custom_where.append(['session_history.media_type', media_type])
|
||||||
|
|
||||||
data_factory = datafactory.DataFactory()
|
data_factory = datafactory.DataFactory()
|
||||||
history = data_factory.get_history(kwargs=kwargs, custom_where=custom_where, grouping=grouping, watched_percent=watched_percent)
|
history = data_factory.get_history(kwargs=kwargs, custom_where=custom_where, grouping=grouping, watched_percent=watched_percent)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue