Private
Public Access
1
0

Merge branch 'release/v4.66'

This commit is contained in:
Sander Roosendaal
2017-10-31 15:08:06 +01:00
10 changed files with 441 additions and 234 deletions
+1 -2
View File
@@ -472,7 +472,7 @@ def delete_strokedata(id,debug=False):
engine.dispose() engine.dispose()
def update_strokedata(id,df,debug=False): def update_strokedata(id,df,debug=False):
delete_strokedata(id) delete_strokedata(id,debug=debug)
if debug: if debug:
print "updating ",id print "updating ",id
rowdata = dataprep(df,id=id,bands=True,barchart=True,otwpower=True, rowdata = dataprep(df,id=id,bands=True,barchart=True,otwpower=True,
@@ -935,7 +935,6 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True,
# write data if id given # write data if id given
if id != 0: if id != 0:
data['workoutid'] = id
if debug: if debug:
engine = create_engine(database_url_debug, echo=False) engine = create_engine(database_url_debug, echo=False)
else: else:
+1 -1
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,
+52 -28
View File
@@ -30,7 +30,7 @@ from rowers.dataprepnodjango import (
) )
from django.core.mail import send_mail, EmailMessage from django.core.mail import send_mail, EmailMessage
from django.db.utils import OperationalError
import datautils import datautils
import utils import utils
@@ -50,7 +50,7 @@ def handle_new_workout_from_file(r, f2,
workouttype='rower', workouttype='rower',
title='Workout', title='Workout',
makeprivate=False, makeprivate=False,
notes=''): notes='',debug=False):
return new_workout_from_file(r, f2, workouttype, return new_workout_from_file(r, f2, workouttype,
title, makeprivate, notes) title, makeprivate, notes)
@@ -92,7 +92,8 @@ def handle_updatedps(useremail, workoutids, debug=False):
@app.task @app.task
def handle_sendemail_breakthrough(workoutid, useremail, def handle_sendemail_breakthrough(workoutid, useremail,
userfirstname, userlastname, userfirstname, userlastname,
btvalues=pd.DataFrame().to_json()): btvalues=pd.DataFrame().to_json(),
debug=False):
# send email with attachment # send email with attachment
subject = "A breakthrough workout on rowsandall.com" subject = "A breakthrough workout on rowsandall.com"
@@ -151,7 +152,8 @@ def handle_sendemail_breakthrough(workoutid, useremail,
@app.task @app.task
def handle_sendemail_hard(workoutid, useremail, def handle_sendemail_hard(workoutid, useremail,
userfirstname, userlastname, userfirstname, userlastname,
btvalues=pd.DataFrame().to_json()): btvalues=pd.DataFrame().to_json(),
debug=False):
# send email with attachment # send email with attachment
subject = "That was a pretty hard workout on rowsandall.com" subject = "That was a pretty hard workout on rowsandall.com"
@@ -183,7 +185,8 @@ def handle_sendemail_hard(workoutid, useremail,
# send email to me when an unrecognized file is uploaded # send email to me when an unrecognized file is uploaded
@app.task @app.task
def handle_sendemail_unrecognized(unrecognizedfile, useremail): def handle_sendemail_unrecognized(unrecognizedfile, useremail,
debug=False):
# send email with attachment # send email with attachment
fullemail = 'roosendaalsander@gmail.com' fullemail = 'roosendaalsander@gmail.com'
@@ -215,7 +218,8 @@ def handle_sendemail_unrecognized(unrecognizedfile, useremail):
# send email to owner when an unrecognized file is uploaded # send email to owner when an unrecognized file is uploaded
@app.task @app.task
def handle_sendemail_unrecognizedowner(useremail, userfirstname): def handle_sendemail_unrecognizedowner(useremail, userfirstname,
debug=False):
# send email with attachment # send email with attachment
fullemail = useremail fullemail = useremail
@@ -246,7 +250,7 @@ def handle_sendemail_unrecognizedowner(useremail, userfirstname):
# Send email with TCX attachment # Send email with TCX attachment
@app.task @app.task
def handle_sendemailtcx(first_name, last_name, email, tcxfile): def handle_sendemailtcx(first_name, last_name, email, tcxfile,debug=False):
# send email with attachment # send email with attachment
fullemail = first_name + " " + last_name + " " + "<" + email + ">" fullemail = first_name + " " + last_name + " " + "<" + email + ">"
@@ -269,7 +273,7 @@ def handle_sendemailtcx(first_name, last_name, email, tcxfile):
@app.task @app.task
def handle_zip_file(emailfrom, subject, file): def handle_zip_file(emailfrom, subject, file,debug=False):
message = "... zip processing ... " message = "... zip processing ... "
email = EmailMessage(subject, message, email = EmailMessage(subject, message,
emailfrom, emailfrom,
@@ -283,7 +287,7 @@ def handle_zip_file(emailfrom, subject, file):
@app.task @app.task
def handle_sendemailcsv(first_name, last_name, email, csvfile): def handle_sendemailcsv(first_name, last_name, email, csvfile,debug=False):
# send email with attachment # send email with attachment
fullemail = first_name + " " + last_name + " " + "<" + email + ">" fullemail = first_name + " " + last_name + " " + "<" + email + ">"
@@ -365,7 +369,9 @@ def handle_otwsetpower(f1, boattype, weightvalue,
totaltime = totaltime + rowdata.df.ix[0, ' ElapsedTime (sec)'] totaltime = totaltime + rowdata.df.ix[0, ' ElapsedTime (sec)']
except KeyError: except KeyError:
pass pass
df = getsmallrowdata_db(['power', 'workoutid', 'time'], ids=[workoutid]) df = getsmallrowdata_db(
['power', 'workoutid', 'time'], ids=[workoutid],
debug=debug)
thesecs = totaltime thesecs = totaltime
maxt = 1.05 * thesecs maxt = 1.05 * thesecs
logarr = datautils.getlogarr(maxt) logarr = datautils.getlogarr(maxt)
@@ -376,9 +382,13 @@ def handle_otwsetpower(f1, boattype, weightvalue,
res, btvalues, res2 = utils.isbreakthrough( res, btvalues, res2 = utils.isbreakthrough(
delta, cpvalues, ps[0], ps[1], ps[2], ps[3], ratio) delta, cpvalues, ps[0], ps[1], ps[2], ps[3], ratio)
if res: if res:
handle_sendemail_breakthrough(workoutid, email, try:
first_name, handle_sendemail_breakthrough(
last_name, btvalues=btvalues.to_json()) workoutid, email,
first_name,
last_name, btvalues=btvalues.to_json())
except:
pass
# send email # send email
fullemail = first_name + " " + last_name + " " + "<" + email + ">" fullemail = first_name + " " + last_name + " " + "<" + email + ">"
@@ -394,9 +404,12 @@ def handle_otwsetpower(f1, boattype, weightvalue,
message += "Please report any bugs/inconsistencies/unexpected results at rowsandall.slack.com or by reply to this email.\n\n" message += "Please report any bugs/inconsistencies/unexpected results at rowsandall.slack.com or by reply to this email.\n\n"
message += "Best Regards, The Rowsandall Physics Department." message += "Best Regards, The Rowsandall Physics Department."
send_mail(subject, message, try:
'Rowsandall Physics Department <info@rowsandall.com>', send_mail(subject, message,
[fullemail]) 'Rowsandall Physics Department <info@rowsandall.com>',
[fullemail])
except:
return 0
return 1 return 1
@@ -440,7 +453,8 @@ def handle_updatecp(rower_id,workoutids,debug=False,table='cpdata'):
return 1 return 1
@app.task @app.task
def handle_makeplot(f1, f2, t, hrdata, plotnr, imagename): def handle_makeplot(f1, f2, t, hrdata, plotnr, imagename,
debug=False):
hrmax = hrdata['hrmax'] hrmax = hrdata['hrmax']
hrut2 = hrdata['hrut2'] hrut2 = hrdata['hrut2']
@@ -512,7 +526,8 @@ def handle_makeplot(f1, f2, t, hrdata, plotnr, imagename):
@app.task @app.task
def handle_sendemail_invite(email, name, code, teamname, manager): def handle_sendemail_invite(email, name, code, teamname, manager,
debug=False):
fullemail = name + ' <' + email + '>' fullemail = name + ' <' + email + '>'
subject = 'Invitation to join team ' + teamname subject = 'Invitation to join team ' + teamname
message = 'Dear ' + name + ',\n\n' message = 'Dear ' + name + ',\n\n'
@@ -553,7 +568,8 @@ def handle_sendemailnewresponse(first_name, last_name,
commenter_first_name, commenter_first_name,
commenter_last_name, commenter_last_name,
comment, comment,
workoutname, workoutid, commentid): workoutname, workoutid, commentid,
debug=False):
fullemail = first_name + ' ' + last_name + ' <' + email + '>' fullemail = first_name + ' ' + last_name + ' <' + email + '>'
subject = 'New comment on workout ' + workoutname subject = 'New comment on workout ' + workoutname
message = 'Dear ' + first_name + ',\n\n' message = 'Dear ' + first_name + ',\n\n'
@@ -587,7 +603,8 @@ def handle_sendemailnewcomment(first_name,
commenter_first_name, commenter_first_name,
commenter_last_name, commenter_last_name,
comment, workoutname, comment, workoutname,
workoutid): workoutid,
debug=False):
fullemail = first_name + ' ' + last_name + ' <' + email + '>' fullemail = first_name + ' ' + last_name + ' <' + email + '>'
subject = 'New comment on workout ' + workoutname subject = 'New comment on workout ' + workoutname
message = 'Dear ' + first_name + ',\n\n' message = 'Dear ' + first_name + ',\n\n'
@@ -610,7 +627,8 @@ def handle_sendemailnewcomment(first_name,
@app.task @app.task
def handle_sendemail_request(email, name, code, teamname, requestor, id): def handle_sendemail_request(email, name, code, teamname, requestor, id,
debug=False):
fullemail = name + ' <' + email + '>' fullemail = name + ' <' + email + '>'
subject = 'Request to join team ' + teamname subject = 'Request to join team ' + teamname
message = 'Dear ' + name + ',\n\n' message = 'Dear ' + name + ',\n\n'
@@ -634,7 +652,8 @@ def handle_sendemail_request(email, name, code, teamname, requestor, id):
@app.task @app.task
def handle_sendemail_request_accept(email, name, teamname, managername): def handle_sendemail_request_accept(email, name, teamname, managername,
debug=False):
fullemail = name + ' <' + email + '>' fullemail = name + ' <' + email + '>'
subject = 'Welcome to ' + teamname subject = 'Welcome to ' + teamname
message = 'Dear ' + name + ',\n\n' message = 'Dear ' + name + ',\n\n'
@@ -654,7 +673,8 @@ def handle_sendemail_request_accept(email, name, teamname, managername):
@app.task @app.task
def handle_sendemail_request_reject(email, name, teamname, managername): def handle_sendemail_request_reject(email, name, teamname, managername,
debug=False):
fullemail = name + ' <' + email + '>' fullemail = name + ' <' + email + '>'
subject = 'Your application to ' + teamname + ' was rejected' subject = 'Your application to ' + teamname + ' was rejected'
message = 'Dear ' + name + ',\n\n' message = 'Dear ' + name + ',\n\n'
@@ -675,7 +695,8 @@ def handle_sendemail_request_reject(email, name, teamname, managername):
@app.task @app.task
def handle_sendemail_member_dropped(email, name, teamname, managername): def handle_sendemail_member_dropped(email, name, teamname, managername,
debug=False):
fullemail = name + ' <' + email + '>' fullemail = name + ' <' + email + '>'
subject = 'You were removed from ' + teamname subject = 'You were removed from ' + teamname
message = 'Dear ' + name + ',\n\n' message = 'Dear ' + name + ',\n\n'
@@ -696,7 +717,8 @@ def handle_sendemail_member_dropped(email, name, teamname, managername):
@app.task @app.task
def handle_sendemail_team_removed(email, name, teamname, managername): def handle_sendemail_team_removed(email, name, teamname, managername,
debug=False):
fullemail = name + ' <' + email + '>' fullemail = name + ' <' + email + '>'
subject = 'Team ' + teamname + ' was deleted' subject = 'Team ' + teamname + ' was deleted'
message = 'Dear ' + name + ',\n\n' message = 'Dear ' + name + ',\n\n'
@@ -718,7 +740,8 @@ def handle_sendemail_team_removed(email, name, teamname, managername):
@app.task @app.task
def handle_sendemail_invite_reject(email, name, teamname, managername): def handle_sendemail_invite_reject(email, name, teamname, managername,
debug=False):
fullemail = managername + ' <' + email + '>' fullemail = managername + ' <' + email + '>'
subject = 'Your invitation to ' + name + ' was rejected' subject = 'Your invitation to ' + name + ' was rejected'
message = 'Dear ' + managername + ',\n\n' message = 'Dear ' + managername + ',\n\n'
@@ -739,7 +762,8 @@ def handle_sendemail_invite_reject(email, name, teamname, managername):
@app.task @app.task
def handle_sendemail_invite_accept(email, name, teamname, managername): def handle_sendemail_invite_accept(email, name, teamname, managername,
debug=False):
fullemail = managername + ' <' + email + '>' fullemail = managername + ' <' + email + '>'
subject = 'Your invitation to ' + name + ' was accepted' subject = 'Your invitation to ' + name + ' was accepted'
message = 'Dear ' + managername + ',\n\n' message = 'Dear ' + managername + ',\n\n'
@@ -756,5 +780,5 @@ def handle_sendemail_invite_accept(email, name, teamname, managername):
# Another simple task for debugging purposes # Another simple task for debugging purposes
def add2(x, y): def add2(x, y,debug=False):
return x + y return x + y
+24 -42
View File
@@ -9,6 +9,7 @@ from django.db import IntegrityError
import uuid import uuid
from django.conf import settings from django.conf import settings
from utils import myqueue
import django_rq import django_rq
queue = django_rq.get_queue('default') queue = django_rq.get_queue('default')
@@ -289,11 +290,9 @@ def send_invite_email(id):
teamname = invitation.team.name teamname = invitation.team.name
manager = invitation.team.manager.first_name+' '+invitation.team.manager.last_name manager = invitation.team.manager.first_name+' '+invitation.team.manager.last_name
if settings.DEBUG: res = myqueue(queuehigh,
res = handle_sendemail_invite.delay(email,name,code,teamname,manager) handle_sendemail_invite,
else: email,name,code,teamname,manager)
res = queuehigh.enqueue(handle_sendemail_invite,
email,name,code,teamname,manager)
return (1,'Invitation email sent') return (1,'Invitation email sent')
@@ -303,11 +302,9 @@ def send_team_delete_mail(t,rower):
email = u.email email = u.email
name = u.first_name+' '+u.last_name name = u.first_name+' '+u.last_name
manager = t.manager.first_name+' '+t.manager.last_name manager = t.manager.first_name+' '+t.manager.last_name
if settings.DEBUG: res = myqueue(queuehigh,
res = handle_sendemail_team_removed.delay(email,name,teamname,manager) handle_sendemail_team_removed,
else: email,name,teamname,manager)
res = queuehigh.enqueue(handle_sendemail_team_removed,
email,name,teamname,manager)
return (1,'Team delete email sent') return (1,'Team delete email sent')
@@ -319,11 +316,8 @@ def send_email_member_dropped(teamid,rower):
name = u.first_name+' '+u.last_name name = u.first_name+' '+u.last_name
manager = t.manager.first_name+' '+t.manager.last_name manager = t.manager.first_name+' '+t.manager.last_name
if settings.DEBUG: res = myqueue(queuehigh,handle_sendemail_member_dropped,
res = handle_sendemail_member_dropped.delay(email,name,teamname,manager) email,name,teamname,manager)
else:
res = queuehigh.enqueue(handle_sendemail_member_dropped,
email,name,teamname,manager)
return (1,'Member dropped email sent') return (1,'Member dropped email sent')
@@ -334,12 +328,9 @@ def send_request_accept_email(rekwest):
teamname = rekwest.team.name teamname = rekwest.team.name
name = rekwest.user.first_name+' '+rekwest.user.last_name name = rekwest.user.first_name+' '+rekwest.user.last_name
manager = rekwest.team.manager.first_name+' '+rekwest.team.manager.last_name manager = rekwest.team.manager.first_name+' '+rekwest.team.manager.last_name
res = myqueue(queuehigh,
if settings.DEBUG: handle_sendemail_request_accept,
res = handle_sendemail_request_accept.delay(email,name,teamname,manager) email,name,teamname,manager)
else:
res = queuehigh.enqueue(handle_sendemail_request_accept,
email,name,teamname,manager)
return (1,'Invitation email sent') return (1,'Invitation email sent')
@@ -351,11 +342,9 @@ def send_request_reject_email(rekwest):
name = rekwest.user.first_name+' '+rekwest.user.last_name name = rekwest.user.first_name+' '+rekwest.user.last_name
manager = rekwest.team.manager.first_name+' '+rekwest.team.manager.last_name manager = rekwest.team.manager.first_name+' '+rekwest.team.manager.last_name
if settings.DEBUG: res = myqueue(queuehigh,
res = handle_sendemail_request_reject.delay(email,name,teamname,manager) handle_sendemail_request_reject,
else: email,name,teamname,manager)
res = queuehigh.enqueue(handle_sendemail_request_reject,
email,name,teamname,manager)
return (1,'Invitation email sent') return (1,'Invitation email sent')
@@ -371,11 +360,9 @@ def send_invite_reject_email(invitation):
teamname = invitation.team.name teamname = invitation.team.name
manager = invitation.team.manager.first_name+' '+invitation.team.manager.last_name manager = invitation.team.manager.first_name+' '+invitation.team.manager.last_name
if settings.DEBUG: res = myqueue(queuehigh,
res = handle_sendemail_invite_reject.delay(email,name,teamname,manager) handle_sendemail_invite_reject,
else: email,name,teamname,manager)
res = queuehigh.enqueue(handle_sendemail_invite_reject,
email,name,teamname,manager)
return (1,'Invitation email sent') return (1,'Invitation email sent')
@@ -391,11 +378,9 @@ def send_invite_accept_email(invitation):
teamname = invitation.team.name teamname = invitation.team.name
manager = invitation.team.manager.first_name+' '+invitation.team.manager.last_name manager = invitation.team.manager.first_name+' '+invitation.team.manager.last_name
if settings.DEBUG: res = myqueue(queuehigh,
res = handle_sendemail_invite_accept.delay(email,name,teamname,manager) handle_sendemail_invite_accept,
else: email,name,teamname,manager)
res = queuehigh.enqueue(handle_sendemail_invite_accept,
email,name,teamname,manager)
return (1,'Invitation email sent') return (1,'Invitation email sent')
@@ -409,12 +394,9 @@ def send_request_email(rekwest):
teamname = rekwest.team.name teamname = rekwest.team.name
requestor = rekwest.user.first_name+' '+rekwest.user.last_name requestor = rekwest.user.first_name+' '+rekwest.user.last_name
if settings.DEBUG: res = myqueue(queuehigh,
res = handle_sendemail_request.delay(email,name,code,teamname, handle_sendemail_request,
requestor,id) email,name,code,teamname,requestor,id)
else:
res = queuehigh.enqueue(handle_sendemail_request,
email,name,code,teamname,requestor,id)
return (1,'Invitation email sent') return (1,'Invitation email sent')
+57
View File
@@ -0,0 +1,57 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}Rowsandall - Tasks {% endblock %}
{% block content %}
<h1>Your Tasks Status</h1>
<p>Manage the asynchronous tasks running for you</p>
<div class="grid_12 alpha">
<table width="100%" class="listtable shortpadded">
<thead>
<tr>
<th>ID</th>
<th style="width:180">Task</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for task in taskstatus %}
<tr>
<td>
{{ task|lookup:'id' }}
</td>
<td>
{{ task|lookup:'verbose' }}
</td>
<td>
{{ task|lookup:'status' }}
</td>
{% if task|lookup:'failed' %}
<td>
<a href="/rowers/job-kill/{{ task|lookup:'id' }}" class="button red small">Remove</a>
</td>
{% elif task|lookup:'finished' %}
<td>
<a href="/rowers/job-kill/{{ task|lookup:'id' }}" class="button green small">Remove</a>
</td>
{% else %}
<td>
&nbsp;
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
+3 -3
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
+3
View File
@@ -138,6 +138,9 @@ urlpatterns = [
url(r'^user-multiflex-select/user/(?P<userid>\d+)/$',views.user_multiflex_select), url(r'^user-multiflex-select/user/(?P<userid>\d+)/$',views.user_multiflex_select),
url(r'^user-multiflex-select/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.user_multiflex_select), url(r'^user-multiflex-select/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.user_multiflex_select),
url(r'^user-multiflex-select/$',views.user_multiflex_select), url(r'^user-multiflex-select/$',views.user_multiflex_select),
url(r'^list-jobs/$',views.session_jobs_view),
url(r'^jobs-status/$',views.session_jobs_status),
url(r'^job-kill/(?P<id>.*)$',views.kill_async_job),
url(r'^list-graphs/$',views.graphs_view), url(r'^list-graphs/$',views.graphs_view),
url(r'^(?P<theuser>\d+)/ote-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view), url(r'^(?P<theuser>\d+)/ote-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view),
url(r'^(?P<theuser>\d+)/ote-bests/(?P<deltadays>\d+)$',views.rankings_view), url(r'^(?P<theuser>\d+)/ote-bests/(?P<deltadays>\d+)$',views.rankings_view),
+13 -1
View File
@@ -2,6 +2,8 @@ import math
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import colorsys import colorsys
from django.conf import settings
lbstoN = 4.44822 lbstoN = 4.44822
@@ -100,7 +102,7 @@ def range_to_color_hex(groupcols,palette='monochrome_blue'):
try: try:
plt = palettes[palette] plt = palettes[palette]
except KeyErro: except KeyError:
plt = palettes['monochrome_blue'] plt = palettes['monochrome_blue']
rgb = [colorsys.hsv_to_rgb((plt[0]+plt[1]*x)/360., rgb = [colorsys.hsv_to_rgb((plt[0]+plt[1]*x)/360.,
@@ -214,3 +216,13 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
return res>1,btdf,res2>1 return res>1,btdf,res2>1
def myqueue(queue,function,*args,**kwargs):
if settings.DEBUG:
kwargs['debug'] = True
job = function.delay(*args,**kwargs)
else:
job = queue.enqueue(function,*args,**kwargs)
return job
+255 -152
View File
@@ -131,13 +131,16 @@ queue = django_rq.get_queue('default')
queuelow = django_rq.get_queue('low') queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('low') queuehigh = django_rq.get_queue('low')
from redis import StrictRedis from redis import StrictRedis,Redis
from rq.exceptions import NoSuchJobError from rq.exceptions import NoSuchJobError
from rq.registry import StartedJobRegistry from rq.registry import StartedJobRegistry
from rq import Queue from rq import Queue,cancel_job
queuefailed = Queue("failed",connection=Redis())
redis_connection = StrictRedis() redis_connection = StrictRedis()
rq_registry = StartedJobRegistry(queue.name,connection=redis_connection) rq_registry = StartedJobRegistry(queue.name,connection=redis_connection)
rq_registryhigh = StartedJobRegistry(queuehigh.name,connection=redis_connection)
rq_registrylow = StartedJobRegistry(queuelow.name,connection=redis_connection)
from rq.job import Job from rq.job import Job
@@ -170,8 +173,22 @@ from rowers.celery import result as celery_result
# Define the API documentation # Define the API documentation
schema_view = get_swagger_view(title='Rowsandall API') schema_view = get_swagger_view(title='Rowsandall API')
def remove_asynctask(request,id):
try:
oldtasks = request.session['async_tasks']
except KeyError:
oldtasks = []
newtasks = []
for task in oldtasks:
print task[0]
if id not in task[0]:
newtasks += [(task[0],task[1])]
request.session['async_tasks'] = newtasks
def get_job_result(jobid): def get_job_result(jobid):
if settings.DEBUG: if settings.EBUG:
result = celery_result.AsyncResult(jobid).result result = celery_result.AsyncResult(jobid).result
else: else:
running_job_ids = rq_registry.get_job_ids() running_job_ids = rq_registry.get_job_ids()
@@ -188,6 +205,132 @@ def get_job_result(jobid):
return result return result
verbose_job_status = {
'updatecp': 'Critical Power Calculation for Ergometer Workouts',
'updatecpwater': 'Critical Power Calculation for OTW Workouts',
'otwsetpower': 'Rowing Physics OTW Power Calculation',
'make_plot': 'Create static chart',
}
def get_job_status(jobid):
if settings.DEBUG:
job = celery_result.AsyncResult(jobid)
jobresult = job.result
if 'fail' in job.status.lower():
jobresult = '0'
summary = {
'status': job.status,
'result': jobresult,
}
else:
try:
job = Job.fetch(jobid,connection=redis_connection)
summary = {
'status':job.status,
'result':job.result
}
except NoSuchJobError:
summary = {}
if 'fail' in summary['status'].lower():
summary['failed'] = True
else:
summary['failed'] = False
if 'success' in summary['status'].lower():
summary['finished'] = True
elif 'finished' in summary['status'].lower():
summary['finished'] = True
else:
summary['finished'] = False
return summary
def kill_async_job(request,id='aap'):
if settings.DEBUG:
job = celery_result.AsyncResult(id)
job.revoke()
else:
try:
cancel_job(id,connect=redis_connection)
except NoSuchJobError:
pass
remove_asynctask(request,id)
url = reverse(session_jobs_status)
return HttpResponseRedirect(url)
def get_all_queued_jobs(userid=0):
r = StrictRedis()
jobs = []
celerykeys = r.keys('celery*')
for key in celerykeys:
id= key[17:]
job = celery_result.AsyncResult(id)
jobresult = job.result
if 'fail' in job.status.lower():
jobresult = '0'
jobs.append(
(id,{
'status':job.status,
'result':jobresult,
'function':'',
'meta':job.info,
}))
ids = [j.id for j in queue.jobs]
ids += [j.id for j in queuehigh.jobs]
ids += [j.id for j in queuelow.jobs]
ids += [j.id for j in queuefailed.jobs]
for id in ids:
job = Job.fetch(id,connection=redis_connection)
jobs.append(
(id,{
'status':job.get_status(),
'result':job.result,
'function':job.func_name,
'meta':job.meta,
}))
return jobs
def get_stored_tasks_status(request):
try:
taskids = request.session['async_tasks']
except KeyError:
taskids = []
taskstatus = [{
'id':id,
'status':get_job_status(id)['status'],
'failed':get_job_status(id)['failed'],
'finished':get_job_status(id)['finished'],
'func_name':func_name,
'verbose': verbose_job_status[func_name]
} for id,func_name in taskids]
return taskstatus
@login_required()
def session_jobs_view(request):
taskstatus = get_stored_tasks_status(request)
return HttpResponse(json.dumps(taskstatus))
@login_required()
def session_jobs_status(request):
taskstatus = get_stored_tasks_status(request)
return render(request,
'async_tasks.html',
{'taskstatus':taskstatus})
# Test if row data include candidates # Test if row data include candidates
def rowhascoordinates(row): def rowhascoordinates(row):
@@ -333,7 +476,7 @@ def splitstdata(lijst):
from utils import ( from utils import (
geo_distance,serialize_list,deserialize_list,uniqify, geo_distance,serialize_list,deserialize_list,uniqify,
str2bool,range_to_color_hex,absolute str2bool,range_to_color_hex,absolute,myqueue
) )
import datautils import datautils
@@ -1155,25 +1298,21 @@ def workout_tcxemail_view(request,id=0):
except Workout.DoesNotExist: except Workout.DoesNotExist:
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
if (checkworkoutuser(request.user,w)): if (checkworkoutuser(request.user,w)):
try: tcxfile,tcxmessg = stravastuff.createstravaworkoutdata(w,dozip=False)
tcxfile,tcxmessg = stravastuff.createstravaworkoutdata(w,dozip=False) if tcxfile == 0:
if tcxfile == 0: message = "Something went wrong (TCX export) "+tcxmessg
message = "Something went wrong (TCX export) "+tcxmessg messages.error(request,message)
messages.error(request,message) url = reverse(workout_export_view,
url = reverse(workout_export_view, kwargs = {
kwargs = { 'id':str(w.id),
'id':str(w.id), })
}) return HttpResponseRedirect(url)
return HttpResponseRedirect(url) if tcxfile:
if settings.DEBUG and tcxfile: res = myqueue(queuehigh,handle_sendemailtcx,
res = handle_sendemailtcx.delay(r.user.first_name, r.user.first_name,
r.user.last_name, r.user.last_name,
r.user.email,tcxfile) r.user.email,
tcxfile)
elif tcxfile:
res = queuehigh.enqueue(handle_sendemailtcx,r.user.first_name,
r.user.last_name,
r.user.email,tcxfile)
successmessage = "The TCX file was sent to you per email" successmessage = "The TCX file was sent to you per email"
messages.info(request,successmessage) messages.info(request,successmessage)
@@ -1181,19 +1320,6 @@ def workout_tcxemail_view(request,id=0):
kwargs = { kwargs = {
'id':str(w.id), 'id':str(w.id),
}) })
except:
successmessage = ""
message = "Something went wrong (TCX export) "+str(sys.exc_info()[0])
with open("media/c2errors.log","a") as errorlog:
errorstring = str(sys.exc_info()[0])
timestr = strftime("%Y%m%d-%H%M%S")
errorlog.write(timestr+errorstring+"\r\n")
messages.error(request,message)
url = reverse(workout_export_view,
kwargs = {
'id':str(w.id),
})
response = HttpResponseRedirect(url) response = HttpResponseRedirect(url)
@@ -1223,15 +1349,11 @@ def workout_gpxemail_view(request,id=0):
row = rdata(filename) row = rdata(filename)
gpxfilename = filename[:-4]+'.gpx' gpxfilename = filename[:-4]+'.gpx'
row.exporttogpx(gpxfilename) row.exporttogpx(gpxfilename)
if settings.DEBUG: res = myqueue(queuehigh,handle_sendemailtcx,
res = handle_sendemailtcx.delay(r.user.first_name, r.user.first_name,
r.user.last_name, r.user.last_name,
r.user.email,gpxfilename) r.user.email,gpxfilename)
else:
res = queuehigh.enqueue(handle_sendemailtcx,r.user.first_name,
r.user.last_name,
r.user.email,gpxfilename)
successmessage = "The GPX file was sent to you per email" successmessage = "The GPX file was sent to you per email"
messages.info(request,successmessage) messages.info(request,successmessage)
@@ -1264,15 +1386,9 @@ def workout_csvemail_view(request,id=0):
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
if (checkworkoutuser(request.user,w)): if (checkworkoutuser(request.user,w)):
csvfile = w.csvfilename csvfile = w.csvfilename
if settings.DEBUG: res = myqueue(queuehigh,handle_sendemailcsv,r.user.first_name,
res = handle_sendemailcsv.delay(r.user.first_name, r.user.last_name,
r.user.last_name, r.user.email,csvfile)
r.user.email,csvfile)
else:
res = queuehigh.enqueue(handle_sendemailcsv,r.user.first_name,
r.user.last_name,
r.user.email,csvfile)
successmessage = "The CSV file was sent to you per email" successmessage = "The CSV file was sent to you per email"
messages.info(request,successmessage) messages.info(request,successmessage)
@@ -1304,19 +1420,12 @@ def workout_csvtoadmin_view(request,id=0):
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
csvfile = w.csvfilename csvfile = w.csvfilename
if settings.DEBUG: res = myqueue(queuehigh,
res = handle_sendemailcsv.delay( handle_sendemailcsv,
'Sander', 'Sander',
'Roosendaal', 'Roosendaal',
'roosendaalsander@gmail.com',csvfile) 'roosendaalsander@gmail.com',
csvfile)
else:
res = queuehigh.enqueue(
handle_sendemailcsv,
'Sander',
'Roosendaal',
'roosendaalsander@gmail.com',
csvfile)
successmessage = "The CSV file was sent to the site admin per email" successmessage = "The CSV file was sent to the site admin per email"
messages.info(request,successmessage) messages.info(request,successmessage)
@@ -2436,11 +2545,7 @@ def workout_forcecurve_view(request,id=0,workstrokesonly=False):
@login_required() @login_required()
def workout_test_task_view(request,id=0): def workout_test_task_view(request,id=0):
row = Workout.objects.get(id=id) row = Workout.objects.get(id=id)
if settings.DEBUG: res = myqueue(queuehigh,addcomment2,request.user.id,row.id)
res = addcomment2.delay(request.user.id,row.id)
else:
#res = queuehigh.enqueue(addcomment2,request.user.id,row.id)
res = queuehigh.enqueue(addcomment2,request.user.id,row.id)
url = reverse(workout_edit_view, url = reverse(workout_edit_view,
@@ -3109,19 +3214,24 @@ def otwrankings_view(request,theuser=0,
runningjob = 0 runningjob = 0
try: taskstatus = get_stored_tasks_status(request)
jobid = request.session['job_id'] for task in taskstatus:
if jobid: if task['func_name'] == 'updatecpwater':
result = get_job_result(jobid) if 'success' in task['status'].lower() or 'finished' in task['status'].lower():
if result:
messages.info(request,'Your calculation is ready')
runningjob = 1 runningjob = 1
request.session['job_id'] = 0 messages.info(request,'CP chart data have been updated')
else: remove_asynctask(request,task['id'])
elif 'fail' in task['status'].lower():
runningjob = 0
remove_asynctask(request,task[id])
messages.error(request,'Oh, your task failed')
elif 'started' in task['status'].lower():
messages.info(request,'Busy updating CP chart data')
runningjob = 1 runningjob = 1
messages.info(request,'Your job is still running') elif 'queued' in task['status'].lower() or 'pending' in task['status'].lower():
except KeyError: messages.info(request,'Getting ready to update CP chart data')
pass runningjob = 1
if not runningjob: if not runningjob:
@@ -3131,6 +3241,10 @@ def otwrankings_view(request,theuser=0,
enddate=enddate enddate=enddate
) )
request.session['job_id'] = job.id request.session['job_id'] = job.id
try:
request.session['async_tasks'] += [(job.id,'updatecpwater')]
except KeyError:
request.session['async_tasks'] = [(job.id,'updatecpwater')]
messages.info(request,'New calculation queued. Refresh page or resubmit the date form to get the result') messages.info(request,'New calculation queued. Refresh page or resubmit the date form to get the result')
powerdf = pd.DataFrame({ powerdf = pd.DataFrame({
@@ -3358,19 +3472,23 @@ def oterankings_view(request,theuser=0,
runningjob = 0 runningjob = 0
try: taskstatus = get_stored_tasks_status(request)
jobid = request.session['job_id'] for task in taskstatus:
if jobid: if task['func_name'] == 'updatecp':
result = get_job_result(jobid) if 'success' in task['status'].lower() or 'finished' in task['status'].lower():
if result:
messages.info(request,'Your calculation is ready')
runningjob = 1 runningjob = 1
request.session['job_id'] = 0 messages.info(request,'CP chart data have been updated')
else: remove_asynctask(request,task['id'])
elif 'fail' in task['status'].lower():
runningjob = 0
remove_asynctask(request,task[id])
messages.error(request,'Oh, your task failed')
elif 'started' in task['status'].lower():
messages.info(request,'Busy updating CP chart data')
runningjob = 1
elif 'queued' in task['status'].lower():
messages.info(request,'Getting ready to update CP chart data')
runningjob = 1 runningjob = 1
messages.info(request,'Your job is still running')
except KeyError:
pass
if not runningjob: if not runningjob:
@@ -3380,7 +3498,11 @@ def oterankings_view(request,theuser=0,
enddate=enddate enddate=enddate
) )
request.session['job_id'] = job.id request.session['job_id'] = job.id
messages.info(request,'New calculation queued. Refresh page or resubmit the date form to get the result') try:
request.session['async_tasks'] += [(job.id,'updatecp')]
except KeyError:
request.session['async_tasks'] = [(job.id,'updatecp')]
messages.info(request,'New calculation queued.')
powerdf = pd.DataFrame({ powerdf = pd.DataFrame({
'Delta':delta, 'Delta':delta,
@@ -5503,21 +5625,19 @@ def workout_otwsetpower_view(request,id=0,message="",successmessage=""):
last_name = u.last_name last_name = u.last_name
emailaddress = u.email emailaddress = u.email
if settings.DEBUG: job = myqueue(queuelow,
res = handle_otwsetpower.delay(f1,boattype,weightvalue, handle_otwsetpower,f1,boattype,
first_name,last_name, weightvalue,
emailaddress,id,debug=True, first_name,last_name,emailaddress,id,
ps=[r.p0,r.p1,r.p2,r.p3], ps=[r.p0,r.p1,r.p2,r.p3],
ratio=r.cpratio) ratio=r.cpratio)
else:
res = queuelow.enqueue(handle_otwsetpower,f1,boattype,
weightvalue,
first_name,last_name,emailaddress,id,
ps=[r.p0,r.p1,r.p2,r.p3],
ratio=r.cpratio)
try:
request.session['async_tasks'] += [(job.id,'otwsetpower')]
except KeyError:
request.session['async_tasks'] = [(job.id,'otwsetpower')]
successmessage = "Your calculations have been submitted. You will receive an email when they are done." successmessage = 'Your calculations have been submitted. You will receive an email when they are done. You can check the status of your calculations <a href="/rowers/jobs-status/">here</a>'
messages.info(request,successmessage) messages.info(request,successmessage)
kwargs = { kwargs = {
'id':int(id)} 'id':int(id)}
@@ -6800,48 +6920,29 @@ def workout_comment_view(request,id=0):
if request.user != r.user: if request.user != r.user:
a_messages.info(r.user,message) a_messages.info(r.user,message)
if settings.DEBUG and request.user != r.user: res = myqueue(queuehigh,
res = handle_sendemailnewcomment.delay(r.user.first_name, handle_sendemailnewcomment,r.user.first_name,
r.user.last_name, r.user.last_name,
r.user.email, r.user.email,
request.user.first_name, request.user.first_name,
request.user.last_name, request.user.last_name,
comment,w.name, comment,w.name,w.id)
w.id)
elif request.user != r.user:
res = queuehigh.enqueue(handle_sendemailnewcomment,r.user.first_name,
r.user.last_name,
r.user.email,
request.user.first_name,
request.user.last_name,
comment,w.name,w.id)
commenters = {oc.user for oc in comments if oc.notification} commenters = {oc.user for oc in comments if oc.notification}
for u in commenters: for u in commenters:
a_messages.info(u,message) a_messages.info(u,message)
if settings.DEBUG and u != request.user and u != r.user: if u != request.user and u != r.user:
res = handle_sendemailnewresponse.delay(u.first_name, res = myqueue(queuelow,
u.last_name, handle_sendemailnewresponse,
u.email, u.first_name,
request.user.first_name, u.last_name,
request.user.last_name, u.email,
comment, request.user.first_name,
w.name, request.user.last_name,
w.id, comment,
c.id) w.name,
elif u != request.user and u != r.user: w.id,
res = queuelow.enqueue(handle_sendemailnewresponse, c.id)
u.first_name,
u.last_name,
u.email,
request.user.first_name,
request.user.last_name,
comment,
w.name,
w.id,
c.id)
url = reverse(workout_comment_view,kwargs = { url = reverse(workout_comment_view,kwargs = {
'id':id}) 'id':id})
@@ -7305,9 +7406,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']
@@ -9485,10 +9591,7 @@ def rower_calcdps_view(request):
r = getrower(request.user) r = getrower(request.user)
ws = [(w.id,w.csvfilename) for w in Workout.objects.filter(user=r)] ws = [(w.id,w.csvfilename) for w in Workout.objects.filter(user=r)]
if settings.DEBUG: res = myqueue(queue,handle_updatedps,r.user.email,ws,debug=False)
res = handle_updatedps.delay(r.user.email,ws,debug=True)
else:
queue.enqueue(handle_updatedps,r.user.email,ws,debug=False)
messages.info(request,"Your workouts are being updated in the background. You will receive email when this is done.") messages.info(request,"Your workouts are being updated in the background. You will receive email when this is done.")
+27
View File
@@ -9,6 +9,33 @@
<!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 type='text/javascript'
src='http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
</script>
<script type="text/javascript">
window.jQuery || document.write('<script src="/static/js/jquery-3.1.0.js"><' + '/script>');
</script>
<script>
var previous = null;
var current = null;
(function checkJobs() {
console.log('polling');
$.getJSON(window.location.protocol + '//'+window.location.host + '/rowers/list-jobs/', function(json) {
current = JSON.stringify(json);
if (previous && current && previous !== current) {
console.log('refresh');
location.reload();
};
previous = current;
});
setTimeout(checkJobs, 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 %}