Private
Public Access
1
0

with jquery to refresh when tasks are complete

jquery lives in basebase.html. Perhaps should live in individual pages
This commit is contained in:
Sander Roosendaal
2017-10-30 22:32:34 +01:00
parent 21be4d278b
commit 98abc68289
5 changed files with 41 additions and 9 deletions

View File

@@ -65,7 +65,7 @@ def processattachment(rower, fileobj, title, uploadoptions):
workoutcsvfilename = workout.csvfilename[6:-4] workoutcsvfilename = workout.csvfilename[6:-4]
timestr = strftime("%Y%m%d-%H%M%S") timestr = strftime("%Y%m%d-%H%M%S")
imagename = workoutcsvfilename + timestr + '.png' imagename = workoutcsvfilename + timestr + '.png'
result = uploads.make_plot( result,jobid = uploads.make_plot(
workout.user, workout, workoutcsvfilename, workout.user, workout, workoutcsvfilename,
workout.csvfilename, workout.csvfilename,
plottype, title, plottype, title,

View File

@@ -6,6 +6,7 @@
{% block content %} {% block content %}
<h1>Your Tasks Status</h1> <h1>Your Tasks Status</h1>
<p>Manage the asynchronous tasks running for you</p> <p>Manage the asynchronous tasks running for you</p>

View File

@@ -175,11 +175,11 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
if settings.DEBUG: if settings.DEBUG:
res = handle_makeplot.delay(f1,f2,title, job = handle_makeplot.delay(f1,f2,title,
hrpwrdata,plotnr, hrpwrdata,plotnr,
imagename) imagename)
else: else:
res = queue.enqueue(handle_makeplot,f1,f2, job = queue.enqueue(handle_makeplot,f1,f2,
title,hrpwrdata, title,hrpwrdata,
plotnr,imagename) plotnr,imagename)
@@ -195,7 +195,7 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
width=width,height=height) width=width,height=height)
i.save() i.save()
return i.id return i.id,job.id
import c2stuff,stravastuff,sporttracksstuff,runkeeperstuff import c2stuff,stravastuff,sporttracksstuff,runkeeperstuff
import underarmourstuff,tpstuff import underarmourstuff,tpstuff

View File

@@ -208,7 +208,8 @@ def get_job_result(jobid):
verbose_job_status = { verbose_job_status = {
'updatecp': 'Critical Power Calculation for Ergometer Workouts', 'updatecp': 'Critical Power Calculation for Ergometer Workouts',
'updatecpwater': 'Critical Power Calculation for OTW Workouts', 'updatecpwater': 'Critical Power Calculation for OTW Workouts',
'otwsetpower': 'Rowing Physics OTW Power Calculation' 'otwsetpower': 'Rowing Physics OTW Power Calculation',
'make_plot': 'Create static chart',
} }
def get_job_status(jobid): def get_job_status(jobid):
@@ -3539,7 +3540,7 @@ def oterankings_view(request,theuser=0,
request.session['async_tasks'] += [(job.id,'updatecp')] request.session['async_tasks'] += [(job.id,'updatecp')]
except KeyError: except KeyError:
request.session['async_tasks'] = [(job.id,'updatecp')] request.session['async_tasks'] = [(job.id,'updatecp')]
messages.info(request,'New calculation queued. Refresh page or resubmit the date form to get the result') messages.info(request,'New calculation queued.')
powerdf = pd.DataFrame({ powerdf = pd.DataFrame({
'Delta':delta, 'Delta':delta,
@@ -7468,9 +7469,14 @@ def workout_add_chart_view(request,id,plotnr=1):
u = w.user.user u = w.user.user
r = getrower(u) r = getrower(u)
title = w.name title = w.name
res = uploads.make_plot(r,w,f1,w.csvfilename,'timeplot',title,plotnr=plotnr, res,jobid = uploads.make_plot(
imagename=imagename) r,w,f1,w.csvfilename,'timeplot',title,plotnr=plotnr,
imagename=imagename
)
try:
request.session['async_tasks'] += [(jobid,'make_plot')]
except KeyError:
request.session['async_tasks'] = [(jobid,'make_plot')]
try: try:
url = request.session['referer'] url = request.session['referer']

View File

@@ -9,6 +9,31 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en"> <html lang="en">
<head> <head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
var previous = null;
var current = null;
$(document).ready(function() {
$.getJSON('http://localhost:8000/rowers/list-jobs/', function(json) {
current = JSON.stringify(json);
previous = current;
});
console.log('initial poll');
});
setInterval(function() {
$.getJSON('http://localhost:8000/rowers/list-jobs/', function(json) {
current = JSON.stringify(json);
if (previous && current && previous !== current) {
console.log('refresh');
location.reload();
};
previous = current;
});
console.log('polling');
}, 15000)
</script>
<script src="/static/cookielaw/js/cookielaw.js"></script> <script src="/static/cookielaw/js/cookielaw.js"></script>
{% analytical_head_top %} {% analytical_head_top %}
{% if GOOGLE_ANALYTICS_PROPERTY_ID %} {% if GOOGLE_ANALYTICS_PROPERTY_ID %}