Add button to regroup play history

This commit is contained in:
JonnyWong16 2023-07-07 13:26:11 -07:00
parent 1fe6d1505f
commit b144e6527f
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
3 changed files with 49 additions and 8 deletions

View file

@ -132,12 +132,6 @@
</label>
<p class="help-block">Change the "<em>Play by day of week</em>" graph to start on Monday. Default is start on Sunday.</p>
</div>
<div class="checkbox advanced-setting">
<label>
<input type="checkbox" id="group_history_tables" name="group_history_tables" value="1" ${config['group_history_tables']}> Group Play History
</label>
<p class="help-block">Group play history for the same item and user as a single entry when progress is less than the watched percent.</p>
</div>
<div class="checkbox advanced-setting">
<label>
<input type="checkbox" id="history_table_activity" name="history_table_activity" value="1" ${config['history_table_activity']}> Current Activity in History Tables
@ -227,6 +221,25 @@
</div>
<p class="help-block">Decide whether to use end credits markers to determine the 'watched' state of video items. When markers are not available the selected threshold percentage will be used.</p>
</div>
<div class="checkbox advanced-setting">
<label>
<input type="checkbox" id="group_history_tables" name="group_history_tables" value="1" ${config['group_history_tables']}> Group Play History
</label>
<p class="help-block">Group play history for the same item and user as a single entry when progress is less than the watched percent.</p>
</div>
<div class="form-group advanced-setting">
<label>Regroup Play History</label>
<p class="help-block">
Fix grouping of play history in the database.<br />
</p>
<div class="row">
<div class="col-md-4">
<div class="btn-group">
<button class="btn btn-form" type="button" id="regroup_history">Regroup</button>
</div>
</div>
</div>
</div>
<div class="form-group advanced-setting">
<label>Flush Temporary Sessions</label>
<p class="help-block">
@ -2484,6 +2497,12 @@ $(document).ready(function() {
confirmAjaxCall(url, msg);
});
$("#regroup_history").click(function () {
var msg = 'Are you sure you want to regroup play history in the database?';
var url = 'regroup_history';
confirmAjaxCall(url, msg, null, 'Regrouping play history...');
});
$("#delete_temp_sessions").click(function () {
var msg = 'Are you sure you want to flush the temporary sessions?<br /><br /><strong>This will reset all currently active sessions.</strong>';
var url = 'delete_temp_sessions';

View file

@ -709,7 +709,8 @@ class ActivityProcessor(object):
def regroup_history(self):
logger.info("Tautulli ActivityProcessor :: Creating database backup...")
database.make_backup()
if not database.make_backup():
return False
logger.info("Tautulli ActivityProcessor :: Regrouping session history...")
@ -720,6 +721,11 @@ class ActivityProcessor(object):
results = self.db.select(query)
for session in results:
self.group_history(session['id'], session)
try:
self.group_history(session['id'], session)
except Exception as e:
logger.error("Tautulli ActivityProcessor :: Error regrouping session history: %s", e)
return False
logger.info("Tautulli ActivityProcessor :: Regrouping session history complete.")
return True

View file

@ -51,6 +51,7 @@ if sys.version_info >= (3, 6):
import plexpy
if plexpy.PYTHON2:
import activity_pinger
import activity_processor
import common
import config
import database
@ -85,6 +86,7 @@ if plexpy.PYTHON2:
import macos
else:
from plexpy import activity_pinger
from plexpy import activity_processor
from plexpy import common
from plexpy import config
from plexpy import database
@ -434,6 +436,20 @@ class WebInterface(object):
logger.warn("Unable to retrieve data for get_recently_added.")
return serve_template(template_name="recently_added.html", data=None)
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
@addtoapi()
def regroup_history(self, **kwargs):
""" Regroup play history in the database."""
result = activity_processor.ActivityProcessor().regroup_history()
if result:
return {'result': 'success', 'message': 'Regrouped play history.'}
else:
return {'result': 'error', 'message': 'Regrouping play history failed.'}
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))